TF 2.0 is out! Get hands-on practice at TF World, Oct 28-31. Use code TF20 for 20% off select passes. Register now


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


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

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

Unlike assign_moving_mean_variance, this function handles variable creation.


  • 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.
  • name: Optional name of the returned operation.


  • mean_var: Variable representing the value-updated exponentially weighted moving mean.
  • variance_var: Variable representing the value-updated exponentially weighted moving variance.


  • TypeError: if value_var does not have float type dtype.
  • TypeError: if value, decay have different base_dtype.


[1]: Tony Finch. Incremental calculation of weighted mean and variance. Technical Report, 2009.