Commit ed983480 authored by Alexander Henkel's avatar Alexander Henkel
Browse files

experiement stuff

parent df6e38a8
This diff is collapsed.
%% Cell type:code id: tags: %% Cell type:code id:dc2c77ba tags:
   
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
   
%matplotlib notebook %matplotlib notebook
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:f21ac9e3 tags:
   
``` python ``` python
import sys import sys
import os import os
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from IPython.display import display, Markdown from IPython.display import display, Markdown
import copy import copy
import dbm import dbm
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:4f6cc421 tags:
   
``` python ``` python
module_path = os.path.abspath(os.path.join('..')) module_path = os.path.abspath(os.path.join('..'))
os.chdir(module_path) os.chdir(module_path)
if module_path not in sys.path: if module_path not in sys.path:
sys.path.append(module_path) sys.path.append(module_path)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:a8b45dae tags:
   
``` python ``` python
from personalization_tools.load_data_sets import * from personalization_tools.load_data_sets import *
from personalization_tools.helpers import * from personalization_tools.helpers import *
from personalization_tools.learner_pipeline import LearnerPipeline, Evaluation from personalization_tools.learner_pipeline import LearnerPipeline, Evaluation
from personalization_tools.dataset_builder import * from personalization_tools.dataset_builder import *
from personalization_tools.model_evaluation import ModelEvaluation from personalization_tools.model_evaluation import ModelEvaluation
from personalization_tools.sensor_recorder_data_reader import SensorRecorderDataReader from personalization_tools.sensor_recorder_data_reader import SensorRecorderDataReader
from personalization_tools.dataset_manager import DatasetManager from personalization_tools.dataset_manager import DatasetManager
from personalization_tools.trainings_manager import TrainingsManager 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_model_settings import pseudo_model_settings, pseudo_label_generators_to_int
from personalization_tools.pseudo_label_evaluation import * from personalization_tools.pseudo_label_evaluation import *
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:12ee6c24 tags:
   
``` python ``` python
predictions_db = './data/cluster/personalization_evolution/evolution_predictions_db' predictions_db = './data/cluster/personalization_evolution/evolution_predictions_db'
training_db = './data/cluster/personalization_evolution/evolution_training_db' training_db = './data/cluster/personalization_evolution/evolution_training_db'
models_directory = './data/cluster/personalization_evolution/evolution_models/' models_directory = './data/cluster/personalization_evolution/evolution_models/'
synthetic_dataset_db = './data/synthetic_dataset_db' synthetic_dataset_db = './data/synthetic_dataset_db'
recorded_dataset_db = './data/recorded_dataset_db' recorded_dataset_db = './data/recorded_dataset_db'
configuration_file = './data/cluster/personalization_evolution/personalization_evolution_config.yaml' configuration_file = './data/cluster/personalization_evolution/personalization_evolution_config.yaml'
base_model_prefix = './data/' base_model_prefix = './data/'
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:aeefd6a9 tags:
   
``` python ``` python
predictions_db = './data/cluster/personalization_evolution_2/evolution_predictions_db' predictions_db = './data/cluster/personalization_evolution_2/evolution_predictions_db'
training_db = './data/cluster/personalization_evolution_2/evolution_training_db' training_db = './data/cluster/personalization_evolution_2/evolution_training_db'
models_directory = './data/cluster/personalization_evolution_2/evolution_models/' models_directory = './data/cluster/personalization_evolution_2/evolution_models/'
synthetic_dataset_db = './data/synthetic_dataset_db' synthetic_dataset_db = './data/synthetic_dataset_db'
recorded_dataset_db = './data/recorded_dataset_db_2' recorded_dataset_db = './data/recorded_dataset_db_2'
configuration_file = './data/cluster/personalization_evolution_2/personalization_evolution_config.yaml' configuration_file = './data/cluster/personalization_evolution_2/personalization_evolution_config.yaml'
base_model_prefix = './data/' base_model_prefix = './data/'
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:42e67d18 tags:
   
``` python ``` python
model_evaluation = ModelEvaluation() model_evaluation = ModelEvaluation()
model_evaluation.load_predictions(predictions_db) model_evaluation.load_predictions(predictions_db)
training_manager = TrainingsManager(training_db) training_manager = TrainingsManager(training_db)
   
