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

Class RatioCounter

tensorpack/utils/stats.py:57–96  ·  view source on GitHub ↗

A counter to count ratio of something.

Source from the content-addressed store, hash-verified

55
56
57class RatioCounter(object):
58 """ A counter to count ratio of something. """
59
60 def __init__(self):
61 self.reset()
62
63 def reset(self):
64 self._tot = 0
65 self._cnt = 0
66
67 def feed(self, count, total=1):
68 """
69 Args:
70 cnt(int): the count of some event of interest.
71 tot(int): the total number of events.
72 """
73 self._tot += total
74 self._cnt += count
75
76 @property
77 def ratio(self):
78 if self._tot == 0:
79 return 0
80 return self._cnt * 1.0 / self._tot
81
82 @property
83 def total(self):
84 """
85 Returns:
86 int: the total
87 """
88 return self._tot
89
90 @property
91 def count(self):
92 """
93 Returns:
94 int: the total
95 """
96 return self._cnt
97
98
99class Accuracy(RatioCounter):

Callers 5

eval_classificationFunction · 0.90
eval_classificationFunction · 0.90
eval_classificationFunction · 0.90
eval_classificationFunction · 0.90
_before_inferenceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected