DiscreteOptimizer

class DiscreteOptimizer

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.

Public Functions

inline DiscreteOptimizer(const std::vector<ContextPtr> &contexts, const std::vector<std::string> &prob_names)
Parameters:
  • contexts – Contexts sharing the probabilities to refine.

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

void add_data(const std::vector<Tensor> &values_and_counts)

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

void optimize()

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