示例#1
0
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import encoders as en
import scipy as sp
from detector import ChangeDetector

from online_simulator import OnlineSimulator
from ddm_detector import DDMDetector
from utils import *

#Numerical data
df = pd.read_csv('sequences/sequence_2017_11_28-18.07.57.csv')
seq = np.array(df['attr_1'])


detector = DDMDetector(lambd=25)

simulator = OnlineSimulator(None,
                            [detector],
                            [seq],
                            ['attr_1'])
simulator.run(plot=True, detect_rules=False)

detected_change_points = np.array(simulator.get_detected_changes())
print_detected_change_points(detected_change_points)

plt.show()

示例#2
0
import sys
sys.path.append('./detectors/')
sys.path.insert(0, './rules_mining/')
import numpy as np
import pandas as pd
import encoders as en

from utils import *
from online_simulator import OnlineSimulator
from adwin_detector import AdwinDetector
from rules_detector import RulesDetector

#Numerical data
#df = pd.read_csv('sequences/sequence_2017_11_24-20.16.00.csv')
df = pd.read_csv('sequences/sequence_2018_04_15-22.22.16.csv')
seq_1 = np.array(df['attr_1'])
seq_2 = np.array(df['attr_4'])

detector_1 = AdwinDetector(delta=0.01)
detector_2 = AdwinDetector(delta=0.01)

rules_detector = RulesDetector(target_seq_index=1)

simulator = OnlineSimulator(rules_detector, [detector_1, detector_2],
                            [seq_1, seq_2], ['attr_1', 'attr_2'])

simulator.run(plot=True, detect_rules=True)

print_rules(simulator.get_rules_sets(), 1)
示例#3
0
detector2 = ZScoreDetector(window_size=25, threshold=4)
# detector1 = ZScoreDetector(window_size = 30, threshold=5)
detector1 = ZScoreDetector(window_size=30, threshold=4.5)
detector3 = ZScoreDetector(window_size=30, threshold=4)

target_seq_index = 1

rules_detector = RulesDetector(target_seq_index=target_seq_index,
                               window_size=1440,
                               round_to=60,
                               type="all",
                               combined=False)

simulator = OnlineSimulator(rules_detector, [detector1, detector2, detector3],
                            sequences,
                            seq_names,
                            round_to=60,
                            predict_ratio=predict_ratio)
simulator.label_encoder = lb
start_time = time.time()

simulator.run(plot=True, detect_rules=True, predict_seq=True)

discovered_rules = simulator.get_rules_sets()
# print_detected_change_points(simulator.get_detected_changes())
# print_rules(simulator.get_rules_sets(), 3)
print_best_rules(discovered_rules)
# print_rules(simulator.get_rules_sets(), 1)
#print_rules_for_attr(discovered_rules, 'light', 1)
end_time = time.time()
print(end_time - start_time)
from zscore_detector import ZScoreDetector
from utils import *

#Numerical data
df = pd.read_csv('sequences/sequence_2018_07_14-18.24.58.csv')
df = pd.read_csv('sequences/sequence_2018_07_21-22.24.18.csv')
seq_1 = np.array(df['attr_1'])
seq_2 = np.array(df['attr_2'])
seq_3 = np.array(df['attr_3'])
seq_4 = np.array(df['attr_4'])


win_size = 30

detector_1 = ZScoreDetector(window_size = win_size, threshold=3.5)
detector_2 = ZScoreDetector(window_size = win_size, threshold=4.5)
#detector_3 = ZScoreDetector(window_size = win_size, threshold=3.5)
detector_4 = ZScoreDetector(window_size = win_size, threshold=4.5)

simulator = OnlineSimulator(None,
                            [detector_1, detector_2, detector_4],
                            [seq_1, seq_2, seq_4],
                            ["attr_1", "attr_2", "attr_4"])
simulator.run(plot=True, detect_rules=False)

detected_change_points = simulator.get_detected_changes()
#print(np.array(detected_change_points))
print_detected_change_points(detected_change_points)


plt.show()
示例#5
0
detector1 = ZScoreDetector(window_size=30, threshold=5)
detector2 = ZScoreDetector(window_size=win_size, threshold=4)
detector3 = ZScoreDetector(window_size=win_size, threshold=4)
detector4 = ZScoreDetector(window_size=win_size, threshold=5)

