API reference

The public API of bayespecon is everything reachable from the top-level bayespecon namespace (model classes, samplers, DGPs, diagnostics, graph helpers). Internal subpackages are prefixed with an underscore (_logdet, _ops, _backends, _jax_dispatch, _numba_dispatch); they are documented here for reference but their APIs are not covered by the package’s stability guarantees and may change without deprecation.

Base Classes

SpatialModel([formula, data, y, X, W, ...])

Base class for Bayesian spatial regression models.

SpatialPanelModel([formula, data, y, X, W, ...])

Base class for static spatial panel models with FE transforms.

Cross-Sectional Spatial Models

OLS([formula, data, y, X, W, priors, ...])

Bayesian ordinary least squares cross-sectional regression.

SAR([formula, data, y, X, W, priors, ...])

Bayesian Spatial Autoregressive (Spatial Lag) model.

SEM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Error Model.

SLX([formula, data, y, X, W, priors, ...])

Bayesian SLX (Spatial Lag X) model.

SDM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Durbin Model.

SDEM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Durbin Error Model.

Panel Spatial Models (Fixed Effects)

OLSPanelFE([formula, data, y, X, W, ...])

Bayesian pooled and fixed-effects linear panel regression.

SARPanelFE([formula, data, y, X, W, ...])

Bayesian spatial-lag panel regression.

SEMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial-error panel regression.

SDMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial Durbin panel regression.

SDEMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial Durbin error panel regression.

SLXPanelFE([formula, data, y, X, W, ...])

Bayesian SLX panel regression.

Panel Spatial Models (Random Effects)

OLSPanelRE(**kwargs)

Bayesian random effects panel regression (non-spatial).

SARPanelRE(**kwargs)

Bayesian spatial lag panel model with unit random effects.

SEMPanelRE([mundlak])

Bayesian spatial error panel model with unit random effects.

SDEMPanelRE(**kwargs)

Bayesian spatial Durbin error panel model with unit random effects.

Dynamic Panel Spatial Models

OLSPanelDynamic(*args[, model])

SDMRPanelDynamic(*args[, model])

SDMUPanelDynamic(*args[, model])

SARPanelDynamic(*args[, model])

SEMPanelDynamic(*args[, model])

SDEMPanelDynamic(*args[, model])

SLXPanelDynamic(*args[, model])

Non-Linear Spatial Models

SpatialProbit([formula, data, y, X, W, ...])

Bayesian spatial probit with regional random effects.

SARTobit(*args[, censoring])

Bayesian spatial autoregressive Tobit model.

SEMTobit(*args[, censoring])

Bayesian spatial error Tobit model.

SDMTobit(*args[, censoring])

Bayesian spatial Durbin Tobit model.

SARNegativeBinomial(*args, **kwargs)

Bayesian SAR model with a Negative Binomial likelihood.

SARNegBinLatent(*args, **kwargs)

Bayesian structural-form SAR-NB with Pólya–Gamma Gibbs sampler.

Panel Spatial Models (Tobit)

SARPanelTobit(*args[, censoring])

SEMPanelTobit(*args[, censoring])

Flow Models

FlowModel(y, G, X[, col_names, k, priors, ...])

Abstract base class for Bayesian spatial flow regression models.

OLSFlow(y, G, X, **kwargs)

Non-spatial Bayesian OD-flow gravity model (independence baseline).

PoissonFlow(y, G, X, **kwargs)

Non-spatial Bayesian OD-flow Poisson gravity model (count baseline).

SARFlow(y, G, X[, col_names, k, priors, ...])

Bayesian SAR flow model with three free spatial autoregressive parameters.

SARFlowSeparable(y, G, X, **kwargs)

Bayesian separable SAR flow model with ρ_w = −ρ_d · ρ_o.

PoissonSARFlow(y, G, X, **kwargs)

Bayesian SAR flow model with a Poisson observation distribution.

PoissonSARFlowSeparable(y, G, X, **kwargs)

Bayesian separable SAR flow model with a Poisson observation distribution.

NegativeBinomialFlow(y, G, X, **kwargs)

Aspatial OD-flow Negative Binomial gravity baseline.

NegativeBinomialSARFlow(y, G, X, **kwargs)