synthetic_dataset_manager = DatasetManager(synthetic_dataset_db) synthetic_dataset_manager = DatasetManager(synthetic_dataset_db)
recorded_dataset_manager = DatasetManager(recorded_dataset_db) recorded_dataset_manager = DatasetManager(recorded_dataset_db)
training_config = dict() training_config = dict()
with open(configuration_file, 'r') as config_file: with open(configuration_file, 'r') as config_file:
training_config = yaml.safe_load(config_file) training_config = yaml.safe_load(config_file)
   
all_models = [pred[0] for pred in model_evaluation.predictions.keys()] all_models = [pred[0] for pred in model_evaluation.predictions.keys()]
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:e6269abd tags:
   
``` python ``` python
model_evaluation.get_evaluations() model_evaluation.get_evaluations()
``` ```
   
%% Output %% Output
   
<pandas.io.formats.style.Styler at 0x7f88203f1250> <pandas.io.formats.style.Styler at 0x7f88203f1250>
   
%% Cell type:code id: tags: %% Cell type:code id:ab4ce094 tags:
   
``` python ``` python
def get_test_collection_of_config(collection_config): def get_test_collection_of_config(collection_config):
if training_config['collection_configs']['synthetic_collections'] is not None: if training_config['collection_configs']['synthetic_collections'] is not None:
for col_conf in training_config['collection_configs']['synthetic_collections'].values(): for col_conf in training_config['collection_configs']['synthetic_collections'].values():
if col_conf['name'] == collection_config['name']: if col_conf['name'] == collection_config['name']:
return list(synthetic_dataset_manager.filter_by_category(collection_config['test_collection_name']).values()) return list(synthetic_dataset_manager.filter_by_category(collection_config['test_collection_name']).values())
return list(recorded_dataset_manager.filter_by_category(collection_config['test_collection_name']).values()) return list(recorded_dataset_manager.filter_by_category(collection_config['test_collection_name']).values())
   
def get_evaluation_models_of_config(collection_config, generators, epochs): def get_evaluation_models_of_config(collection_config, generators, epochs):
return get_models_with_infos({'collection_name': collection_config['name'], 'generators': generators, 'epochs': epochs}, training_manager.get_all_information(), all_models, allow_missing=False) return get_models_with_infos({'collection_name': collection_config['name'], 'generators': generators, 'epochs': epochs}, training_manager.get_all_information(), all_models, allow_missing=False)
   
def plot_evolution(collection_conf, target_value, pseudo_label_conf, epochs, ax=None): def plot_evolution(collection_conf, target_value, pseudo_label_conf, epochs, ax=None):
test_collection = get_test_collection_of_config(collection_conf) test_collection = get_test_collection_of_config(collection_conf)
# print(test_collection) # print(test_collection)
collection_models = get_evaluation_models_of_config(collection_conf,pseudo_label_generators_to_int(pseudo_model_settings[pseudo_label_conf]), epochs) collection_models = get_evaluation_models_of_config(collection_conf,pseudo_label_generators_to_int(pseudo_model_settings[pseudo_label_conf]), epochs)
# print(collection_models) # print(collection_models)
averages = calc_average_pseudo_model_evaluation(model_evaluation.predictions, target_value, collection_models, [str(ds) for ds in test_collection]) averages = calc_average_pseudo_model_evaluation(model_evaluation.predictions, target_value, collection_models, [str(ds) for ds in test_collection])
iterative_averages = dict() iterative_averages = dict()
single_averages = dict() single_averages = dict()
for key, value in averages.items(): for key, value in averages.items():
if training_manager.get_all_information()[key]['iteration'] == 'single': if training_manager.get_all_information()[key]['iteration'] == 'single':
single_averages[key] = value single_averages[key] = value
else: else:
iterative_averages[key] = value iterative_averages[key] = value
   
# print(averages) # print(averages)
   
iterative_averages_keys = list(iterative_averages.keys()) iterative_averages_keys = list(iterative_averages.keys())
iterative_averages_keys = sorted(iterative_averages_keys, key=lambda model_name: training_manager.get_all_information()[model_name]['iteration']) iterative_averages_keys = sorted(iterative_averages_keys, key=lambda model_name: training_manager.get_all_information()[model_name]['iteration'])
# print(iterative_averages_keys) # print(iterative_averages_keys)
   
