Commit 32297bd2 authored by Alexander Henkel's avatar Alexander Henkel
Browse files

bugfixing

parent 56b185ac
%% Cell type:code id: tags:
%% Cell type:code id:347f47a4 tags:
``` python
%load_ext autoreload
%autoreload 2
%matplotlib notebook
```
%% Cell type:code id: tags:
%% Cell type:code id:1e458131 tags:
``` python
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display, Markdown
import copy
import dbm
```
%% Cell type:code id: tags:
%% Cell type:code id:55746bea tags:
``` python
module_path = os.path.abspath(os.path.join('..'))
os.chdir(module_path)
if module_path not in sys.path:
sys.path.append(module_path)
```
%% Cell type:code id: tags:
%% Cell type:code id:86d3a948 tags:
``` python
from personalization_tools.load_data_sets import *
from personalization_tools.helpers import *
from personalization_tools.learner_pipeline import LearnerPipeline, Evaluation
from personalization_tools.dataset_builder import *
from personalization_tools.model_evaluation import ModelEvaluation
from personalization_tools.sensor_recorder_data_reader import SensorRecorderDataReader
from personalization_tools.dataset_manager import DatasetManager
from personalization_tools.trainings_manager import TrainingsManager
from personalization_tools.pseudo_model_settings import pseudo_model_settings, pseudo_label_generators_to_int
from personalization_tools.pseudo_label_evaluation import *
from personalization_tools.evaluation_manager import EvaluationManager
```
%% Cell type:code id: tags:
%% Cell type:code id:cf5ca0eb tags:
``` python
predictions_db = './data/cluster/participant_training/predictions_db_2'
configuration_file = './data/cluster/participant_training/config_2.yaml'
evaluation_manager = EvaluationManager(predictions_db)
```
%% Cell type:code id: tags:
%% Cell type:code id:6a8d5388 tags:
``` python
evaluation_manager.load_config(configuration_file)
```
%% Cell type:code id: tags:
%% Output
load config
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-6-1a95d51ed4d9> in <module>
----> 1 evaluation_manager.load_config(configuration_file)
~/gitrepos/uni/handwashing_personalizer/src/personalization_tools/evaluation_manager.py in load_config(self, config_file_path)
105
106 self.personalized_models[collection_config['name']] = list()
--> 107 for model in self.training_managers[training_db].get_all_training_runs()[collection_config['training_run_name']]:
108 # print('add model', model, 'assign', test_collection)
109 # print('assign', train_collection)
KeyError: 'pseudo_collection_01_run1'
%% Cell type:code id:05dd3052 tags:
``` python
for dataset_manager in evaluation_manager.dataset_managers.values():
for dataset in dataset_manager.get_all_datasets().values():
dataset.generate_windows()
```
%% Cell type:code id: tags:
%% Cell type:code id:d206ac9a tags:
``` python
evaluation_manager.do_predictions()
```
%% Cell type:code id: tags:
%% Cell type:code id:b2bced4c tags:
``` python
evaluation_manager.model_evaluation.get_evaluations(calc_averages=True, sort_by='f1')
```
%% Cell type:code id: tags:
%% Cell type:code id:9b59398e tags:
``` python
simulated_trigger_buffer = dict()
#simulated_trigger_buffer = None
```
%% Cell type:code id: tags:
%% Cell type:code id:cb52bd2f tags:
``` python
# observed_models = ['pseudo_collection_01_run1_allnoise_correctedhwgt.pt', 'pseudo_collection_01_run1_allnoise_correctedscore.pt', 'pseudo_collection_01_run1_allnoise_correctbydeepconvfilter.pt', 'pseudo_collection_01_run1_allnoise_correctbyfcndaefilter.pt', 'pseudo_collection_01_run1_allnoise_correctbyconvlstmfilter.pt', 'pseudo_collection_01_run1_allnoise_correctbyconvlstm2filter.pt', 'pseudo_collection_01_run1_allnoise_correctbyconvlstm3filter.pt','pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter2.pt', 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter4.pt', 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt']
observed_models = ['pseudo_collection_01_run1_allnoise_correctbydeepconvfilter.pt', 'pseudo_collection_01_run1_allnoise_correctbyfcndaefilter.pt', 'pseudo_collection_01_run1_allnoise_correctbyconvlstm3filter.pt', 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt']
```
%% Cell type:code id: tags:
%% Cell type:code id:7b84c451 tags:
``` python
def filter_possible_handwashes(dataset, prediction):
possible_spots = []
filtered_predictions = np.zeros(prediction.shape)
filtered_predictions[:, 0] = 1.00001
for ts in range(75, dataset.x_data.shape[0], 75):
min_val = np.min(dataset.x_data[ts-75:ts], axis=0)
max_val = np.max(dataset.x_data[ts-75:ts], axis=0)
diff = np.absolute(max_val - min_val)
if np.any(diff > 10):
possible_spots.append(int(ts/75))
for possible_spot in possible_spots:
for i in range(0, 5):
if possible_spot+ i < prediction.shape[0]:
filtered_predictions[possible_spot + i] = prediction[possible_spot + i]
return filtered_predictions
def build_simulated_running_mean(dataset, model_name, kernel_size=20, kernel_threshold=0.59, prediction_buffer=None):
if prediction_buffer is not None and (dataset.name, model_name) in prediction_buffer:
prediction = prediction_buffer[(dataset.name, model_name)]
else:
prediction = generate_predictions([dataset,], model_name, verbose=False)[dataset.name]
if prediction_buffer is not None:
prediction_buffer[(dataset.name, model_name)] = prediction
if isinstance(dataset, SyntheticDataset):
dataset.generate_synthetic_evaluation(prediction, kernel_size=kernel_size, kernel_threshold=kernel_threshold)
dataset.generate_feedback_areas(prediction=prediction)
prediction = filter_possible_handwashes(dataset, prediction)
kernel = np.ones(kernel_size) / kernel_size
mean = np.convolve(prediction[:, 1], kernel, mode='same')
r_mean = np.empty_like(mean)
r_mean[kernel_size:] = mean[:-kernel_size]
return r_mean, prediction
def get_triggers_on_running_mean(dataset, r_mean, kernel_threshold=0.59):
trigger_spots = []
for high_mean_spot in np.where(r_mean*1 > kernel_threshold)[0]:
if len(trigger_spots) == 0:
trigger_spots.append(high_mean_spot)
else:
if high_mean_spot - trigger_spots[-1] > 15:
trigger_spots.append(high_mean_spot)
# print(len(trigger_spots), 'handwash triggers:', trigger_spots)
correct_triggers = 0
detected_regions = []
for trigger_spot in trigger_spots[:]:
for region in dataset.feedback_areas.labeled_regions_hw:
if region[0] <= trigger_spot <= region[1]:
if region in detected_regions:
trigger_spots.remove(trigger_spot)
else:
correct_triggers += 1
detected_regions.append(region)
break
return trigger_spots, correct_triggers
def simulate_dataset(dataset, model_name, kernel_size=20, kernel_threshold=0.59, do_plot=False, prediction_buffer=None):
if simulated_trigger_buffer is not None and (dataset.name, model_name, kernel_size, kernel_threshold) in simulated_trigger_buffer and not do_plot:
return simulated_trigger_buffer[(dataset.name, model_name, kernel_size, kernel_threshold)]
r_mean, prediction = build_simulated_running_mean(dataset, model_name, kernel_size=kernel_size, kernel_threshold=kernel_threshold, prediction_buffer=prediction_buffer)
trigger_spots, correct_triggers = get_triggers_on_running_mean(dataset, r_mean, kernel_threshold=kernel_threshold)
if do_plot:
ax = dataset.plot_windows()
dataset.plot_feedback_areas(ax=ax)
dataset.plot_prediction(prediction, ax=ax)
ax.scatter(trigger_spots, [1]*len(trigger_spots))
if simulated_trigger_buffer is not None:
simulated_trigger_buffer[(dataset.name, model_name, kernel_size, kernel_threshold)] = (len(trigger_spots)-correct_triggers, correct_triggers)
return len(trigger_spots)-correct_triggers, correct_triggers
def compare_personalized(collection_config, personalized_model):
if personalized_model == collection_config['base_model'] or personalized_model == collection_config['base_inc_model']:
personalized_model = collection_config['model_prefix'] + personalized_model
else:
personalized_model = collection_config['models_directory'] + personalized_model
all_datasets = evaluation_manager.test_collections[collection_config['name']][:]
all_datasets += evaluation_manager.train_collections[collection_config['name']]
base_triggers = dict()
pers_triggers = dict()
for dataset in all_datasets[:]:
pers_triggers[dataset] = simulate_dataset(dataset, personalized_model)
base_triggers[dataset] = simulate_dataset(dataset, collection_config['base_model'])
fig, ax = plt.subplots()
base_triggers = np.array(list(base_triggers.values()))
pers_triggers = np.array(list(pers_triggers.values()))
ax.plot(np.arange(base_triggers.shape[0]), base_triggers[:, 0], c='red')
ax.plot(np.arange(pers_triggers.shape[0]), pers_triggers[:, 0], c='orange')
ax.plot(np.arange(base_triggers.shape[0]), base_triggers[:, 1], c='green')
ax.plot(np.arange(pers_triggers.shape[0]), pers_triggers[:, 1], c='blue')
fig.show()
def calc_diff_between_perso_base(collection_config, personalized_model, use_percentage=False, kernel_threshold=0.59, kernel_size=20, include_training=False):
if personalized_model == collection_config['base_model'] or personalized_model == collection_config['base_inc_model']:
personalized_model = collection_config['model_prefix'] + personalized_model
else:
personalized_model = collection_config['models_directory'] + personalized_model
# print(personalized_model)
all_datasets = evaluation_manager.test_collections[collection_config['name']][:]
if include_training:
all_datasets += evaluation_manager.train_collections[collection_config['name']]
base_triggers = dict()
pers_triggers = dict()
for dataset in all_datasets[:]:
pers_triggers[dataset] = simulate_dataset(dataset, personalized_model, kernel_threshold=kernel_threshold, kernel_size=kernel_size)
base_triggers[dataset] = simulate_dataset(dataset, collection_config['model_prefix'] + collection_config['base_model'])
# print(base_triggers[dataset], 'vs.', pers_triggers[dataset])
base_triggers = np.array(list(base_triggers.values()), dtype=float)
pers_triggers = np.array(list(pers_triggers.values()), dtype=float)
wrong_diff = pers_triggers[:, 0] - base_triggers[:, 0]
correct_diff = pers_triggers[:, 1] - base_triggers[:, 1]
if use_percentage:
wrong_diff[base_triggers[:, 0] != 0] = wrong_diff[base_triggers[:, 0] != 0] / base_triggers[base_triggers[:, 0] != 0, 0]
correct_diff[base_triggers[:, 1] != 0] = correct_diff[base_triggers[:, 1] != 0] / base_triggers[base_triggers[:, 1] != 0, 1]
wd_zero = wrong_diff[base_triggers[:, 0] == 0]
cd_zero = correct_diff[base_triggers[:, 1] == 0]
wd_zero = np.minimum(np.ones(wd_zero.shape[0]), wd_zero)
cd_zero = np.minimum(np.ones(cd_zero.shape[0]), cd_zero)
return wrong_diff, correct_diff
def plot_diff_between_perso_base(collection_config, use_percentage=False, kernel_threshold=0.59, kernel_size=20, include_training=False):
diffs = dict()
cycle_models = evaluation_manager.personalized_models[collection_config['name']]
if len(observed_models) > 0:
cycle_models = observed_models
for model in cycle_models + [collection_config['base_model'], collection_config['base_inc_model']]:
model = os.path.basename(model)
diffs[model] = calc_diff_between_perso_base(collection_config, model, use_percentage=use_percentage, kernel_threshold=kernel_threshold, kernel_size=kernel_size, include_training=include_training)
x_vals = np.array(remove_model_name_suffix(list(diffs.keys())[:-2]) + list(diffs.keys())[-2:])
y_vals = np.array(list(diffs.values()))
print(y_vals.shape)
y_vals = np.sum(y_vals, axis=2)/y_vals.shape[2]
fig, ax = plt.subplots(figsize=(9,7))
fig.suptitle(collection_config['name'])
ax.set_ylabel('num difference in triggers')
if use_percentage:
ax.set_ylabel('% trigger difference')
y_vals *= 100
ax.plot(x_vals, y_vals[:, 0], c='red', label='false')
ax.plot(x_vals, y_vals[:, 1], c='green', label='correct')
ax.tick_params(axis='x', labelrotation = 75)
#plt.subplots_adjust(hspace=0.8)
plt.subplots_adjust(bottom=0.4, top=0.95)
plt.grid()
fig.legend()
fig.show()
```
%% Cell type:code id: tags:
%% Cell type:code id:f70d19fe tags:
``` python
#compare_personalized(evaluation_manager.get_collection_config('participant_02'), 'pseudo_collection_01_run1_allnoise_correctbyconvlstm3filter.pt')
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True)
#calc_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), 'pseudo_collection_01_run1_allnoise_correctbyconvlstm3filter.pt')
# plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_01'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_01'), use_percentage=True, kernel_size=20)
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_01'), use_percentage=True, kernel_size=15)
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_01'), use_percentage=True, kernel_size=10)
# plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_02'), use_percentage=True)
# plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_10'), use_percentage=True)
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_01'), use_percentage=True)
```
%% Cell type:code id: tags:
%% Cell type:code id:5c009e53 tags:
``` python
compare_personalized(evaluation_manager.get_collection_config('alex_01'), 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt')
```
%% Cell type:code id: tags:
%% Cell type:code id:108d2ba6 tags:
``` python
calc_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), 'pseudo_collection_01_run1_allnoise_correctbydeepconvfilter.pt')
```
%% Cell type:code id: tags:
%% Cell type:code id:47dd7b06 tags:
``` python
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.59)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.69)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.79)
```
%% Cell type:code id: tags:
%% Cell type:code id:ef3b4b5d tags:
``` python
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.79, kernel_size=15)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.89, kernel_size=10)
```
%% Cell type:code id: tags:
%% Cell type:code id:a4734880 tags:
``` python
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.59, kernel_size=20)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.69, kernel_size=15)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.75, kernel_size=15)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.75, kernel_size=10)
```
%% Cell type:code id: tags:
%% Cell type:code id:dc9b2909 tags:
``` python
plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_01'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_02'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('synthetic_10'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_01'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True)
```
%% Cell type:code id: tags:
%% Cell type:code id:39ec6407 tags:
``` python
target_config = evaluation_manager.get_collection_config('participant_02')
target_dataset = evaluation_manager.test_collections[target_config['name']][2]
target_model = 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt'
simulate_dataset(target_dataset, target_config['models_directory'] + target_model, kernel_size=10, kernel_threshold=0.75, do_plot=True)
```
%% Cell type:code id: tags:
%% Cell type:code id:ae86a944 tags:
``` python
mean_cache = dict()
```
%% Cell type:code id: tags:
%% Cell type:code id:2f12eb6e tags:
``` python
def calc_settings_score(false_triggers, correct_triggers):
if correct_triggers < 0.1:
return 0
return correct_triggers - false_triggers * 10
def get_buffered_triggers(dataset, model_name, kernel_size, kernel_threshold, prediction_buffer=None):
if (dataset, model_name, kernel_size, kernel_size) in mean_cache:
r_mean = mean_cache[(dataset, model_name, kernel_size, kernel_threshold)]
else:
r_mean, prediction = build_simulated_running_mean(dataset, model_name, kernel_size=kernel_size, kernel_threshold=kernel_threshold, prediction_buffer=prediction_buffer)
mean_cache[(dataset, model_name, kernel_size, kernel_threshold)] = r_mean
trigger_spots, correct_triggers = get_triggers_on_running_mean(dataset, r_mean, kernel_threshold=kernel_threshold)
false_triggers = len(trigger_spots) - correct_triggers
return false_triggers, correct_triggers
def calc_best_running_mean_settings(collection_config, model_name):
all_datasets = evaluation_manager.test_collections[collection_config['name']][:]
prediction_buffer = dict()
# all_datasets += evaluation_manager.train_collections[collection_config['name']]
base_false_triggers = 0
base_correct_triggers = 0
print('calc base')
print(all_datasets)
for dataset in all_datasets:
false_triggers, correct_triggers = get_buffered_triggers(dataset, collection_config['model_prefix'] + collection_config['base_model'], 20, 0.59, prediction_buffer=prediction_buffer)
base_false_triggers += false_triggers
base_correct_triggers += correct_triggers
if base_false_triggers == 0:
base_false_triggers = 1
if base_correct_triggers == 0:
base_correct_triggers = 1
print('base ft:', base_false_triggers, 'base ct:', base_correct_triggers)
target_kernel_size = 20
target_kernel_theshold = 0.30
results = []
while target_kernel_size >= 10:
target_kernel_theshold = 0.50
while target_kernel_theshold <= 0.99:
print('calc', target_kernel_size, target_kernel_theshold)
false_triggers_sum = 0
correct_triggers_sum = 0
for dataset in all_datasets:
false_triggers, correct_triggers = get_buffered_triggers(dataset, model_name, target_kernel_size, target_kernel_theshold, prediction_buffer=prediction_buffer)
false_triggers_sum += false_triggers
correct_triggers_sum += correct_triggers
false_diff = false_triggers_sum - base_false_triggers
correct_diff = correct_triggers_sum - base_correct_triggers
false_diff_relative = false_diff / base_false_triggers
correct_diff_relative = correct_diff / base_correct_triggers
# false_triggers_sum += false_diff_relative
# correct_triggers_sum += correct_diff_relative
# false_triggers_sum /= len(all_datasets)
# correct_triggers_sum /= len(all_datasets)
score = calc_settings_score(false_diff_relative, correct_diff_relative)
print('ft:', false_diff_relative, 'ct:', correct_diff_relative, 'score:', score)
results.append((score, (target_kernel_size, target_kernel_theshold)))
target_kernel_theshold += 0.02
target_kernel_theshold = np.around(target_kernel_theshold, decimals=4)
target_kernel_size -= 5
results = sorted(results, key=lambda result: result[0], reverse=True)
return results
```
%% Cell type:code id: tags:
%% Cell type:code id:e29b5fb1 tags:
``` python
target_config = evaluation_manager.get_collection_config('participant_02')
target_model = target_config['models_directory'] + 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt'
#target_model = target_config['model_prefix'] + target_config['base_model']
calc_best_running_mean_settings(target_config, target_model)
```
%% Cell type:code id: tags:
%% Cell type:code id:2e75ada1 tags:
``` python
mean_cache
```
%% Cell type:code id: tags:
%% Cell type:code id:e706d405 tags:
``` python
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.72, kernel_size=15)
# plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.86, kernel_size=15)
#plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=True, kernel_threshold=0.96, kernel_size=10, include_training=True)
# plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=True, kernel_threshold=0.82, kernel_size=10, include_training=False)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_01'), use_percentage=False, kernel_threshold=0.88, kernel_size=15, include_training=False)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=False, kernel_threshold=0.94, kernel_size=10, include_training=False)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=False, kernel_threshold=0.68, kernel_size=20, include_training=False)
```
%% Cell type:code id: tags:
%% Cell type:code id:fe1618e3 tags:
``` python
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_01'), use_percentage=False, kernel_threshold=0.88, kernel_size=15, include_training=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('alex_02'), use_percentage=False, kernel_threshold=0.94, kernel_size=10, include_training=True)
plot_diff_between_perso_base(evaluation_manager.get_collection_config('participant_02'), use_percentage=False, kernel_threshold=0.68, kernel_size=20, include_training=True)
```
%% Cell type:code id: tags:
%% Cell type:code id:2b32f5e2 tags:
``` python
target_config = evaluation_manager.get_collection_config('participant_02')
target_dataset = evaluation_manager.test_collections[target_config['name']][0]
target_model = target_config['models_directory'] + 'pseudo_collection_01_run1_alldeepconv_correctbyconvlstm3filter6.pt'
#target_model = target_config['model_prefix'] + target_config['base_model']
simulate_dataset(target_dataset, target_model, do_plot=True, kernel_threshold=0.68, kernel_size=20)
```
%% Cell type:code id: tags:
%% Cell type:code id:f36a252e tags:
``` python
target_dataset.name
```
%% Cell type:code id: tags:
%% Cell type:code id:5a2b72ba tags:
``` python
start = 798012-75
x_data = target_dataset.x_data[start:800763]
for ts in range(75, x_data.shape[0], 75):
min_val = np.min(x_data[ts-75:ts], axis=0)
max_val = np.max(x_data[ts-75:ts], axis=0)
diff = np.absolute(max_val - min_val)
target_ts = ts/75
print( start/75 + target_ts, diff, np.any(diff > 12))
```
%% Cell type:code id: tags:
%% Cell type:code id:da69022d tags:
``` python
target_dataset.plot_windows()
target_dataset.plot()
```
%% Cell type:code id: tags:
%% Cell type:code id:93c1376f tags:
``` python
def find_hw_flags(y_data):
if len(y_data.shape) == 1:
prev_val = y_data[0]
else:
prev_val = y_data[0, 1]
spots = []
for i, y in enumerate(y_data):
if len(y_data.shape) == 1:
if prev_val != y:
spots.append(i)
prev_val = y
else:
if prev_val != y[1]:
spots.append(i)
prev_val = y[1]
return spots
def transform_base_to_window(ts_list):
results = []
for ts in ts_list:
results.append(ts/75)
return results
def get_ts_diffs(ts_true, ts_translated):
for i in range(len(ts_true)):
yield ts_true[i] - ts_translated[i]
```
%% Cell type:code id: tags:
%% Cell type:code id:2861399b tags:
``` python
flags_base = find_hw_flags(target_dataset.y_data)
flags_win = find_hw_flags(target_dataset.y_win)
print(flags_base, flags_win)
ts_trans = transform_base_to_window(flags_base)
list(get_ts_diffs(flags_win, ts_trans))
```
%% Cell type:code id: tags:
%% Cell type:code id:9c2f5f53 tags:
``` python
target_dataset.generate_windows()
```
%% Cell type:code id: tags:
%% Cell type:code id:bc6e1251 tags:
``` python
```
......
This diff is collapsed.
......@@ -235,10 +235,10 @@ class Dataset:
#print('HW:', hw_indicators_hw.shape, 'NOISE:', hw_indicators_noise.shape)
consistent_indicators_hw_indexes = np.random.choice(np.arange(hw_indicators_hw.shape[0]),
size=int(np.ceil(hw_indicators_hw.shape[0]*evaluation_reliability_yes)),
size=int(np.round(hw_indicators_hw.shape[0]*evaluation_reliability_yes)),
replace=False)
consistent_indicators_noise_indexes = np.random.choice(np.arange(hw_indicators_noise.shape[0]),
size=int(np.ceil(hw_indicators_noise.shape[0] * evaluation_reliability_no)),
size=int(np.round(hw_indicators_noise.shape[0] * evaluation_reliability_no)),
replace=False)
#print('take hw', hw_indicators_hw[consistent_indicators_hw_indexes], 'take noise:', hw_indicators_noise[consistent_indicators_noise_indexes])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment