ENH: Enable batch size > 1 for CAR distribution
Author: ckrapuCreated Aug 28, 2026Updated Sep 14, 2026
Labelsfeature request
Before
Currently, the CAR distribution takes only scalar values for alpha and tau, requiring the user to instantiate multiple random variables even when the adjacency matrix is shared.
import numpy as np
import pymc as pm
import pytensor.tensor as pt
n_fields = 3
n_locations = W.shape[0]
with pm.Model():
alpha = pm.Beta("alpha", 2, 2, shape=n_fields)
tau = pm.Gamma("tau", 2, 1, shape=n_fields)
car = pt.stack([
pm.CAR(
f"car_{i}",
mu=np.zeros(n_locations),
W=W,
alpha=alpha[i],
tau=tau[i],
)
for i in range(n_fields)
])After
This proposal allows alpha and tau to be vector-valued parameters of pm.CAR, enabling a batch size greater than one:
import numpy as np
import pymc as pm
n_fields = 3
n_locations = W.shape[0]
with pm.Model():
alpha = pm.Beta("alpha", 2, 2, shape=n_fields)
tau = pm.Gamma("tau", 2, 1, shape=n_fields)
car = pm.CAR(
"car",
mu=np.zeros(n_locations),
W=W,
alpha=alpha,
tau=tau,
)
# car.shape == (n_fields, n_locations)
Context for the issue
This pattern arises frequently in multivariate spatial statistics and probabilistic computer-vision models, where several spatial fields share the same adjacency structure but require different autocorrelation and precision parameters.
Source: pymc-devs/pymc