Bayesian SAR flow model with NB2 observation noise.

NegativeBinomialSARFlowSeparable(y, G, X, ...)

Separable SAR flow model with NB2 observation noise.

SARNegBinFlowLatent(y, G, X, **kwargs)

Bayesian structural-form SAR-NB flow model with Pólya–Gamma Gibbs sampler.

SARNegBinFlowSeparableLatent(y, G, X, **kwargs)

Bayesian separable SAR-NB flow model with Pólya–Gamma Gibbs sampler.

SEMFlow(y, G, X, **kwargs)

Bayesian spatial-error flow model with three free spatial parameters.

SEMFlowSeparable(y, G, X, **kwargs)

Bayesian separable spatial-error flow model with \(\lambda_w = -\lambda_d \lambda_o\).

Panel Flow Models

FlowPanelModel(y, G, X, T[, col_names, k, ...])

Abstract base class for balanced panel spatial flow models.

OLSFlowPanel(y, G, X, T, **kwargs)

Non-spatial Bayesian OD-flow gravity model for balanced panel data.

PoissonFlowPanel(y, G, X, T, **kwargs)

Non-spatial Bayesian OD-flow Poisson gravity model for balanced panel data.

SARFlowPanel(y, G, X, T[, col_names, k, ...])

Panel spatial-lag origin-destination flow model with unrestricted dependence.

SARFlowSeparablePanel(y, G, X, **kwargs)

Panel separable spatial-lag flow model with \(\rho_w = -\rho_d \rho_o\).

PoissonSARFlowPanel(y, G, X, **kwargs)

Panel Poisson spatial-lag flow model with unrestricted dependence.

PoissonSARFlowSeparablePanel(y, G, X, **kwargs)

Panel separable Poisson spatial-lag flow model.

NegativeBinomialFlowPanel(y, G, X, T, **kwargs)

Aspatial panel OD-flow NB2 gravity baseline.

NegativeBinomialSARFlowPanel(y, G, X, **kwargs)

Panel NB2 SAR flow model with unrestricted dependence parameters.

NegativeBinomialSARFlowSeparablePanel(y, G, ...)

Panel separable NB2 SAR flow model.

SEMFlowPanel(y, G, X, T, **kwargs)

Panel spatial-error flow model with three free spatial parameters.

SEMFlowSeparablePanel(y, G, X, T, **kwargs)

Panel separable spatial-error flow model with \(\lambda_w = -\lambda_d \lambda_o\).

Bayesian Diagnostics

BayesianLMTestResult(lm_samples, mean, ...)

Container for Bayesian LM test results.

bayesian_lm_lag_test(model)

Bayesian LM test for omitted spatial lag (SAR) model.

bayesian_lm_error_test(model)

Bayesian LM test for omitted spatial error (SEM) model.

bayesian_lm_wx_test(model)

Bayesian LM test for WX coefficients (H₀: γ = 0 | SAR).

bayesian_lm_sdm_joint_test(model)

Bayesian joint LM test for SDM (H₀: ρ = 0 AND γ = 0 | OLS).

bayesian_lm_slx_error_joint_test(model)

Bayesian joint LM test for SDEM (H₀: λ = 0 AND γ = 0 | OLS).

bayesian_lm_error_from_sar_test(model)

Bayesian LM-Error test from a SAR posterior (H₀: λ = 0 | SAR).

bayesian_lm_error_sdm_test(model)

Bayesian LM-Error test from an SDM posterior (H₀: λ = 0 | SDM).

bayesian_lm_lag_sdem_test(model)

Bayesian LM-Lag test from an SDEM posterior (H₀: ρ = 0 | SDEM).

bayesian_lm_wx_sem_test(model)

Bayesian LM test for WX coefficients in SEM (H₀: γ = 0 | SEM).

bayesian_robust_lm_lag_test(model)

Bayesian robust LM-Lag test (H₀: ρ = 0, robust to local λ).

bayesian_robust_lm_error_test(model)

Bayesian robust LM-Error test (H₀: λ = 0, robust to local ρ).

bayesian_robust_lm_lag_sdm_test(model)

Bayesian robust LM-Lag test in SDM context (H₀: ρ = 0, robust to γ).

