onlinerake.OnlineRakingMWU

class onlinerake.OnlineRakingMWU(targets, learning_rate: float = 1.0, min_weight: float = 0.001, max_weight: float = 100.0, n_steps: int = 3, verbose: bool = False, track_convergence: bool = True, convergence_window: int = 20, compute_weight_stats: bool | int = False)[source]

Bases: OnlineRakingSGD

Online raking via multiplicative weights updates.

Parameters:
  • targets (Targets) – Target population proportions for each demographic characteristic.

  • learning_rate (float, optional) – Step size used in the exponent of the multiplicative update. A typical default is learning_rate=1.0. The algorithm automatically clips extreme exponents based on the weights dtype to prevent numerical overflow/underflow, making it robust even with very large learning rates.

  • min_weight (float, optional) – Lower bound applied to the weights after each update. This prevents weights from collapsing to zero. Must be positive.

  • max_weight (float, optional) – Upper bound applied to the weights after each update. This prevents runaway weights. Must exceed min_weight.

  • n_steps (int, optional) – Number of multiplicative updates applied each time a new observation arrives.

  • compute_weight_stats (bool or int, optional) – Controls computation of weight distribution statistics for performance. If True, compute on every call. If False, use cached values. If integer k, compute every k observations. Default is False.

__init__(targets, learning_rate: float = 1.0, min_weight: float = 0.001, max_weight: float = 100.0, n_steps: int = 3, verbose: bool = False, track_convergence: bool = True, convergence_window: int = 20, compute_weight_stats: bool | int = False) None[source]

Methods

__init__(targets[, learning_rate, ...])

check_convergence([tolerance])

Check if algorithm has converged based on loss stability.

detect_oscillation([threshold])

Detect if loss is oscillating rather than converging.

fit_one(obs)

Consume a single observation and update weights multiplicatively.

partial_fit(obs)

Consume a single observation and update weights multiplicatively.

Attributes

converged

Return True if the algorithm has detected convergence.

convergence_step

Return the step number where convergence was detected, if any.

effective_sample_size

Return the effective sample size (ESS).

gradient_norm_history

Return history of gradient norms for convergence analysis.

loss

Return the current squared‑error loss on margins.

loss_moving_average

Return moving average of loss over convergence window.

margins

Return current weighted margins as a dictionary.

raw_margins

Return unweighted (raw) margins as a dictionary.

weight_distribution_stats

Return comprehensive weight distribution statistics.

weights

Return a copy of the current weight vector.

fit_one(obs: Any) None

Consume a single observation and update weights multiplicatively.

partial_fit(obs: Any) None[source]

Consume a single observation and update weights multiplicatively.