PowerPriceResponse#

class pymc_marketing.mmm.price_response.PowerPriceResponse(*, elasticity=0.0, reference_spend=None, max_slope_ratio=100.0, reference_spend_tolerance=10.0, assume_delivery_units=False)[source]#

Iso-elastic price: the unit price rises as a power of the money spent in the period.

\[p_t(s) = p_{0,t}\left(\frac{s}{s^{\text{ref}}}\right)^{\gamma}, \qquad u_t(s) = \frac{s}{p_t(s)} = \frac{s^{1-\gamma}\,(s^{\text{ref}})^{\gamma}}{p_{0,t}}, \qquad 0 \le \gamma < 1\]

\(p_0\) is the optimizer’s cost_per_unit (1 when none is given) and applies at the reference spend; \(\gamma\) is the price elasticity of the buy. elasticity=0 reproduces the constant-price optimizer exactly. Below a small floor the map is a quadratic pinned at \(u(0) = 0\), so a channel at zero spend delivers nothing and has a finite marginal return; see ResolvedPowerPriceResponse.

Parameters:
  • elasticity (Union[float, dict[str, float], DataArray]) – \(\gamma\) per cell in [0, 1). A float applies everywhere. A dict maps coordinate labels of exactly one budget dim (usually channels) to values; labels not named default to 0.0. Keys are matched to labels by their string form, as the fitted cost_per_unit table’s columns are, so {1: 0.3} and {"1": 0.3} both name channel 1. A DataArray over a subset of the budget dims is aligned to the model’s coordinates. It may not carry the date dim: a date-varying cost_per_unit already covers seasonal price level, and seasonal price sensitivity is not supported.

  • reference_spend (Optional[DataArray]) – Where \(p_0\) applies: per-period money per cell, in the units of result.budgets and total_budget, carrying every budget dim. Default None derives it from the fitted model as the mean of constant_data["channel_spend"] over the periods each cell was on air (spend > 0), so a flighted channel is anchored at the level it actually bought at. Only channels the historical cost_per_unit table prices get a derived value: an unpriced channel’s channel_spend is its units, not money. As \(p_0\) applies here, anchor it at the spend the window cost_per_unit was quoted at: for a channel whose spend trended over the fit, the whole-fit mean lags today’s level, and the on-air mean of a trailing window anchors at recent buying (see Examples). A supplied value overrides the default cell by cell: its labels may be partial, cells it leaves out (absent labels or nan) keep the derived one, and the cells it gives are checked against it where it exists (see reference_spend_tolerance). It must cover every curved cell with no derived value: every cell of a spend variable or of a custom channel_data_var, and the channels the historical table does not price.

  • max_slope_ratio (float) – Cap on \(u'(0) / u'(s^{\text{ref}})\), the spread of marginal returns the solver can meet on one cell. Sets the floor \(s_f / s^{\text{ref}} = \max\big((M (1-\gamma)/(1+\gamma))^{-1/\gamma},\; 10^{-12}\big)\); must exceed \((1+\gamma)/(1-\gamma)\). Default 100. The second term wins below \(\gamma \approx 0.16\) at the default: there the spread is \((1+\gamma)/(1-\gamma)\, 10^{12 \gamma}\), already under the cap, so this setting has no effect on those cells. Warns when the floor exceeds 1% of the reference, which happens at high elasticity. Leave a channel whose bounds pin it to zero at elasticity=0 or drop it from budgets_to_optimize: the map is steepest at zero, so pricing an immovable channel hands the solver its largest gradient on a variable that cannot move, which SLSQP tolerates on some platforms and not on others. allocate_budget warns when budget_bounds does this.

  • reference_spend_tolerance (float) – Largest factor by which a supplied reference_spend may differ from the derived default on any curved cell before it is rejected. Default 10. The unit error this catches is a window total handed over as a per-period rate: off by num_periods, shifting every price by num_periods ** elasticity. When the supplied value is num_periods times the derived one on every cell it can be checked on (within 5%), a warning names that hypothesis instead of refusing. A window total for a window of num_periods <= reference_spend_tolerance periods is therefore accepted with only the warning; lower the tolerance for short windows if that is a risk.

  • assume_delivery_units (bool) – Attest that the node’s data are in delivery units (or in spend deflated to constant prices). Required wherever the response bends money, on every node; a cell left at elasticity=0 needs no attestation, since its money passes through unbent. Default False: the optimizer then refuses, because a saturation curve fitted on nominal spend has already absorbed part of the price curvature and a concave price map on top would bend it twice (see PriceResponse.adds_curvature). The fitted model cannot establish its own units: its historical cost_per_unit table is a declaration, written the same way by MMM(cost_per_unit=...) and by set_cost_per_unit() after the fit, so it does not stand in for this flag. It anchors reference_spend instead, on the channels it prices.

Notes

Precondition. Only sound when the model was fitted on delivery units or constant-price spend. The optimizer cannot check this and requires assume_delivery_units=True on every channel the response bends; channels left at elasticity=0 need no attestation. The historical cost_per_unit table on the fitted model (written by set_cost_per_unit() or MMM(cost_per_unit=...)) anchors reference_spend on the channels it prices; it describes the channel_data node of MMM only, so a custom channel_data_var, a spend variable and any channel the table does not price need a reference_spend. The cost_per_unit passed to the optimizer is independent of that table and proves nothing about the fit. A merged model (merge_inference_data()) carries no root attrs and so no derived reference.

Below the reference. The power law is as confident below the reference as above it, so a priced channel bought far below its reference looks cheap and can attract budget: anchor reference_spend where you plan to buy (raising reference_spend_tolerance if that is far from the fitted spend) and read implied_price on every channel before trusting the allocation. A variant flat below the reference is #3089.

Not a rate schedule. One smooth curve cannot hold a committed tranche at a contracted rate while the increment clears at another: calibrated to that case, its marginal price keeps climbing where the true rate is flat. Bracket rates are #3067.

Units. The map acts on per-period money at the model’s date granularity, after budget_distribution_over_period has redistributed the total. total_budget, result.budgets and reference_spend are all per-period quantities; the window total is budgets * num_periods. Without a window cost_per_unit the base price is 1 and money reaches the model as units, which the optimizer warns about.

Behavior change with \(\gamma > 0\). Above the floor each period’s price rises with that period’s money alone, \(p_t / p_{0,t} = (s_t / s^{\text{ref}})^{\gamma}\), so concentrated buying clears higher relative to the base price. At a base price that is the same in every period, a non-uniform budget_distribution_over_period therefore buys less delivery than a uniform one at equal total spend. With a date-varying cost_per_unit this need not hold: moving money into the cheaper periods can buy more and clear lower on average. Across windows, a given per-period plan pays the same price relative to the base price whatever the window length. Holding the window total fixed, a shorter window spends more per period and pays more relative to its base price.

Volume discounts are out of scope. \(\gamma\) models bid-up on the incremental money of this plan. A negotiated or contract discount belongs in the base price, cost_per_unit. A price that falls with volume (\(\gamma < 0\)) makes delivery convex and the allocation non-convex for SLSQP, so it is refused; leave such a channel at elasticity=0.

The elasticity is an input. The model never observes price, so \(\gamma\) comes from buying data with its own endogeneity. Treat it as a sensitivity sweep, running elasticity=0.0 beside the values you believe.

Why not fixed-point iteration. Re-solving at repriced constant prices misses the \((1 - \gamma_i)\) factor of the first-order condition, so it over-allocates to the high-elasticity channels whenever elasticities differ.

Reading the result. result.implied_delivery is per-period delivery before channel_scales. Score a plan with evaluate_response_distribution(), which runs the same graph the solver used, price map included. The deprecated sample_response_distribution repeats one date-less allocation over the window, so implied_delivery.mean(date_dim) passed on its own matches the delivery the solver used only when that delivery is constant over the window: the optimizer’s budget_distribution_over_period is uniform and cost_per_unit does not vary by date. Uniform spend alone is not enough, because a date-varying base price buys different units on different dates, and averaging them before adstock and saturation changes the response. By default that method also adds input noise and starts from a cold adstock, so it approximates the solver’s response rather than reproducing it. Above the floor implied_marginal_price / implied_price == 1 / (1 - elasticity).

The price report is sparse. Both price arrays are nan wherever no money was spent, including periods a budget_distribution_over_period zeroes out: nothing was bought, so nothing was paid per unit. implied_delivery is 0.0 there, and the money identity holds on the spent cells. Reduce with .mean(skipna=True), or weight by delivery: budgets * num_periods / implied_delivery.sum(date_dim).

Examples

from pymc_marketing.mmm import PowerPriceResponse

mmm.set_cost_per_unit(
    historical_cpu_df
)  # anchors reference_spend on tv and display
optimizer = mmm.budget_optimizer(
    start_date,
    end_date,
    cost_per_unit=window_cpu,  # xarray.DataArray over (date, *budget_dims); see BudgetOptimizer
    price_response=PowerPriceResponse(
        elasticity={"tv": 0.25, "display": 0.10},
        assume_delivery_units=True,  # the fit is in impressions, not spend
    ),
)
result = optimizer.allocate_budget(total_budget=weekly_budget)
result.budgets, result.implied_price, result.implied_marginal_price

Anchor the base price at recent buying instead of the whole fit, here the last 13 weekly periods (a quarter), on the priced channels the response bends. A cell off air in that window is nan and keeps the derived default:

spend = mmm.idata.constant_data["channel_spend"].isel(date=slice(-13, None))
recent = spend.where(spend > 0).mean("date").sel(channel=["tv", "display"])
price_response = PowerPriceResponse(
    elasticity={"tv": 0.25, "display": 0.10},
    reference_spend=recent,
    assume_delivery_units=True,
)

Methods

PowerPriceResponse.__init__(**data)

Create a new model by parsing and validating input data from keyword arguments.

PowerPriceResponse.construct([_fields_set])

PowerPriceResponse.copy(*[, include, ...])

Returns a copy of the model.

PowerPriceResponse.curved_cells(*, dims, ...)

Optimized cells with a non-zero elasticity; see PriceResponse.curved_cells().

PowerPriceResponse.dict(*[, include, ...])

PowerPriceResponse.from_orm(obj)

PowerPriceResponse.json(*[, include, ...])

PowerPriceResponse.model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

PowerPriceResponse.parse_file(path, *[, ...])

PowerPriceResponse.parse_obj(obj)

PowerPriceResponse.parse_raw(b, *[, ...])

PowerPriceResponse.resolve(*, dims, coords, ...)

Bind to one variable's layout; see PriceResponse.resolve().

PowerPriceResponse.schema([by_alias, ...])

PowerPriceResponse.schema_json(*[, ...])

PowerPriceResponse.update_forward_refs(**localns)

PowerPriceResponse.validate(value)

Attributes

PowerPriceResponse.adds_curvature

The power law bends money wherever its elasticity is not zero.

PowerPriceResponse.attests_delivery_units

See assume_delivery_units.

PowerPriceResponse.model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

PowerPriceResponse.needs_derived_reference

A relative price needs a level; without a supplied one it has to come from the fitted model.

PowerPriceResponse.elasticity

PowerPriceResponse.reference_spend

PowerPriceResponse.max_slope_ratio

PowerPriceResponse.reference_spend_tolerance

PowerPriceResponse.assume_delivery_units