tianshou.utils

class tianshou.utils.MovAvg(size=100)[source]

Bases: object

Class for moving average. 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
add(x)[source]

Add a scalar into MovAvg. You can add torch.Tensor with only one element, a python scalar, or a list of python scalar. It will automatically exclude the infinity.

get()[source]

Get the average.

mean()[source]

Get the average. Same as get().

std()[source]

Get the standard deviation.