parse_model_config#

pymc_marketing.model_config.parse_model_config(model_config, hsgp_kwargs_fields=None, non_distributions=None)[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.

non_distributionslist[str], optional

A list of keys to ignore when parsing the model configuration dictionary due to them not being distributions.

Returns:
dict

The parsed model configuration dictionary.

Examples

Parse all keys in model configuration but ignore the key “tvp_intercept”.

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

model_config = {
    "alpha": {
        "dist": "Normal",
        "kwargs": {
            "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"],
    non_distributions=["other_intercept"],
)
# {'alpha': Prior("Normal", mu=0, sigma=1),
#  'beta': Prior("HalfNormal"),
#  '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'}}

Parsing with an error:

from pymc_marketing.model_config import (
    parse_model_config,
    ModelConfigError,
)

model_config = {
    "alpha": {"key": "Non distribution"},
    "beta": {"dist": "UnknownDistribution"},
    "gamma": "Completely wrong",
}

try:
    parse_model_config(model_config)
except ModelConfigError as e:
    print(e)