single_averages_keys = list(single_averages.keys()) single_averages_keys = list(single_averages.keys())
single_averages_keys = sorted(single_averages_keys, key=lambda model_name: training_manager.get_all_information()[model_name]['based_on_iteration']) single_averages_keys = sorted(single_averages_keys, key=lambda model_name: training_manager.get_all_information()[model_name]['based_on_iteration'])
# print(single_averages_keys) # print(single_averages_keys)
   
learning_rate = np.array([iterative_averages[key] for key in iterative_averages_keys]) learning_rate = np.array([iterative_averages[key] for key in iterative_averages_keys])
learning_rate -= np.array([single_averages[key] for key in single_averages_keys]) learning_rate -= np.array([single_averages[key] for key in single_averages_keys])
   
base_averages = calc_average_pseudo_model_evaluation(model_evaluation.predictions, target_value, [collection_conf['base_model'], collection_conf['base_inc_model']], [str(ds) for ds in test_collection]) base_averages = calc_average_pseudo_model_evaluation(model_evaluation.predictions, target_value, [collection_conf['base_model'], collection_conf['base_inc_model']], [str(ds) for ds in test_collection])
# print('base averages:', base_averages) # print('base averages:', base_averages)
   
if ax is None: if ax is None:
fig, ax = plt.subplots(figsize=(9,6)) fig, ax = plt.subplots(figsize=(9,6))
ax.set_title(collection_conf['name'] + ' epochs: ' + str(epochs)) ax.set_title(collection_conf['name'] + ' epochs: ' + str(epochs))
ax.set_xlabel('iteration step') ax.set_xlabel('iteration step')
ax.set_ylabel(target_value) ax.set_ylabel(target_value)
   
ax.axhline(base_averages[collection_conf['base_model']], linestyle=':', label='base', color='red') ax.axhline(base_averages[collection_conf['base_model']], linestyle=':', label='base', color='red')
ax.axhline(base_averages[collection_conf['base_inc_model']], linestyle=':', label='inc', color='green') ax.axhline(base_averages[collection_conf['base_inc_model']], linestyle=':', label='inc', color='green')
ax.plot(np.arange(len(iterative_averages_keys)), [iterative_averages[key] for key in iterative_averages_keys], label='iterative') ax.plot(np.arange(len(iterative_averages_keys)), [iterative_averages[key] for key in iterative_averages_keys], label='iterative')
ax.plot(np.arange(len(single_averages_keys)), [single_averages[key] for key in single_averages_keys], label='single') ax.plot(np.arange(len(single_averages_keys)), [single_averages[key] for key in single_averages_keys], label='single')
#ax.plot(np.arange(learning_rate.shape[0]), learning_rate, label='learning rate') #ax.plot(np.arange(learning_rate.shape[0]), learning_rate, label='learning rate')
   
# ax.tick_params(labelrotation=75) # ax.tick_params(labelrotation=75)
plt.subplots_adjust(hspace=0.3) plt.subplots_adjust(hspace=0.3)
plt.subplots_adjust(bottom=0.1) plt.subplots_adjust(bottom=0.1)
if 'fig' in locals(): if 'fig' in locals():
fig.legend() fig.legend()
fig.show() fig.show()
else: else:
ax.legend() ax.legend()
   
def plot_evolution_over_epochs(collection_conf, target_value, pseudo_label_conf): def plot_evolution_over_epochs(collection_conf, target_value, pseudo_label_conf):
epochs = (25, 50, 100, 150) epochs = (25, 50, 100, 150)
fig, axes = plt.subplots(len(epochs), figsize=(9, 6*len(epochs))) fig, axes = plt.subplots(len(epochs), figsize=(9, 6*len(epochs)))
fig.suptitle(pseudo_label_conf, fontsize=16) fig.suptitle(pseudo_label_conf, fontsize=16)
for i, epoch in enumerate(epochs): for i, epoch in enumerate(epochs):
plot_evolution(collection_conf, target_value, pseudo_label_conf, epoch, axes[i]) plot_evolution(collection_conf, target_value, pseudo_label_conf, epoch, axes[i])
# fig.legend() # fig.legend()
fig.show() fig.show()
   
def filter_group_plot(config, collection_group, collection_name, target_value, filters): def filter_group_plot(config, collection_group, collection_name, target_value, filters):
for filter_config in filters: for filter_config in filters:
plot_evolution_over_epochs(config['collection_configs'][collection_group][collection_name], target_value, filter_config) plot_evolution_over_epochs(config['collection_configs'][collection_group][collection_name], target_value, filter_config)
   
