Class SlidingWindow

template<typename NT>
class SlidingWindow

Sliding window for tracking convergence based on relative error Maintains a fixed-size window of recent values to detect when optimization has converged by comparing the oldest and newest entries.

Template Parameters:

NT – Numeric type for stored values

Public Functions

inline SlidingWindow(int windowSize)

Construct a sliding window with specified size

Parameters:

windowSize[in] Maximum number of values to store

inline void push(NT value)

Add a new value to the window Adds value to the front of the window. If window is full, removes the oldest value from the back.

Parameters:

value[in] The new value to add

inline NT getRelativeError() const

Calculate relative error between newest and oldest values Computes |oldest - newest| / |oldest| to measure convergence. Returns 1.0 if window not full or to avoid division by zero.

Returns:

Relative error in range [0, infinity), or 1.0 if not converged

inline bool isFull() const

Check if window is full

Returns:

True if window has collected windowSize entries, false otherwise

inline void clear()

Clear all values from the window Resets the window to empty state.

Public Members

std::list<NT> values

Stored values (newest at front, oldest at back)

int windowSize

Maximum number of values to store in the window.

int numEntries

Current number of entries in the window.