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 (MATLAB lndetfull style), then spline interpolation. "int" — sparse-LU + cubic-spline interpolation (MATLAB lndetint style). "mc" — Monte Carlo trace approximation ([Barry and Kelley Pace, 1999]), then spline interpolation. "ichol" — ILU-based approximation (MATLAB lndetichol analog), 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 rho to symbolic log-determinant.

Return type:

callable

Notes

Per-method valid rho domains:

  • "eigenvalue" and "exact" — accept the full numerical stability domain rho (1/min(eigs), 1/max(eigs)); for row-standardised W this reduces to rho (-1, 1).

  • "dense_grid" ("grid") and "sparse_grid" ("full") — accept any rho (rho_min + 1e-6, rho_max - 1e-6); outside this interval the cubic spline extrapolates with rapidly degrading accuracy and must not be trusted. Set rho_min / rho_max to match your prior bounds.

  • "spline" ("int") — restricted to rho 0 because the MATLAB lndetint routine builds its grid on [max(rho_min, 0), rho_max]; passing negative rho is silently extrapolated, which is rarely intended.

  • "mc" — restricted to rho 1e-5 for the same reason (mc builds 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 any rho inside 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.