def __init__(self,
              bins,
              source_data_dir,
              calibration_features,
              config,
              model_data_store_dir,
              apply_old,
              apply_difference,
              model_type,
              model_number,
              player_info,
              focus_actions_list=[]):
     self.bins = bins
     # self.bins_names = bins.keys()
     self.apply_old = apply_old
     self.apply_difference = apply_difference
     self.data_path = source_data_dir
     self.calibration_features = calibration_features
     if self.apply_difference:
         self.calibration_values_all_dict = {
             'all': {
                 'cali_sum': [0],
                 'model_sum': [0],
                 'number': 0
             }
         }
     else:
         self.calibration_values_all_dict = {
             'all': {
                 'cali_sum': [0, 0, 0],
                 'model_sum': [0, 0, 0],
                 'number': 0
             }
         }
     self.data_store_dir = model_data_store_dir
     self.config = config
     self.focus_actions_list = focus_actions_list
     if self.apply_difference:
         self.save_calibration_dir = './calibration_results/difference-calibration_{2}_{0}_{1}{3}.txt'. \
             format(str(self.focus_actions_list), datetime.date.today().strftime("%Y%B%d"), model_type, player_info)
     else:
         self.save_calibration_dir = './calibration_results/calibration_{2}_{0}_{1}{3}.txt'. \
             format(str(self.focus_actions_list), datetime.date.today().strftime("%Y%B%d"), model_type, player_info)
     self.save_calibration_file = open(self.save_calibration_dir, 'w')
     if apply_difference:
         self.teams = ['home-away']
     else:
         self.teams = ['home', 'away', 'end']
         # learning_rate = tt_lstm_config.learn.learning_rate
         # pass
     self.data_name = get_data_name(config=config,
                                    model_catagoery=model_type,
                                    model_number=model_number)
     self.data_name = self.data_name.replace('Qs', 'next_Qs')
     print(self.data_name)
