Implement streaming min-max normalization: given multiple batches of data, update per-feature running min and max, and normalize each incoming batch.
Streaming normalization processes data in real-time without knowing the full dataset statistics upfront. Your implementation should maintain running minimum and maximum values for each feature, updating them as new batches arrive, then normalize each batch using the current global statistics.
Normalization Formula:
x′=max−min+ϵx−minD: int - Number of featuresstate: dict - Contains 'min' and 'max' arrays (shape D,)X_batch: array-like, shape (B, D) - Input batcheps: float - Small value to avoid division by zeroInput: streaming_minmax_init(D=2), streaming_minmax_update(state, [[1,3],[2,1]])
Output: streaming_minmax_init({'min': [inf,inf], 'max': [-inf,-inf]}), streaming_minmax_update([[0,1],[1,0]])
Input: streaming_minmax_init(D=1), streaming_minmax_update(state, [[5],[3]])
Output: streaming_minmax_init({'min': [inf], 'max': [-inf]}), streaming_minmax_update([[1],[0]])
Initialize with np.full() for min and max arrays.
Use np.minimum() and np.maximum() to update running statistics.
Use np.maximum() to handle constant features safely with eps.
Sign in to take notes on this problem
Accepts: number
Accepts: array
Implement streaming min-max normalization: given multiple batches of data, update per-feature running min and max, and normalize each incoming batch.
Streaming normalization processes data in real-time without knowing the full dataset statistics upfront. Your implementation should maintain running minimum and maximum values for each feature, updating them as new batches arrive, then normalize each batch using the current global statistics.
Normalization Formula:
x′=max−min+ϵx−minD: int - Number of featuresstate: dict - Contains 'min' and 'max' arrays (shape D,)X_batch: array-like, shape (B, D) - Input batcheps: float - Small value to avoid division by zeroInput: streaming_minmax_init(D=2), streaming_minmax_update(state, [[1,3],[2,1]])
Output: streaming_minmax_init({'min': [inf,inf], 'max': [-inf,-inf]}), streaming_minmax_update([[0,1],[1,0]])
Input: streaming_minmax_init(D=1), streaming_minmax_update(state, [[5],[3]])
Output: streaming_minmax_init({'min': [inf], 'max': [-inf]}), streaming_minmax_update([[1],[0]])
Initialize with np.full() for min and max arrays.
Use np.minimum() and np.maximum() to update running statistics.
Use np.maximum() to handle constant features safely with eps.
Sign in to take notes on this problem
Accepts: number
Accepts: array