def testTrackW(self): self.spirit = spirit.Spirit(k=1) x_t = spirit.new_matrix(shape=(self.spirit.n, 1)) for i in range(self.spirit.n): # [1, 2, 3]^T x_t[i] = i + 1 prev_w_shape = self.spirit.w[0].shape prev_w_len = len(self.spirit.w) self.spirit._trackW(x_t, self.spirit.k, self.spirit.w, self.spirit.d, self.spirit.l) oracle_d = np.mat([ self.spirit.l * spirit.SMALL_POSITIVE_VALUE + 1 * 1 + 0 * 2 + 0 * 3 ]) self.assertEqual(self.spirit.d[0], oracle_d[0]) self.assertEqual(prev_w_shape, self.spirit.w[0].shape) self.assertEqual(prev_w_len, len(self.spirit.w)) # test normality self.assertEqual(np.linalg.norm(self.spirit.w[:,:self.spirit.k]), 1)
def detect_anomalies(trace_filename, detector, motes_to_ignore=tuple()): ''' @return: summarized, anomaly_levels ''' anomaly_levels = [] summarized_series = [] sp = spirit.Spirit(l=1., k=1, fixed_k=True) tr = tracetools.TraceReader(trace_filename, motes_to_ignore=motes_to_ignore) trace_start = -1 for data in tr.read(): if trace_start < 0: trace_start = data['timestamp'] data = np.matrix([v for k, v in data.iteritems() if k != "timestamp"]).T k, w, Y = sp.update(data) summ_Y = Y[0, 0] anomaly_level = detector.apply(summ_Y) anomaly_levels.append(anomaly_level) summarized_series.append(summ_Y) return summarized_series, anomaly_levels, trace_start
def run(self, input): data = input["data"] #smoothed data from cypress smoothds = [] for dtas in data: smoothds.append(dtas[0]) dmat = numpy.array(smoothds) if self.ispca: #lower -> retain more energy alg = spirit.PCA(self.thresh) if self.pcafixk: alg.setfixk(self.pcafixk) else: alg = spirit.Spirit(dmat.shape[0], self.startm, self.ebounds, self.vlambda) alg.run(dmat.T, True) output = input #time history of hidden variables output["hvlog"] = alg.gethvlog().T #time history of SPIRIT reconstructions output["reconlog"] = alg.getreclog() #final SPIRIT projection matrix output["projection"] = alg.W #number of hidden variables at each time tick mlog = alg.getmlog() output["mlog"] = mlog #maximum number of hidden variables output["maxhvs"] = int(max(mlog)) #minimum number of hidden variables output["minhvs"] = int(min(mlog)) if alg.getcenter() != None: output["center"] = alg.getcenter() return input
pyglet.sprite.Sprite(img=resources.salamander_frames[0], x=obj.get(u'x'), y=m_height - obj.get(u'y'))) hz.frames = resources.salamander_frames game_objects.append(hz) """ sg = subghost.SubGhost(pyglet.sprite.Sprite(img = resources.subghost_frames[0], x=200, y=400)) sg.frames = resources.subghost_frames game_objects.append(sg) """ #game_objects.append(subghost.SubGhost(pyglet.sprite.Sprite(img = resources.subghost_image, x=100, y=600))) #game_objects.append(speech.Speech("Hi")) sp = spirit.Spirit( pyglet.sprite.Sprite(img=resources.sprite_frames[0], x=200, y=m_height / 2)) sp.frames = resources.sprite_frames game_objects.append(sp) game_objects.append(player) label = pyglet.text.Label('', font_name='Times New Roman', font_size=12, x=player.x, y=player.y + 24) #game_objects.append(label)
def setUp(self): self.spirit = spirit.Spirit()
def __init__(self, detectors): self.spirit = spirit.Spirit(l=1., k=len(detectors), fixed_k=True) self.detectors = detectors