Bladeren bron

computation seems correct

Steve L. Nyemba 8 jaren geleden
bovenliggende
commit
44674bb83c
1 gewijzigde bestanden met toevoegingen van 7 en 4 verwijderingen
  1. 7 4
      test/demo.py

+ 7 - 4
test/demo.py

@@ -12,16 +12,19 @@ yr_ = np.sqrt(np.var(m[1,:]))
 mn = np.array([list( (m[0,:]-xu_)/xr_),list( (m[1,:]-yu_)/yr_)])
 cx = np.cov(mn)
 n = m.shape[0]
-x = np.array([2.5,3.1])
+x = np.array([2.4,3.1])
 u = np.array([xu_,yu_])
 d = np.matrix(x - u)
 d.shape = (n,1)
 a  = (2*(np.pi)**(n/2))*np.linalg.det(cx)**0.5
-b = np.exp(-0.5*np.transpose(d) * (cx**-1)*d)
+b = np.exp((-0.5*np.transpose(d)) * (np.linalg.inv(cx)*d))
 
 from scipy.stats import multivariate_normal
 xo= multivariate_normal.pdf(x,u,cx)
 yo= (b/a)[0,0]
-for row in np.transpose(m):
-	print ",".join([str(value) for value in row])
+e= 0.001
+print [yo,yo < e]
+print [xo,xo < e]
+#for row in np.transpose(m):
+#	print ",".join([str(value) for value in row])
 #-- We are ready to perform anomaly detection ...