Adds in the state from a list of metrics. Default implementation sums all the metric variables. Args: metrics: A list of metrics with the same type as `self`. Raises: ValueError: If metrics contains invalid data.
(self, metrics)
| 235 | # I'm going with the second strategy since we can define a default |
| 236 | # implementation of aggregate() that will work for most descendants. |
| 237 | def aggregate(self, metrics): |
| 238 | """Adds in the state from a list of metrics. |
| 239 | |
| 240 | Default implementation sums all the metric variables. |
| 241 | |
| 242 | Args: |
| 243 | metrics: A list of metrics with the same type as `self`. |
| 244 | |
| 245 | Raises: |
| 246 | ValueError: If metrics contains invalid data. |
| 247 | """ |
| 248 | for m in metrics: |
| 249 | if type(self) != type(m): # pylint: disable=unidiomatic-typecheck |
| 250 | raise TypeError("All metrics must be the same type, '%s' != '%s'." % |
| 251 | (type(self), type(m))) |
| 252 | # pylint: disable=protected-access |
| 253 | for i in range(len(self._vars)): |
| 254 | if any(m._vars[i].name != self._vars[i].name for m in metrics): |
| 255 | raise ValueError("All metrics must have variables in the same order.") |
| 256 | self._vars[i].assign_add(math_ops.add_n([m._vars[i] for m in metrics])) |
| 257 | # pylint: enable=protected-access |
| 258 | |
| 259 | # ---- For use by descendants --- |
| 260 | def add_variable(self, name, shape=None, dtype=None, initializer=None): |
no test coverage detected