HistoryBuffer — mmengine 0.10.7 documentation (original) (raw)

class mmengine.logging.HistoryBuffer(log_history=[], count_history=[], max_length=1000000)[source]

Unified storage format for different log types.

HistoryBuffer records the history of log for further statistics.

Examples

history_buffer = HistoryBuffer()

Update history_buffer.

history_buffer.update(1) history_buffer.update(2) history_buffer.min() # minimum of (1, 2) 1 history_buffer.max() # maximum of (1, 2) 2 history_buffer.mean() # mean of (1, 2) 1.5 history_buffer.statistics('mean') # access method by string. 1.5

Parameters:

current()[source]

Return the recently updated values in log histories.

Returns:

Recently updated values in log histories.

Return type:

np.ndarray

property data_: Tuple[ndarray, ndarray]_

Get the _log_history and _count_history.

Returns:

History logs and the counts of the history logs.

Return type:

Tuple[np.ndarray, np.ndarray]

max(window_size=None)[source]

Return the maximum value of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global maximum value of history logs.

Parameters:

window_size (int, optional) – Size of statistics window.

Returns:

The maximum value within the window.

Return type:

np.ndarray

mean(window_size=None)[source]

Return the mean of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global mean value of history logs.

Parameters:

window_size (int, optional) – Size of statistics window.

Returns:

Mean value within the window.

Return type:

np.ndarray

min(window_size=None)[source]

Return the minimum value of the latest window_size values in log histories.

If window_size is None or window_size > len(self._log_history), return the global minimum value of history logs.

Parameters:

window_size (int, optional) – Size of statistics window.

Returns:

The minimum value within the window.

Return type:

np.ndarray

classmethod register_statistics(method)[source]

Register custom statistics method to _statistics_methods.

The registered method can be called by history_buffer.statisticswith corresponding method name and arguments.

Examples

@HistoryBuffer.register_statistics def weighted_mean(self, window_size, weight): assert len(weight) == window_size return (self._log_history[-window_size:] * np.array(weight)).sum() / >>> self._count_history[-window_size:]

log_buffer = HistoryBuffer([1, 2], [1, 1]) log_buffer.statistics('weighted_mean', 2, [2, 1]) 2

Parameters:

method (Callable) – Custom statistics method.

Returns:

Original custom statistics method.

Return type:

Callable

statistics(method_name, *arg, **kwargs)[source]

Access statistics method by name.

Parameters:

method_name (str) – Name of method.

Returns:

Depends on corresponding method.

Return type:

Any

update(log_val, count=1)[source]

Update the log history.

If the length of the buffer exceeds self._max_length, the oldest element will be removed from the buffer.

Parameters:

Return type:

None