HSGPTerm#
- class pymc_marketing.terms_gp.HSGPTerm(*, var_name='date', name='hsgp', X_mid=None, dims=None, demeaned_basis=False, time_resolution=None, eta=None, ls=None, m=None, L=None, centered=False, drop_first=True, eta_mass=0.05, eta_upper=1.0, ls_lower=1.0, ls_upper=None, ls_mass=0.9, cov_func=CovFunc.ExpQuad)[source]#
Hilbert Space Gaussian Process term.
A one-dimensional GP over the time reference
var_namewith optional higher-dimensional coefficients viadims. Composes with the other terms via+/*/-.All of
m,L,X_mid,eta, andlsare deferred: whenNone, they are resolved from the dataset inside the model context with the same heuristics and prior recommendations aspymc_marketing.mmm.hsgp.HSGP.parameterize_from_data(), then cached on the instance. Explicit values always win.- Parameters:
var_name (
str) – Name of the time reference in the dataset, read withds[var_name](works for both coordinates and data variables). Datetimes are converted to days since the first date, divided bytime_resolution, and registered aspmd.Dataunder{name}_index. Defaults to"date".name (
str) – Prefix for the variables and the output deterministic. Defaults to"hsgp".eta (
VariableFactory|float|None) – Prior for the GP variance. Defaults to the Exponential prior frompymc_marketing.mmm.hsgp.create_eta_prior().ls (
VariableFactory|float|None) – Prior for the lengthscale. Defaults to the complexity-penalizing Weibull prior, or a constrained InverseGamma whenls_upperis set.m (
int|None) – Number of basis functions. Defaults to the Ruitort-Mayol et al. recommendation from the data.L (
float|None) – Extent of the basis functions. Defaults to the recommendation from the data.dims (
str|tuple[str,...] |None) – Extra dims for the coefficients beyond the time dim, e.g."channel"for one GP curve per channel. Coordinates are collected from the dataset. The coordinates of these dims are recorded on the first registration, andset_data()refuses a window whose coordinates differ (reordered, dropped, or added), since each curve is fit per coordinate in order and a mismatch would report it under the wrong label.time_resolution (
int|None) – Number of days per observation period, dividing the day offsets of a datetime time reference. DefaultNone, which infers it from the observed date spacing so the numeric index counts periods (the same convention aspymc_marketing.mmm.MMM). Pass an explicit value only to override the inferred unit.centered (
bool) – Whether the coefficient prior is centered. DefaultFalse.drop_first (
bool) – Whether to drop the first (constant) basis function. DefaultTrue.demeaned_basis (
bool) – Whether each basis has its mean subtracted. DefaultFalse.eta_mass (
float) – Knobs for the deferred prior resolution. Defaults mirrorHSGP.parameterize_from_data(0.05,1.0,1.0,None,0.9).eta_upper (
float) – Knobs for the deferred prior resolution. Defaults mirrorHSGP.parameterize_from_data(0.05,1.0,1.0,None,0.9).ls_lower (
float) – Knobs for the deferred prior resolution. Defaults mirrorHSGP.parameterize_from_data(0.05,1.0,1.0,None,0.9).ls_upper (
float|None) – Knobs for the deferred prior resolution. Defaults mirrorHSGP.parameterize_from_data(0.05,1.0,1.0,None,0.9).ls_mass (
float) – Knobs for the deferred prior resolution. Defaults mirrorHSGP.parameterize_from_data(0.05,1.0,1.0,None,0.9).cov_func (
CovFunc) – Covariance function. DefaultCovFunc.ExpQuad.
Examples
Deferred defaults composed into an outcome equation:
from pymc_extras.prior import Prior from pymc_marketing.terms import ( Intercept, Dot, collect_coords, register_data, build_param, ) from pymc_marketing.terms_gp import HSGPTerm trend = HSGPTerm(var_name="time", name="trend") mu = ( Intercept("intercept") + trend + Dot(var_name="x", prior=Prior("Normal", dims="feature")) ) coords = collect_coords(mu, ds=ds) with pm.Model(coords=coords) as model: register_data(mu, ds=ds) mu_value = build_param(mu)
Explicit configuration:
from pymc_extras.prior import Prior from pymc_marketing.terms_gp import HSGPTerm trend = HSGPTerm( var_name="time", name="trend", eta=Prior("Exponential", lam=1), ls=Prior("InverseGamma", alpha=2, beta=1), m=20, L=150, )
Methods
HSGPTerm.__init__(*[, var_name, name, ...])Resolve deferred values.
Build the GP curve through the wrapped HSGP class.
HSGPTerm.from_dict(data)Reconstruct a term from its serialized form.
Collect coordinates from the time reference and extra dims.
HSGPTerm.named(name[, dims])Record this expression as a named deterministic model variable.
Register the numeric time index as
pmd.Dataand freezeX_mid.HSGPTerm.set_data(ds[, model])Update the shared time index for out-of-sample prediction.
HSGPTerm.sum(dim)Sum this expression over one named dimension.
HSGPTerm.to_dict([_orig])Attributes
Dataset variables this term reads as shared data.
Dims beyond the time dimension.
Deterministics this term freezes for out-of-sample evaluation.
Name of this term's registered numeric index data variable.