MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / StatCounter

Class StatCounter

tensorpack/utils/stats.py:10–54  ·  view source on GitHub ↗

A simple counter

Source from the content-addressed store, hash-verified

8
9
10class StatCounter(object):
11 """ A simple counter"""
12
13 def __init__(self):
14 self.reset()
15
16 def feed(self, v):
17 """
18 Args:
19 v(float or np.ndarray): has to be the same shape between calls.
20 """
21 self._values.append(v)
22
23 def reset(self):
24 self._values = []
25
26 @property
27 def count(self):
28 return len(self._values)
29
30 @property
31 def average(self):
32 assert len(self._values)
33 return np.mean(self._values)
34
35 @property
36 def sum(self):
37 assert len(self._values)
38 return np.sum(self._values)
39
40 @property
41 def max(self):
42 assert len(self._values)
43 return max(self._values)
44
45 @property
46 def min(self):
47 assert len(self._values)
48 return min(self._values)
49
50 def samples(self):
51 """
52 Returns all samples.
53 """
54 return self._values
55
56
57class RatioCounter(object):

Callers 3

eval_with_funcsFunction · 0.90
eval_with_funcsFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected