-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_me.py
63 lines (50 loc) · 2.5 KB
/
run_me.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
from distance_changepoint_detectors import ODBODTHRESHOLD, ODBODTHRESHOLDCHI2DISTANCE, CustomODBODHistogram
_author__ = '[email protected]'
class ChangeDistanceDetectorThreshold:
def __init__(self, dim_input=10, num_predecessor=9, lambda_p=1.0, beta_p=4.0, threshold=None):
self.dim = dim_input # input dimension
self.num_predecessor = num_predecessor # number of predecessor
self.odbod = ODBODTHRESHOLD(['PacketHistogram'], self.dim, self.num_predecessor,
threshold, lambda_p, beta_p, initial_mahalanobis_matrix=None,
max_threshold=40.0)
result_file = "distances.txt"
alarm_file = "alarms.txt"
self.odbod.print_verbosely(True)
self.odbod.set_result_save(result_file)
self.odbod.set_alarm_save(alarm_file)
self.odbod.create_odbodwindows()
def handle_data_vector(self, data_vector):
self.odbod.process(data_vector)
self.odbod.update_windows()
class ChangeDistanceDetectorChiSquared:
def __init__(self, dim_input=10, num_predecessor=9, lambda_p=1.0, beta_p=4.0, threshold=None):
self.dim = dim_input # input dimension
self.num_predecessor = num_predecessor # number of predecessor
self.odbod = ODBODTHRESHOLDCHI2DISTANCE(['PacketHistogram'], dim_input=self.dim,
num_predecessor=self.num_predecessor,
threshold=1, lambda_p=lambda_p, beta_p=beta_p)
result_file = "distances.txt"
alarm_file = "alarms.txt"
self.odbod.print_verbosely(True)
self.odbod.set_result_save(result_file)
self.odbod.set_alarm_save(alarm_file)
self.odbod.create_odbodwindows()
def handle_data_vector(self, data_vector):
self.odbod.process(data_vector)
self.odbod.update_windows()
def main():
num_of_features = 3
num_of_samples = 100
max_counts = 100
feature_names = ['Feat1', 'Feat2', 'Feat3']
cpd = ChangeDistanceDetectorChiSquared(dim_input=num_of_features)
# cpd = ChangeDistanceDetectorThreshold(dim_input=num_of_features)
cstWindows = CustomODBODHistogram(headers=feature_names)
cstWindows.set_max_value(max_value=max_counts)
for _ in range(num_of_samples):
values = np.random.randint(0, max_counts, size=(num_of_features))
cpd.handle_data_vector(values)
cstWindows.update(values)
if __name__ == '__main__':
main()