def gen_LDS(self): self.log.info('forming LDS model') # form the state space representation A = np.hstack([ self.Phi_inv * outer(self.phi, self.phi, F) for F in self.F ]) # this is [A_1 A_2 .. A_p; I 0] I = np.eye(len(self.phi)*(self.p-1)) O = np.zeros((len(self.phi)*(self.p-1), len(self.phi))) A = np.vstack([A, np.hstack([I, O])]) if self.G: B = np.hstack([ self.Phi_inv * outer(self.phi, self.phi, G) for G in self.G ]) # this is [B_1 B_2 .. B_q; I 0] O = np.zeros((len(self.phi)*(self.p-1), self.q*len(self.phi))) B = np.vstack([B, O]) else: B = None # C = <H,phi>(s1 ... sn) # <H,phi> = a^T <psi, phi> Cop = np.array([inner(self.H, phi_i) for phi_i in self.phi]) # So we need to go through each basis function in Cop (C-operator) and # evalutate it at each observation location. This begs the question of # where the observation locations should come into the program. For # the moment, though, we'll assume them fixed and store them in the # HIDEX object C = np.zeros((len(self.obs_locns),len(self.phi)*(self.p))) for i,s in enumerate(self.obs_locns): for j,basis_function in enumerate(Cop): C[i,j] = basis_function(s) # make the covariance matrices Sw = np.zeros( (len(self.phi)*(self.p), len(self.phi)*(self.p)) ,dtype=float ) for i, basis_i in enumerate(self.phi): for j, basis_j in enumerate(self.phi): Sw[i,j] = inner(basis_i, basis_j, self.Q) # form the initial state x0 = np.hstack([self.f0.weights,np.zeros((len(self.phi)*(self.p-1)))]) # turn everything into matrices for the LDS model A = np.matrix(A) B = np.matrix(B) C = np.matrix(C) Sw = np.matrix(Sw) Sv = np.matrix(self.R) x0 = np.matrix(x0).T Pi0 = np.matrix(self.Pi0) # make a state space model return LDS.LDS(A, B, C, Sw, Sv, x0, Pi0)
def __init__(self, F, G, H, f0, Q, R, Pi0, obs_locns): """ Parameters ========== F : list list of dynamic kernels G : list list of input kernels H : Kernel object observation kernel f0 : Field object initial field Q : CovarianceFunction object covariance of the field R : matrix covariance matrix of the observation noise Pi0 : matrix initial covariance matrix of the field weights obs_locns : list list of observation locations """ # process and store arguments self.p = len(F) self.q = len(G) self.psi = F[0].bases self.phi = f0.bases self.F = F self.G = G self.H = H self.Q = Q self.R = R self.f0 = f0 self.Pi0 = Pi0 self.obs_locns = obs_locns # form Phi = \int phi(s) phi^T(s) ds self.Phi = outer(self.phi, self.phi) # store the inversion self.Phi_inv = np.linalg.inv(self.Phi) # logging self.log = logging.getLogger('Field') self.log.info('Initialised new HIDEX model') # genreate an LDS representation self.LDS = self.gen_LDS()