Multiplicative Filter Networks (MFN)¶
Multiplicative Filter Networks (Fathony, Sahu, Willmott, Kolter — ICLR 2021) replace MLP composition with multiplicative filter chaining. Instead of deeply composing nonlinearities, each layer multiplies the previous activation by a new filter evaluated directly on the original input:
Two filter families ship in pyrox_nn:
- FourierNet — \(g_i(x) = \sin(\Omega_i x + \varphi_i)\), frequency-domain filters. Products of sinusoids span exponentially many frequencies with depth \(L\).
- GaborNet — \(g_i(x) = \sin(\Omega_i x + \varphi_i) \odot \exp(-\tfrac{\gamma_i}{2}\|x - \mu_i\|^2)\), Gabor atoms with learned frequency \(\Omega_i\), phase \(\varphi_i\), location \(\mu_i\), and bandwidth \(\gamma_i\).
Connection to RBFFourierFeatures:
A GaborNet with depth=1 and \(\mu = 0\) is a localized variant of random Fourier features.
As \(\gamma \to 0\) (very wide envelope) it recovers the plain RBF-RFF feature map.
See HSGPFeatures for the related Hilbert-space GP basis.
Quick example¶
import jax.random as jr
from pyrox_nn import GaborNet
from numpyro import handlers
key = jr.PRNGKey(0)
# Deterministic GaborNet
net = GaborNet.init(in_features=2, hidden_features=64, out_features=1, depth=3, key=key)
import jax.numpy as jnp
x = jnp.ones((100, 2))
y = net(x) # (100, 1)
# Bayesian GaborNet — sample sites registered for every parameter
from pyrox_nn import BayesianGaborNet
bnet = BayesianGaborNet.init(
in_features=2, hidden_features=64, out_features=1, depth=3, key=key,
pyrox_name="gabor",
)
with handlers.seed(rng_seed=1):
y_sample = bnet(x) # weights sampled from prior
Filter primitives¶
FourierFilter
¶
Bases: Module
Single Fourier filter: \(g(x) = \sin(\Omega x + \varphi)\).
One multiplicative filter primitive for use inside a
FourierNet.
Init follows Fathony et al. (2021) §4.1: frequencies are drawn as
\(\Omega_{ij} \sim \mathcal{N}(0,\,\sigma_f^2/D)\) where
\(D\) is in_features and \(\sigma_f\) is
freq_scale; phases are drawn as
\(\varphi_i \sim \mathrm{Uniform}(-\pi, \pi)\).
Attributes:
| Name | Type | Description |
|---|---|---|
Omega |
Float[Array, 'out in']
|
Frequency matrix of shape |
phi |
Float[Array, ' out']
|
Phase vector of shape |
in_features |
int
|
Input dimension. |
out_features |
int
|
Output (filter) dimension. |
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
init(in_features: int, out_features: int, *, key: PRNGKeyArray, freq_scale: float = 256.0) -> FourierFilter
classmethod
¶
Construct with Fathony-et-al. §4.1 initialization.
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.mfn import FourierFilter
>>> f = FourierFilter.init(3, 8, key=jr.PRNGKey(0))
>>> f(jnp.ones(3)).shape # (3,) -> (8,)
(8,)
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
GaborFilter
¶
Bases: Module
Single Gabor filter: \(g(x) = \sin(\Omega x + \varphi) \odot \exp(-\tfrac{\gamma}{2}\|x - \mu\|^2)\).
Init follows Fathony et al. (2021) §4.2: per-filter \(\gamma_i \sim \mathrm{Gamma}(\alpha, \beta)\), \(\mu_i \sim \mathrm{Uniform}(\text{domain})\), \(\Omega_{i,:} \sim \mathcal{N}(0, \gamma_i\,I_D)\) (the load-bearing tied initialization).
\(\gamma\) is stored in log space so positivity is preserved without optimizer constraints.
Attributes:
| Name | Type | Description |
|---|---|---|
Omega |
Float[Array, 'out in']
|
Frequency matrix |
phi |
Float[Array, ' out']
|
Phase vector |
mu |
Float[Array, 'out in']
|
Envelope centres |
log_gamma |
Float[Array, ' out']
|
Log-bandwidth |
in_features |
int
|
Input dimension. |
out_features |
int
|
Output (filter) dimension. |
domain |
tuple[float, float]
|
|
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
init(in_features: int, out_features: int, *, key: PRNGKeyArray, domain: tuple[float, float] = (-1.0, 1.0), gamma_alpha: float = 6.0, gamma_beta: float = 1.0) -> GaborFilter
classmethod
¶
Construct with Fathony-et-al. §4.2 initialization.
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.mfn import GaborFilter
>>> g = GaborFilter.init(2, 6, key=jr.PRNGKey(0))
>>> g(jnp.zeros(2)).shape # (2,) -> (6,)
(6,)
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
Composite networks¶
FourierNet
¶
Bases: Module
Multiplicative Fourier Filter Network (Fathony et al., ICLR 2021).
Chains FourierFilter primitives multiplicatively:
Each \(g_i\) is a FourierFilter of width
hidden_features; the last linear is the readout projecting to
out_features.
Attributes:
| Name | Type | Description |
|---|---|---|
filters |
list[FourierFilter]
|
Length- |
linears |
list[Linear]
|
Length- |
in_features |
int
|
Input dimension. |
hidden_features |
int
|
Filter / hidden width. |
out_features |
int
|
Output dimension. |
depth |
int
|
Number of filter layers \(L\). |
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
init(in_features: int, hidden_features: int, out_features: int, *, depth: int, key: PRNGKeyArray, freq_scale: float = 256.0) -> FourierNet
classmethod
¶
Construct a FourierNet with depth filters and readout linears.
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.mfn import FourierNet
>>> net = FourierNet.init(2, 16, 1, depth=3, key=jr.PRNGKey(0))
>>> net(jnp.zeros(2)).shape # (2,) -> (1,)
(1,)
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
GaborNet
¶
Bases: Module
Multiplicative Gabor Filter Network (Fathony et al., ICLR 2021).
Same MFN topology as FourierNet but each \(g_i\) is a
GaborFilter — a sinusoidal oscillation modulated by a
Gaussian envelope:
Attributes:
| Name | Type | Description |
|---|---|---|
filters |
list[GaborFilter]
|
Length- |
linears |
list[Linear]
|
Length- |
in_features |
int
|
Input dimension. |
hidden_features |
int
|
Filter / hidden width. |
out_features |
int
|
Output dimension. |
depth |
int
|
Number of filter layers \(L\). |
domain |
tuple[float, float]
|
|
gamma_alpha |
float
|
Shape parameter of the \(\gamma\) Gamma prior. |
gamma_beta |
float
|
Rate parameter of the \(\gamma\) Gamma prior. |
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
init(in_features: int, hidden_features: int, out_features: int, *, depth: int, key: PRNGKeyArray, domain: tuple[float, float] = (-1.0, 1.0), gamma_alpha: float = 6.0, gamma_beta: float = 1.0) -> GaborNet
classmethod
¶
Construct a GaborNet with depth Gabor filters and readouts.
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.mfn import GaborNet
>>> net = GaborNet.init(2, 16, 1, depth=3, key=jr.PRNGKey(0))
>>> net(jnp.zeros(2)).shape # (2,) -> (1,)
(1,)
Source code in .venv/lib/python3.12/site-packages/geonnax/mfn.py
Bayesian variants¶
BayesianFourierNet
¶
Bases: PyroxModule
FourierNet with Bayesian priors on all filter and linear weights.
A thin subclass of FourierNet that overrides __call__ to
register NumPyro sample sites for every parameter:
- Per filter i:
filter_{i}.Omegaandfilter_{i}.phi. - Per linear i:
linear_{i}.Wandlinear_{i}.b.
Total number of sites: \(4L\) where \(L\) is depth.
Priors:
- \(\Omega_i \sim \mathcal{N}(0, \sigma^2)\) (matrix).
- \(\varphi_i \sim \mathrm{Uniform}(-\pi, \pi)\).
- \(W_i \sim \mathcal{N}(0, \sigma^2)\) (matrix).
- \(b_i \sim \mathcal{N}(0, \sigma^2)\) (vector).
Attributes:
| Name | Type | Description |
|---|---|---|
prior_std |
float
|
Prior standard deviation \(\\sigma\) for Gaussian sites (default 1.0). Phase sites always use \(\mathrm{Uniform}(-\pi, \pi)\). |
Source code in packages/pyrox-nn/src/pyrox_nn/_mfn.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
init(in_features: int, hidden_features: int, out_features: int, *, depth: int, key: PRNGKeyArray, freq_scale: float = 256.0, prior_std: float = 1.0, pyrox_name: str | None = None) -> BayesianFourierNet
classmethod
¶
Construct a BayesianFourierNet.
Args mirror FourierNet.init, plus:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_std
|
float
|
Prior standard deviation for Gaussian sites (default 1.0). |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/pyrox-nn/src/pyrox_nn/_mfn.py
BayesianGaborNet
¶
Bases: PyroxModule
GaborNet with Bayesian priors on all filter and linear weights.
A thin subclass of GaborNet that overrides __call__ to
register NumPyro sample sites for every parameter:
- Per filter i:
filter_{i}.Omega,filter_{i}.phi,filter_{i}.mu, andfilter_{i}.log_gamma. - Per linear i:
linear_{i}.Wandlinear_{i}.b.
Total number of sites: \(6L\) where \(L\) is depth.
Priors:
- \(\Omega_i \sim \mathcal{N}(0, \sigma^2)\) (matrix).
- \(\varphi_i \sim \mathrm{Uniform}(-\pi, \pi)\).
- \(\mu_i \sim \mathrm{Uniform}(\texttt{domain\_low},\texttt{domain\_high})\).
- \(\log\gamma_i \sim \mathcal{N}(0, \sigma^2)\) (log-space).
- \(W_i \sim \mathcal{N}(0, \sigma^2)\) (matrix).
- \(b_i \sim \mathcal{N}(0, \sigma^2)\) (vector).
Attributes:
| Name | Type | Description |
|---|---|---|
prior_std |
float
|
Prior standard deviation \(\\sigma\) for Gaussian and log-gamma sites (default 1.0). |
Source code in packages/pyrox-nn/src/pyrox_nn/_mfn.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
init(in_features: int, hidden_features: int, out_features: int, *, depth: int, key: PRNGKeyArray, domain: tuple[float, float] = (-1.0, 1.0), gamma_alpha: float = 6.0, gamma_beta: float = 1.0, prior_std: float = 1.0, pyrox_name: str | None = None) -> BayesianGaborNet
classmethod
¶
Construct a BayesianGaborNet.
Args mirror GaborNet.init, plus:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior_std
|
float
|
Prior standard deviation for Gaussian and log-gamma sites (default 1.0). |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/pyrox-nn/src/pyrox_nn/_mfn.py
Pure-JAX helper¶
mfn_forward(x: Float[Array, ' D'], filters: Sequence[Callable[[JaxArray], JaxArray]], linears: Sequence[Callable[[JaxArray], JaxArray]]) -> Float[Array, ' O']
¶
Pure-JAX MFN forward pass given user-supplied filter and linear callables.
Implements the Fathony et al. (2021) multiplicative chaining:
Exists as an escape hatch so users can plug custom filter families
into the MFN topology without subclassing FourierNet or
GaborNet.
filters and linears must have the same length \(L\).
x is a single example of shape (in_features,); use
jax.vmap for batched application.
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.mfn import FourierNet, mfn_forward
>>> net = FourierNet.init(2, 4, 3, depth=2, key=jr.PRNGKey(0))
>>> mfn_forward(jnp.zeros(2), net.filters, net.linears).shape
(3,)