Computes and stores the average and current value.
| 385 | |
| 386 | |
| 387 | class MyAverageMeter(object): |
| 388 | """Computes and stores the average and current value.""" |
| 389 | |
| 390 | def __init__(self, max_len=-1): |
| 391 | self.val_list = [] |
| 392 | self.count = [] |
| 393 | self.max_len = max_len |
| 394 | self.val = 0 |
| 395 | self.avg = 0 |
| 396 | self.var = 0 |
| 397 | |
| 398 | def update(self, val): |
| 399 | self.val = val |
| 400 | self.avg = 0 |
| 401 | self.var = 0 |
| 402 | if not math.isnan(val) and not math.isinf(val): |
| 403 | self.val_list.append(val) |
| 404 | if self.max_len > 0 and len(self.val_list) > self.max_len: |
| 405 | self.val_list = self.val_list[-self.max_len:] |
| 406 | if len(self.val_list) > 0: |
| 407 | self.avg = np.mean(np.array(self.val_list)) |
| 408 | self.var = np.std(np.array(self.val_list)) |
no outgoing calls
no test coverage detected