mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-07 11:02:38 +02:00
UPD: Added SVD Kalman Filter, EM algorithm for gradient calculation (only for discrete KF)
This commit is contained in:
parent
abdce992ec
commit
b8e21057f5
5 changed files with 786 additions and 67 deletions
|
|
@ -38,11 +38,11 @@ class sde_Matern32(Matern32):
|
|||
lengthscale = float(self.lengthscale.values)
|
||||
|
||||
foo = np.sqrt(3.)/lengthscale
|
||||
F = np.array(((0, 1), (-foo**2, -2*foo)))
|
||||
L = np.array(( (0,), (1,) ))
|
||||
F = np.array(((0, 1.0), (-foo**2, -2*foo)))
|
||||
L = np.array(( (0,), (1.0,) ))
|
||||
Qc = np.array(((12.*np.sqrt(3) / lengthscale**3 * variance,),))
|
||||
H = np.array(((1, 0),))
|
||||
Pinf = np.array(((variance, 0), (0, 3.*variance/(lengthscale**2))))
|
||||
H = np.array(((1.0, 0),))
|
||||
Pinf = np.array(((variance, 0.0), (0.0, 3.*variance/(lengthscale**2))))
|
||||
P0 = Pinf.copy()
|
||||
|
||||
# Allocate space for the derivatives
|
||||
|
|
|
|||
|
|
@ -56,19 +56,20 @@ class sde_StdPeriodic(StdPeriodic):
|
|||
|
||||
|
||||
w0 = 2*np.pi/self.wavelengths # frequency
|
||||
lengthscales = 2*self.lengthscales
|
||||
|
||||
[q2,dq2l] = seriescoeff(N,2*self.lengthscales,self.variance)
|
||||
[q2,dq2l] = seriescoeff(N,lengthscales,self.variance)
|
||||
# lengthscale is multiplied by 2 because of slightly different
|
||||
# formula for periodic covariance function.
|
||||
# For the same reason:
|
||||
|
||||
dq2l = 2*dq2l
|
||||
|
||||
if np.any( np.isnan(q2)):
|
||||
raise ValueError("SDE periodic covariance error1")
|
||||
if np.any( np.isfinite(q2) == False):
|
||||
raise ValueError("SDE periodic covariance error 1")
|
||||
|
||||
if np.any( np.isnan(dq2l)):
|
||||
raise ValueError("SDE periodic covariance error1")
|
||||
if np.any( np.isfinite(dq2l) == False):
|
||||
raise ValueError("SDE periodic covariance error 2")
|
||||
|
||||
F = np.kron(np.diag(range(0,N+1)),np.array( ((0, -w0), (w0, 0)) ) )
|
||||
L = np.eye(2*(N+1))
|
||||
|
|
@ -159,8 +160,9 @@ def seriescoeff(m=6,lengthScale=1.0,magnSigma2=1.0, true_covariance=False):
|
|||
|
||||
else:
|
||||
coeffs = 2*magnSigma2*sp.exp( -lengthScale**(-2) ) * special.iv(range(0,m+1),1.0/lengthScale**(2))
|
||||
if np.any( np.isnan(coeffs)):
|
||||
pass
|
||||
if np.any( np.isfinite(coeffs) == False):
|
||||
raise ValueError("sde_standard_periodic: Coefficients are not finite!")
|
||||
#import pdb; pdb.set_trace()
|
||||
coeffs[0] = 0.5*coeffs[0]
|
||||
|
||||
# Derivatives wrt (lengthScale)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class sde_RBF(RBF):
|
|||
|
||||
# Infinite covariance:
|
||||
Pinf = sp.linalg.solve_lyapunov(F, -np.dot(L,np.dot( Qc[0,0],L.T)))
|
||||
|
||||
Pinf = 0.5*(Pinf + Pinf.T)
|
||||
# Allocating space for derivatives
|
||||
dF = np.empty([F.shape[0],F.shape[1],2])
|
||||
dQc = np.empty([Qc.shape[0],Qc.shape[1],2])
|
||||
|
|
@ -96,13 +96,14 @@ class sde_RBF(RBF):
|
|||
dPinf[:,:,0] = dPinf_variance
|
||||
dPinf[:,:,1] = dPinf_lengthscale
|
||||
|
||||
# Benefits of this are unjustified
|
||||
#import GPy.models.state_space_main as ssm
|
||||
#(F, L, Qc, H, Pinf, dF, dQc, dPinf,T) = ssm.balance_ss_model(F, L, Qc, H, Pinf, dF, dQc, dPinf)
|
||||
|
||||
P0 = Pinf.copy()
|
||||
dP0 = dPinf.copy()
|
||||
|
||||
# Benefits of this are not very sound. Helps only in one case:
|
||||
# SVD Kalman + RBF kernel
|
||||
import GPy.models.state_space_main as ssm
|
||||
(F, L, Qc, H, Pinf, P0, dF, dQc, dPinf,dP0, T) = ssm.balance_ss_model(F, L, Qc, H, Pinf, P0, dF, dQc, dPinf, dP0 )
|
||||
|
||||
return (F, L, Qc, H, Pinf, P0, dF, dQc, dPinf, dP0)
|
||||
|
||||
class sde_Exponential(Exponential):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue