bayespecon._logdet.make_logdet_fn

bayespecon._logdet.make_logdet_fn(W, method=None, rho_min=-1.0, rho_max=1.0, T=1, trace_estimator='hutchpp', trace_k=None)[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" for n <= 500 else "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. Coefficients are built from exact eigenvalues when n is small (or eigs is supplied); otherwise from a stochastic trace estimator selected by trace_estimator.

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.

trace_estimator : {"hutchinson", "hutchpp", "xtrace"}, default "hutchpp"

Stochastic trace estimator used to build the Chebyshev coefficients when an eigendecomposition is unavailable. Ignored for non-Chebyshev methods and when eigenvalues are passed in. See docs/source/user-guide/logdet_profiling.ipynb for the cost/accuracy frontier.

trace_k : int, optional

Number of probe vectors for the trace estimator. Defaults: 30 (hutchinson), 50 (hutchpp), 25 (xtrace).

Returns:

Function mapping symbolic rho to symbolic log-determinant.

Return type:

callable