Skip to content

Commit 659ec41

Browse files
author
Jose Gomez-Dans
committed
Catch when the non-linear Hessian correction can't be done
Sometimes, the observation operator might not be a GP, and thus the higher-order Hessian correction might not be feasible. This is now flagged.
1 parent f3af99d commit 659ec41

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

kafka/inference/kf_tools.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
from utils import block_diag
1212

13+
class NoHessianMethod(Exception):
14+
"""An exception triggered when the forward model isn't able to provide an
15+
estimation of the Hessian"""
16+
def __init__(self, message):
17+
self.message = message
1318

1419
def band_selecta(band):
1520
if band == 0:
@@ -33,6 +38,10 @@ def hessian_correction(gp, x0, R_mat, innovation, mask, state_mask, band,
3338
nparams):
3439
"""Calculates higher order Hessian correction for the likelihood term.
3540
Needs the GP, the Observational uncertainty, the mask...."""
41+
if not hasattr(gp, "hessian"):
42+
# The observation operator does not provide a Hessian method. We just
43+
# return 0, meaning no Hessian correction.
44+
return 0.
3645
C_obs_inv = R_mat.diagonal()[state_mask.flatten()]
3746
mask = mask[state_mask].flatten()
3847
little_hess = []
@@ -59,12 +68,13 @@ def tip_prior():
5968
Returns
6069
-------
6170
The mean prior vector, covariance and inverse covariance matrices."""
62-
sigma = np.array([0.12, 0.7, 0.0959, 0.15, 1.5, 0.2, 0.5]) # broadly TLAI 0->7 for 1sigma
71+
# broadly TLAI 0->7 for 1sigma
72+
sigma = np.array([0.12, 0.7, 0.0959, 0.15, 1.5, 0.2, 0.5])
6373
x0 = np.array([0.17, 1.0, 0.1, 0.7, 2.0, 0.18, np.exp(-0.5*1.5)])
6474
# The individual covariance matrix
65-
little_p = np.diag ( sigma**2).astype(np.float32)
66-
little_p[5,2] = 0.8862*0.0959*0.2
67-
little_p[2,5] = 0.8862*0.0959*0.2
75+
little_p = np.diag(sigma**2).astype(np.float32)
76+
little_p[5, 2] = 0.8862*0.0959*0.2
77+
little_p[2, 5] = 0.8862*0.0959*0.2
6878

6979
inv_p = np.linalg.inv(little_p)
7080
return x0, little_p, inv_p

0 commit comments

Comments
 (0)