def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) if MODE == MODE_TRAIN: from scripts.test_model import BHSMMTestModel from hassbrain_algorithm.models.hmm.bhmm_hp import BernoulliHMM_HandcraftedPriors from hassbrain_algorithm.models.tads import TADS if MODEL_CLASS == BHMM: hmm_model = BHMMTestModel(ctrl) elif MODEL_CLASS == BHSMM: hmm_model = BHSMMTestModel(ctrl) hmm_model.set_training_steps(50) elif MODEL_CLASS == BHMMPC: hmm_model = BernoulliHMM_HandcraftedPriors(ctrl) elif MODEL_CLASS == MCTADS: hmm_model = TADS(ctrl) else: raise ValueError ctrl.register_model(hmm_model, MODEL_NAME) # load domain knowledge if MODEL_CLASS == BHMMPC: path = '/home/cmeier/code/data/hassbrain/datasets/hass_chris_final/data/domain_knowledge.json' act_data, loc_data = load_domain_knowledge(path) ctrl.register_location_info(MODEL_NAME, loc_data) ctrl.register_activity_info(MODEL_NAME, act_data) # load model elif MODE == MODE_BENCH: ctrl.load_model(MODEL_FILE_PATH, MODEL_NAME) else: raise ValueError ctrl.register_benchmark(MODEL_NAME) ctrl.init_model_on_dataset(MODEL_NAME) if MODE == MODE_TRAIN: ctrl.register_loss_file_path(MD_LOSS_FILE_PATH, MODEL_NAME) ctrl.train_model(MODEL_NAME) ctrl.save_model(MODEL_FILE_PATH, MODEL_NAME) # bench the model reports = ctrl.bench_models() # save metrics ctrl.save_df_metrics_to_file(MODEL_NAME, MD_METRICS_FILE_PATH) ctrl.save_df_confusion(MODEL_NAME, MD_CONF_MAT_FILE_PATH) ctrl.save_df_act_dur_dists(MODEL_NAME, MD_ACT_DUR_DISTS_DF_FILE_PATH, DATA_ACT_DUR_DISTS_DF_FILE_PATH) ctrl.save_df_class_accs(MODEL_NAME, MD_CLASS_ACTS_FILE_PATH) # plots if MODE == MODE_TRAIN and MODEL_CLASS != MCTADS: ctrl.save_plot_trainloss(MODEL_NAME, MD_LOSS_IMG_FILE_PATH) ctrl.save_plot_inferred_states(MODEL_NAME, MD_INFST_IMG_FILE_PATH) ctrl.save_plot_act_dur_dists([MODEL_NAME], MD_ACT_DUR_DISTS_IMG_FILE_PATH)
def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) # load model model_name = 'bhmm' ctrl.load_model(MODEL_FILE_PATH, model_name) ctrl.create_model_agnostics(model_name) hm = ctrl.get_model(model_name)._obs_lbl_hashmap file_path = MODEL_FOLDER_PATH + '/' + MODEL_NAME + '.lime_sleeping.png' file_paths = [file_path] labels_to_explain=['sleeping'] import numpy as np # typical for activation pattern for sleeping raw_feature_sleeping = np.array( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=bool) ch_feature_sleeping = np.array( [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=bool) lf_feature_sleeping = np.array( [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=bool) data = ctrl._dataset # type: _Dataset ctrl.plot_and_save_explanation( model_name, ch_feature_sleeping, labels_to_explain, file_paths )
def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) # load model model_name = 'bhmm' ctrl.load_model(MODEL_FILE_PATH, model_name) ctrl.create_model_agnostics(model_name) file_path = MODEL_FOLDER_PATH + '/' + MODEL_NAME + '.feature_importance.png' ctrl.save_plot_feature_importance(model_name, file_path)
def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) print() # load model ctrl.load_model(MODEL_FILE_PATH, 'bhmm') ctrl.load_model(MODEL_FILE_PATH2, 'bhsmm') state_sel = ['dental_care', 'outside_activity', 'learning'] #state_sel = ['dental_care', 'enter_home', 'kitchen_social_activity'] img_file_path = MODEL_FOLDER_PATH + '/' + 'comparision.png' ctrl.compare_dur_dists_and_save('bhmm', 'bhsmm', state_sel, img_file_path)
def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) from scripts.test_model import BHSMMTestModel from hassbrain_algorithm.models.hmm.bhmm_hp import BernoulliHMM_HandcraftedPriors from hassbrain_algorithm.models.tads import TADS if MODEL_CLASS == BHMM: hmm_model = BHMMTestModel(ctrl) hmm_model.set_training_steps(10) elif MODEL_CLASS == BHSMM: hmm_model = BHSMMTestModel(ctrl) hmm_model.set_training_steps(50) elif MODEL_CLASS == BHMMPC: hmm_model = BernoulliHMM_HandcraftedPriors(ctrl) elif MODEL_CLASS == MCTADS: hmm_model = TADS(ctrl) else: raise ValueError ctrl.register_model(hmm_model, MODEL_NAME) ctrl.register_benchmark(MODEL_NAME) ctrl.init_model_on_dataset(MODEL_NAME) ctrl.register_loss_file_path(MD_LOSS_FILE_PATH, MODEL_NAME) ctrl.train_model(MODEL_NAME) ctrl.save_model(MODEL_FILE_PATH, MODEL_NAME) # bench the model params = { 'metrics': False, 'act_dur_dist': True, 'feature_importance': False } reports = ctrl.bench_models(**params) # save metrics #ctrl.save_df_metrics_to_file(MODEL_NAME, MD_METRICS_FILE_PATH) #ctrl.save_df_confusion(MODEL_NAME, MD_CONF_MAT_FILE_PATH) #ctrl.save_df_act_dur_dists(MODEL_NAME, MD_ACT_DUR_DISTS_DF_FILE_PATH, # DATA_ACT_DUR_DISTS_DF_FILE_PATH) #ctrl.save_df_class_accs(MODEL_NAME, MD_CLASS_ACTS_FILE_PATH) dict = { #'feature_importance' : MD_FEATURE_IMP_PLT_FILE_PATH, 'train_loss': MD_LOSS_IMG_FILE_PATH, #'inf_states' : MD_INFST_IMG_FILE_PATH, 'act_dur': MD_ACT_DUR_DISTS_IMG_FILE_PATH } ctrl.save_plots(MODEL_NAME, dict)
def main(): # set of observations ctrl = Controller() # todo this is only for testing interpretability from scripts.test_model import BHMMTestModel from scripts.test_model import BHSMMTestModel #hmm_model = BHMMTestModel(ctrl) hmm_model = BHSMMTestModel(ctrl) ctrl.load_dataset_from_file(DATASET_FILE_PATH) ctrl.register_model(hmm_model, MODEL_NAME) ctrl.register_benchmark(MODEL_NAME) ctrl.init_model_on_dataset(MODEL_NAME) #ctrl.register_loss_file_path(MD_LOSS_FILE_PATH, MODEL_NAME) ctrl.train_model(MODEL_NAME) print(MODEL_FILE_PATH) ctrl.save_model(MODEL_FILE_PATH, MODEL_NAME) print()
def main(): ctrl = Controller() ctrl.load_dataset_from_file(DATASET_FILE_PATH) #hmm_model = BHMMTestModel(ctrl) #hmm_model = BHSMMTestModel(ctrl) from hassbrain_algorithm.models.hmm.bhmm_hp import BernoulliHMM_HandcraftedPriors hmm_model = BernoulliHMM_HandcraftedPriors(ctrl) ctrl.register_model(hmm_model, MODEL_NAME) # load domain knowledge path = '/home/cmeier/code/data/hassbrain/datasets/hass_chris_final/data/domain_knowledge.json' act_data, loc_data = load_domain_knowledge(path) ctrl.register_location_info(MODEL_NAME, loc_data) ctrl.register_activity_info(MODEL_NAME, act_data) # load model #ctrl.load_model(MODEL_FILE_PATH, MODEL_NAME) from scripts.test_model import BHSMMTestModel ctrl.register_benchmark(MODEL_NAME) ctrl.init_model_on_dataset(MODEL_NAME) ctrl.register_loss_file_path(MD_LOSS_FILE_PATH, MODEL_NAME) ctrl.train_model(MODEL_NAME) # bench the model reports = ctrl.bench_models() # save metrics ctrl.save_df_metrics_to_file(MODEL_NAME, MD_METRICS_FILE_PATH) ctrl.save_df_confusion(MODEL_NAME, MD_CONF_MAT_FILE_PATH) ctrl.save_df_act_dur_dists(MODEL_NAME, MD_ACT_DUR_DISTS_DF_FILE_PATH, DATA_ACT_DUR_DISTS_DF_FILE_PATH) # plots ctrl.save_plot_trainloss(MD_LOSS_IMG_FILE_PATH, MODEL_NAME) ctrl.plot_and_save_inferred_states(MD_INFST_IMG_FILE_PATH, MODEL_NAME) ctrl.save_plot_act_dur_dists(MODEL_NAME, MD_ACT_DUR_DISTS_IMG_FILE_PATH, DATA_ACT_DUR_DISTS_IMG_FILE_PATH)
def _create_ctrl_for_hass_instance(self, algorithm, person, datainstance, model_name): from hassbrain_algorithm.controller import Controller """ the case where the data should be loaded from the active homeassistant instance """ ctrl = Controller(path_to_config=settings.HASSBRAIN_ALGO_CONFIG) ctrl.load_dataset_from_file(datainstance.data_file) model_object = self._create_class_from_name(ctrl, algorithm) self._set_custom_act_n_dev(ctrl) ctrl.register_model(model_object, model_name) #if algorithm.location: # loc_data = AlgorithmView.get_location_data() # ctrl.register_location_info(loc_data) #if algorithm.synthetic_activities: # act_data = AlgorithmView.get_activity_data(algorithm.selected_person) # ctrl.register_activity_info(act_data) return ctrl