Meridian budget optimization estimates the optimal total budget per
channel over a set of geos and time periods. Budget optimization assumes that
each channel's *flighting pattern* is fixed and that the *cost per media unit*
does not depend on the channel's assigned budget. (The *cost per media unit* may
vary by geo or time period or both, but it does not depend on the channel's
assigned budget.) These assumptions determine how any given channel budget
translates to a media unit count for each geo and time period.

A channel's *flighting pattern* is defined as the relative allocation of media
units across geos and time periods. By default, optimization is based on the set
of geos and time periods of the historical data, and the historical flighting
pattern is assumed. However, the flighting pattern can be customized and can
include different time periods than the historical time window. For example, a
hypothetical flighting pattern may be specified corresponding to a future time
window for budget planning.

A channel's *cost per media unit* is inferred from the input data provided. It
can (but need not) vary by geo or time period or both. By default, optimization
is based on the set of geos and time periods of the historical data, and the
historical cost per media unit is assumed. However, the cost per media unit can
be customized to reflect anticipated future costs, for example.

The flighting pattern and cost per media unit are applied as follows. Suppose
you want to compute a budget optimization for \\(N_M\\) media channels for a set
of regions \\(G\\) and time interval \\(\[t_0,t_1\]\\). Consider any budget vector
\\(b=(b_1,\\ldots b_{N_M})\\) where \\(b_i \\geq 0\\) denotes the total budget
allocated to channel \\(i\\) over these regions and time periods. Let
\\(c_i=\\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}\\ \\ddot{x}\^{\[M\]}_{g,t,i}
u_{g,t,i}\^{\[M\]}\\) be the actual historical budget for each channel \\(i\\) over
the optimization regions and time periods. To obtain the media units for each
geo and time period under the budget vector \\(b\\), you scale each channel's
historical media units by the ratio \\(\\frac{b_i}{c_i}\\).

Accordingly, you define the raw media units under a given budget vector \\(b\\)
as:

\\( \\ddot{x}_{g,t,i}\^{\[b\]} = \\dfrac{\\ddot{x}\^{\[M\]}_{g,t,i}b_i }{c_i}\\) for
\\(t \\in \[t_0-L,t_1\] \\)

and the corresponding transformed media units as:

\\( x_{g,t,m}\^{\[b\]} = L_{g,i}\^{\[M\]}\\left( \\ddot{x}_{g,t,i}\^{\[b\]} \\right) =
\\dfrac{x_{g,t,i}b_i}{c_i} \\)

The media units are scaled for *all time periods*, including time periods prior
to \\(t_0\\). The budget \\(C\\) corresponds to the time interval
\\(\[t_0,t_1\],\\) and this scenario captures the expected outcome generated
during the same interval \\(\[t_0,t_1\]\\). This includes outcome driven by media
executed prior to \\(t_0\\), but excludes the lagged effect of media beyond
\\(t_1\\). As such, the expected outcome does not exactly correspond to the
budget but it should be similar if the time interval is long, or if the media
execution during \\(\[t_0-L,t_0-1\]\\) is similar to the media execution during
\\(\[t_1+1,t_1+L\]\\).

There are advantages and disadvantages to this definition,
but an advantage is that the expected outcome doesn't depend on future media
execution beyond \\(t_1\\), which might be unknown. This is particularly an
issue when `hill_before_adstock=False`, where the media execution after
\\(t_1\\) can alter the lagged effect of media executed during
\\(\[t_1+1,t_1+L\]\\).

## Fixed budget optimization

Consider a fixed budget optimization with total budget \\(C\\). Define the set
of all budget vectors with this total budget as \\( B_C = \\left\\{ b:
\\sum\\limits_{i=1}\^{N_M} b_i=C \\right\\} \\). The quantity being optimized is
expected outcome, defined as follows:
$$ \\begin{multline\*} \\text{ExpectedOutcome}(b) = \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1} E \\left( \\overset \\sim Y_{g,t}\^{ \\left( \\left\\{ x_{g,t,i}\^{\[b\]} \\right\\} \\right) } \\Bigg\| \\{z_{g,t,i}\\} \\right) \\\\ = \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1} u_{g,t}\^{\[Y\]}L_{g,t}\^{\[y\]-1} \\left( \\mu_t + \\tau_g + \\sum\\limits_{i=1}\^{N_C} \\gamma\^{\[C\]}_{g,i}z_{g,t,i}\\ + \\sum\\limits_{i=1}\^{N_M} \\beta\^{\[M\]}_{g,i} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{\[b\]} \\right\\}_{s=0}\^L; \\alpha\^{M}_i, ec\^{\[M\]}_i, \\text{slope}\^{\[M\]}_i \\right) \\right) \\end{multline\*} $$

The true parameter values are unknown. Because Meridian is a Bayesian
model, the expected outcome has a posterior distribution. The objective function
of the budget optimization is chosen to be the posterior mean of the expected
outcome, which is equivalent to the mean of the posterior predictive outcome
distribution. The optimal budget vector is defined as:
$$ \\begin{align\*} b_{optimal} = \\underset{b \\in B_C}{\\text{argmax}}\\ \& E\\left\[ \\text{ExpectedOutcome}(b) \| \\text{Data} \\right\] \\\\ = \\underset{b \\in B_C}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[y\]}L_{g,t}\^{\[Y\]-1} \\Biggl( \\mu_t\^{(j)} + \\tau_g\^{(j)} + \\sum\\limits_{i=1}\^{N_C} \\gamma_{g,i}\^{\[C\](j)}z_{g,t,i} \\\\\& + \\sum\\limits_{i-1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{\[b\]} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)}, ec_i\^{\[M\](j)}, \\text{slope}_i\^{\[M\](j)} \\right) \\Biggl) \\\\ = \\underset{b \\in B_C}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[Y\]}L_{g,t}\^{\[Y\]-1} \\left( \\sum\\limits_{i=1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{\[b\]} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)}, ec_i\^{\[M\](j)}, \\text{slope}_i\^{\[M\](j)} \\right) \\right) \\end{align\*} $$

