No title

Anonymous Coward 2018-03-05 14:00:25.723405 UTC

1#Comput norms and inverses of sigma for various classes
2 log_sig_norm = np.zeros((Nclasses))
3 sig_inv = np.zeros((Nclasses,Ndims,Ndims))
4 for i in range(Nclasses):
5 log_sig_norm[i] = np.log(np.linalg.norm(sigma[i,:,:], 2))
6 sig_inv_temp = np.diag(sigma[i,:,:])
7 sig_inv_temp = 1.0/sig_inv_temp
8 sig_inv[i,:,:] = np.diag(sig_inv_temp)
9 #print(sig_inv)
10
11 #Loop over data-points
12 for i in range(Npts):
13 x = X[i,:]
14 #Loop over classes
15 for j in range(Nclasses):
16 #Compute log-probabilities for each point and class
17 delta = -0.5 * log_sig_norm[j]
18 delta += np.log(prior[j])
19 y = x - mu[j,:]
20 z = np.dot(y,sig_inv[j,:,:])
21 delta -= 0.5 * np.dot(z,y)
22 logProb[j,i] = delta