DiscreteFlow¶
-
class DiscreteFlow : public madspace::Mapping¶
Autoregressive adaptive sampler for discrete choices.
Like DiscreteSampler, but the categorical distribution for each discrete dimension is predicted by an MLP subnetwork from the earlier choices and an optional conditioning input [1]. The subnetwork weights are compute-graph globals named after
prefix; callinitialize_globals(context)once before use.batchis the leading batch dimension.dindexes the discrete dimensions.Inputs
random_d–float, shape(batch,)– one uniform number per dimension.
Conditions
condition–float, shape(batch, condition_dim)– conditioning input. Present only whencondition_dimis nonzero.prior_d–float, shape(batch, option_counts[d])– prior category weights. Present only for the dimensions indims_with_prior.
Outputs
index_d–int, shape(batch,)– the chosen category per dimension.
In addition every mapping returns a
weight(float, shape(batch,)), the Jacobian of the transformation.References
[1] T. Heimel, O. Mattelaer, R. Winterhalder, “MadSpace”, https://arxiv.org/abs/2602.06895 (Sec. 3.2.2)
Public Functions
-
DiscreteFlow(const std::vector<std::size_t> &option_counts, const std::string &prefix = "", const std::vector<std::size_t> &dims_with_prior = {}, std::size_t condition_dim = 0, std::size_t subnet_hidden_dim = 32, std::size_t subnet_layers = 3, MLP::Activation subnet_activation = MLP::leaky_relu)¶
- Parameters:
option_counts – Number of categories for each discrete dimension.
prefix – Prefix for the trainable global names.
dims_with_prior – Dimensions conditioned on a
prior_dinput.condition_dim – Width of the conditioning input;
0for none.subnet_hidden_dim – Hidden width of the MLP subnetworks.
subnet_layers – Number of layers in the subnetworks.
subnet_activation – Activation of the subnetworks.
-
inline const std::vector<std::size_t> &option_counts() const¶
Number of categories per discrete dimension.
-
inline std::size_t condition_dim() const¶
Width of the conditioning input.
-
void initialize_globals(ContextPtr context, std::optional<std::uint64_t> seed = std::nullopt) const¶
Register the flow’s trainable parameters on
context.- Parameters:
context – Context receiving the globals.
seed – Seed for the random initialization. If unset (the default), the initialization is non-deterministic.