MLP

class madspace.MLP(self: madspace._madspace_py.MLP, input_dim: SupportsInt, output_dim: SupportsInt, hidden_dim: SupportsInt = 32, layers: SupportsInt = 3, activation: madspace._madspace_py.MLP.Activation = <Activation.leaky_relu: 1>, prefix: str = '')

Bases: FunctionGenerator

Fully connected neural network as a compute-graph function.

A stack of layers dense layers of width hidden_dim with activation between them and a linear output layer. Used as the subnetwork of the Flow and DiscreteFlow adaptive samplers [1]. The weights and biases are compute-graph globals named with prefix. Call initialize_globals(context) once before use.

batch is the leading batch dimension.

Arguments

  • input – float, shape (batch, input_dim) – the network input.

Returns

  • output – float, shape (batch, output_dim) – the network output.

References

Parameters:
  • input_dim – Input width.

  • output_dim – Output width.

  • hidden_dim – Hidden-layer width.

  • layers – Number of layers.

  • activation – Activation between the hidden layers.

  • prefix – Prefix for the trainable global names.

class Activation(*args, **kwargs)

Bases: pybind11_object

Members:

relu

leaky_relu

elu

gelu

sigmoid

softplus

linear

Overloaded function.

  1. __init__(self: madspace._madspace_py.MLP.Activation, value: typing.SupportsInt) -> None

  2. __init__(self: madspace._madspace_py.MLP.Activation, name: str) -> None

elu = <Activation.elu: 2>
gelu = <Activation.gelu: 3>
leaky_relu = <Activation.leaky_relu: 1>
linear = <Activation.linear: 6>
MLP.Activation.name -> str
relu = <Activation.relu: 0>
sigmoid = <Activation.sigmoid: 4>
softplus = <Activation.softplus: 5>
property value
elu = <Activation.elu: 2>
gelu = <Activation.gelu: 3>
global_names(self: madspace._madspace_py.MLP) → list[str]

Global names of all trainable parameters.

initialize_globals(self: madspace._madspace_py.MLP, context: madspace._madspace_py.Context, seed: SupportsInt | None = None) → None

Register the network’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.

input_dim(self: madspace._madspace_py.MLP) → int

Input width.

last_layer_bias_name(self: madspace._madspace_py.MLP) → str

Global name of the final layer’s bias vector.

leaky_relu = <Activation.leaky_relu: 1>
linear = <Activation.linear: 6>
output_dim(self: madspace._madspace_py.MLP) → int

Output width.

relu = <Activation.relu: 0>
sigmoid = <Activation.sigmoid: 4>
softplus = <Activation.softplus: 5>