Tensor ofalphaparameters taking values in[0, 1]with
dimensions[..., n_media_channels]. Batch dimensions(...)are
optional. Note thatalpha = 0is allowed, so it is possible to put a
point mass prior at zero (effectively no Adstock).
max_lag
Integer indicating the maximum number of lag periods (≥0) to
include in the Adstock calculation.
n_times_output
Integer indicating the number of time periods to include
in the output tensor. Cannot exceed the number of time periods of the
media argument, for example,media.shape[-2]. The output time periods
correspond to the most recent time periods of the media argument. For
example,media[..., -n_times_output:, :]represents the media
execution of the output weeks.
decay_functions
String or list of strings indicating the decay
function(s) to use for the Adstock calculation for each channel.
Default is geometric decay for all channels.
Computes the Adstock transformation of a givenmediatensor.
For geog, time periodt, and media channelm, Adstock is calculated
asadstock_{g,t,m} = sum_{i=0}^max_lag media_{g,t-i,m} alpha^i.
Args
media
Tensor of media values with dimensions[..., n_geos,
n_media_times, n_media_channels]. Batch dimensions(...)are
optional, but if batch dimensions are included, they must match the
batch dimensions ofalpha. Media is not required to have batch
dimensions even ifalphacontains batch dimensions.
Returns
Tensor with dimensions[..., n_geos, n_times_output, n_media_channels]representing Adstock transformed media.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[[["\u003cp\u003eThis code implements an Adstock transformation for media data, which calculates the cumulative effect of media exposure over time, considering a decay factor.\u003c/p\u003e\n"],["\u003cp\u003eThe transformation uses an \u003ccode\u003ealpha\u003c/code\u003e parameter (decay rate) for each media channel, which can be set between 0 and 1, allowing flexibility in modeling the decay of media effectiveness, and a \u003ccode\u003emax_lag\u003c/code\u003e parameter that dictates how many previous periods contribute to the current adstock value.\u003c/p\u003e\n"],["\u003cp\u003eThe method takes a \u003ccode\u003emedia\u003c/code\u003e tensor as input, which can optionally include batch dimensions and must specify the number of geos, media time periods, and media channels, and outputs an Adstock-transformed tensor.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003en_times_output\u003c/code\u003e argument controls how many recent time periods are included in the output tensor, always drawing from the end of the media tensor's time periods.\u003c/p\u003e\n"],["\u003cp\u003eThe Adstock calculation, for each geo, time period, and channel, sums the contribution of media impressions from the current and previous time periods up to the max_lag, with each previous period having less weight based on the alpha parameter.\u003c/p\u003e\n"]]],["The `AdstockTransformer` computes the Adstock transformation of media data. It takes `alpha` (decay rate), `max_lag` (lag periods), and `n_times_output` (output time periods) as input. The `forward` method calculates Adstock for each geo, time period, and media channel using the formula `sum_{i=0}^max_lag media_{g,t-i,m} alpha^i`. Input `media` is a tensor of media values. The output is a tensor representing Adstock-transformed media with specified dimensions.\n"],null,["\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/meridian/blob/v1.2.0/meridian/model/adstock_hill.py#L339-L401) |\n\nClass to compute the Adstock transformation of media.\n\nInherits From: [`AdstockHillTransformer`](../../../meridian/model/adstock_hill/AdstockHillTransformer.md) \n\n meridian.model.adstock_hill.AdstockTransformer(\n alpha: ../../../meridian/backend/Tensor.md,\n max_lag: int,\n n_times_output: int,\n decay_functions: (str | Sequence[str]) = constants.GEOMETRIC_DECAY\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `alpha` | Tensor of `alpha` parameters taking values in `[0, 1]` with dimensions `[..., n_media_channels]`. Batch dimensions `(...)` are optional. Note that `alpha = 0` is allowed, so it is possible to put a point mass prior at zero (effectively no Adstock). |\n| `max_lag` | Integer indicating the maximum number of lag periods (≥ `0`) to include in the Adstock calculation. |\n| `n_times_output` | Integer indicating the number of time periods to include in the output tensor. Cannot exceed the number of time periods of the media argument, for example, `media.shape[-2]`. The output time periods correspond to the most recent time periods of the media argument. For example, `media[..., -n_times_output:, :]` represents the media execution of the output weeks. |\n| `decay_functions` | String or list of strings indicating the decay function(s) to use for the Adstock calculation for each channel. Default is geometric decay for all channels. |\n\n\u003cbr /\u003e\n\nMethods\n\n`forward`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/model/adstock_hill.py#L373-L401) \n\n forward(\n media: ../../../meridian/backend/Tensor.md\n ) -\u003e ../../../meridian/backend/Tensor.md\n\nComputes the Adstock transformation of a given `media` tensor.\n\nFor geo `g`, time period `t`, and media channel `m`, Adstock is calculated\nas `adstock_{g,t,m} = sum_{i=0}^max_lag media_{g,t-i,m} alpha^i`.\n| **Note:** The Hill function can be applied before or after Adstock. If Hill is applied first, then the Adstock media input can contain batch dimensions because the transformed media tensor will be different for each posterior sample.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `media` | Tensor of media values with dimensions `[..., n_geos, n_media_times, n_media_channels]`. Batch dimensions `(...)` are optional, but if batch dimensions are included, they must match the batch dimensions of `alpha`. Media is not required to have batch dimensions even if `alpha` contains batch dimensions. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Tensor with dimensions `[..., n_geos, n_times_output, n_media_channels]` representing Adstock transformed media. ||\n\n\u003cbr /\u003e"]]