bayesian_robust_lm_wx_test(model)

Bayesian robust LM-WX test (H₀: γ = 0, robust to ρ).

bayesian_robust_lm_error_sdem_test(model)

Bayesian robust LM-Error test in SDEM context (H₀: λ = 0, robust to γ).

bayesian_robust_lm_error_sar_test(model)

Bayesian robust LM-Error test in SAR context (H₀: λ = 0 | SAR).

bayesian_robust_lm_error_sdm_test(model)

Bayesian robust LM-Error test in SDM context (H₀: λ = 0 | SDM).

bayesian_robust_lm_lag_sdem_test(model)

Bayesian robust LM-Lag test in SDEM context (H₀: ρ = 0 | SDEM).

bayesian_robust_lm_lag_sem_test(model)

Bayesian robust LM-Lag test in SEM context (H₀: ρ = 0 | SEM).

bayesian_robust_lm_wx_sem_test(model)

Bayesian robust LM-WX test in SEM context (H₀: γ = 0 | SEM).

Panel Bayesian LM Tests

bayesian_panel_lm_lag_test(model)

Bayesian panel LM test for omitted spatial lag (H₀: ρ = 0).

bayesian_panel_lm_error_test(model)

Bayesian panel LM test for omitted spatial error (H₀: λ = 0).

bayesian_panel_robust_lm_lag_test(model)

Bayesian panel robust LM-Lag test (H₀: ρ = 0, robust to λ).

bayesian_panel_robust_lm_error_test(model)

Bayesian panel robust LM-Error test (H₀: λ = 0, robust to ρ).

bayesian_panel_lm_wx_test(model)

Bayesian panel LM test for WX coefficients (H₀: γ = 0).

bayesian_panel_lm_sdm_joint_test(model)

Bayesian panel joint LM test for SDM (H₀: ρ = 0 AND γ = 0).

bayesian_panel_lm_slx_error_joint_test(model)

Bayesian panel joint LM test for SDEM (H₀: λ = 0 AND γ = 0).

bayesian_panel_lm_error_sdm_test(model)

Panel LM-Error test from an SDM panel posterior (H₀: λ = 0 | SDM).

bayesian_panel_lm_lag_sdem_test(model)

Panel LM-Lag test from an SDEM panel posterior (H₀: ρ = 0 | SDEM).

bayesian_panel_lm_wx_sem_test(model)

Bayesian panel LM test for WX coefficients in SEM (H₀: γ = 0 | SEM).

bayesian_panel_robust_lm_lag_sdm_test(model)

Bayesian panel robust LM-Lag in SDM context (H₀: ρ = 0 | SLX panel).

bayesian_panel_robust_lm_wx_test(model)

Bayesian panel robust LM-WX (H₀: γ = 0 | SAR panel, robust to ρ).

bayesian_panel_robust_lm_error_sdem_test(model)

Bayesian panel robust LM-Error in SDEM context (H₀: λ = 0 | SLX panel).

Flow Bayesian LM Tests

bayesian_lm_flow_dest_test(model)

Bayesian LM test for an omitted destination-side spatial lag.

bayesian_lm_flow_orig_test(model)

Bayesian LM test for an omitted origin-side spatial lag (\(H_0\colon \rho_o = 0\)).

bayesian_lm_flow_network_test(model)

Bayesian LM test for an omitted network spatial lag (\(H_0\colon \rho_w = 0\)).

bayesian_lm_flow_intra_test(model)

Bayesian LM (WX-style) test for the intra block in an OLSFlow null.

bayesian_lm_flow_joint_test(model)

Joint Bayesian LM test for the SARFlow filter (\(H_0\colon \rho_d = \rho_o = \rho_w = 0\)).

bayesian_robust_lm_flow_dest_test(sarflow_model)

Robust Bayesian LM test for \(\rho_d\) adjusting for \((\rho_o, \rho_w)\) nuisance via the Neyman-orthogonal score (Bera and Yoon [1993], Anselin et al. [1996], Doğan et al. [2021]).

bayesian_robust_lm_flow_orig_test(sarflow_model)

Robust Bayesian LM test for \(\rho_o\) adjusting for \((\rho_d, \rho_w)\) nuisance.

bayesian_robust_lm_flow_network_test(...)

Robust Bayesian LM test for \(\rho_w\) adjusting for \((\rho_d, \rho_o)\) nuisance.

bayesian_panel_lm_flow_dest_test(model)

Panel analogue of bayesian_lm_flow_dest_test() operating on a fitted OLSFlowPanel.

bayesian_panel_lm_flow_orig_test(model)

Panel analogue of bayesian_lm_flow_orig_test() (\(H_0\colon \rho_o = 0\)).

bayesian_panel_lm_flow_network_test(model)

Panel analogue of bayesian_lm_flow_network_test() (\(H_0\colon \rho_w = 0\)).

bayesian_panel_lm_flow_intra_test(model)

Panel analogue of bayesian_lm_flow_intra_test() on OLSFlowPanel.

bayesian_panel_lm_flow_joint_test(model)

Panel analogue of bayesian_lm_flow_joint_test() on OLSFlowPanel.

Diagnostic Test Suites

Pre-bundled collections of LM tests used by model.spatial_diagnostics() and the decision-tree renderers.

DiagnosticSuite(name, tests)

Named, immutable registry of Bayesian LM specification tests.

get_diagnostic_suite(model)

Return the DiagnosticSuite for model, or None.

OLS_SUITE

Named, immutable registry of Bayesian LM specification tests.

OLS_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_NEGBIN_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_TOBIT_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_PANEL_DYNAMIC_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_PANEL_DYNAMIC_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_TOBIT_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDEM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDEM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_INTRA_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

Bayesian Model Comparison

ModelComparison(models[, labels, method])

Compare a collection of fitted Bayesian models.

bayes_factor_compare_models(models[, ...])

Compute all pairwise Bayes factors for a set of Bayesian models.

bic_to_bf(bic_values[, denominator, log])

Convert BIC values to Bayes factors via the BIC-approximation method.

compile_log_posterior(pymc_model)

Compile a PyMC model's log-posterior into a callable for bridge sampling.

post_prob(logml_list[, model_names, prior_prob])

Compute posterior model probabilities from marginal likelihoods.

MCMC Efficiency

SpatialMCMCReport(parameters, ess_bulk, ...)

Summary of MCMC sampling-efficiency checks for a spatial model.

spatial_mcmc_diagnostic(model, *[, min_ess, ...])

Run MCMC adequacy checks on a fitted Bayesian spatial model.

Spatial Cross-Validation

SpatialCVResult(elpd, se, elpd_per_fold, ...)

Result of spatial_kfold().

spatial_kfold(model, *[, fold_ids, ...])

Spatial block cross-validation for a fitted Bayesian spatial model.

Data Generating Processes

Note

The cross-sectional and (scalar) panel DGP simulators accept W (Graph/sparse/dense) and gdf inputs. You may provide both together; in that case W is used for simulation and is checked against gdf for dimensional compatibility (a ValueError is raised when they do not describe the same number of spatial units).

The flow DGPs below take G (libpysal Graph), gdf, n, and knn_k instead. All four are optional: when none is supplied the DGP synthesises a point grid via synth_point_geodataframe() and builds a row-standardised KNN graph automatically.

simulate_ols([n, W, gdf, beta, sigma, ...])

Simulate data from a non-spatial OLS DGP y = X beta + eps.

simulate_sar([n, W, gdf, rho, beta, sigma, ...])

Simulate data from SAR DGP y = (I-rho W)^(-1)(X beta + eps).

simulate_sem([n, W, gdf, lam, beta, sigma, ...])

Simulate data from SEM DGP y = X beta + (I-lam W)^(-1) eps.

simulate_slx([n, W, gdf, beta1, beta2, ...])

Simulate data from SLX DGP y = X beta1 + W X_no_intercept beta2 + eps.

simulate_sdm([n, W, gdf, rho, beta1, beta2, ...])

Simulate data from SDM DGP y = (I-rho W)^(-1)(Xb1 + WXb2 + eps).

simulate_sdem([n, W, gdf, lam, beta1, ...])

Simulate data from SDEM DGP y = Xb1 + WXb2 + (I-lam W)^(-1)eps.

simulate_sar_negbin([n, W, gdf, rho, beta, ...])

Simulate data from a SAR-NB2 DGP.

