Ejemplo n.º 1
0
    def load_data_from_file(self, op='true'):
        """Load raw data and save it"""

        if op == 'true':
            eta_true = bf.load_pickle_file(self.true_file_path)
            self.true_raw = eta_true
            # eta[v_idx] = [eta_l1, ... eta_l5]
            self.eta = bf.is_list(self.true_raw)
            # compute z,  z[v_idx] = argmax eta_l \in {1,..5}
            self.z = self.compute_all_z(self.eta, self.z_true_op, None)
            # compute H, H[v_idx] = [cumulative for each level]
            self.H = self.compute_all_H(self.eta)

        elif op == 'hat':

            eta_hat = bf.load_pickle_file(self.estimated_file_path)
            self.estimated_raw = eta_hat
            # set lookup table
            etahat_list = bf.is_list(self.estimated_raw)
            # make it easier, lookup eta_hat
            self.lookup_eta_hat = etahat_list
            # compute z_hat
            self.lookup_z_hat = self.compute_all_z(self.lookup_eta_hat,
                                                   self.z_est_op)
            # compute H_hat
            self.lookup_H_hat = self.compute_all_H(self.lookup_eta_hat)

        return
Ejemplo n.º 2
0
    def collect_data(self, parent_folder='10-07-2', start_name='point', date_name='1008'):

        self.set_path_data(parent_folder)

        middle_name = '_G46V_ss2_' + date_name + '_'

        f_name = 'saved_data'
        extension = 'pkl'

        for per in self.percentages:

            for n_file in self.instances:
                folder = start_name + str(per) + middle_name + str(n_file).zfill(3)

                temp_path = self.parent + '/' + folder
                f_path = bf.assemble_file_path(temp_path, f_name, extension)

                data = bf.load_pickle_file(f_path)

                self.belief[per, n_file] = data['belief']
                self.target[per, n_file] = data['target']
                self.danger[per, n_file] = data['danger']
                try:
                    self.mission[per, n_file] = data['mission']
                except:
                    print('No mission obj')
                self.team[per, n_file] = data['team']
                self.solver_data[per, n_file] = data['solver_data']
                self.specs[per, n_file] = data['specs']

        self.prob_kill = [round(l * 100, 2) for l in self.danger[per, n_file].prob_kill]
        self.k_team = self.team[per, n_file].kappa
Ejemplo n.º 3
0
    def retrieve_times(self, pickle_names: list):

        times_list = []
        times_cum = []

        self.configs = len(pickle_names)

        for f_name in pickle_names:

            print('Getting data from %s' % f_name)
            out_data = []
            cum_data = []

            f_path = self.get_file_path(f_name)
            # load pickle file
            stat = bf.load_pickle_file(f_path)

            cum_data.append(stat.cum_mission_time)
            cum_data.append(stat.cum_capture_time)
            cum_data.append(stat.cum_abort_rate)

            out_data.append(stat.mission_time_list)
            out_data.append(stat.capture_time_list)
            out_data.append(stat.abort_time_list)

            times_list.append(out_data)
            times_cum.append(cum_data)

            del stat

        self.cum_times = times_cum
        self.times = times_list  # self.change_format_outcomes(self.N, times_list)
        self.compute_MC(2)

        self.plot_error_point(2)
Ejemplo n.º 4
0
    def load_scores(f_name='node_score_dict_Fire'):
        """Load pickle file with similarity scores"""
        # load file
        folder_path = MyDanger.get_folder_path()
        f_path = bf.assemble_file_path(folder_path, f_name, 'p')

        # xi_data[v] = [i1, i2, i3...], i = [xi_1, xi_2, xi_3..]
        xi_data = bf.load_pickle_file(f_path)

        return xi_data
