parent
2884f3d78b
commit
278636bb14
@ -0,0 +1,43 @@
|
|||||||
|
from utils import transport
|
||||||
|
from utils.ml import ML
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
path = os.environ['MONITOR_CONFIG_PATH']
|
||||||
|
f = open(path)
|
||||||
|
CONFIG = json.loads( f.read())
|
||||||
|
f.close()
|
||||||
|
factory = transport.DataSourceFactory()
|
||||||
|
#greader = factory.instance(type=ref,args=p)
|
||||||
|
|
||||||
|
class TestML(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
|
||||||
|
ref = CONFIG['store']['class']['read']
|
||||||
|
p = CONFIG['store']['args']
|
||||||
|
p['qid'] = ['apps']
|
||||||
|
self.greader = factory.instance(type=ref,args=p)
|
||||||
|
def test_has_date(self):
|
||||||
|
r = self.greader.read()
|
||||||
|
|
||||||
|
self.assertTrue(r)
|
||||||
|
def test_Filter(self):
|
||||||
|
r = self.greader.read()
|
||||||
|
r = r['apps']
|
||||||
|
x = ML.Filter('label','Google Chrome',r)
|
||||||
|
for row in x:
|
||||||
|
self.assertTrue(row['label'] == 'Google Chrome')
|
||||||
|
def test_Extract(self):
|
||||||
|
r = self.greader.read()
|
||||||
|
r = r['apps']
|
||||||
|
x = ML.Filter('label','Google Chrome',r)
|
||||||
|
x_ = ML.Extract(['cpu_usage','memory_usage'], x)
|
||||||
|
print x[0]
|
||||||
|
print x_
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__' :
|
||||||
|
unittest.main()
|
@ -0,0 +1,24 @@
|
|||||||
|
import numpy as np
|
||||||
|
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]]
|
||||||
|
|
||||||
|
m_ = np.array(m)
|
||||||
|
x_ = np.mean(m_[:,0])
|
||||||
|
y_ = np.mean(m_[:,1])
|
||||||
|
u = np.array([x_,y_])
|
||||||
|
r = [np.sqrt(np.var(m_[:,0])),np.sqrt(np.var(m_[:,1]))]
|
||||||
|
x__ = (m_[:,0] - x_ )/r[0]
|
||||||
|
y__ = (m_[:,1] - y_ )/r[1]
|
||||||
|
|
||||||
|
nm = np.matrix([x__,y__])
|
||||||
|
|
||||||
|
|
||||||
|
cx = np.cov(nm)
|
||||||
|
print cx.shape
|
||||||
|
x = np.array([1.9,3])
|
||||||
|
|
||||||
|
a = 1/ np.sqrt(2*np.pi)
|
||||||
|
#from scipy.stats import multivariate_normal
|
||||||
|
#print multivariate_normal.pdf(x,u,cx)
|
||||||
|
|
||||||
|
|
||||||
|
#-- We are ready to perform anomaly detection ...
|
Loading…
Reference in new issue