# tf.contrib.distributions.moving_mean_variance

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/distributions/python/ops/moving_stats.py#L176-L246) |

Compute exponentially weighted moving {mean,variance} of a streaming value.

    tf.contrib.distributions.moving_mean_variance(
        value, decay, collections=None, name=None
    )

The exponentially-weighting moving `mean_var` and `variance_var` are updated
by `value` according to the following recurrence:

    variance_var = decay * (variance_var + (1-decay) * (value - mean_var)**2)
    mean_var     = decay * mean_var + (1 - decay) * value

> [!NOTE]
> **Note:** `mean_var` is updated *after* `variance_var`, i.e., `variance_var` uses the lag-`1` mean.

For derivation justification, see \[Finch (2009; Eq. 143)\]\[1\].

Unlike `assign_moving_mean_variance`, this function handles
variable creation.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `value` | `float`-like `Tensor`. Same shape as `mean_var` and `variance_var`. |
| `decay` | A `float`-like `Tensor`. The moving mean decay. Typically close to `1.`, e.g., `0.999`. |
| `collections` | Python list of graph-collections keys to which the internal variables `mean_var` and `variance_var` are added. Default value is `[GraphKeys.GLOBAL_VARIABLES]`. |
| `name` | Optional name of the returned operation. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `mean_var` | `Variable` representing the `value`-updated exponentially weighted moving mean. |
| `variance_var` | `Variable` representing the `value`-updated exponentially weighted moving variance. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | if `value_var` does not have float type `dtype`. |
| `TypeError` | if `value`, `decay` have different `base_dtype`. |

<br />

#### References

\[1\]: Tony Finch. Incremental calculation of weighted mean and variance.
*Technical Report* , 2009.
<http://people.ds.cam.ac.uk/fanf2/hermes/doc/antiforgery/stats.pdf>