statistics#
Source code: tianshou/utils/statistics.py
- class MovAvg(size: int = 100)[source]#
Bases:
object
Class for moving average.
It will automatically exclude the infinity and NaN. Usage:
>>> stat = MovAvg(size=66) >>> stat.add(torch.tensor(5)) 5.0 >>> stat.add(float('inf')) # which will not add to stat 5.0 >>> stat.add([6, 7, 8]) 6.5 >>> stat.get() 6.5 >>> print(f'{stat.mean():.2f}±{stat.std():.2f}') 6.50±1.12
- class RunningMeanStd(mean: float | ndarray = 0.0, std: float | ndarray = 1.0, clip_max: float | None = 10.0, epsilon: float = 1.1920928955078125e-07)[source]#
Bases:
object
Calculates the running mean and std of a data stream.
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
- Parameters:
mean – the initial mean estimation for data array. Default to 0.
std – the initial standard error estimation for data array. Default to 1.
clip_max – the maximum absolute value for data array. Default to 10.0.
epsilon – To avoid division by zero.