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
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
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(): change_point(j) j = j + 1 plt.plot(list_data) for i in change_point: plt.axvline(i, color='black', linestyle='-', linewidth=0.1) fig = plt.gcf() fig.set_size_inches(20, 5.5) plt.ylabel('value') plt.xlabel('Time') plt.show()