create_hsgp_from_config#

pymc_marketing.mmm.tvp.create_hsgp_from_config(X, dims, config, X_mid=None)[source]#

Create a SoftPlusHSGP instance from either HSGPKwargs or dict config.

This function provides a unified interface for creating SoftPlusHSGP instances, supporting both the legacy HSGPKwargs format and the newer parameterize_from_data format.

Parameters:
Xpt.TensorVariable | npt.NDArray[np.floating[Any]]

Time index or input data for the HSGP.

dimsDims

Dimensions for the HSGP variable (e.g., ("date",) or ("date", "channel")).

configHSGPKwargs | dict[str, Any]

Configuration for the HSGP. Can be:

  • An HSGPKwargs instance

  • A dict with HSGPKwargs keys (m, L, eta_lam, ls_mu, ls_sigma, cov_func)

  • A dict with parameterize_from_data keys (ls_lower, ls_upper, etc.)

X_midint | float | None, optional

Midpoint of the time index. If None, computed from X.

Returns:
SoftPlusHSGP

Configured SoftPlusHSGP instance ready for use.

Raises:
TypeError

If config is neither HSGPKwargs, dict, nor a valid format.

See also

pymc_marketing.hsgp_kwargs.HSGPKwargs

Legacy configuration format.

pymc_marketing.mmm.hsgp.SoftPlusHSGP.parameterize_from_data

New configuration format.

Examples

Using HSGPKwargs instance:

>>> from pymc_marketing.hsgp_kwargs import HSGPKwargs
>>> config = HSGPKwargs(m=200, eta_lam=1.0, ls_mu=5.0, ls_sigma=10.0)
>>> hsgp = create_hsgp_from_config(X=np.arange(52), dims="date", config=config)

Using parameterize_from_data format dict:

>>> config = {"ls_lower": 0.3, "ls_upper": 2.0}
>>> hsgp = create_hsgp_from_config(X=np.arange(52), dims="date", config=config)