-
Notifications
You must be signed in to change notification settings - Fork 0
/
MEB12.py
126 lines (113 loc) · 4.44 KB
/
MEB12.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import ExSpaceState2 as EE
import numpy as np
class MultMEB:
def __init__(self):
self.EE = EE.EspaceState()
self.__init_matrix()
self.__set_init()
self.EE.set_system(self.z,self.t,self.r,self.h,self.q,self.c,self.d,self.z_func,self.t_func)
def filter(self,y):
return self.EE.diffuse_filter(y)
def simulate(self,nr_params):
return self.EE.simulate(nr_params)
def get_params(self):
return self.EE.params
def set_params(self,params):
self.EE.params = params
def fit(self,y):
return self.EE.optimize(y)
def __init_matrix(self):
self.z = lambda alpha,params : self.Z(alpha,params)
self.t = lambda alpha,params : self.T(alpha,params)
self.r = lambda alpha,params : self.R(alpha,params)
self.q = lambda alpha,params : self.Q(alpha,params)
self.h = lambda alpha,params : self.H(alpha,params)
self.c = lambda alpha,params : self.C(alpha,params)
self.d = lambda alpha,params : self.D(alpha,params)
self.z_func = lambda alpha,params : self.Z_func(alpha,params)
self.t_func = lambda alpha,params : self.T_func(alpha,params)
def __set_init(self):
init_params = [0,0,0,0,-0.2,-0.1]
self.EE.set_dims(alpha_dim =13,y_dim = 1,burn = 13)
init_a = lambda params : np.matrix([0,0,0,0,0,0,0,0,0,0,0,0,0]).T
init_P = lambda params : np.diag([10e5]*13)
self.EE.set_init(init_params,init_a,init_P)
def Z_func(self,alpha,params):
mu = alpha.item(0)
gamma = alpha.item(2)
c_0 = params[4]
c_mu = params[5]
exp = np.exp(c_0 + c_mu*mu)
return np.matrix([mu + gamma*exp])
def T_func(self,alpha,params):
return self.T(alpha,params)*alpha
@staticmethod
def Z(alpha,params):
mu = alpha.item(0)
gamma = alpha.item(2)
c_0 = params[4]
c_mu = params[5]
exp = np.exp(c_0 + c_mu*mu)
return np.matrix([1 + gamma*c_mu*exp,0,exp,0,0,0,0,0,0,0,0,0,0])
@staticmethod
def T(alpha,params):
return np.matrix([[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]])
@staticmethod
def R(alpha,params):
return np.matrix([[1,0,0],
[0,1,0],
[0,0,1],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0]])
@staticmethod
def H(alpha,params):
return np.matrix([np.exp(params[0])])
@staticmethod
def Q(alpha,params):
return np.matrix([[np.exp(params[1]),0 , 0],
[0 ,np.exp(params[2]), 0],
[0 ,0 ,np.exp(params[3])]])
@staticmethod
def C(alpha,params):
return np.matrix([[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0]])
@staticmethod
def D(alpha,params):
return np.matrix([0])
def frac(x):
return np.exp(x)/(1 + np.exp(x))
def pos(x):
return np.exp(x)
def freq(x):
return (np.pi*2)/np.exp(x)