CumMax#
Description#
The CumMax function returns the running maximum of all samples seen since the start of the stream (or since the last reset). The output is monotonically non-decreasing while inputs are finite. It is the streaming equivalent of numpy.maximum.accumulate. Memory is O(1) regardless of how many samples have been processed.
This is an expanding (cumulative-from-zero) reduction, not a sliding window. For a fixed-window peak see RollingMax.
Equation:
Parameters: none.
NaN handling: Once an input is NaN, every subsequent output is NaN. This matches numpy.maximum.accumulate.
NaN handling#
Policy: ignore. A NaN in any input at index t causes the function to skip that step: output at t is NaN and internal state is unchanged. Subsequent finite samples are processed as if step t had not occurred.
Examples#
Usage example#
import numpy as np
import plotly.graph_objects as go
from screamer import CumMax
rng = np.random.default_rng(2)
x = np.cumsum(rng.normal(0.0, 1.0, size=300))
peak = CumMax()(x)
fig = go.Figure()
fig.add_trace(go.Scatter(y=x, mode='lines',
name='x[t]', line=dict(color='steelblue')))
fig.add_trace(go.Scatter(y=peak, mode='lines',
name='CumMax(x)[t]',
line=dict(color='green', dash='dash')))
fig.update_layout(
title="CumMax: High-Water Mark of a Random Walk",
xaxis_title="Index",
yaxis_title="Value",
margin=dict(l=20, r=20, t=60, b=20),
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
)
fig.show()
Implementation Details#
CumMax keeps a single double initialised to -infinity. Each input is compared and the larger value retained. There is no warmup. The numpy reference is numpy.maximum.accumulate.