MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / AverageMeter

Class AverageMeter

util/time_counter.py:36–61  ·  view source on GitHub ↗

Computes and stores the average and current value.

Source from the content-addressed store, hash-verified

34
35
36class AverageMeter(object):
37 """Computes and stores the average and current value."""
38 def __init__(self, name, fmt=':f', val_only=False):
39 self.name = name
40 self.fmt = fmt
41 self.val_only = val_only
42 self.reset()
43
44 def reset(self):
45 self.val = 0
46 self.avg = 0
47 self.sum = 0
48 self.count = 0
49
50 def update(self, val, n=1):
51 self.val = val
52 self.sum += val * n
53 self.count += n
54 self.avg = self.sum / self.count
55
56 def __str__(self):
57 if self.val_only:
58 fmtstr = '{name} {val' + self.fmt + '}'
59 else:
60 fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})'
61 return fmtstr.format(**self.__dict__)

Callers 1

updateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected