MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / set

Method set

hmm_class/hmmc_theano2.py:84–163  ·  view source on GitHub ↗
(self, preSoftmaxPi, preSoftmaxA, preSoftmaxR, mu, sigmaFactor)

Source from the content-addressed store, hash-verified

82 plt.show()
83
84 def set(self, preSoftmaxPi, preSoftmaxA, preSoftmaxR, mu, sigmaFactor):
85 self.preSoftmaxPi = theano.shared(preSoftmaxPi)
86 self.preSoftmaxA = theano.shared(preSoftmaxA)
87 self.preSoftmaxR = theano.shared(preSoftmaxR)
88 self.mu = theano.shared(mu)
89 self.sigmaFactor = theano.shared(sigmaFactor)
90 M, K = preSoftmaxR.shape
91 self.M = M
92 self.K = K
93
94 pi = T.nnet.softmax(self.preSoftmaxPi).flatten()
95 A = T.nnet.softmax(self.preSoftmaxA)
96 R = T.nnet.softmax(self.preSoftmaxR)
97
98
99 D = self.mu.shape[2]
100 twopiD = (2*np.pi)**D
101
102 # set up theano variables and functions
103 thx = T.matrix('X') # represents a TxD matrix of sequential observations
104 def mvn_pdf(x, m, S):
105 k = 1 / T.sqrt(twopiD * T.nlinalg.det(S))
106 e = T.exp(-0.5*(x - m).T.dot(T.nlinalg.matrix_inverse(S).dot(x - m)))
107 return k*e
108
109 def gmm_pdf(x):
110 def state_pdfs(xt):
111 def component_pdf(j, xt):
112 Bj_t = 0
113 # j = T.cast(j, 'int32')
114 for k in range(self.K):
115 # k = int(k)
116 # a = R[j,k]
117 # b = mu[j,k]
118 # c = sigma[j,k]
119 L = self.sigmaFactor[j,k]
120 S = L.dot(L.T)
121 Bj_t += R[j,k] * mvn_pdf(xt, self.mu[j,k], S)
122 return Bj_t
123
124 Bt, _ = theano.scan(
125 fn=component_pdf,
126 sequences=T.arange(self.M),
127 n_steps=self.M,
128 outputs_info=None,
129 non_sequences=[xt],
130 )
131 return Bt
132
133 B, _ = theano.scan(
134 fn=state_pdfs,
135 sequences=x,
136 n_steps=x.shape[0],
137 outputs_info=None,
138 )
139 return B.T
140
141 B = gmm_pdf(thx)

Callers 2

fitMethod · 0.95
fake_signalFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected