demo.py 619 B

123456789101112131415161718192021222324
  1. import numpy as np
  2. m = [[0.0, 4.5], [0.0, 4.5], [11.6, 4.4], [12.2, 4.3], [1.4, 3.9], [1.4, 3.9], [2.5, 3.8], [0.1, 3.8], [0.5, 5.1], [0.7, 5.2], [0.7, 5.1], [0.0, 4.6], [0.0, 4.6]]
  3. m_ = np.array(m)
  4. x_ = np.mean(m_[:,0])
  5. y_ = np.mean(m_[:,1])
  6. u = np.array([x_,y_])
  7. r = [np.sqrt(np.var(m_[:,0])),np.sqrt(np.var(m_[:,1]))]
  8. x__ = (m_[:,0] - x_ )/r[0]
  9. y__ = (m_[:,1] - y_ )/r[1]
  10. nm = np.matrix([x__,y__])
  11. cx = np.cov(nm)
  12. print cx.shape
  13. x = np.array([1.9,3])
  14. a = 1/ np.sqrt(2*np.pi)
  15. #from scipy.stats import multivariate_normal
  16. #print multivariate_normal.pdf(x,u,cx)
  17. #-- We are ready to perform anomaly detection ...