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¶
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'and'exact'methods are not available in that case and fall back to'eigenvalue'.- method : str¶
"eigenvalue"— pre-compute W’s eigenvalues once (O(n³)); every subsequent evaluation costs O(n) and is exact (default)."exact"— exact O(n³) symbolic det via pytensor (slow for n > 500)."grid"— spline interpolation over pre-computed grid (approximate)."full"— exact sparse-LU grid (MATLABlndetfullstyle), then spline interpolation."int"— sparse-LU + cubic-spline interpolation (MATLABlndetintstyle)."mc"— Monte Carlo trace approximation ([Barry and Kelley Pace, 1999]), then spline interpolation."ichol"— ILU-based approximation (MATLABlndeticholanalog), then spline interpolation."chebyshev"— Chebyshev polynomial approximation ([Pace and LeSage, 2004]); near-minimax polynomial approximation evaluated via Clenshaw’s algorithm. O(m) per evaluation after O(n³) or O(R·n·m) pre-computation.- 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)."dense_grid"("grid") and"sparse_grid"("full") — 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."spline"("int") — restricted torho ≥ 0because the MATLABlndetintroutine builds its grid on[max(rho_min, 0), rho_max]; passing negativerhois silently extrapolated, which is rarely intended."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."ilu"("ichol") — 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.