Update xmisc

This commit is contained in:
D-X-Y
2021-06-10 23:42:00 -07:00
parent 98f981dd45
commit 248686820c
8 changed files with 72 additions and 487 deletions

View File

@@ -0,0 +1,22 @@
class AverageMeter:
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0.0
self.avg = 0.0
self.sum = 0.0
self.count = 0.0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
def __repr__(self):
return "{name}(val={val}, avg={avg}, count={count})".format(
name=self.__class__.__name__, **self.__dict__
)