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=0reproduces 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; seeResolvedPowerPriceResponse.- 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 to0.0. Keys are matched to labels by their string form, as the fittedcost_per_unittable’s columns are, so{1: 0.3}and{"1": 0.3}both name channel1. ADataArrayover a subset of the budget dims is aligned to the model’s coordinates. It may not carry the date dim: a date-varyingcost_per_unitalready 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 ofresult.budgetsandtotal_budget, carrying every budget dim. DefaultNonederives it from the fitted model as the mean ofconstant_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 historicalcost_per_unittable prices get a derived value: an unpriced channel’schannel_spendis its units, not money. As \(p_0\) applies here, anchor it at the spend the windowcost_per_unitwas 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 ornan) keep the derived one, and the cells it gives are checked against it where it exists (seereference_spend_tolerance). It must cover every curved cell with no derived value: every cell of a spend variable or of a customchannel_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)\). Default100. 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 atelasticity=0or drop it frombudgets_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_budgetwarns whenbudget_boundsdoes this.reference_spend_tolerance (
float) – Largest factor by which a suppliedreference_spendmay differ from the derived default on any curved cell before it is rejected. Default10. The unit error this catches is a window total handed over as a per-period rate: off bynum_periods, shifting every price bynum_periods ** elasticity. When the supplied value isnum_periodstimes 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 ofnum_periods <= reference_spend_toleranceperiods 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 atelasticity=0needs no attestation, since its money passes through unbent. DefaultFalse: 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 (seePriceResponse.adds_curvature). The fitted model cannot establish its own units: its historicalcost_per_unittable is a declaration, written the same way byMMM(cost_per_unit=...)and byset_cost_per_unit()after the fit, so it does not stand in for this flag. It anchorsreference_spendinstead, 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=Trueon every channel the response bends; channels left atelasticity=0need no attestation. The historicalcost_per_unittable on the fitted model (written byset_cost_per_unit()orMMM(cost_per_unit=...)) anchorsreference_spendon the channels it prices; it describes thechannel_datanode ofMMMonly, so a customchannel_data_var, a spend variable and any channel the table does not price need areference_spend. Thecost_per_unitpassed 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_spendwhere you plan to buy (raisingreference_spend_toleranceif that is far from the fitted spend) and readimplied_priceon 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_periodhas redistributed the total.total_budget,result.budgetsandreference_spendare all per-period quantities; the window total isbudgets * num_periods. Without a windowcost_per_unitthe 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_periodtherefore buys less delivery than a uniform one at equal total spend. With a date-varyingcost_per_unitthis 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 atelasticity=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.0beside 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_deliveryis per-period delivery beforechannel_scales. Score a plan withevaluate_response_distribution(), which runs the same graph the solver used, price map included. The deprecatedsample_response_distributionrepeats one date-less allocation over the window, soimplied_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’sbudget_distribution_over_periodis uniform andcost_per_unitdoes 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 floorimplied_marginal_price / implied_price == 1 / (1 - elasticity).The price report is sparse. Both price arrays are
nanwherever no money was spent, including periods abudget_distribution_over_periodzeroes out: nothing was bought, so nothing was paid per unit.implied_deliveryis0.0there, 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
nanand 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.json(*[, include, ...])Compute the class name for parametrizations of generic classes.
PowerPriceResponse.parse_file(path, *[, ...])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
The power law bends money wherever its elasticity is not zero.
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].A relative price needs a level; without a supplied one it has to come from the fitted model.