Skip to content

Commit f78d5b6

Browse files
authored
Add regularisation term before Cholesky decomposition (#459)
1 parent 53df690 commit f78d5b6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pymc_extras/inference/pathfinder/pathfinder.py

+5
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ def bfgs_sample_dense(
489489

490490
N = x.shape[-1]
491491
IdN = pt.eye(N)[None, ...]
492+
IdN += IdN * REGULARISATION_TERM
492493

493494
# inverse Hessian
494495
H_inv = (
@@ -568,9 +569,13 @@ def bfgs_sample_sparse(
568569
# qr_input: (L, N, 2J)
569570
qr_input = inv_sqrt_alpha_diag @ beta
570571
(Q, R), _ = pytensor.scan(fn=pt.nlinalg.qr, sequences=[qr_input], allow_gc=False)
572+
571573
IdN = pt.eye(R.shape[1])[None, ...]
574+
IdN += IdN * REGULARISATION_TERM
575+
572576
Lchol_input = IdN + R @ gamma @ pt.matrix_transpose(R)
573577

578+
# TODO: make robust Lchol calcs more robust, ie. try exceptions, increase REGULARISATION_TERM if non-finite exists
574579
Lchol = pt.linalg.cholesky(Lchol_input, lower=False, check_finite=False, on_error="nan")
575580

576581
logdet = 2.0 * pt.sum(pt.log(pt.abs(pt.diagonal(Lchol, axis1=-2, axis2=-1))), axis=-1)

0 commit comments

Comments
 (0)