示例#1
0
def compute_and_cache_metrics(dataset_id):
    # Returns a dict (one entry for each technique) with lists of dataframes
    dataframes = Parser.parse_dataset(dataset_id)

    for technique, df_list in dataframes.items():
        print(technique, end='')
        # Compute aspect ratios and weight of cells
        ar_cache_path = 'metric_results/' + technique + '-' + dataset_id + '-ar.csv'
        ar_df = pd.DataFrame()
        if not os.path.isfile(ar_cache_path):
            for revision, df in enumerate(df_list):
                weight = compute_relative_weight(df, revision)
                ar = compute_aspect_ratio(df, revision)
                ar_df = pd.merge(ar_df,
                                 weight,
                                 how='outer',
                                 left_index=True,
                                 right_index=True)
                ar_df = pd.merge(ar_df,
                                 ar,
                                 how='outer',
                                 left_index=True,
                                 right_index=True)
            ar_df.fillna(0, inplace=True)
            ar_df.to_csv(ar_cache_path, index_label='id')

        # Compute Corner Travel (real and baseline)
        ct_cache_path = 'metric_results/' + technique + '-' + dataset_id + '-ct.csv'
        ct_df = pd.DataFrame()
        if not os.path.isfile(ct_cache_path):
            for revision in range(len(df_list) - 1):
                r0 = df_list[revision][['rx', 'ry', 'rw',
                                        'rh']].dropna(axis=0, subset=['rx'])
                r1 = df_list[revision + 1][['rx', 'ry', 'rw',
                                            'rh']].dropna(axis=0,
                                                          subset=['rx'])
                b1 = df_list[revision + 1][['bx', 'by', 'bw',
                                            'bh']].dropna(axis=0,
                                                          subset=['bx'])
                ct = corner_travel_values(r0, r1, b1, revision)
                ct_df = pd.merge(ct_df,
                                 ct,
                                 how='outer',
                                 left_index=True,
                                 right_index=True)
            ct_df.fillna(0, inplace=True)
            ct_df.to_csv(ct_cache_path, index_label='id')

        # Compute Relative Position Change metric
        rpc_cache_path = 'metric_results/' + technique + '-' + dataset_id + '-rpc.csv'
        rpc_df = pd.DataFrame()
        if not os.path.isfile(rpc_cache_path):
            for revision in range(len(df_list) - 1):
                real = relative_position_change_wrapper(
                    df_list[revision][['rx', 'ry', 'rw', 'rh']],
                    df_list[revision + 1][['rx', 'ry', 'rw', 'rh']])

                baseline = relative_position_change_wrapper(
                    df_list[revision][['rx', 'ry', 'rw', 'rh']],
                    df_list[revision + 1][['bx', 'by', 'bw', 'bh']])

                df_temp = pd.DataFrame({
                    'r_' + str(revision): real,
                    'b_' + str(revision): baseline
                })
                df_temp.sort_index(axis=1, ascending=False, inplace=True)
                rpc_df = pd.merge(rpc_df,
                                  df_temp,
                                  how='outer',
                                  left_index=True,
                                  right_index=True)
            rpc_df.fillna(0, inplace=True)
            rpc_df.to_csv(rpc_cache_path, index_label='id')

        print(' done.')
    return None
示例#2
0
    Boxplots.plot_instability(ct_values, dataset_id, 'ct')
    print('---')

    rpc_values = Parser.read_rpc_metric(dataset_id)
    Boxplots.plot_instability(rpc_values, dataset_id, 'rpc')
    print('---')

elif action == 'scatter':
    dataset_ids = sys.argv[2:]
    Scatter.plot(dataset_ids, True, False)
    # Scatter.plot(dataset_ids, False, True)
    # Scatter.plot(dataset_ids, True, True)

elif action == "matrix":
    dataset_ids = sys.argv[2:]
    Matrix.plot(dataset_ids)

elif action == "simple-trails":
    dataset_id = sys.argv[2]
    dataframes = Parser.parse_dataset(dataset_id)
    SimpleTrails.plot(dataframes, dataset_id)

elif action == "directed-trails":
    dataset_id = sys.argv[2]
    dataframes = Parser.parse_dataset(dataset_id)
    DirectedTrails.plot(dataframes, dataset_id)

elif action == "trail-heatmap":
    dataset_id = sys.argv[2]
    dataframes = Parser.parse_dataset(dataset_id)
    TrailHeatmap.plot(dataframes, dataset_id)