Skip to content

Commit

Permalink
docs(python): Fix formula in ewm_mean_by (#18506)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Sep 2, 2024
1 parent 8a143c0 commit 8f3d988
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
23 changes: 12 additions & 11 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9311,7 +9311,7 @@ def ewm_mean(
ignore_nulls: bool = False,
) -> Expr:
r"""
Exponentially-weighted moving average.
Compute exponentially-weighted moving average.
Parameters
----------
Expand All @@ -9326,11 +9326,11 @@ def ewm_mean(
.. math::
\alpha = \frac{2}{\theta + 1} \; \forall \; \theta \geq 1
half_life
Specify decay in terms of half-life, :math:`\lambda`, with
Specify decay in terms of half-life, :math:`\tau`, with
.. math::
\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \lambda } \right\} \;
\forall \; \lambda > 0
\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \tau } \right\} \;
\forall \; \tau > 0
alpha
Specify smoothing factor alpha directly, :math:`0 < \alpha \leq 1`.
adjust
Expand Down Expand Up @@ -9393,20 +9393,21 @@ def ewm_mean_by(
half_life: str | timedelta,
) -> Expr:
r"""
Calculate time-based exponentially weighted moving average.
Compute time-based exponentially weighted moving average.
Given observations :math:`x_1, x_2, \ldots, x_n` at times
:math:`t_1, t_2, \ldots, t_n`, the EWMA is calculated as
Given observations :math:`x_0, x_1, \ldots, x_{n-1}` at times
:math:`t_0, t_1, \ldots, t_{n-1}`, the EWMA is calculated as
.. math::
y_0 &= x_0
\alpha_i &= \exp(-\lambda(t_i - t_{i-1}))
\alpha_i &= 1 - \exp \left\{ \frac{ -\ln(2)(t_i-t_{i-1}) }
{ \tau } \right\}
y_i &= \alpha_i x_i + (1 - \alpha_i) y_{i-1}; \quad i > 0
where :math:`\lambda` equals :math:`\ln(2) / \text{half_life}`.
where :math:`\tau` is the `half_life`.
Parameters
----------
Expand Down Expand Up @@ -9490,7 +9491,7 @@ def ewm_std(
ignore_nulls: bool = False,
) -> Expr:
r"""
Exponentially-weighted moving standard deviation.
Compute exponentially-weighted moving standard deviation.
Parameters
----------
Expand Down Expand Up @@ -9581,7 +9582,7 @@ def ewm_var(
ignore_nulls: bool = False,
) -> Expr:
r"""
Exponentially-weighted moving variance.
Compute exponentially-weighted moving variance.
Parameters
----------
Expand Down
23 changes: 12 additions & 11 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6883,7 +6883,7 @@ def ewm_mean(
ignore_nulls: bool = False,
) -> Series:
r"""
Exponentially-weighted moving average.
Compute exponentially-weighted moving average.
Parameters
----------
Expand All @@ -6898,11 +6898,11 @@ def ewm_mean(
.. math::
\alpha = \frac{2}{\theta + 1} \; \forall \; \theta \geq 1
half_life
Specify decay in terms of half-life, :math:`\lambda`, with
Specify decay in terms of half-life, :math:`\tau`, with
.. math::
\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \lambda } \right\} \;
\forall \; \lambda > 0
\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \tau } \right\} \;
\forall \; \tau > 0
alpha
Specify smoothing factor alpha directly, :math:`0 < \alpha \leq 1`.
adjust
Expand Down Expand Up @@ -6958,20 +6958,21 @@ def ewm_mean_by(
half_life: str | timedelta,
) -> Series:
r"""
Calculate time-based exponentially weighted moving average.
Compute time-based exponentially weighted moving average.
Given observations :math:`x_1, x_2, \ldots, x_n` at times
:math:`t_1, t_2, \ldots, t_n`, the EWMA is calculated as
Given observations :math:`x_0, x_1, \ldots, x_{n-1}` at times
:math:`t_0, t_1, \ldots, t_{n-1}`, the EWMA is calculated as
.. math::
y_0 &= x_0
\alpha_i &= \exp(-\lambda(t_i - t_{i-1}))
\alpha_i &= 1 - \exp \left\{ \frac{ -\ln(2)(t_i-t_{i-1}) }
{ \tau } \right\}
y_i &= \alpha_i x_i + (1 - \alpha_i) y_{i-1}; \quad i > 0
where :math:`\lambda` equals :math:`\ln(2) / \text{half_life}`.
where :math:`\tau` is the `half_life`.
Parameters
----------
Expand Down Expand Up @@ -7047,7 +7048,7 @@ def ewm_std(
ignore_nulls: bool = False,
) -> Series:
r"""
Exponentially-weighted moving standard deviation.
Compute exponentially-weighted moving standard deviation.
Parameters
----------
Expand Down Expand Up @@ -7131,7 +7132,7 @@ def ewm_var(
ignore_nulls: bool = False,
) -> Series:
r"""
Exponentially-weighted moving variance.
Compute exponentially-weighted moving variance.
Parameters
----------
Expand Down

0 comments on commit 8f3d988

Please sign in to comment.