Provides core, stateless mathematical functions for Meridian MMM.
meridian
.
model
.
equations
.
ModelEquations
(
model_context
:
meridian
.
model
.
context
.
ModelContext
)
Methods
adstock_hill_media
adstock_hill_media
(
*
,
media
:
meridian
.
backend
.
Tensor
,
alpha
:
meridian
.
backend
.
Tensor
,
ec
:
meridian
.
backend
.
Tensor
,
slope
:
meridian
.
backend
.
Tensor
,
decay_functions
:
(
str
|
Sequence
[
str
])
=
constants
.
GEOMETRIC_DECAY
,
n_times_output
:
(
int
|
None
)
=
None
)
->
meridian
.
backend
.
Tensor
Transforms media or using Adstock and Hill functions in the desired order.
media
(n_geos, n_media_times, n_media_channels)
containing non-negative media execution values. Typically this is
impressions, but it can be any metric, such as media_spend
. Clicks are
often used for paid search ads.alpha
ec
slope
decay_functions
n_times_output
media
equals n_media_times
, in which case n_times_output
defaults to n_times
.
[..., n_geos, n_times, n_media_channels]
representing Adstock and Hill-transformed media. adstock_hill_rf
adstock_hill_rf
(
*
,
reach
:
meridian
.
backend
.
Tensor
,
frequency
:
meridian
.
backend
.
Tensor
,
alpha
:
meridian
.
backend
.
Tensor
,
ec
:
meridian
.
backend
.
Tensor
,
slope
:
meridian
.
backend
.
Tensor
,
decay_functions
:
(
str
|
Sequence
[
str
])
=
constants
.
GEOMETRIC_DECAY
,
n_times_output
:
(
int
|
None
)
=
None
)
->
meridian
.
backend
.
Tensor
Transforms reach and frequency (RF) using Hill and Adstock functions.
reach
(n_geos, n_media_times, n_rf_channels)
containing non-negative media for reach.frequency
(n_geos, n_media_times, n_rf_channels)
containing non-negative media for frequency.alpha
ec
slope
decay_functions
n_times_output
reach
equals n_media_times
, in which case n_times_output
defaults to n_times
.
[..., n_geos, n_times, n_rf_channels]
representing Hill and Adstock-transformed RF. calculate_beta_x
calculate_beta_x
(
*
,
is_non_media
:
bool
,
incremental_outcome_x
:
meridian
.
backend
.
Tensor
,
linear_predictor_counterfactual_difference
:
meridian
.
backend
.
Tensor
,
eta_x
:
meridian
.
backend
.
Tensor
,
beta_gx_dev
:
meridian
.
backend
.
Tensor
)
->
meridian
.
backend
.
Tensor
Calculates coefficient mean parameter for any treatment variable type.
The "beta_x" in the function name refers to the coefficient mean parameter of any treatment variable. The "x" can represent "m", "rf", "om", or "orf". This function can also be used to calculate "gamma_n" for any non-media treatments.
is_non_media
True
, then
random effects are assumed to be normal. Otherwise, the distribution is
inferred from self._context.media_effects_dist
.incremental_outcome_x
linear_predictor_counterfactual_difference
eta_x
xi_n
, which is analogous to
"eta".beta_gx_dev
gamma_gn_dev
, which is analogous to "beta_gx_dev".
compute_non_media_treatments_baseline
compute_non_media_treatments_baseline
(
non_media_baseline_values
:
(
Sequence
[
str
|
float
]
|
None
)
=
None
)
->
meridian
.
backend
.
Tensor
Computes the baseline for each non-media treatment channel.
non_media_baseline_values
(n_non_media_channels,)
. Each element is either a float (which means
that the fixed value will be used as baseline for the given channel) or
one of the strings "min" or "max" (which mean that the global minimum or
maximum value will be used as baseline for the values of the given
non_media treatment channel). If float values are provided, it is
expected that they are scaled by population for the channels where model_spec.non_media_population_scaling_id
is True
. If None
, the model_spec.non_media_baseline_values
is used, which defaults to the
minimum value for each non_media treatment channel.
(n_non_media_channels,)
containing the
baseline values for each non-media treatment channel. linear_predictor_counterfactual_difference_media
linear_predictor_counterfactual_difference_media
(
*
,
media_transformed
:
meridian
.
backend
.
Tensor
,
alpha_m
:
meridian
.
backend
.
Tensor
,
ec_m
:
meridian
.
backend
.
Tensor
,
slope_m
:
meridian
.
backend
.
Tensor
)
->
meridian
.
backend
.
Tensor
Calculates linear predictor counterfactual difference for non-RF media.
For non-RF media variables (paid or organic), this function calculates the linear predictor difference between the treatment variable and its counterfactual. "Linear predictor" refers to the output of the hill/adstock function, which is multiplied by the geo-level coefficient.
This function does the calculation efficiently by only calculating calling the hill/adstock function if the prior counterfactual is not all zeros.
media_transformed
alpha_m
ec_m
slope_m
linear_predictor_counterfactual_difference_rf
linear_predictor_counterfactual_difference_rf
(
*
,
rf_transformed
:
meridian
.
backend
.
Tensor
,
alpha_rf
:
meridian
.
backend
.
Tensor
,
ec_rf
:
meridian
.
backend
.
Tensor
,
slope_rf
:
meridian
.
backend
.
Tensor
)
->
meridian
.
backend
.
Tensor
Calculates linear predictor counterfactual difference for RF media.
For RF media variables (paid or organic), this function calculates the linear predictor difference between the treatment variable and its counterfactual. "Linear predictor" refers to the output of the hill/adstock function, which is multiplied by the geo-level coefficient.
This function does the calculation efficiently by only calculating calling the hill/adstock function if the prior counterfactual is not all zeros.
rf_transformed
alpha_rf
ec_rf
slope_rf