Where:

- \\(J\\) is the total number of Markov Chain Monte Carlo (MCMC) posterior draws.
- The \\(j\\)^*th*^ posterior draw of each parameter is denoted with the superscript \\(\^{(j)}\\).

## Flexible budget optimization

For flexible budget optimization, the expected outcome is optimized while
allowing the total budget to vary. The optimization is constrained on either the
minimal marginal ROI or the target ROI constraints.

### Target ROI constraint

When the target ROI is specified, Meridian searches over all budget
vectors \\(b=(b_1,\\ldots ,b_{N_M})\\) such that the total ROI \\(\\text{ROI} \\geq
\\text{ROI}_{target}\\
\\forall m\\), while allowing the total budget \\(\\sum\\limits_{i=1}\^{N_M} b_i\\)
to vary. The optimal budget vector is defined as follows:
$$ \\begin{align\*} b_{optimal} = \\underset{b}{\\text{argmax}}\\ \& E\\left\[ \\text{ExpectedOutcome}(b) \| \\text{Data} \\right\] \\\\ = \\underset{b}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[Y\]}L_{g,t}\^{\[Y\]-1} \\Biggl( \\mu_t\^{(j)} + \\tau_g\^{(j)} + \\sum\\limits_{i=1}\^{N_C} \\gamma_{g,i}\^{\[C\](j)}z_{g,t,i} \\\\ \& + \\sum\\limits_{i-1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{\[b\]} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)}, ec\^{\[M\](j)}_i, \\text{slope}_i\^{\[M\](j)} \\right) \\Biggl) \\\\ = \\underset{b}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[Y\]}L_{g,t}\^{\[Y\]-1} \\left( \\sum\\limits_{i=1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{\[b\]} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)},ec_i\^{\[M\](j)},\\text{slope}_i\^{\[M\](j)} \\right) \\right) \\\\ \\end{align\*} $$

\\( s.t.\\ \\dfrac{\\sum\\limits_{i=1}\^{N_M} \\text{ExpectedOutcome}_i}{
\\sum\\limits_{i=1}\^{N_M} b_i } \> \\text{ROI}_{target} \\)

Where the target ROI constraint is applied at the total marketing ROI level, and
not at channel level.

### Minimal mROI constraint

When the minimal marginal ROI is specified, Meridian searches over all
budget vectors \\(b=(b_1,\\dots,b_{N_M})\\) such that the marginal ROI
\\(\\text{mROI}_i \\geq \\text{mROI}_{minimal}\\ \\forall i\\), while allowing the
total budget \\(\\sum\\limits_{i=1}\^{N_M} b_i\\) to vary. The optimal budget
vector is defined as follows:
$$ \\begin{align\*} b_{optimal} = \\underset{b}{\\text{argmax}}\\ \& E\\left\[ \\text{ExpectedOutcome}(b) \| \\text{Data} \\right\] \\\\ = \\underset{b}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[Y\]}L_{g,t}\^{\[Y\]-1} \\Biggl( \\mu_t\^{(j)} + \\tau_g\^{(j)} + \\sum\\limits_{i=1}\^{N_C} \\gamma_{g,i}\^{\[C\](j)}z_{g,t,i} \\\\ \& + \\sum\\limits_{i-1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{(b)} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)}, ec_i\^{\[M\](j)}, \\text{slope}_i\^{\[M\](j)} \\right) \\Biggl) \\\\ = \\underset{b}{\\text{argmax}}\\ \& \\frac{1}{J} \\sum\\limits_{j=1}\^J \\sum\\limits_{g \\in G} \\sum\\limits_{t=t_0}\^{t_1}u_{g,t}\^{\[Y\]}L_{g,t}\^{\[Y\]-1} \\left( \\sum\\limits_{i=1}\^{N_M} \\beta_{g,i}\^{\[M\](j)} \\text{HillAdstock} \\left( \\left\\{ x_{g,t-s,i}\^{(b)} \\right\\}_{s=0}\^L; \\alpha_i\^{\[M\](j)},ec_i\^{\[M\](j)},\\text{slope}_i\^{\[M\](j)} \\right) \\right) \\\\ \\end{align\*} $$

\\( s.t.\\ \\text{mROI}_i(b_i) \> \\text{mROI}_{minimal}\\ \\forall i \\)

Where the minimal mROI is applied at channel level, and not at the total
marketing level.

## Channel-level spend constraints

Channel-level spend constraints are available for both fixed and flexible budget
optimization to prevent unreasonable optimization outcomes, such as putting all
spend into one single channel. The channel-level spend constraint is defined as:
$$ (b_i\^{'} \\times LB_i) \\leq b_i \\leq (b_i{'} \\times UB_i) \\space \\forall i $$

Where:

- \\(b_i\^{'}\\) is the non-optimized spend for channel \\(i\\).
- \\(LB_i\\) is the user-specified lower bound with the value between \\(0\\) and \\(1\\).
- \\(UB_i\\) is the user-specified upper bound with the value greater than \\(1\\).