onlinerake.OnlineRakingMWU¶
- class onlinerake.OnlineRakingMWU(targets, learning_rate=1.0, min_weight=0.001, max_weight=100.0, n_sgd_steps=3, verbose=False, track_convergence=True, convergence_window=20, compute_weight_stats=False, max_history=1000, track_kl_divergence=False)[source]¶
Online raking via multiplicative weights updates.
Parameters¶
- targets
Targets Target population proportions for each feature.
- learning_ratefloat, optional
Step size used in the exponent of the multiplicative update. A typical default is
learning_rate=1.0. The algorithm automatically clips updated log weights to the configured bounds before exponentiation. This avoids overflow in the multiplicative step, but large rates may still oscillate or leave substantial moment error.- min_weightfloat, optional
Lower bound applied to the weights after each update. This prevents weights from collapsing to zero. Must be positive.
- max_weightfloat, optional
Upper bound applied to the weights after each update. This prevents runaway weights. Must exceed
min_weight.- n_sgd_stepsint, optional
Number of multiplicative updates applied each time a new observation arrives.
- compute_weight_statsbool or int, optional
Controls computation of weight distribution statistics for performance. If True, compute on every call. If False, never compute. If integer k, compute every k observations. Default is False.
- max_historyint or None, optional
Cap on retained per-observation history,
Noneto disable it, as onOnlineRakingSGD. This subclass used to omit it, so the parent accepted it and the child raisedTypeErrorfor the same keyword.
- __init__(targets, learning_rate=1.0, min_weight=0.001, max_weight=100.0, n_sgd_steps=3, verbose=False, track_convergence=True, convergence_window=20, compute_weight_stats=False, max_history=1000, track_kl_divergence=False)[source]¶
Methods
__init__(targets[, learning_rate, ...])check_convergence([tolerance])Check the current squared moment error against an absolute tolerance.
detect_oscillation([threshold])Detect if loss is oscillating rather than converging.
partial_fit(obs)Consume a single observation and update weights multiplicatively.
partial_fit_batch(observations)Process multiple observations in batch.
Attributes
convergedReturn True if the algorithm has detected convergence.
convergence_stepGet step number where convergence was detected.
cumulative_kl_divergenceGet total KL divergence accumulated over all updates.
current_learning_rateGet current learning rate (may vary if using a schedule).
effective_sample_sizeReturn the effective sample size (ESS).
gradient_norm_historyGet history of gradient norms.
kl_divergence_historyGet history of KL divergence between consecutive weight updates.
learning_rate_historyGet history of learning rates used at each observation.
lossGet current squared-error loss.
loss_moving_averageReturn moving average of loss over convergence window.
marginsGet current weighted margins.
raw_marginsGet unweighted (raw) margins.
uses_lr_scheduleReturn True if using a dynamic learning rate schedule.
weight_distribution_statsReturn comprehensive weight distribution statistics.
weightsGet copy of current weight vector.
- targets