Ejemplo n.º 5
0
def plot_only():

    extension = '.pkl'
    folder_path = MyDanger.get_folder_path('data_compiled')
    low_prob = ['1010NCDKHT-s-100', '1010DCDKHT-s-100']
    high_prob = ['1009NCDKHT-b-100', '1009NCDKHT-b-05', '1010DCDKHT-b-100', '1010DCDKHT-b-05']
    f_names = low_prob
    success_rate = []
    casualty_mission_rate = []
    avg_mission_time = []
    casualty_mvp = []

    for f_name in f_names:
        f_path = folder_path + '/' + f_name + extension
        stats = bf.load_pickle_file(f_path)
        # ---
        stats.print_name(stats.parent_name, '--\nStats for')
        stats.print_final_stats()

        success_rate.append(copy.deepcopy(stats.cum_success_rate))
        casualty_mission_rate.append(copy.deepcopy(stats.cum_casualty_mission_rate))
        avg_mission_time.append(copy.deepcopy(stats.cum_mission_time))
        casualty_mvp.append(copy.deepcopy(stats.cum_casualty_mvp_rate))

        print(stats.prob_kill)

        del stats

    rp = RiskPlot()

    for success in success_rate:
        rp.add_stats(success)

    rp.plot_stat()
    rp.clear_list()
    #
    for avg_time in avg_mission_time:
        rp.add_stats(avg_time)
    #
    rp.plot_stat()
    rp.clear_list()

    for casual in casualty_mission_rate:
        rp.add_stats(casual)

    rp.plot_stat()
    rp.clear_list()

    for mvp in casualty_mvp:
        rp.add_stats(mvp)

    rp.plot_stat()
    rp.clear_list()
Ejemplo n.º 6
0
    def load_danger_data(f_name, folder_path=None):
        """return danger data as dict data[v] = [eta1, ..., eta5]"""

        if folder_path is None:
            folder_path = MyDanger.get_folder_path()

        f_path = bf.assemble_file_path(folder_path, f_name, 'pkl')

        # danger_data[v] = [eta1, ..., eta5]
        danger_data = bf.load_pickle_file(f_path)

        return danger_data
Ejemplo n.º 7
0
    def retrieve_casualties(self, pickle_names: list):

        print('Collecting casualties...')

        casualties_list = []
        casualties_cum = []

        plot_n = 1

        # order:
        # any, other MVA

        self.configs = len(pickle_names)

        for f_name in pickle_names:

            print('Getting data from %s' % f_name)
            list_data = []
            cum_data = []

            f_path = self.get_file_path(f_name)
            # load pickle file
            stat = bf.load_pickle_file(f_path)

            # actual data collection
            cum_data.append(stat.cum_casualty_mission_rate)
            cum_data.append(stat.cum_casualty_not_mvp_rate)
            cum_data.append(stat.cum_casualty_mvp_rate)

            list_data.append(stat.casualty_list)
            list_data.append([])
            list_data.append(stat.casualty_mvp)

            print('Missions with MVA/any casualty: %d / %d' %
                  (stat.casualty_counter_mvp, stat.casualty_counter_any))

            casualties_list.append(list_data)
            casualties_cum.append(cum_data)

        self.cum_casualties = casualties_cum
        self.casualties = self.change_format_casualties(
            self.N, casualties_list)
        self.compute_MC(plot_n)

        self.plot_error_point(plot_n)
Ejemplo n.º 8
0
    def print_distribution(f_name: str, extension='pkl'):
        f_path_danger = MyDanger.get_folder_path('danger_files')
        f_name_danger = f_path_danger + '/' + f_name + '.' + extension
        eta = bf.load_pickle_file(f_name_danger)

        # print for all vertices
        for v in eta.keys():
            eta_v = eta[v]
            print('---')
            print('Vertex %d, eta = %s ' % (v, eta_v))

            if not MyDanger.sum_1(eta_v):
                print('Watch out, distribution does not sum to 1, %.3f' %
                      sum(eta_v))
            H = MyDanger.compute_H(eta_v)
            z = MyDanger.z_from_eta(eta_v, 1)
            print('H = %s' % str(H))
            print('z = %d' % z)
Ejemplo n.º 9
0
    def retrieve_outcomes(self, pickle_names: list):

        outcomes_list = []
        outcomes_cum = []

        # order:
        # success, cutoff, abort

        self.configs = len(pickle_names)

        for f_name in pickle_names:

            print('Getting data from %s' % f_name)
            out_data = []
            cum_data = []

            f_path = self.get_file_path(f_name)
            # load pickle file
            stat = bf.load_pickle_file(f_path)

            cum_data.append(stat.cum_success_rate)
            # cum_data.append(stat.cum_fail_rate)
            cum_data.append(stat.cum_cutoff_rate)
            cum_data.append(stat.cum_abort_rate)

            out_data.append(stat.success_list)
            # out_data.append(stat.fail_list)
            out_data.append(stat.cutoff_list)
            out_data.append(stat.abort_list)

            print('Missions aborted: %d' % len(stat.abort_list))

            outcomes_list.append(out_data)
            outcomes_cum.append(cum_data)

            del stat

        self.cum_outcomes = outcomes_cum
        self.outcomes = self.change_format_outcomes(self.N, outcomes_list)
        self.compute_MC(0)

        self.plot_error_point(0)