def cal_k_tran(data, input_k, input_bin): x_start = 10 x_var_start = 10000 model_mean = 0 model_variance = 0.01 data.clear_change_points() cheb = chebyshev_base(min_size=60, max_window=60, k=input_k) for i, file_name in enumerate(data.get_files_test()): change_points = [] measurements = data.get_dataset_test(i) # xs = np.zeros((len(measurements), 2)) # ps = np.zeros((len(measurements), 2)) x = x_start x_var = x_var_start for index, measurement in enumerate(measurements): x, x_var = kalman.update(x, x_var, measurement, model_variance) # xs[i] = x, x_var x, x_var = kalman.predict(x, x_var, model_mean, model_variance) # ps[i] = x, x_var is_change = cheb.add_element(x) if is_change: change_points.append(index) data.set_change_points(change_points) return data
def get_changepoint_kalmanBinCheb(self, instances, inpput_x=10, input_var=10000, model_mean=0, model_variance=0.01): x_start = inpput_x x_var_start = input_var model_mean = model_mean model_variance = model_variance cheb = chebyshev_base(min_size=self.min_winsize, max_window=self.max_winsize, k=self.K) bin = binning(bin_period=self.Bin_size) change_points = [] measurements = instances # xs = np.zeros((len(measurements), 2)) # ps = np.zeros((len(measurements), 2)) x = x_start x_var = x_var_start for index, measurement in enumerate(measurements): x, x_var = kalman.update(x, x_var, measurement, model_variance) # xs[i] = x, x_var x, x_var = kalman.predict(x, x_var, model_mean, model_variance) # ps[i] = x, x_var is_change = False can_add_bin = bin.can_add_bin() if not can_add_bin: mean_bin = mean(bin.get_bin()) is_change = cheb.add_element(mean_bin) bin.reset_bin() bin.add_instance(x) if is_change: for j in range(index - self.bin_period + 1, index + 1): change_points.append(j) return change_points
def get_changepoint_kalmanCheb(self, measurements, inpput_x=10, input_var=10000, model_mean=0, model_variance=0.01): x_start = inpput_x x_var_start = input_var model_mean = model_mean model_variance = model_variance cheb = chebyshev_base(min_size=self.min_winsize, max_window=self.max_winsize, k=self.K) change_points = [] # measurements = instances # xs = np.zeros((len(measurements), 2)) # ps = np.zeros((len(measurements), 2)) x = x_start x_var = x_var_start for index, measurement in enumerate(measurements): x, x_var = kalman.update(x, x_var, measurement, model_variance) # xs[i] = x, x_var x, x_var = kalman.predict(x, x_var, model_mean, model_variance) # ps[i] = x, x_var is_change = False is_change = cheb.add_element(x) if is_change: change_points.append(index) std_low_list = cheb.get_std_low_list() std_high_list = cheb.get_std_high_list() mean_list = cheb.get_mean_list() return change_points, std_low_list, std_high_list, mean_list
def cal_k_tran(data, input_k, input_bin): x_start = 10 x_var_start = 10000 model_mean = 0 model_variance = 0.01 data.clear_change_points() cheb = chebyshev_base(min_size=60, max_window=60, k=input_k) bin = binning(bin_period=input_bin) for i, file_name in enumerate(data.get_files_test()): change_points = [] measurements = data.get_dataset_test(i) xs = np.zeros((len(measurements), 2)) ps = np.zeros((len(measurements), 2)) x = x_start x_var = x_var_start for index, measurement in enumerate(measurements): x, x_var = kalman.update(x, x_var, measurement, model_variance) xs[i] = x, x_var x, x_var = kalman.predict(x, x_var, model_mean, model_variance) ps[i] = x, x_var is_change = False can_add_bin = bin.can_add_bin() if not can_add_bin: mean_bin = mean(bin.get_bin()) is_change = cheb.add_element(mean_bin) bin.reset_bin() bin.add_instance(x) if is_change: for j in range(index - bin_period + 1, index + 1): change_points.append(j) data.set_change_points(change_points) return data
#Kalman for i in range(data.get_file_lenght()): file_name = data.get_file_name(i) measurements = data.get_dataset_test(i) xs = np.zeros((len(measurements), 2)) ps = np.zeros((len(measurements), 2)) x = x_start x_var = x_var_start for index, measurement in enumerate(measurements): pre_x = x x, x_var = kalman.update(x, x_var, measurement, model_variance) xs[index] = x, x_var x, x_var = kalman.predict(x, x_var, model_mean, model_variance) ps[index] = x, x_var if (index == 31300): print("a") is_change = kalman_detection.add_element( pre_x, measurement) if is_change: change_points.append(index) data.set_change_points(change_points) # print(change_points) result_name = '{}_W{}_L{}'.format(type, L, I) data.save_result_to_csv(dataset_index=0, threshold_after=100, L=L,