simulate_spatial_probit([W, gdf, n, rho, ...])

Simulate SpatialProbit-style binary outcome data.

simulate_sar_tobit(*[, censoring, err_hetero])

Simulate left-censored SAR Tobit data.

simulate_sem_tobit(*[, censoring, err_hetero])

Simulate left-censored SEM Tobit data.

simulate_sdm_tobit(*[, censoring, err_hetero])

Simulate left-censored SDM Tobit data.

simulate_panel_ols_fe(N, T[, beta, sigma, ...])

Simulate pooled data compatible with OLSPanelFE model assumptions.

simulate_panel_sar_fe(N, T[, rho, beta, ...])

Simulate SAR panel data in time-first stacking order.

simulate_panel_sem_fe(N, T[, lam, beta, ...])

Simulate SEM panel data in time-first stacking order.

simulate_panel_sdm_fe(N, T[, rho, beta1, ...])

Simulate SDM panel FE data.

simulate_panel_sdem_fe(N, T[, lam, beta1, ...])

Simulate SDEM panel FE data.

simulate_panel_slx_fe(N, T[, beta1, beta2, ...])

Simulate SLX panel FE data.

simulate_panel_ols_re(*[, err_hetero])

Simulate OLS random-effects panel style data.

simulate_panel_sar_re(*[, err_hetero])

Simulate SAR random-effects panel style data.

simulate_panel_sem_re(*[, err_hetero])

Simulate SEM random-effects panel style data.

simulate_panel_dlm_fe(N, T[, phi, beta, ...])

Simulate dynamic non-spatial panel FE data.

simulate_panel_sdmr_fe(N, T[, rho, phi, ...])

Simulate dynamic restricted SDM panel FE data.

simulate_panel_sdmu_fe(N, T[, rho, phi, ...])

Simulate dynamic unrestricted SDM panel FE data.

simulate_panel_sar_dynamic_fe(N, T[, rho, ...])

Simulate dynamic SAR panel FE data.

simulate_panel_sem_dynamic_fe(N, T[, lam, ...])

Simulate dynamic SEM panel FE data.

simulate_panel_sdem_dynamic_fe(N, T[, lam, ...])

Simulate dynamic SDEM panel FE data.

simulate_panel_slx_dynamic_fe(N, T[, phi, ...])

Simulate dynamic SLX panel FE data.

simulate_panel_sar_tobit_fe(*[, censoring, ...])

Simulate left-censored panel SAR FE data.

simulate_panel_sem_tobit_fe(*[, censoring, ...])

Simulate left-censored panel SEM FE data.

Flow Data Generating Processes

Each flow DGP accepts n, G, gdf, and knn_k as optional arguments and (unless gamma_dist=0.0) appends a log_distance column log(1 + d_{ij}) with default coefficient gamma_dist=-0.5.

The Gaussian flow DGPs (generate_flow_data, generate_panel_flow_data and their separable variants) default to distribution="lognormal", returning strictly-positive flows y = exp(eta) where eta is the latent SAR-filtered linear predictor (also exposed in the result dict as "eta_vec" / "eta"). Pass distribution="normal" to recover the legacy Gaussian-on-y behaviour. The Gaussian-likelihood flow models in bayespecon.models.flow operate on the latent scale, so fit on np.log(y) to recover the SAR parameters. The Poisson and Negative Binomial DGPs are unchanged.

generate_flow_data([n, G, rho_d, rho_o, ...])

Simulate flow data from a SAR flow model.

generate_flow_data_separable([n, G, rho_d, ...])

Simulate flow data from a separable SAR flow model.

generate_poisson_flow_data([n, k, k_d, k_o, ...])

Generate synthetic origin-destination flow count data for a Poisson spatial autoregressive flow model.

generate_poisson_flow_data_separable([n, k, ...])

Simulate Poisson flow count data from a separable SAR flow model.

generate_negbin_flow_data([n, k, k_d, k_o, ...])

Generate synthetic O-D flow counts from an NB2 SAR flow DGP.

generate_negbin_flow_data_separable([n, ...])

NB2 flow DGP with separability constraint rho_w = -rho_d * rho_o.

generate_sem_flow_data([n, G, lam_d, lam_o, ...])

