DiscreteOptimizer

class madspace.DiscreteOptimizer(self: madspace._madspace_py.DiscreteOptimizer, contexts: collections.abc.Sequence[madspace._madspace_py.Context], prob_names: collections.abc.Sequence[str])

Bases: pybind11_object

Refines the categorical probabilities of a DiscreteSampler or DiscreteFlow from accumulated per-category statistics.

The training-time counterpart of DiscreteHistogram — add_data feeds in the per-category weight sums accumulated during a warm-up run, and optimize rewrites every prob_names global on every context in contexts with the refined distribution.

Parameters:
  • contexts – Contexts sharing the probabilities to refine.

  • prob_names – Global names of the probability tensors, one per discrete dimension.

add_data(self: madspace._madspace_py.DiscreteOptimizer, values_and_counts: collections.abc.Sequence[object]) → None

Accumulate one batch of values and counts for each dimension of prob_names, interleaved as [values_0, counts_0, values_1, ...].

optimize(self: madspace._madspace_py.DiscreteOptimizer) → None

Refine the probabilities from the accumulated data and write them back to every context.