def compare_collections(config, collection_1, collection_2, target_value, pseudo_label_conf): def compare_collections(config, collection_1, collection_2, target_value, pseudo_label_conf):
epochs = (25, 50, 100) epochs = (25, 50, 100)
fig, axes = plt.subplots(len(epochs)*2, figsize=(9, 6*len(epochs)*2)) fig, axes = plt.subplots(len(epochs)*2, figsize=(9, 6*len(epochs)*2))
fig.suptitle(pseudo_label_conf, fontsize=16) fig.suptitle(pseudo_label_conf, fontsize=16)
for i, epoch in enumerate(epochs): for i, epoch in enumerate(epochs):
plot_evolution(config['collection_configs'][collection_1[0]][collection_1[1]], target_value, pseudo_label_conf, epoch, axes[i*2]) plot_evolution(config['collection_configs'][collection_1[0]][collection_1[1]], target_value, pseudo_label_conf, epoch, axes[i*2])
plot_evolution(config['collection_configs'][collection_2[0]][collection_2[1]], target_value, pseudo_label_conf, epoch, axes[i*2+1]) plot_evolution(config['collection_configs'][collection_2[0]][collection_2[1]], target_value, pseudo_label_conf, epoch, axes[i*2+1])
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:4d4844f4 tags:
   
``` python ``` python
#filter_group_plot(training_config, 'synthetic_collections', 1, 's1', ['allnoise_correctedscore', 'allnoise_correctbyconvlstm3filter', 'alldeepconv_correctbyconvlstm3filter6']) #filter_group_plot(training_config, 'synthetic_collections', 1, 's1', ['allnoise_correctedscore', 'allnoise_correctbyconvlstm3filter', 'alldeepconv_correctbyconvlstm3filter6'])
#filter_group_plot(training_config, 'synthetic_collections', '01_regularized', 's1', ['allnoise_correctedscore', 'allnoise_correctbyconvlstm3filter', 'alldeepconv_correctbyconvlstm3filter6']) #filter_group_plot(training_config, 'synthetic_collections', '01_regularized', 's1', ['allnoise_correctedscore', 'allnoise_correctbyconvlstm3filter', 'alldeepconv_correctbyconvlstm3filter6'])
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'allnoise_correctedscore') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'allnoise_correctedscore')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'allnoise_correctbyconvlstm3filter') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'allnoise_correctbyconvlstm3filter')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'alldeepconv_correctbyconvlstm3filter6') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['01_regularized'], 's1', 'alldeepconv_correctbyconvlstm3filter6')
   
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections'][10], 'f1', 'allnoise_correctedscore') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections'][10], 'f1', 'allnoise_correctedscore')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_regularized_regularized'], 'f1', 'allnoise_correctedscore') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_regularized_regularized'], 'f1', 'allnoise_correctedscore')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections'][10], 'f1', 'alldeepconv_correctbyconvlstm3filter6') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections'][10], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_swapped'], 'f1', 'allnoise_correctedscore') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_swapped'], 'f1', 'allnoise_correctedscore')
#plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_swapped'], 'f1', 'alldeepconv_correctbyconvlstm3filter6') #plot_evolution_over_epochs(training_config['collection_configs']['synthetic_collections']['10_swapped'], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
   
#plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'allnoise_correctedscore') #plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'allnoise_correctedscore')
#plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'allnoise_correctbyconvlstm3filter') #plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'allnoise_correctbyconvlstm3filter')
#plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'alldeepconv_correctbyconvlstm3filter6') #plot_evolution_over_epochs(training_config['collection_configs']['recorded_collections'][1], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
   
#plot_evolution(training_config['collection_configs']['synthetic_collections'][1], 'f1', 'allnoise_correctedscore', 50) #plot_evolution(training_config['collection_configs']['synthetic_collections'][1], 'f1', 'allnoise_correctedscore', 50)
#plot_evolution(training_config['collection_configs']['synthetic_collections']['01_regularized'], 'f1', 'allnoise_correctedhwgt', 100) #plot_evolution(training_config['collection_configs']['synthetic_collections']['01_regularized'], 'f1', 'allnoise_correctedhwgt', 100)
   
   
#compare_collections(training_config, ['synthetic_collections', 1], ['synthetic_collections', '01_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6') #compare_collections(training_config, ['synthetic_collections', 1], ['synthetic_collections', '01_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
# mpare_collections(training_config, ['synthetic_collections', 2], ['synthetic_collections', '02_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6') # mpare_collections(training_config, ['synthetic_collections', 2], ['synthetic_collections', '02_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
   
