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(Ω x + φ).
One multiplicative filter primitive for use inside a FourierNet. Following
Fathony et al. (2021, §4.1), the frequencies are drawn as
Ω_ij ~ 𝒩(0, σ_f² / D) with D = in_features, and the phases as
φ_i ~ Uniform(-π, π).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Omega
|
Frequency matrix |
required | |
phi
|
Phase vector |
required | |
in_features
|
Input dimension |
required | |
out_features
|
Output (filter) dimension |
required |
Examples:
A filter from three inputs to eight outputs:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import FourierFilter
>>> f = FourierFilter.init(3, 8, key=jr.PRNGKey(0))
>>> f(jnp.ones(3)).shape
(8,)
A one-dimensional input, with every response bounded by one:
>>> f_1d = FourierFilter.init(1, 4, key=jr.PRNGKey(0))
>>> bool(jnp.all(jnp.abs(f_1d(jnp.zeros(1))) <= 1.0))
True
Composition with vmap over a batch of inputs:
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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 | |
init(in_features: int, out_features: int, *, key: PRNGKeyArray, freq_scale: float = 256.0) -> FourierFilter
classmethod
¶
Construct with the Fathony et al. (2021, §4.1) initialisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Input dimension |
required |
out_features
|
int
|
Output (filter) dimension |
required |
key
|
PRNGKeyArray
|
PRNG key for the frequencies and phases. |
required |
freq_scale
|
float
|
Frequency scale |
256.0
|
Returns:
| Type | Description |
|---|---|
FourierFilter
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import FourierFilter
>>> f = FourierFilter.init(3, 8, key=jr.PRNGKey(0))
>>> f(jnp.ones(3)).shape
(8,)
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
GaborFilter
¶
Bases: Module
Single Gabor filter, a sinusoid under a Gaussian envelope.
g(x) = sin(Ω x + φ) ⊙ exp(-γ/2 · ‖x - μ‖²)
One multiplicative filter primitive for use inside a GaborNet. Following
Fathony et al. (2021, §4.2), each bandwidth is drawn as
γ_i ~ Gamma(α, β), each centre as μ_i ~ Uniform(domain), and the frequencies
as Ω_i ~ 𝒩(0, γ_i I_D), which ties the oscillation to the envelope width.
The bandwidth is stored as log γ, so positivity holds without constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Omega
|
Frequency matrix |
required | |
phi
|
Phase vector |
required | |
mu
|
Envelope centres |
required | |
log_gamma
|
Log bandwidth |
required | |
in_features
|
Input dimension |
required | |
out_features
|
Output (filter) dimension |
required | |
domain
|
Pair |
required |
Examples:
A filter from two inputs to six outputs:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import GaborFilter
>>> g = GaborFilter.init(2, 6, key=jr.PRNGKey(0))
>>> g(jnp.zeros(2)).shape
(6,)
A one-dimensional input with a wider centre domain:
>>> g_1d = GaborFilter.init(1, 4, key=jr.PRNGKey(0), domain=(-3.0, 3.0))
>>> g_1d(jnp.zeros(1)).shape
(4,)
Composition with vmap over a batch of inputs:
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
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 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 | |
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 the Fathony et al. (2021, §4.2) initialisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Input dimension |
required |
out_features
|
int
|
Output (filter) dimension |
required |
key
|
PRNGKeyArray
|
PRNG key for the bandwidths, centres, frequencies and phases. |
required |
domain
|
tuple[float, float]
|
Pair |
(-1.0, 1.0)
|
gamma_alpha
|
float
|
Shape |
6.0
|
gamma_beta
|
float
|
Rate |
1.0
|
Returns:
| Type | Description |
|---|---|
GaborFilter
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a size or a Gamma parameter is not positive, or if
|
Examples:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import GaborFilter
>>> g = GaborFilter.init(2, 6, key=jr.PRNGKey(0))
>>> g(jnp.zeros(2)).shape
(6,)
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
Composite networks¶
FourierNet
¶
Bases: Module
Multiplicative Fourier Filter Network (Fathony et al., 2021).
Chains FourierFilter primitives multiplicatively:
z₁ = g₁(x), z_{i+1} = g_{i+1}(x) ⊙ (W_i z_i + b_i), y = W_L z_L + b_L.
Each g_i is a FourierFilter of width hidden_features. The last linear is
the readout, which projects to out_features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
Length- |
required | |
linears
|
Length- |
required | |
in_features
|
Input dimension |
required | |
hidden_features
|
Filter and hidden width |
required | |
out_features
|
Output dimension |
required | |
depth
|
Number of filter layers |
required |
Examples:
A network from two inputs to one output:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import FourierNet
>>> net = FourierNet.init(2, 16, 1, depth=3, key=jr.PRNGKey(0))
>>> net(jnp.zeros(2)).shape
(1,)
A one-dimensional input with four outputs:
>>> net_1d = FourierNet.init(1, 8, 4, depth=2, key=jr.PRNGKey(0))
>>> net_1d(jnp.ones(1)).shape
(4,)
Composition with vmap over a batch of inputs:
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
359 360 361 362 363 364 365 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 477 478 479 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Input dimension |
required |
hidden_features
|
int
|
Filter and hidden width |
required |
out_features
|
int
|
Output dimension |
required |
depth
|
int
|
Number of filter layers |
required |
key
|
PRNGKeyArray
|
PRNG key, split into one key per filter and one per linear. |
required |
freq_scale
|
float
|
Frequency scale |
256.0
|
Returns:
| Type | Description |
|---|---|
FourierNet
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
GaborNet
¶
Bases: Module
Multiplicative Gabor Filter Network (Fathony et al., 2021).
The same MFN topology as FourierNet, but each g_i is a GaborFilter, a
sinusoidal oscillation modulated by a Gaussian envelope:
g_i(x) = sin(Ω_i x + φ_i) ⊙ exp(-γ_i/2 · ‖x - μ_i‖²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
Length- |
required | |
linears
|
Length- |
required | |
in_features
|
Input dimension |
required | |
hidden_features
|
Filter and hidden width |
required | |
out_features
|
Output dimension |
required | |
depth
|
Number of filter layers |
required | |
domain
|
Pair |
required | |
gamma_alpha
|
Shape |
required | |
gamma_beta
|
Rate |
required |
Examples:
A network from two inputs to one output:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields import GaborNet
>>> net = GaborNet.init(2, 16, 1, depth=3, key=jr.PRNGKey(0))
>>> net(jnp.zeros(2)).shape
(1,)
A one-dimensional input with four outputs:
Composition with vmap over a batch of inputs:
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_mfn.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_features
|
int
|
Input dimension |
required |
hidden_features
|
int
|
Filter and hidden width |
required |
out_features
|
int
|
Output dimension |
required |
depth
|
int
|
Number of filter layers |
required |
key
|
PRNGKeyArray
|
PRNG key, split into one key per filter and one per linear. |
required |
domain
|
tuple[float, float]
|
Pair |
(-1.0, 1.0)
|
gamma_alpha
|
float
|
Shape |
6.0
|
gamma_beta
|
float
|
Rate |
1.0
|
Returns:
| Type | Description |
|---|---|
GaborNet
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/geonnax/_src/fields/_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 for user-supplied filter and linear callables.
Implements the multiplicative chaining of Fathony et al. (2021):
z₁ = g₁(x), z_{i+1} = g_{i+1}(x) ⊙ (W_i z_i + b_i), y = W_L z_L + b_L.
This is an escape hatch: it lets custom filter families sit in the MFN topology
without subclassing FourierNet or GaborNet. filters and linears must
have the same length L. x is one example of shape (D,); use jax.vmap
for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' D']
|
Input vector |
required |
filters
|
Sequence[Callable[[Array], Array]]
|
The |
required |
linears
|
Sequence[Callable[[Array], Array]]
|
The |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' O']
|
The output |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
A FourierNet topology with two layers:
>>> import jax.numpy as jnp, jax.random as jr
>>> from geonnax.fields 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,)
Mismatched lengths are rejected:
>>> short, x0 = net.linears[:1], jnp.zeros(2)
>>> mfn_forward(x0, net.filters, short)
Traceback (most recent call last):
ValueError: filters and linears must have equal length; got 2 and 1.
Composition with vmap over a batch of inputs:
>>> import jax
>>> jax.vmap(lambda v: mfn_forward(v, net.filters, net.linears))(
... jnp.ones((5, 2))
... ).shape
(5, 3)