analysis of anomalies @TODO: road test

master
Steve L. Nyemba 8 years ago
parent 584cc86b56
commit 2c0905091b

@ -1,9 +0,0 @@
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = '[0v8-247]-4qdm-h8r5!'
socketio = SocketIO(app)
if __name__ == '__main__':
socketio.run(app)

@ -25,9 +25,18 @@ class ML:
# #
r = [] r = []
for row in data : for row in data :
for item in row : if isinstance(row,list) :
if attr in item and item[attr] == value: for item in row :
r.append(item)
if attr in item and item[attr] == value:
r.append(item)
else:
#
# We are dealing with a vector of objects
#
if attr in row and row[attr] == value:
r.append(row)
return r return r
@staticmethod @staticmethod
def Extract(lattr,data): def Extract(lattr,data):
@ -43,7 +52,8 @@ class ML:
@TODO: determine computationally determine epsilon @TODO: determine computationally determine epsilon
""" """
class AnomalyDetection: class AnomalyDetection:
def __init__(self):
pass
def split(self,data,index=-1,threshold=0.65) : def split(self,data,index=-1,threshold=0.65) :
N = len(data) N = len(data)
# if N < LIMIT: # if N < LIMIT:
@ -226,7 +236,9 @@ class AnomalyDetection:
sigma = [ list(row) for row in sigma] sigma = [ list(row) for row in sigma]
return {"cov":sigma,"mean":list(u)} return {"cov":sigma,"mean":list(u)}
class AnalyzeAnomalies(AnomalyDetection): class AnalyzeAnomaly(AnomalyDetection):
def __init__(self):
AnomalyDetection.__init__(self)
""" """
This analysis function will include a predicted status because an anomaly can either be This analysis function will include a predicted status because an anomaly can either be
- A downtime i.e end of day - A downtime i.e end of day
@ -236,17 +248,28 @@ class AnalyzeAnomalies(AnomalyDetection):
""" """
def predict(self,xo,info): def predict(self,xo,info):
x = xo[len(xo)-1] x = xo[len(xo)-1]
r = AnomalyDetection.predict(x,info) r = AnomalyDetection.predict(self,[x],info)
# #
# In order to determine what the anomaly is we compute the slope (idle or crash) # In order to determine what the anomaly is we compute the slope (idle or crash)
# The slope is computed using the covariance / variance of features # The slope is computed using the covariance / variance of features
# #
N = len(info['features']) if r is not None:
xy = ML.Extract(info['features'],xo) N = len(info['features'])
xy = np.matrix(xy) xy = ML.Extract(info['features'],xo)
vxy= [xy[:,i] for i in range(0,N)] xy = np.array(xy)
print N,vxy.shape
alpha = info['cov'] / vxy vxy= np.array([ np.var(xy[:,i]) for i in range(0,N)])
cxy=np.array(info['parameters']['cov'])
#cxy=np.cov(np.transpose(xy))
if np.sum(vxy) == 0:
vxy = cxy
alpha = cxy/vxy
r = {"anomaly":r[0][1],"slope":list(alpha[:,0])}
return r return r
class Regression: class Regression:
parameters = {} parameters = {}

Loading…
Cancel
Save