1
Fork 0

feat: generic network

This commit is contained in:
cedric 2026-04-02 17:38:46 +00:00
parent 2263c97fe8
commit 15ae86796f
5 changed files with 9 additions and 8 deletions

View file

View file

View file

@ -1,19 +1,20 @@
from typing import Sequence
from typing import Sequence, Callable
import flax.linen as nn
import jax.numpy as jnp
from flax.linen.initializers import constant, orthogonal
class Network(nn.Module):
hidden_size: int = 256
# example usage: network = SemiGenericNetwork(layer_sizes=[256, 256], activation=nn.relu)
# semi generic so we can easily make a config for it in experiments
class SemiGenericNetwork(nn.Module):
layer_sizes: Sequence[int] = [64, 64] # default 2 layers of 64 neurons
activation: Callable = nn.tanh # default tanh
@nn.compact
def __call__(self, x):
# x shape: (batch, obs_dim)
x = nn.Dense(self.hidden_size, kernel_init=orthogonal(jnp.sqrt(2)))(x)
x = nn.tanh(x)
x = nn.Dense(self.hidden_size, kernel_init=orthogonal(jnp.sqrt(2)))(x)
x = nn.tanh(x)
for size in self.layer_sizes:
x = nn.Dense(size, kernel_init=orthogonal(jnp.sqrt(2)))(x)
x = self.activation(x)
return x

View file

View file