Simulate flow data from a spatial-error (SEM) flow model.

generate_sem_flow_data_separable([n, G, ...])

Simulate SEM flow data with the separability constraint \(\lambda_w = -\lambda_d \lambda_o\).

generate_panel_flow_data([n, T, G, rho_d, ...])

Simulate panel flow data from a SAR flow model with unit effects.

generate_panel_flow_data_separable([n, T, ...])

Simulate panel flow data from a separable SAR flow model.

generate_panel_poisson_flow_data([n, T, G, ...])

Simulate panel Poisson flow data from a spatial autoregressive model.

generate_panel_poisson_flow_data_separable([...])

Simulate panel Poisson flow data from a separable SAR flow model.

generate_panel_negbin_flow_data([n, T, G, ...])

Generate panel NB2 flow counts from a spatial autoregressive DGP.

generate_panel_negbin_flow_data_separable([...])

Panel NB2 flow DGP with separability constraint rho_w=-rho_d*rho_o.

generate_panel_sem_flow_data([n, T, G, ...])

Simulate panel SEM flow data with O-D-pair random effects.

generate_panel_sem_flow_data_separable([n, ...])

Panel SEM flow DGP with separability constraint \(\lambda_w = -\lambda_d \lambda_o\).

Graph Utilities

FlowDesignMatrix(X_dest, X_orig, X_intra, ...)

Combined design matrix for an O-D flow regression.

flow_design_matrix(X[, col_names, dist, ...])

Build a flow regression design matrix from regional attribute data.

flow_design_matrix_asymmetric(Xd, Xo[, ...])

Build a flow design matrix with different numbers of dest/origin variables.

flow_design_matrix_with_orig(Xd, Xo[, ...])

Build a flow design matrix with separate destination and origin data.

flow_weight_matrices(G)

Build all three N×N flow weight matrices from a single Graph.

destination_weights(G)

Build the N×N destination weight matrix \(W_d = I_n \otimes W\).

origin_weights(G)

Build the N×N origin weight matrix \(W_o = W \otimes I_n\).

network_weights(G)

Build the N×N network weight matrix \(W_w = W \otimes W\).

Gibbs Samplers

Block-Gibbs samplers for Gaussian spatial models. These bypass NUTS entirely and exploit conditional conjugacy for faster sampling. All four symbols are re-exported from the top-level bayespecon namespace.

GibbsEstimation(y, X, W_sparse, Wy, priors, ...)

Base class for Gaussian spatial Gibbs sampler configuration and execution.

GaussianSARGibbs(y, X, W_sparse, Wy, priors, ...)

Gibbs sampler for SAR/SDM Gaussian models.

GaussianSEMGibbs(y, X, W_sparse, priors, ...)

Gibbs sampler for SEM/SDEM Gaussian models.

GaussianGibbsPriors([beta_mu, beta_sigma, ...])

Prior hyperparameters for Gaussian spatial Gibbs.

Configuration

enable_compile_cache([path])

Enable persistent on-disk compile caches for JAX and PyTensor.

Internal Modules

The following subpackages are private (underscore-prefixed). They back the public model classes and samplers and may change without deprecation; they are documented here for reference and for users writing custom extensions.

Custom PyTensor Ops (bayespecon._ops)

Differentiable sparse and Kronecker-structured linear solves with adjoint-method gradients, used inside the flow-model PyMC graphs.

SparseFlowSolveOp(Wd, Wo, Ww)

Differentiable sparse solve \(\eta = A(\rho)^{-1} b\).

SparseFlowSolveMatrixOp(Wd, Wo, Ww)

Differentiable sparse solve \(H = A(\rho)^{-1} B\) for matrix RHS.

KroneckerFlowSolveOp(W, n)

Differentiable Kronecker-factored solve for separable Poisson flow models.

KroneckerFlowSolveMatrixOp(W, n)

Kronecker-factored solve for separable panel Poisson flow models.

kron_solve_vec(Lo, Ld, b, n)

Solve \((L_o \otimes L_d)\,\eta = b\) via two \(n \times n\) sparse solves.

kron_solve_matrix(Lo, Ld, B, n)

Solve \((L_o \otimes L_d)\,H = B\) for a matrix RHS via batched two-step solve.