Esempio n. 2
0
                                            "icehockey_stats_lstm_encoder{0}" \
                                            "_config{1}.yaml".format(predicted_target, player_info)
            icehockey_model_config = EncoderConfig.load(
                icehockey_encoder_config_path)
        elif model_category == 'lstm_diff':
            icehockey_config_path = "../../environment_settings/" \
                                    "ice_hockey_predict_score_diff_lstm{0}.yaml".format(player_info)
            icehockey_model_config = LSTMDiffCongfig.load(
                icehockey_config_path)
            player_id_cluster_dir = None
        else:
            raise ValueError(
                "uknown model catagoery {0}".format(model_category))

        if model_category != 'zero':
            data_name = get_data_name(icehockey_model_config, model_category,
                                      model_number)
            data_name = data_name.replace('Qs', 'accumu_Qs') + "_cv"
        else:
            data_name = None

        print(model_category + '_' + model_number + player_info)
        acc_diff_mean_by_event, acc_diff_var_by_event, event_numbers, \
        acc_diff_mean_by_time, acc_diff_var_by_time, game_time_list = validate_score_diff(model_data_store_dir,
                                                                                          data_name,
                                                                                          model_data_store_dir,
                                                                                          data_store,
                                                                                          model_category,
                                                                                          None,
                                                                                          cv_number=5)
        event_numbers_all.append(event_numbers)
        acc_diff_mean_by_event_all.append(acc_diff_mean_by_event)
                               model_number=model_number,
                               player_id_cluster_dir=player_id_cluster_dir,
                               model_category=model_type,
                               return_values_flag=False,
                               apply_cv=True,
                               running_number=running_number)
        # for dir_game_index in range(0, len(dir_games_all)):
        #     cv_record_all_model_next_Q_values[dir_game_index].update(
        #         {running_number: model_next_Q_values_all[dir_game_index]})
        #     cv_record_all_model_accumu_Q_values[dir_game_index].update(
        #         {running_number: model_accumu_Q_value_all[dir_game_index]})

    # dir_games_all = dir_games_all[1:]
    for dir_game_index in range(0, len(dir_games_all)):
        data_name = get_data_name(config=icehockey_model_config,
                                  model_catagoery=model_type,
                                  model_number=model_number)
        game_name_dir = dir_games_all[dir_game_index]
        game_store_dir = game_name_dir.split('.')[0]
        game_all_next_Qs_values = {}
        game_all_accumu_Qs_values = {}
        for running_number in running_numbers:
            if model_type != 'lstm_diff' and model_type != 'multi_agent' and model_type != 'clvrnn' and model_type != 'caernn':
                with open(
                        data_store_dir + "/" + game_store_dir + "/" +
                        data_name.replace('Qs', 'next_Qs') + '_r' +
                        str(running_number), 'r') as outfile:
                    cv_next_Qs_game_values = json.load(outfile)
                game_all_next_Qs_values.update(
                    {running_number: cv_next_Qs_game_values})
                os.remove(data_store_dir + "/" + game_store_dir + "/" +
    def __init__(self,
                 bins,
                 source_data_dir,
                 calibration_features,
                 config,
                 model_data_store_dir,
                 apply_old,
                 apply_difference,
                 model_type,
                 model_number,
                 player_info,
                 calibration_type,
                 embed_mode,
                 focus_actions_list=[],
                 if_apply_cv=False,
                 running_numbers=[None]):
        self.calibration_type = calibration_type
        self.bins = bins
        # self.bins_names = bins.keys()
        self.apply_old = apply_old
        self.if_apply_difference = apply_difference
        self.data_path = source_data_dir
        self.calibration_features = calibration_features
        self.if_apply_cv = if_apply_cv
        self.running_numbers = running_numbers
        if self.if_apply_difference:
            if self.if_apply_cv:
                self.cv_calibration_values_all_list = []
                for running_number in self.running_numbers:
                    self.cv_calibration_values_all_list.append({
                        'all'.format(str(running_number)): {
                            'cali_sum': [0],
                            'model_sum': [0],
                            'number': 0
                        }
                    })
            else:
                self.calibration_values_all_dict = {
                    'all': {
                        'cali_sum': [0],
                        'model_sum': [0],
                        'number': 0
                    }
                }
        else:
            if self.if_apply_cv:
                self.cv_calibration_values_all_list = []
                for running_number in self.running_numbers:
                    self.cv_calibration_values_all_list.append({
                        'all'.format(str(running_number)): {
                            'cali_sum': [0, 0, 0],
                            'model_sum': [0, 0, 0],
                            'number': 0
                        }
                    })
            else:
                self.calibration_values_all_dict = {
                    'all': {
                        'cali_sum': [0, 0, 0],
                        'model_sum': [0, 0, 0],
                        'number': 0
                    }
                }
        self.data_store_dir = model_data_store_dir
        self.config = config
        self.focus_actions_list = focus_actions_list
        if self.if_apply_difference:
            self.save_calibration_dir = './calibration_results/difference-calibration_{2}_{0}_{1}{3}_model{4}_{5}.txt'. \
                format(str(self.focus_actions_list), datetime.date.today().strftime("%Y%B%d"), model_type,
                       player_info, model_number, embed_mode)
        else:
            self.save_calibration_dir = './calibration_results/calibration_{2}_{0}_{1}{3}_model{4}_{5}.txt'. \
                format(str(self.focus_actions_list), datetime.date.today().strftime("%Y%B%d"), model_type,
                       player_info, model_number, embed_mode)
        if self.if_apply_cv:
            self.save_calibration_dir = self.save_calibration_dir.replace(
                '.txt', '_cv.txt')
        self.save_calibration_file = open(self.save_calibration_dir, 'w')
        if apply_difference:
            self.teams = ['home-away']
        else:
            if self.calibration_type == 'next_goal':
                self.teams = ['home', 'away', 'end']
            elif self.calibration_type == 'score_diff':
                self.teams = ['home', 'away']
            # learning_rate = tt_lstm_config.learn.learning_rate
            # pass
        data_name = get_data_name(config=config,
                                  model_catagoery=model_type,
                                  model_number=model_number)

        if self.calibration_type == 'next_goal':
            self.data_name = data_name.replace('Qs', 'next_Qs')
        elif self.calibration_type == 'score_diff':
            self.data_name = data_name.replace('Qs', 'accumu_Qs')
        else:
            raise ValueError('unknown calibration type {0}'.format(
                self.calibration_type))
        if if_apply_cv:
            self.data_name = self.data_name + "_cv"
        print(self.data_name)
        self.calibration_type = calibration_type