Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Neural Network Utilities

sindae.nn_utils

MLP architecture and parameter utilities built on Equinox.

Usage

import jax
import jax.numpy as jnp
from sindae import SimpleMLP, flatten_fn, make_unflatten_fn

mlp = SimpleMLP(
    in_size=2, out_size=1,
    widths=[16, 16],                              # two hidden layers
    activations=[jax.nn.softplus, jax.nn.softplus],
    key=jax.random.PRNGKey(0),
)

y = mlp(jnp.array([0.5, 1.0]))                    # forward pass -> shape (1,)

flat    = flatten_fn(mlp)                         # trainable params as a 1-D array
rebuild = make_unflatten_fn(mlp)                  # inverse: flat array -> SimpleMLP
mlp2    = rebuild(flat)                           # round-trips back to the same network

API reference

SimpleMLP

class SimpleMLP(
    in_size: int,
    out_size: int,
    widths: List[int],
    activations: List[Callable],
    *,
    key: jax.Array = jax.random.PRNGKey(0),
)

Parameters

Methods

__call__

__call__(x)

Parameters

flatten_fn

flatten_fn(mlp)

Flatten an equinox SimpleMLP’s trainable parameters to a 1-D array.

Parameters

make_unflatten_fn

make_unflatten_fn(mlp)

Return a callable that rebuilds a SimpleMLP from a flat parameter array.

Parameters