(self, val, n=1, decay=0)
| 53 | self.count = 0 |
| 54 | |
| 55 | def update(self, val, n=1, decay=0): |
| 56 | self.val = val |
| 57 | if decay: |
| 58 | alpha = math.exp(-n / decay) # exponential decay over 100 updates |
| 59 | self.sum = alpha * self.sum + (1 - alpha) * val * n |
| 60 | self.count = alpha * self.count + (1 - alpha) * n |
| 61 | else: |
| 62 | self.sum += val * n |
| 63 | self.count += n |
| 64 | self.avg = self.sum / self.count |
no outgoing calls
no test coverage detected