A dictionary of running averages.
| 72 | |
| 73 | |
| 74 | class RunningAverageDict: |
| 75 | """A dictionary of running averages.""" |
| 76 | def __init__(self): |
| 77 | self._dict = None |
| 78 | |
| 79 | def update(self, new_dict): |
| 80 | if new_dict is None: |
| 81 | return |
| 82 | |
| 83 | if self._dict is None: |
| 84 | self._dict = dict() |
| 85 | for key, value in new_dict.items(): |
| 86 | self._dict[key] = RunningAverage() |
| 87 | |
| 88 | for key, value in new_dict.items(): |
| 89 | self._dict[key].append(value) |
| 90 | |
| 91 | def get_value(self): |
| 92 | if self._dict is None: |
| 93 | return None |
| 94 | return {key: value.get_value() for key, value in self._dict.items()} |
| 95 | |
| 96 | |
| 97 | def colorize(value, vmin=None, vmax=None, cmap='gray_r', invalid_val=-99, invalid_mask=None, background_color=(128, 128, 128, 255), gamma_corrected=False, value_transform=None): |