parse_model_config#

pymc_marketing.model_config.parse_model_config(model_config, hsgp_kwargs_fields=None, **kwargs)[source]#

Parse the model config dictionary.

Parameters:
model_configdict

The model configuration dictionary.

hsgp_kwargs_fieldslist[str], optional

A list of keys to parse as HSGP kwargs.

**kwargs

Not accepted. Present only so that parameters removed in v1.0.0 (non_distributions) fail with a migration hint rather than a bare TypeError.

Returns:
dict

The parsed model configuration dictionary.

Raises:
ModelConfigError

If an entry looks like a legacy dict-format prior spec, if an hsgp_kwargs_fields entry fails HSGPKwargs validation, or if a parameter removed in v1.0.0 is passed.

Examples

Parse the HSGP kwargs field in a model configuration.

from pymc_marketing.hsgp_kwargs import HSGPKwargs
from pymc_marketing.model_config import parse_model_config
from pymc_extras.prior import Prior

model_config = {
    "alpha": Prior("Normal", mu=0, sigma=1),
    "beta": Prior("HalfNormal"),
    "intercept_tvp_config": {
        "m": 200,
        "L": 119.17,
        "eta_lam": 1.0,
        "ls_mu": 5.0,
        "ls_sigma": 10.0,
        "cov_func": None,
    },
    "other_intercept": {
        "key": "Some other non-distribution configuration",
    },
}

parsed_model_config = parse_model_config(
    model_config,
    hsgp_kwargs_fields=["intercept_tvp_config"],
)
# {'alpha': Prior("Normal", mu=0, sigma=1),  # unchanged
#  'beta': Prior("HalfNormal"),  # unchanged
#  'intercept_tvp_config': HSGPKwargs(m=200, L=119.17, eta_lam=1.0, ls_mu=5.0, ls_sigma=10.0, cov_func=None),
#  'other_intercept': {'key': 'Some other non-distribution configuration'}}