Computes and stores the average and current value
| 31 | |
| 32 | |
| 33 | class AverageMeter(object): |
| 34 | """Computes and stores the average and current value""" |
| 35 | def __init__(self): |
| 36 | self.initialized = False |
| 37 | self.val = None |
| 38 | self.avg = None |
| 39 | self.sum = None |
| 40 | self.count = None |
| 41 | |
| 42 | def initialize(self, val, weight): |
| 43 | self.val = val |
| 44 | self.avg = val |
| 45 | self.sum = val * weight |
| 46 | self.count = weight |
| 47 | self.initialized = True |
| 48 | |
| 49 | def update(self, val, weight=1): |
| 50 | if not self.initialized: |
| 51 | self.initialize(val, weight) |
| 52 | else: |
| 53 | self.add(val, weight) |
| 54 | |
| 55 | def add(self, val, weight): |
| 56 | self.val = val |
| 57 | self.sum += val * weight |
| 58 | self.count += weight |
| 59 | self.avg = self.sum / self.count |
| 60 | |
| 61 | def value(self): |
| 62 | return self.val |
| 63 | |
| 64 | def average(self): |
| 65 | return self.avg |
| 66 | |
| 67 | |
| 68 | def unique(ar, return_index=False, return_inverse=False, return_counts=False): |
nothing calls this directly
no outgoing calls
no test coverage detected