target_seq_index = 3

rules_detector = RulesDetector(target_seq_index=target_seq_index,
                               window_size=0,
                               round_to=100,
                               type="all",
                               combined=False)

simulator = OnlineSimulator(rules_detector,
                            [detector1, detector2, detector3, detector4],
                            sequences,
                            seq_names,
                            predict_ratio=predict_ratio)
simulator.random_subsequences = False

start_time = time.time()

simulator.run(plot=True, detect_rules=True, predict_seq=True)

#print_detected_change_points(simulator.get_detected_changes())
#print_rules(simulator.get_rules_sets(), 0)

end_time = time.time()

print("Rules used for prediction:")
for br in simulator.best_rules:
#                                       round_to=100)

rules_detector = AllRulesGenerator(target_seq_index=target_seq_index,
                                   window_size=0,
                                   round_to=100)

# rules_detector = ClosedRulesGenerator(target_seq_index=target_seq_index,
#                                       window_size=0,
#                                       round_to=100)

rules_detector = DiscretizedDatasetGenerator(target_seq_index=target_seq_index,
                                             window_size=0,
                                             round_to=100)

simulator = OnlineSimulator(rules_detector,
                            [detector1, detector2, detector3, detector4],
                            sequences, seq_names)

# simulator.label_encoder = lb

start_time = time.time()

simulator.run(plot=True, detect_rules=True, predict_seq=False)

discovered_rules = simulator.get_rules_sets()
#print_detected_change_points(simulator.get_detected_changes())
# print_rules(simulator.get_rules_sets(), 5)
# print_combined_rules(simulator.get_combined_rules(), 0)
# print_rules(discovered_rules, 1)
#print_best_rules(discovered_rules)
# print_rules_for_attr(discovered_rules, 'light', 1)
import sys
sys.path.append('./detectors/')
sys.path.insert(0, './rules_mining/')

import pandas as pd
import numpy as np
from online_simulator import OnlineSimulator
from page_hinkley_detector import PageHinkleyDetector
from utils import *

#Numerical data
df = pd.read_csv('sequences/sequence_2018_03_25-17.24.22.csv')
seq1 = np.array(df['attr_1'])
seq2 = np.array(df['attr_2'])
seq3 = np.array(df['attr_3'])
seq4 = np.array(df['attr_4'])

detector1 = PageHinkleyDetector(delta=0.001, lambd=20, alpha=0.99)
detector2 = PageHinkleyDetector(delta=0.001, lambd=20, alpha=0.99)
detector3 = PageHinkleyDetector(delta=0.001, lambd=30, alpha=0.99)
detector4 = PageHinkleyDetector(delta=0.001, lambd=20, alpha=0.99)

simulator = OnlineSimulator(None, [detector1, detector2, detector3, detector4],
                            [seq1, seq2, seq3, seq4],
                            ["attr_1", "attr_2", "attr_3", "attr_4"])

simulator.run(plot=True, detect_rules=False)

detected_change_points = np.array(simulator.get_detected_changes())
print_detected_change_points(detected_change_points)
        sequences[i] = np.concatenate((seq, base_seqs[i]))

win_size = 20
detector1 = ZScoreDetector(window_size = 30, threshold=5)
detector2 = ZScoreDetector(window_size = win_size, threshold=4.5)
detector3 = ZScoreDetector(window_size = win_size, threshold=5.5)
detector4 = ZScoreDetector(window_size = win_size, threshold=4)

rules_detector = RulesDetector(target_seq_index=3,
                               window_size=0,
                               round_to=100,
                               type="all",
                               combined=True)

simulator = OnlineSimulator(rules_detector,
                            [detector1, detector2, detector3, detector4],
                            sequences,
                            seq_names)

start_time = time.time()

simulator.run(plot=False, detect_rules=True, predict_seq=False)

# print_detected_change_points(simulator.get_detected_changes())
# generate_classical_dataset(simulator.get_detected_changes())
# print_rules(simulator.get_rules_sets(), 0)

print_combined_rules(simulator.get_combined_rules(), 0)
# for cr in simulator.get_combined_rules():
#     print(cr)