This function applies an adstock process to media spend data. It achieves
this by creating a windowed view of the media tensor and then using
tf.einsum to efficiently compute the weighted sum based on the provided
weights. The weights tensor defines the decay effect over a specific
window_size. The output is truncated to n_times_output periods.
Args
media
Input media tensor. Expected shape is (..., num_geos,
num_times_in, num_channels). The ... represents optional batch
dimensions.
weights
Adstock weights tensor. Expected shape is (..., num_channels,
window_size). The batch dimensions must be broadcast-compatible with
those in media.
n_times_output
The number of time periods to output. This should be less
than or equal to num_times_in - window_size + 1.
Returns
A tensor of shape (..., num_geos, n_times_output, num_channels)
representing the adstocked 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 2026-05-19 UTC."],[],[]]