Constrained Models
Regression with coefficient constraints: bounded and non-negative solutions.
BLS - Bounded Least Squares
Constrained regression with coefficient bounds.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
y | DOUBLE | Yes | - | Target values |
x | LIST(DOUBLE) | Yes | - | Predictors |
options | MAP | Yes | - | lower_bounds, upper_bounds, fit_intercept |
Example
-- Elasticity must be negative (law of demand)
SELECT anofox_stats_bls_fit_agg(
log(quantity),
[log(price), log(income)],
MAP {
'lower_bounds': '[-5.0, 0.0]',
'upper_bounds': '[0.0, 3.0]'
}
) as model
FROM demand_data;
When to use BLS:
- Economic constraints (negative elasticities)
- Physical constraints (positive effects)
- Domain knowledge requiring bounded coefficients
NNLS - Non-Negative Least Squares
Regression with non-negativity constraints on all coefficients.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
y | DOUBLE | Yes | - | Target values |
x | LIST(DOUBLE) | Yes | - | Predictors |
options | MAP | No | - | fit_intercept (default: false), max_iterations, tolerance |
Example
-- Channel contributions must be non-negative
SELECT
(model).coefficients[1] as search_contribution,
(model).coefficients[2] as social_contribution,
(model).coefficients[3] as email_contribution
FROM (
SELECT anofox_stats_nnls_fit_agg(
conversions,
[search_spend, social_spend, email_spend]
) as model
FROM marketing_data
);
When to use NNLS:
- Marketing mix modeling (positive contributions only)
- Spectral decomposition
- Portfolio weights (no short selling)