Constrained Models
AnoFox provides 2 constrained regression methods: BLS (Bounded Least Squares) with user-defined upper and lower coefficient bounds, and NNLS (Non-Negative Least Squares) that enforces all coefficients to be zero or positive. BLS is essential for economic models where domain knowledge dictates constraints -- for example, price elasticity must be negative (law of demand). NNLS is the standard approach for marketing mix modeling, spectral decomposition, and portfolio allocation where negative contributions are physically impossible.
Constrained regression refers to least squares estimation where the coefficients are restricted to lie within specified bounds or satisfy certain constraints, such as non-negativity. These constraints encode domain knowledge that standard unconstrained regression ignores.
BLS - Bounded Least Squares
Bounded Least Squares is a constrained regression method that restricts each coefficient to lie within user-specified lower and upper bounds. This allows you to enforce domain knowledge -- for example, that price elasticity must be negative or that marketing effects cannot exceed a physical maximum.
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
Non-Negative Least Squares (NNLS) is a special case of constrained regression where all coefficients are restricted to be zero or positive. This constraint is appropriate when negative coefficients are physically meaningless -- for example, marketing channel contributions to sales cannot be negative, and spectral components cannot have negative weights.
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)