Spatial models often force a tradeoff between interpretability (classical CAR), flexibility (Gaussian processes), and computational scalability.
SDM-CAR is a modular framework designed to make these tradeoffs explicit and controllable. Rather than fixing a neighborhood-based precision matrix, the framework parameterizes spatial dependence in the graph spectral domain, allowing controlled movement between rigid CAR models and flexible, nonparametric spectral priors—while retaining scalable inference.
The system supports:
- exact recovery of classical CAR models,
- progressively more flexible spectral families,
- collapsed variational inference (VI) for fast experimentation,
- collapsed Metropolis-within-Gibbs MCMC for validation,
- and a filter-agnostic experimental pipeline for fair comparison.
All inference—VI or MCMC, across any filter family—is executed through a single, filter-agnostic runner.
SDM-CAR was designed around several practical constraints:
Dense Gaussian process models scale as
Decision: Represent spatial covariance in the graph spectral domain so that:
- covariance is diagonal in the eigenbasis,
- inference reduces to elementwise operations,
- flexibility is introduced via
$F(\lambda)$ instead of dense matrices.
Highly flexible spectral parameterizations can introduce ridges and non-identifiability.
Decision:
- enforce positivity through constrained parameterizations,
- structure MCMC proposals in parameter blocks,
- implement ridge diagnostics and spectrum error metrics,
- benchmark VI against collapsed MCMC.
Variational inference is fast but may underestimate uncertainty. MCMC is accurate but computationally heavier.
Decision:
- implement both collapsed VI and collapsed MCMC,
- ensure they operate on identical abstractions,
- directly quantify discrepancies between them.
Conditional Autoregressive (CAR) models are widely used for spatially indexed data, but they rely on fixed neighborhood-based precision structures that restrict flexibility and impose strong structural assumptions.
SDM-CAR replaces fixed CAR precision matrices with parametric spectral filters of a graph Laplacian, yielding a flexible covariance model of the form
where
This formulation:
- strictly generalizes classical CAR models,
- provides interpretable parameters controlling variance, range, and smoothness,
- recovers CAR exactly as a special case,
- separates graph construction from covariance modeling,
- enables scalable inference via spectral diagonalization.
Importantly, SDM-CAR is graph-based rather than distance-based. Spatial dependence is defined relative to the spectrum of an arbitrary graph Laplacian — not directly as a function of Euclidean distance. This allows the framework to operate on any domain where a meaningful graph structure can be defined.
Both collapsed variational inference (VI) and collapsed Metropolis-within-Gibbs MCMC are implemented under a shared abstraction, enabling principled comparison between approximate and exact inference.
The current implementation supports:
- k-nearest-neighbor (kNN) graph construction on regular grids,
- weighted Laplacian construction,
- full eigendecomposition for spectral diagonalization,
- filter-agnostic inference over arbitrary Laplacians.
All experiments in this repository are conducted on grid-based graphs constructed via kNN, demonstrating that:
- SDM-CAR does not require explicit covariance kernels of the form
$k(|x_i - x_j|)$ , - spatial smoothness is controlled entirely in the spectral domain,
- model flexibility arises from
$F(\lambda;\theta)$ rather than fixed precision templates.
Because SDM-CAR depends only on the graph Laplacian, the framework naturally extends to:
- irregular spatial lattices (e.g., administrative region adjacency graphs),
- transportation or road networks,
- social and communication networks,
- feature-similarity graphs (e.g., kNN in embedding space),
- community-structured or modular graphs,
- non-Euclidean domains such as brain connectivity networks.
Planned future directions include:
- experiments on non-geometric graph constructions,
- robustness analysis under graph rewiring,
- learned or data-driven graph structures,
- sparse eigensolvers for large-scale graphs,
- structured priors over graph spectra. These extensions would further demonstrate the generality of the spectral framework beyond grid-based spatial settings.
Let
denote the eigendecomposition of a graph Laplacian constructed from spatial locations.
The spatial random effect is defined as
where
This induces the covariance
The observation model is
All inference is performed after analytically marginalizing
When the spectral filter is chosen as
the resulting covariance satisfies
which corresponds exactly to a proper CAR model.
This guarantees that SDM-CAR strictly contains classical CAR as a special case and allows direct empirical validation against established spatial models.
All filters are implemented under a unified interface and support both VI and MCMC.
| Filter family | Spectrum |
Interpretation |
|---|---|---|
| Classic CAR | Classical intrinsic CAR (fixed ridge) | |
| Inverse-linear CAR | Proper CAR with learnable ridge | |
| Leroux CAR | Convex blend of IID and CAR | |
| Matérn-like | Learnable smoothness exponent | |
| Polynomial / Rational | Low-order polynomial or rational functions of |
Structured parametric flexibility |
| Multiscale bump mixture | Mixture of localized spectral bumps (multi-scale spatial structure) | |
| Log-spline | Semi-nonparametric spectral correction |
Where:
- Multiscale bump mixture models the spectrum as a weighted sum of Gaussian bumps in log-frequency space, enabling the model to capture localized spectral energy and multi-scale spatial structure.
- The bump centers
$m_k$ are constrained to the valid log-frequency domain [ \log(\lambda + \varepsilon_{\text{car}}) \in [\log(\varepsilon_{\text{car}}), \log(\lambda_{\max} + \varepsilon_{\text{car}})] ] via a sigmoid transformation. - Mixture weights
$w_k$ are obtained through a softmax transformation of unconstrained logits. - Width parameters
$s_k$ are constrained to be positive via a softplus transform with a minimum width for numerical stability. -
$s(\lambda)$ in Log-spline is a B-spline expansion over$[0, \lambda_{\max}]$ . - Polynomial/Rational filters allow low-degree flexible approximations to unknown spectra.
- Leroux provides a proper CAR with bounded spectrum.
-
Classic CAR fixes the ridge parameter to a known
$\varepsilon_{\text{car}}$ .
Each filter family defines:
- unconstrained parameterization,
- positivity-preserving transforms,
- KL divergence to priors (for VI),
- block structure for MCMC proposals,
pack()/unpack()API for sampler compatibility,- compatibility with the benchmark registry system.
- Spatial effect
$\phi$ integrated out analytically - Exact conditional Gaussian posterior for
$\beta$ - Monte Carlo integration only over spectral hyperparameters
- Efficient for large graphs and rapid experimentation
- Spatial effect analytically marginalized
- Gibbs updates for regression coefficients
- Random-walk MH updates for spectral hyperparameters
- Blockwise proposals aligned with filter structure
- Used as a gold standard for validation
Both inference methods operate on the same model and filter abstractions.
The repository is organized to cleanly separate modeling and inference logic from experimental configuration and execution.
sdm-car/
│
├── sdmcar/ # Core research library (model + inference)
│ ├── graph.py # Graph construction and Laplacian eigendecomposition
│ ├── filters.py # Spectral filter families (VI + MCMC compatible)
│ ├── models.py # Collapsed variational inference engine
│ ├── mcmc.py # Collapsed Metropolis-within-Gibbs sampler
│ ├── diagnostics.py # Posterior diagnostics and visualization
│ └── utils.py # Shared utilities (transforms, KLs, helpers)
│
├── examples/
│ ├── run_benchmark.py # Universal benchmark runner (VI + MCMC comparison)
│ ├── run_misspec_demo.py # Spectral misspecification experiments
│ ├── run_surface_block_missing.py# Block-missing surface reconstruction experiments
│ │
│ └── benchmarks/
│ ├── base.py # CaseSpec / FilterSpec abstractions
│ ├── registry.py # Global filter registry
│ ├── matern.py # Matérn-like SDM-CAR filter family
│ ├── invlinear_car.py # Proper CAR (inverse-linear spectrum)
│ ├── classic_car.py # Intrinsic CAR with fixed ridge ε
│ ├── leroux.py # Leroux CAR (convex blend of IID and CAR)
│ ├── polyrational.py # Polynomial / rational spectral filters
│ ├── logspline.py # Log-spline semi-nonparametric spectral filter
│ └── __init__.py # Auto-registration of benchmark modules
│
├── examples/figures/
│ ├── benchmarks/ # VI vs MCMC spectrum recovery results
│ ├── misspec/ # Misspecified-truth experiments
│ └── surface_block_missing/ # Block-missing imputation outputs├── examples/figures/benchmarks # Auto-generated figures and summaries
│
└── README.md
Everything under sdmcar/ is experiment-agnostic and mirrors the mathematical structure of the model.
-
graph.pyConstructs spatial graphs, Laplacians, and eigendecompositions. This is the only place where spatial structure enters the model. -
filters.pyDefines spectral covariance families$F(\lambda;\theta)$ . Filters expose a common interface used by both VI and MCMC and optionally define parameter blocks for joint MCMC proposals. -
models.pyImplements collapsed variational inference with exact marginalization of spatial effects and analytic posteriors for regression coefficients. -
mcmc.pyImplements collapsed Metropolis-within-Gibbs MCMC. The sampler is constructed directly from a fitted VI model, ensuring consistency between inference methods. -
diagnostics.pyPosterior diagnostics and visualization utilities.
Nothing in sdmcar/ is aware of specific experiments, benchmarks, ablations, or datasets.
All filter families and experimental configurations are defined declaratively, without embedding inference logic.
-
base.pyFilterSpec: defines a filter familyCaseSpec: defines a specific experimental configuration (baseline, fixed parameters, ablations)
-
registry.pyMaintains a global registry mapping filter names toFilterSpecs, enabling dynamic discovery from the command line. -
matern.py,invlinear_car.py,leroux.py,polyrational.py,classic_car.py,logspline.pyEach file defines a filter family, its valid cases, and registers itself automatically on import.
Adding a new filter family or ablation case does not require modifying inference code or experiment runners.
All experiments are executed through filter-agnostic entry points under examples/.
Run via:
python -m examples.run_benchmark --filter <name> --cases <ids>This runner:
- builds a spatial graph and Laplacian,
- generates synthetic data under a CAR ground truth,
- runs collapsed variational inference,
- initializes and runs collapsed MCMC from the VI solution,
- produces diagnostics, plots, and summaries.
This setting evaluates:
- parameter recovery,
- spectrum recovery,
- VI–MCMC agreement.
The runner is filter-agnostic and case-agnostic.
Run via:
python -m examples.run_misspec_demo --truth <type> --filters <names>This experiment:
- constructs a graph Laplacian,
- generates data under a deliberately misspecified spectrum
$F_{\text{true}}(\lambda)$ , - fits multiple filter families,
- compares log-spectrum RMSE and surface recovery error,
- benchmarks VI against MCMC under misspecification.
This evaluates:
- robustness to model misspecification,
- ability of flexible filters (e.g. log-spline, rational) to capture non-CAR structure,
- stability of approximate inference.
Run via:
python -m examples.run_surface_block_missing --filter <name> --case <id>This runner:
- generates deterministic latent surfaces (e.g.
$f_1, f_2$ ), - constructs a graph Laplacian over the full grid,
- removes structured blocks of observations,
- performs iterative VI-based reconstruction,
- optionally performs conditional Gaussian imputation,
- evaluates MSE and correlation on held-out regions.
This setting evaluates:
- spatial extrapolation capability,
- robustness to structured missing data,
- sensitivity to graph construction and filter family,
- performance across different missing block locations.
The repository cleanly separates:
| Layer | Responsibility |
|---|---|
sdmcar/ |
Mathematical model + inference |
examples/benchmarks/ |
Declarative filter definitions |
examples/run_*.py |
Experimental protocols |
examples/figures/ |
Generated outputs |
This separation ensures:
- inference code is reusable across experiments,
- filters are interchangeable,
- experiments are reproducible,
- extensions (new graphs, new filters, new protocols) do not require rewriting core logic.
All experimental results are written automatically to structured directories under:
examples/figures/
The exact subdirectory depends on the experiment type:
examples/figures/
├── benchmarks/<filter>/<case>/
├── misspec/truth_<type>/<filter>/<case>/
└── surface_block_missing/
examples/figures/benchmarks/<filter>/<case>/
Contain:
- spectrum recovery plots (linear + log scale),
- posterior mean surface comparisons,
- VI–MCMC diagnostics,
- parameter summaries.
examples/figures/misspec/truth_<type>/<filter>/<case>/
Contain:
- true vs estimated spectra,
- log-spectrum RMSE comparisons,
- VI–MCMC performance summaries.
examples/figures/surface_block_missing/
Contain:
- latent surface visualizations,
- observed surface with structured missing blocks,
- imputed surfaces across outer iterations,
- MSE and correlation summaries across missing regions,
- metadata files recording experiment settings.
This structure ensures:
- no manual bookkeeping,
- deterministic results given a fixed random seed,
- clean separation between modeling code and experiment outputs,
- direct VI–MCMC comparison for validation,
- consistent evaluation across filters and experimental regimes.
All experiment scripts are filter-agnostic and registry-driven, allowing systematic comparison without modifying inference code.
New spectral filters can be added by:
- Implementing a filter class in
sdmcar/filters.py, - Defining experimental cases in
examples/benchmarks/<name>.py, - Registering the filter via
FilterSpec.
No changes to inference code or the runner are required.
This repository is intended for:
- methodological research in spatial statistics and GMRFs,
- development of structured covariance models on graphs,
- reproducible comparison of CAR and CAR-generalized models.
It is not optimized as a production library. Instead, it is structured to demonstrate architectural decisions, inference tradeoffs, and robustness under misspecification—core concerns in research and advanced ML system design.
@misc{sdmcar2026,
title = {Spectral-Density-Modulated Conditional Autoregressive Models},
author = {Pratik Dahal},
year = {2026},
note = {Contact: pd006@uark.edu, mapratikdahal@gmail.com}
}