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
log_history (Sequence) – History logs. Defaults to [].
count_history (Sequence) – Counts of history logs. Defaults to [].
max_length (int) – The max length of history logs. Defaults to 1000000.
Return the recently updated values in log histories.
Recently updated values in log histories.
np.ndarray
Get the _log_history
and _count_history
.
History logs and the counts of the history logs.
Tuple[np.ndarray, np.ndarray]
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.
window_size (int, optional) – Size of statistics window.
The maximum value within the window.
np.ndarray
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.
window_size (int, optional) – Size of statistics window.
Mean value within the window.
np.ndarray
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.
window_size (int, optional) – Size of statistics window.
The minimum value within the window.
np.ndarray
Register custom statistics method to _statistics_methods
.
The registered method can be called by history_buffer.statistics
with 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
method (Callable) – Custom statistics method.
Original custom statistics method.
Callable
Access statistics method by name.
method_name (str) – Name of method.
Depends on corresponding method.
Any
Update the log history.
If the length of the buffer exceeds self._max_length
, the oldest element will be removed from the buffer.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4