# mpare_collections(training_config, ['recorded_collections', 1], ['recorded_collections', '01_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6') # mpare_collections(training_config, ['recorded_collections', 1], ['recorded_collections', '01_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
compare_collections(training_config, ['recorded_collections', 2], ['recorded_collections', '02_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6') compare_collections(training_config, ['recorded_collections', 2], ['recorded_collections', '02_regularized'], 'f1', 'alldeepconv_correctbyconvlstm3filter6')
   
#compare_collections(training_config, ['recorded_collections', 1], ['recorded_collections', '01_regularized'], 'specificity', 'alldeepconv_correctbyconvlstm3filter6') #compare_collections(training_config, ['recorded_collections', 1], ['recorded_collections', '01_regularized'], 'specificity', 'alldeepconv_correctbyconvlstm3filter6')
   
``` ```
   
%% Output %% Output
   
   
   
%% Cell type:code id: tags: %% Cell type:code id:c4d792ed tags:
   
``` python ``` python
plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50)
plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50)
``` ```
   
%% Output %% Output
   
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
KeyError Traceback (most recent call last) KeyError Traceback (most recent call last)
<ipython-input-10-255874a4d5f2> in <module> <ipython-input-10-255874a4d5f2> in <module>
----> 1 plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50) ----> 1 plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50)
2 plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50) 2 plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50)
KeyError: 11 KeyError: 11
   
%% Cell type:code id: tags: %% Cell type:code id:c1430ef2 tags:
   
``` python ``` python
plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50)
plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:f06a47d1 tags:
   
``` python ``` python
plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections'][11], 'f1', 'allnoise_correctedscore', 50)
plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50) plot_evolution(training_config['collection_configs']['synthetic_collections']['11_regularized'], 'f1', 'allnoise_correctedscore', 50)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id:babebc45 tags:
   
