Skip to content

Commit 899beda

Browse files
authored
Clarify mean_tightness_score docstring and formula (#1980)
Expanded and clarified the docstring for mean_tightness_score to better explain the Mean Tightness Score (MTS) metric, its formula, properties, and parameter effects. Added explicit mathematical notation and improved parameter documentation for clarity.
1 parent 4af1cfc commit 899beda

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

pymc_marketing/mmm/utility.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,35 +163,45 @@ def mean_tightness_score(
163163
alpha: float = 0.5, confidence_level: float = 0.75
164164
) -> UtilityFunctionType:
165165
R"""
166-
Calculate the mean tightness score.
166+
Calculate the Mean Tightness Score (MTS).
167167
168-
The mean tightness score is a risk metric that balances the mean return and the tail variability.
169-
It is calculated as:
168+
MTS balances the posterior mean against a symmetric, quantile-based tail spread and
169+
returns a dimensionless, normalized score:
170170
171171
.. math::
172-
Mean\ Tightness\ Score = \mu - \alpha \cdot Tail\ Distance / \mu
172+
\mathrm{MTS}(X; \alpha, p) = 1 - \alpha \frac{T_p(X)}{\mu}
173173
174174
where:
175-
- :math:`\mu` is the mean of the sample returns.
176-
- :math:`Tail\ Distance` is the tail distance metric.
177-
- :math:`\alpha` is the risk tolerance parameter.
175+
- :math:`\mu` is the posterior mean of the samples.
176+
- :math:`T_p(X) = |Q_p - \mu| + |\mu - Q_{1-p}|` is a symmetric tail distance.
177+
178+
Larger :math:`T_p` indicates a more dispersed posterior and thus a lower score.
178179
179-
alpha (Risk Tolerance Parameter): This parameter controls the trade-off.
180-
- Higher :math:`\alpha` increases sensitivity to variability, making the metric value higher for spread dist
181-
- Lower :math:`\alpha` decreases sensitivity to variability, making the metric value lower for spread dist
180+
This formulation makes the following properties explicit:
181+
- :math:`\alpha` controls risk aversion: increasing :math:`\alpha` increases the
182+
penalty on dispersion, so the score decreases for more spread posteriors (all else equal).
183+
- With :math:`\alpha = 0`, the score is identically 1 for any samples (no preference signal).
184+
- For fixed :math:`X` and :math:`p`, the score is linear and non-increasing in :math:`\alpha`.
185+
- For fixed :math:`X` and :math:`\alpha`, the score is non-increasing in :math:`p`
186+
(since :math:`Q_p - Q_{1-p}` widens as :math:`p` moves away from 0.5).
182187
183188
Parameters
184189
----------
185190
alpha : float, optional
186-
Risk tolerance parameter (default is 0.5).
191+
Risk-aversion weight. Larger values increase the penalty from tail spread (default 0.5).
187192
confidence_level : float, optional
188-
Confidence level for the quantiles (default is 0.75).
189-
Confidence level must be between 0 and 1.
193+
Quantile probability :math:`p \in (0, 1)` used to compute :math:`T_p`.
194+
Typical choices are :math:`p \in [0.6, 0.9]` (default 0.75).
190195
191196
Returns
192197
-------
193198
UtilityFunctionType
194-
A function that calculates the mean tightness score given samples and budgets.
199+
A function that calculates the normalized mean tightness score given samples and budgets.
200+
201+
Raises
202+
------
203+
ValueError
204+
If ``confidence_level`` is not between 0 and 1.
195205
"""
196206
if not 0 < confidence_level < 1:
197207
raise ValueError("Confidence level must be between 0 and 1.")

0 commit comments

Comments
 (0)