Log-Determinant Methods (bayespecon._logdet)

Positive-only methods (sparse_spline, grid_mc) auto-restrict the rho/lambda support to [1e-5, 1.0] when the prior or method default would otherwise admit negative values. Explicit rho_min/rho_max overrides still raise.

Method resolution and bound handling

LogDetMethod(*values)

Canonical names for the log-determinant approximation methods.

LogdetBounds(method, rho_min, rho_max, source)

Resolved logdet method and rho interval used for approximation.

resolve_logdet_method(method, *, n)

Validate method and auto-select when None.

resolve_logdet_bounds(method, *, n[, ...])

Resolve method-specific rho bounds from defaults, priors, or overrides.

Factories

make_logdet_fn(W[, method, rho_min, ...])

Return a function (rho) -> pytensor log|I - rho*W| expression.

make_logdet_numpy_fn(W_sparse, eigs, method)

Return a pure-numpy (rho: float) -> float logdet evaluator.

make_logdet_numpy_vec_fn(W_sparse, eigs, method)

Return a vectorized numpy (rho_arr: np.ndarray) -> np.ndarray logdet evaluator.

make_logdet_jax_fn(W[, method, rho_min, ...])

Return a JAX-native function (rho) -> log|I - rho*W|.

get_cached_logdet_fn(W[, method, rho_min, ...])

Return a shared cached make_logdet_fn callable.

clear_logdet_fn_cache()

Clear the shared cache of precomputed PyTensor logdet callables.

PyTensor kernels

logdet_eigenvalue(rho, eigs)

Eigenvalue-based log|I - rho*W|.

logdet_exact(rho, W_dense)

Exact log|I - rho*W| as a pytensor expression.

logdet_chebyshev(rho, coeffs[, rmin, rmax])

Evaluate Chebyshev approximation of log|I - rho*W| symbolically.

logdet_interpolated(rho, W_dense[, rho_min, ...])

Cubic spline interpolation of log|I - rho*W|.

logdet_mc_poly_pytensor(rho, traces)

Evaluate Barry-Pace trace polynomial approximation of log|I - rho*W| symbolically.

JAX kernels

jax_logdet_chebyshev(rho, coeffs[, rmin, rmax])

Evaluate Chebyshev approximation of log|I - rho*W| in JAX.

jax_logdet_trace_poly(rho, traces)

Evaluate trace-polynomial approximation of log|I - rho*W| in JAX.

Grid / polynomial primitives

mc(order, iter, W[, rmin, rmax, grid, ...])

Compute Monte Carlo log-determinant approximation (Barry and Kelley Pace [1999]).

chebyshev(W[, order, rmin, rmax, ...])

Compute Chebyshev approximation of log|I - rho*W| ([Pace and LeSage, 2004]).

spline(W[, rmin, rmax, n_grid])

Compute a spline-interpolated log-determinant grid.

Flow log-determinants

flow_logdet_pytensor(rho_d, rho_o, rho_w, ...)

Differentiable PyTensor log-determinant for the flow SAR model.

flow_logdet_numpy(rho_d, rho_o, rho_w, ...)

Vectorised numpy port of flow_logdet_pytensor().

compute_flow_traces(W_sparse[, miter, ...])

Estimate tr(W^k) for k=1..miter via Barry-Pace stochastic traces.

make_flow_separable_logdet(W_sparse, n[, ...])

Pre-compute logdet data for separable flow models and return a logdet callable.

make_flow_separable_logdet_numpy(W_sparse, n)

Pre-compute numeric logdet data for separable flow models.

Stochastic trace estimation

The XTrace (Epperly–Tropp–Webber 2024) and Hutch++ (Meyer et al. 2021) estimators are implemented natively in NumPy + SciPy sparse and used inside the Chebyshev log-determinant path. Selection is via the trace_estimator= keyword on each model.

traceax_available()

Return True when traceax, lineax, and equinox are all importable.

traceax_traces(W_sparse, order, k[, ...])

Estimate tr(W^k) for k=1..order via variance-reduced stochastic trace estimation.

traceax_traces_for_chebyshev(W_sparse, ...)

Estimate tr(W^k) for the Chebyshev MC path via traceax.