<jupyter_start><jupyter_text>Import libraries<jupyter_code>%load_ext autoreload
%autoreload 2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
from utils import *<jupyter_output><empty_output><jupyter_text>Parameters<jupyter_code>fig_dir = 'data/figure'
exp_name = 'compare_methods'
time_path = 'data/time/compare_methods_2020_12_14_1_4_52.npy'
cost_path = 'data/cost/compare_methods_2020_12_14_1_4_52.npy'
methods = ['greedy', 'optimal', 'approx', 'approx_woc']
sizes = np.arange(1, 11)
repeats = 10<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>%%time
run_time = np.load(time_path)
travel_cost = np.load(cost_path)
print(run_time.shape, travel_cost.shape)<jupyter_output>(40,) (40,)
Wall time: 2 ms<jupyter_text>Convert to DataFrame<jupyter_code>df_time = pd.DataFrame(run_time.reshape(repeats,-1)/np.power(10, 6), columns=methods)
print(df_time.shape)
print(df_time.info())
display(df_time)
df_cost =  pd.DataFrame(travel_cost.reshape(repeats,-1), columns=methods)
print(df_cost.shape)
print(df_cost.info())
display(df_cost)<jupyter_output>(10, 4)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 4 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   greedy      10 non-null     float64
 1   optimal     10 non-null     float64
 2   approx      10 non-null     float64
 3   approx_woc  10 non-null     float64
dtypes: float64(4)
memory usage: 448.0 bytes
None<jupyter_text>Calculate metrics   Processing time<jupyter_code>df_time.mean()<jupyter_output><empty_output><jupyter_text>Approximation ratio<jupyter_code>df_cost.loc[:, 'approx_ratio'] = df_cost['approx']/df_cost['optimal']
df_cost.loc[:, 'approx_woc_ratio'] = df_cost['approx_woc']/df_cost['optimal']
df_cost.loc[:, 'greedy_ratio'] = df_cost['greedy']/df_cost['optimal']
display(df_cost)
df_cost[['approx_ratio', 'approx_woc_ratio', 'greedy_ratio']].mean()<jupyter_output><empty_output><jupyter_text>Ride-sharing efficiency<jupyter_code>df_cost.loc[:, 'approx_gain'] = df_cost['greedy']/df_cost['approx']
df_cost.loc[:, 'approx_woc_gain'] = df_cost['greedy']/df_cost['approx_woc']
df_cost.loc[:, 'optimal_gain'] = df_cost['greedy']/df_cost['optimal']
display(df_cost)
df_cost[['approx_gain', 'approx_woc_gain', 'optimal_gain']].mean()
df_cost[['greedy', 'optimal', 'approx', 'approx_woc']].mean()<jupyter_output><empty_output><jupyter_text>Plots  Processing time<jupyter_code>plot_proc_time(
    df_time, 
    sizes, 
    exp_name, 
    ylim=(10**-2, 10**2),
    plot_optimal=True
)<jupyter_output><empty_output><jupyter_text>Travel cost<jupyter_code>plot_travel_cost(
    df_cost, 
    sizes, 
    exp_name, 
    ylim=(7000,14000),
    plot_optimal=True
)<jupyter_output><empty_output><jupyter_text>Approximation ratio<jupyter_code>plot_approx_ratio(
    df_cost, 
    sizes, 
    exp_name, 
    ylim=(0.9,1.5),
    legend_loc=(0.3, 0.65)
)<jupyter_output><empty_output><jupyter_text>Ride-sharing efficiency<jupyter_code>plot_rs_efficiency(
    df_cost, 
    sizes, 
    exp_name, 
    ylim=(0.9,1.5),
    plot_optimal=True,
    legend_loc=(0.3, 0.65)
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14949748743718594, 'fraction_numerical': 0.03391959798994975, 'mean_word_length': 6.062084257206209, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '243098', 'license': 'MIT', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1260, 'n_words': 177, 'path': 'Evaluate_methods.ipynb', 'repo_name': 'hsgser/ABRSWC', 'size': '3184'}