def concept_drift_detection(self, X, Y): if self.init_drift_detection: if self.drift_detector == "KSWIN": self.cdd = [ KSWIN(w_size=100, stat_size=30, alpha=self.confidence) for elem in X.T ] if self.drift_detector == "ADWIN": self.cdd = [ADWIN() for elem in X.T] if self.drift_detector == "DDM": self.cdd = [DDM() for elem in X.T] if self.drift_detector == "EDDM": self.cdd = [EDDM() for elem in X.T] self.init_drift_detection = False self.drift_detected = False if not self.init_drift_detection: for elem, detector in zip(X.T, self.cdd): for e in elem: detector.add_element(e) if detector.detected_change(): self.drift_detected = True self.n_detections = self.n_detections + 1 return self.drift_detected # if name=="__main__": # from skmultiflow import
def main(): def eval_drift(detector, element): detector.add_element(element) return detector.detected_warning_zone(), detector.detected_change() predictions = np.random.randint(2, size=2000) predictions[1500:] = np.random.randint(1000, size=500) hddm_w = HDDM_W() hddm_a = HDDM_A() eddm = EDDM() hddm_w_warn, hddm_w_change = zip( *[eval_drift(hddm_w, e) for e in predictions]) hddm_a_warn, hddm_a_change = zip( *[eval_drift(hddm_a, e) for e in predictions]) eddm_warn, eddm_change = zip(*[eval_drift(eddm, e) for e in predictions]) plt.figure() plt.plot(hddm_w_change, label='hddm-w') plt.plot(hddm_a_change, label='hddm-a') plt.plot(eddm_change, label='eddm') # plt.plot(hddm_w_warn, label='hddm-w') # plt.plot(hddm_a_warn, label='hddm-a') # plt.plot(eddm_warn, label='eddm') plt.legend(loc=0) plt.figure() plt.plot(predictions) plt.show()
def concept_drift_detection(self, X, Y): if self.init_drift_detection: if self.drift_detector == "KSWIN": self.cdd = [KSWIN(w_size = 100, stat_size = 30, alpha=self.confidence) for elem in X.T] if self.drift_detector == "ADWIN": self.cdd = [ADWIN() for elem in X.T] if self.drift_detector == "DDM": self.cdd = [DDM() for elem in X.T] if self.drift_detector == "EDDM": self.cdd = [EDDM() for elem in X.T] if self.drift_detector == "KSVEC": self.cdd = KSVEC(vec_size=X.shape[1]) self.init_drift_detection = False self.drift_detected = False if not self.init_drift_detection: if self.drift_detector == "KSVEC": self.cdd.add_element(X) if self.cdd.detected_change(): self.drift_detected = True else: for elem, detector in zip(X.T, self.cdd): for e in elem: detector.add_element(e) if detector.detected_change(): self.drift_detected = True self.n_detections = self.n_detections +1 return self.drift_detected
def make_detector(warn=False, s=1e-5, drift_detector='adwin'): sensitivity = s * 10 if warn else s if drift_detector == 'adwin': return ADWIN(delta=sensitivity) if drift_detector == 'EDDM': return EDDM() if drift_detector == 'DDM': return DDM()
def test_eddm(test_path): """ EDDM drift detection test. The first half of the stream contains a sequence corresponding to a normal distribution of integers from 0 to 1. From index 999 to 1999 the sequence is a normal distribution of integers from 0 to 7. """ eddm = EDDM() test_file = os.path.join(test_path, 'drift_stream.npy') data_stream = np.load(test_file) expected_indices = [51, 129, 291, 337, 396, 456, 523, 581, 675, 730, 851] detected_indices = [] for i in range(data_stream.size): eddm.add_element(data_stream[i]) if eddm.detected_change(): detected_indices.append(i) assert detected_indices == expected_indices
def test_eddm(): """ EDDM drift detection test. The first half of the data contains a sequence corresponding to a normal distribution with mean 0 and sigma 0.1. The second half corresponds to a normal distribution with mean 0.5 and sigma 0.1. """ eddm = EDDM() np.random.seed(1) mu, sigma = 0, 0.1 # mean and standard deviation d_1 = np.random.normal(mu, sigma, 1000) > 0 mu, sigma = 0.5, 0.1 # mean and standard deviation d_2 = np.random.normal(mu, sigma, 1000) > 0 data_stream = np.concatenate((d_1.astype(int), d_2.astype(int))) expected_indices = [64, 1135] detected_indices = [] for i in range(data_stream.size): eddm.add_element(data_stream[i]) if eddm.detected_change(): detected_indices.append(i) assert detected_indices == expected_indices expected_info = "EDDM()" assert eddm.get_info() == expected_info
def sim_eddm(input_stream, start_point=0): eddm = EDDM() change_point = [] detected_warning = [] for i in range(len(input_stream)): eddm.add_element(input_stream[i]) if eddm.detected_warning_zone(): detected_warning.append(i + start_point) if eddm.detected_change(): # plt.axvline(i, color='r', linestyle='dashed') change_point.append(i + start_point) # print('Change detected in data: ' + str(input_stream[i]) + ' - at index: ' + str(i)+'\n\n') return detected_warning, change_point
return stream def drift_flow(stream, method, name, beginning_stream, end_tables): detected_change = [] detected_warning = [] number_of_changes = 0 for i in range(len(stream)): method.add_element(stream[i]) if method.detected_warning_zone(): print(f'Warning zone has been detected in data: {stream[i]} - of index: {i}') detected_warning.append((stream[i])) if method.detected_change(): detected_change.append(stream[i]) print(f'Change has been detected in data: {stream[i]} - of index: {i}') number_of_changes += 1 else: detected_change.append(None) print(f'{name} Detected changes: {number_of_changes}') print(f'{name} Detected warning zones: {str(len(detected_warning))}') plots(stream, detected_change, name, beginning_stream, end_tables) stream = make_stream(PATH) drift_flow(stream, EDDM(), 'EDDM', 0, 500) drift_flow(stream, HDDM_A(), 'HDDM_A', 0, 500) drift_flow(stream, HDDM_W(), 'HDDM_W', 0, 500) drift_flow(stream, PageHinkley(), 'PH', 0, 500) drift_flow(stream, DDM(), 'DDM', 0, 500)
# Incorrect number of clusters if DETECTOR == "IGMM": adaptor = IGMM(min_components=3, max_components=10) elif DETECTOR == "CMGMM": adaptor = CMGMM(min_components=4, max_components=6) else: adaptor = GaussianMixture(n_components=4) if DETECTOR == "ADWIN": detector = ADWIN() elif DETECTOR == "PageHinkley": detector = PageHinkley() elif DETECTOR == "HDDM": detector = HDDM_A() elif DETECTOR == "EDDM": detector = EDDM() elif DETECTOR == "KSWIN": detector = KSWIN(alpha=0.001, window_size=20, stat_size=15) elif DETECTOR == "KD3": detector = KD3(window_size=args.window_size, accumulative_threshold=args.p2, detection_threshold=args.p1) else: detector = None model = EvolvingClassifier(adaptor=adaptor, detector=detector, label=LABEL) model.train(trainDataset, 'label', 'mfcc') #model.validate(validation.mfcc.to_numpy(),validation.label.to_numpy()) start_time = time.time() logdrift = []
def __init__(self): """Inicjalizacja klasy algorytmu EDDM""" self.name = 'EDDM' self.model = EDDM() self.change_indexes = [] self.warning_zones_indexes = []
def reset_model(self): self.model = EDDM() self.change_indexes = [] self.warning_zones_indexes = []
# Imports from skmultiflow.data.sine_generator import SineGenerator import matplotlib.pyplot as plt from chebyshev_adwin import chebyshev_adwin as chebyshev import sim_adwin as sim import numpy as np # from skmultiflow.drift_detection.adwin import ADWIN # adwin = ADWIN() from skmultiflow.drift_detection.eddm import EDDM eddm = EDDM() # Setting up the stream # from skmultiflow.data.sine_generator import SineGenerator # stream = SineGenerator(classification_function = 0, random_state = 112, # balance_classes = False, has_noise = False) # from skmultiflow.data.led_generator_drift import LEDGeneratorDrift # stream = LEDGeneratorDrift(random_state = 112, noise_percentage = 0.28,has_noise= True,n_drift_features=4) # from skmultiflow.data import ConceptDriftStream # stream = ConceptDriftStream(random_state=123456, position=25000) from skmultiflow.data.mixed_generator import MIXEDGenerator stream = MIXEDGenerator(classification_function=1, random_state=112, balance_classes=False)
######################## CURIE ################### lst_dim = [n_bins] * n_feats curie = CA_VonNeumann_Classifier(bins=[], bins_margin=bins_margin, dimensions=lst_dim, cells=empties(lst_dim)) limits_automata = list(np.zeros(1)) #ca_names=['CURIE'] mutants_time = empty_mutant(curie.dimensions) ######################## LEARNERS ################### learners_ref = [HoeffdingTree(), KNN(), NaiveBayes()] ######################## DETECTORS ################### detectores_ref = [DDM(), EDDM(), ADWIN(), PageHinkley(), curie] n_pasos = len(datasets) * len(tipos) * len(learners_ref) * len( detectores_ref) SCORES_LER = [] TIMES_LER = [] RAMS_LER = [] DETECTIONS_LER = [] for ler in range(len(learners_ref)): learner = deepcopy(learners_ref[ler]) SCORES_DET = [] TIMES_DET = []
# Imports from skmultiflow.data.sine_generator import SineGenerator import matplotlib.pyplot as plt from skmultiflow.data import ConceptDriftStream import sim_adwin as sim import numpy as np # from skmultiflow.drift_detection.adwin import ADWIN # adwin = ADWIN() from skmultiflow.drift_detection.eddm import EDDM eddm = EDDM() # Setting up the stream stream = SineGenerator(classification_function=0, random_state=112, balance_classes=True, has_noise=True) # stream = ConceptDriftStream(random_state=123456, position=25000) # Retrieving one sample stream.generate_drift() data = stream.next_sample(2000) list_data = [] change_point = [] print(data[0].size) j = 0 for i in range(data[0].size): list_data.append(data[0].item(i)) eddm.add_element(data[0].item(i)) if eddm.detected_change():