StatisticsCollector¶
-
class
tfsnippet.utils.StatisticsCollector(shape=())¶ Bases:
objectComputing \(\mathrm{E}[X]\) and \(\operatorname{Var}[X]\) online.
Attributes Summary
counterGet the counter of collected values. has_valueWhether or not any value has been collected? meanGet the mean of the values, i.e., \(\mathrm{E}[X]\). shapeGet the shape of the values. squareGet \(\mathrm{E}[X^2]\) of the values. stddevGet the std of the values, i.e., \(\sqrt{\operatorname{Var}[X]}\). varGet the variance of the values, i.e., \(\operatorname{Var}[X]\). weight_sumGet the weight summation. Methods Summary
collect(values[, weight])Update the statistics from values. reset()Reset the collector to initial state. Attributes Documentation
-
counter¶ Get the counter of collected values.
-
has_value¶ Whether or not any value has been collected?
-
mean¶ Get the mean of the values, i.e., \(\mathrm{E}[X]\).
-
shape¶ Get the shape of the values.
-
square¶ Get \(\mathrm{E}[X^2]\) of the values.
-
stddev¶ Get the std of the values, i.e., \(\sqrt{\operatorname{Var}[X]}\).
-
var¶ Get the variance of the values, i.e., \(\operatorname{Var}[X]\).
-
weight_sum¶ Get the weight summation.
Methods Documentation
-
collect(values, weight=1.0)¶ Update the statistics from values.
This method uses the following equation to update mean and square:
\[\frac{\sum_{i=1}^n w_i f(x_i)}{\sum_{j=1}^n w_j} = \frac{\sum_{i=1}^m w_i f(x_i)}{\sum_{j=1}^m w_j} + \frac{\sum_{i=m+1}^n w_i}{\sum_{j=1}^n w_j} \Bigg( \frac{\sum_{i=m+1}^n w_i f(x_i)}{\sum_{j=m+1}^n w_j} - \frac{\sum_{i=1}^m w_i f(x_i)}{\sum_{j=1}^m w_j} \Bigg)\]Parameters: - values – Values to be collected in batch, numpy array or scalar
whose shape ends with
self.shape. The leading shape in front ofself.shapeis regarded as the batch shape. - weight – Weights of the values, should be broadcastable against the batch shape. (default is 1)
Raises: ValueError– If the shape of values does not end with self.shape.- values – Values to be collected in batch, numpy array or scalar
whose shape ends with
-
reset()¶ Reset the collector to initial state.
-