Skip to content

Commit 7e2e264

Browse files
various improvements to the saturation function docs: clarified when the logistic function reaches the half-saturation point, removed the chemistry language from the michaelis-menten function, added hints to the lam and c parameters about how the function behaves wrt to increasing the parameter, added some hints about when one saturation function is useful vs others. (#1892)
1 parent 6cf6138 commit 7e2e264

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

pymc_marketing/mmm/transformers.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ def logistic_saturation(x, lam: npt.NDArray | float = 0.5):
425425
.. math::
426426
f(x) = \frac{1 - e^{-\lambda x}}{1 + e^{-\lambda x}}
427427
428+
The logistic saturation function reaches the half-saturation point at
429+
:math:`x = \frac{ln(3)}{\lambda}`. This means the half-saturation point
430+
is approximately :math:`1/\lambda`. If you want to set a prior on the
431+
exact half-saturation point, you can use the inverse_scaled_logistic_saturation
432+
function, available in this package.
433+
428434
.. plot::
429435
:context: close-figs
430436
@@ -451,7 +457,8 @@ def logistic_saturation(x, lam: npt.NDArray | float = 0.5):
451457
x : tensor
452458
Input tensor.
453459
lam : float or array-like, optional, by default 0.5
454-
Saturation parameter.
460+
Represents the efficiency of the channel.
461+
Larger values represent a more efficient channel.
455462
456463
Returns
457464
-------
@@ -500,7 +507,7 @@ def inverse_scaled_logistic_saturation(
500507
x : tensor
501508
Input tensor.
502509
lam : float or array-like, optional, by default 0.5
503-
Saturation parameter.
510+
The half-saturation point. Larger values represent less efficient channels.
504511
eps : float or array-like, optional, by default ln(3)
505512
Scaling parameter. ln(3) results in halfway saturation at lam
506513
@@ -595,6 +602,13 @@ def tanh_saturation(
595602
.. math::
596603
f(x) = b \tanh \left( \frac{x}{bc} \right)
597604
605+
The tanh saturation function has a nice property that is useful when
606+
setting priors. The slope of the function when x is zero is
607+
:math:`\frac{1}{c}`. This means that you can set a prior by considering
608+
how many units of media are required to acquire the first customer. Unlike most
609+
other saturation functions, the slope at 0 is independent of the saturation
610+
point.
611+
598612
.. plot::
599613
:context: close-figs
600614
@@ -628,9 +642,12 @@ def tanh_saturation(
628642
x : tensor
629643
Input tensor.
630644
b : float, by default 0.5
631-
Number of users at saturation. Must be non-negative.
645+
The saturation point. It represents the maximium number of
646+
customers that could be acquired through this channel at any
647+
point time. Must be non-negative.
632648
c : float, by default 0.5
633-
Initial cost per user. Must be non-zero.
649+
Initial cost per user. Larger values represent less efficient channels.
650+
Must be non-zero.
634651
635652
Returns
636653
-------
@@ -804,17 +821,13 @@ def michaelis_menten(
804821
) -> float | Any:
805822
r"""Evaluate the Michaelis-Menten function for given values of x, alpha, and lambda.
806823
807-
The Michaelis-Menten function models enzyme kinetics and describes how the rate of
808-
a chemical reaction increases with substrate concentration until it reaches its
809-
maximum value.
810-
811824
.. math::
812825
\alpha \cdot \frac{x}{\lambda + x}
813826
814827
where:
815-
- :math:`x`: Channel spend or substrate concentration.
816-
- :math:`\alpha`: Maximum contribution or efficiency factor.
817-
- :math:`\lambda` (k): Michaelis constant, representing the threshold substrate concentration.
828+
- :math:`x`: Channel spend.
829+
- :math:`\alpha`: Maximum contribution.
830+
- :math:`\lambda` (k): The half-saturation point.
818831
819832
.. plot::
820833
:context: close-figs
@@ -872,9 +885,11 @@ def michaelis_menten(
872885
x : float
873886
The spent on a channel.
874887
alpha : float
875-
The maximum contribution a channel can make.
888+
The saturation point. It represents the maximium number of
889+
customers that could be acquired through this channel at any
890+
point time. Must be non-negative.
876891
lam : float
877-
The Michaelis constant for the given enzyme-substrate system.
892+
The half-saturation point. Larger values represent less efficient channels.
878893
879894
Returns
880895
-------
@@ -940,7 +955,7 @@ def hill_function(
940955
The independent variable, typically representing the concentration of a
941956
substrate or the intensity of a stimulus.
942957
slope : float
943-
The slope of the hill. Must pe non-positive.
958+
The slope of the hill. Must be non-positive.
944959
kappa : float
945960
The half-saturation point as :math:`f(\kappa) = 0.5` for any value of :math:`s` and :math:`\kappa`.
946961

0 commit comments

Comments
 (0)