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

targetsTargets

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, None to disable it, as on OnlineRakingSGD. This subclass used to omit it, so the parent accepted it and the child raised TypeError for 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]
Parameters:
  • learning_rate (float | LearningRateSchedule)

  • min_weight (float)

  • max_weight (float)

  • n_sgd_steps (int)

  • verbose (bool)

  • track_convergence (bool)

  • convergence_window (int)

  • compute_weight_stats (bool | int)

  • max_history (int | None)

  • track_kl_divergence (bool)

Return type:

None

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

converged

Return True if the algorithm has detected convergence.

convergence_step

Get step number where convergence was detected.

cumulative_kl_divergence

Get total KL divergence accumulated over all updates.

current_learning_rate

Get current learning rate (may vary if using a schedule).

effective_sample_size

Return the effective sample size (ESS).

gradient_norm_history

Get history of gradient norms.

kl_divergence_history

Get history of KL divergence between consecutive weight updates.

learning_rate_history

Get history of learning rates used at each observation.

loss

Get current squared-error loss.

loss_moving_average

Return moving average of loss over convergence window.

margins

Get current weighted margins.

raw_margins

Get unweighted (raw) margins.

uses_lr_schedule

Return True if using a dynamic learning rate schedule.

weight_distribution_stats

Return comprehensive weight distribution statistics.

weights

Get copy of current weight vector.

Parameters:
  • learning_rate (float | LearningRateSchedule)

  • min_weight (float)

  • max_weight (float)

  • n_sgd_steps (int)

  • verbose (bool)

  • track_convergence (bool)

  • convergence_window (int)

  • compute_weight_stats (bool | int)

  • max_history (int | None)

  • track_kl_divergence (bool)