bayespecon.logdet.make_logdet_fn¶
-
bayespecon.logdet.make_logdet_fn(W, method=
None, rho_min=-1.0, rho_max=1.0, T=1)[source]¶ Return a function (rho) -> pytensor log|I - rho*W| expression.
- Parameters:¶
- W : np.ndarray or scipy.sparse matrix¶
Either a 2-D dense
(n, n)spatial weights matrix or a 1-D array of pre-computed real eigenvalues. Passing eigenvalues skips the O(n³) decomposition inside this function; the'grid_dense'and'exact'methods are not available in that case and fall back to'eigenvalue'.- method : str¶
Auto-selected when
None("eigenvalue"forn <= 2000else"chebyshev"). Supported values:"eigenvalue"— pre-compute W’s eigenvalues once (O(n³)); every subsequent evaluation costs O(n) and is exact."exact"— exact O(n³) symbolic det via pytensor (slow for n > 500)."grid_dense"— dense eigenvalue grid + cubic-spline interpolation."grid_sparse"— sparse-LU grid + cubic-spline interpolation for large sparse W."sparse_spline"— sparse-LU + cubic-spline interpolation on[max(rho_min, 0), rho_max]."grid_mc"— Monte Carlo trace approximation ([Barry and Kelley Pace, 1999]) + spline interpolation."grid_ilu"— ILU-based approximation + spline interpolation."chebyshev"— Chebyshev polynomial approximation ([Pace and LeSage, 2004]); near-minimax polynomial evaluated via Clenshaw’s algorithm. O(m) per evaluation after O(n³) or O(R·n·m) pre-computation."trace_mc"— Hutchinson stochastic trace estimator with a truncated polynomial expansion (used by the flow models).- rho_min : float, default=-1.0¶
Lower bound for the grid method.
- rho_max : float, default=1.0¶
Upper bound for the grid method.
- T : int, default 1¶
Panel time-period count. The returned log-determinant is multiplied by T, exploiting
log|I_{NT} - ρ(I_T⊗W_N)| = T · log|I_N - ρW_N|. Leave at 1 for cross-sectional models.
- Returns:¶
Function mapping symbolic
rhoto symbolic log-determinant.- Return type:¶
callable
Notes
Per-method valid
rhodomains:"eigenvalue"and"exact"— accept the full numerical stability domainrho ∈ (1/min(eigs), 1/max(eigs)); for row-standardised W this reduces torho ∈ (-1, 1)."grid_dense"and"grid_sparse"— accept anyrho ∈ (rho_min + 1e-6, rho_max - 1e-6); outside this interval the cubic spline extrapolates with rapidly degrading accuracy and must not be trusted. Setrho_min/rho_maxto match your prior bounds."sparse_spline"— restricted torho ≥ 0because this routine buildsits grid on
[max(rho_min, 0), rho_max]; passing negativerhois silently extrapolated, which is rarely intended."grid_mc"— restricted torho ≥ 1e-5for the same reason (mcbuilds the grid on[max(rho_min, 1e-5), rho_max]); negative ρ is supported only via separate calls with reversed sign on a row-standardised W."grid_ilu"— accepts anyrhoinside the supplied grid bounds, but the ILU factorisation degrades with|rho|approaching the spectral boundary and should be paired with a tight prior."chebyshev"— exact within[rmin, rmax] = [rho_min, rho_max]up to the polynomial order (default 20); evaluation outside the Chebyshev interval diverges rapidly and should never be attempted."trace_mc"— accuracy controlled by the polynomial order and number of Hutchinson probes; intended for very large sparse W where eigendecomposition is infeasible.