``` python ``` python
``` ```
This diff is collapsed.
%% Cell type:code id:b9f62c58 tags: %% Cell type:code id:b9f62c58 tags:
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
%matplotlib notebook %matplotlib notebook
``` ```
%% Cell type:code id:621e3e7f tags: %% Cell type:code id:621e3e7f tags:
``` python ``` python
import sys import sys
import os import os
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from IPython.display import display, Markdown from IPython.display import display, Markdown
``` ```
%% Cell type:code id:0dab0b49 tags: %% Cell type:code id:0dab0b49 tags:
``` python ``` python
module_path = os.path.abspath(os.path.join('..')) module_path = os.path.abspath(os.path.join('..'))
os.chdir(module_path) os.chdir(module_path)
if module_path not in sys.path: if module_path not in sys.path:
sys.path.append(module_path) sys.path.append(module_path)
``` ```
%% Cell type:code id:16e7ff01 tags: %% Cell type:code id:16e7ff01 tags:
``` python ``` python
from personalization_tools.load_data_sets import * from personalization_tools.load_data_sets import *
from personalization_tools.helpers import * from personalization_tools.helpers import *
from personalization_tools.learner_pipeline import LearnerPipeline from personalization_tools.learner_pipeline import LearnerPipeline
from personalization_tools.dataset_builder import * from personalization_tools.dataset_builder import *
from personalization_tools.personalizer import Personalizer from personalization_tools.personalizer import Personalizer
from personalization_tools.dataset_manager import DatasetManager from personalization_tools.dataset_manager import DatasetManager
from personalization_tools.trainings_manager import TrainingsManager from personalization_tools.trainings_manager import TrainingsManager
from personalization_tools.sensor_recorder_data_reader import SensorRecorderDataReader from personalization_tools.sensor_recorder_data_reader import SensorRecorderDataReader
from personalization_tools.pseudo_model_settings import pseudo_model_settings from personalization_tools.pseudo_model_settings import pseudo_model_settings
``` ```
%% Cell type:code id:6f7b32bb tags: %% Cell type:code id:6f7b32bb tags:
``` python ``` python
WINDOW_LENGTH = 150 WINDOW_LENGTH = 150
WINDOW_SHIFT = 75 WINDOW_SHIFT = 75
inc_model_name = 'recorded_inc_01.pt' inc_model_name = 'recorded_inc_02.pt'
training_run_name = '01_training' training_run_name = '02_training'
base_model_name = './data/DeepConvLSTMA_statedict.pt' base_model_name = './data/DeepConvLSTMA_statedict.pt'
``` ```
%% Cell type:code id:3f93660a tags: %% Cell type:code id:3f93660a tags:
``` python ``` python
personalizer = Personalizer() personalizer = Personalizer()
personalizer.initialize(base_model_name) personalizer.initialize(base_model_name)
``` ```
%% Cell type:code id:7e0d7f13 tags: %% Cell type:code id:7e0d7f13 tags:
``` python ``` python
trainings_manager = TrainingsManager('./data/cluster/recorded_pseudo_training_db_2') trainings_manager = TrainingsManager('./data/cluster/recorded_pseudo_training_db_2')
``` ```
%% Cell type:code id:f0a6fd1b tags: %% Cell type:code id:f0a6fd1b tags:
``` python ``` python
dataset_manager = DatasetManager('./data/recorded_dataset_db') dataset_manager = DatasetManager('./data/recorded_dataset_db')
``` ```
%% Cell type:code id:608252a0 tags: %% Cell type:code id:608252a0 tags:
``` python ``` python
record_reader = SensorRecorderDataReader('/home/alex/gitrepos/uni/MasterProject/Webserver/uploads/recordings') record_reader = SensorRecorderDataReader('/home/alex/gitrepos/uni/MasterProject/Webserver/uploads/recordings')
``` ```
%% Cell type:code id:7090d170 tags: %% Cell type:code id:7090d170 tags:
``` python ``` python
series = dataset_manager.filter_by_category(training_run_name).values() series = dataset_manager.filter_by_category(training_run_name).values()
``` ```
%% Cell type:code id:cf454d2f tags: %% Cell type:code id:cf454d2f tags:
``` python ``` python
series = record_reader.get_collection(['e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6', '2252f3d0-cd90-42b4-9b4e-4172ed5fa847', '88134a7c-00f9-4b82-b579-95ef47cb8a20', '9c1913f3-e44d-40a0-a89a-feb2d3692494']) series = record_reader.get_collection(['e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6', '2252f3d0-cd90-42b4-9b4e-4172ed5fa847', '88134a7c-00f9-4b82-b579-95ef47cb8a20', '9c1913f3-e44d-40a0-a89a-feb2d3692494'])
``` ```
%% Output %% Output
Load: e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6 Load: e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6
Load: 2252f3d0-cd90-42b4-9b4e-4172ed5fa847 Load: 2252f3d0-cd90-42b4-9b4e-4172ed5fa847
Load: 88134a7c-00f9-4b82-b579-95ef47cb8a20 Load: 88134a7c-00f9-4b82-b579-95ef47cb8a20
Load: 9c1913f3-e44d-40a0-a89a-feb2d3692494 Load: 9c1913f3-e44d-40a0-a89a-feb2d3692494
%% Cell type:code id:ecbb38ae tags: %% Cell type:code id:ecbb38ae tags:
``` python ``` python
personalizer.plot_series(series) personalizer.plot_series(series)
``` ```
%% Output %% Output
%% Cell type:code id:1f6f9f91 tags: %% Cell type:code id:1f6f9f91 tags:
``` python ``` python
personalizer.incremental_learn_series_gt(series, save_model_as='./data/' + inc_model_name, epochs=100) personalizer.incremental_learn_series_gt(series, save_model_as='./data/' + inc_model_name, epochs=100)
#trainings_manager.database['training_runs'][training_run_name] = [] #trainings_manager.database['training_runs'][training_run_name] = []
#trainings_manager.database['training_runs'][training_run_name].append(inc_model_name) #trainings_manager.database['training_runs'][training_run_name].append(inc_model_name)
# trainings_manager.db_update() # trainings_manager.db_update()
``` ```
%% Output %% Output
Load base model: ./data/DeepConvLSTMA_statedict.pt
Train on: e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6 Train on: e5fbd0a6-11c9-409b-a2ba-0d392fdb0af6
tensor([ 0.5024, 102.6791]) tensor([ 0.5024, 102.6791])
Starting Training cuda