-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAnalysis_SA.py
More file actions
86 lines (71 loc) · 4.06 KB
/
Copy pathAnalysis_SA.py
File metadata and controls
86 lines (71 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import pickle
import numpy as np
import pandas as pd
from scipy.optimize import differential_evolution
import matplotlib.pyplot as plt
import networkx as nx
import scipy as sp
import matplotlib.gridspec as gridspec
from scipy.stats import norm, multivariate_normal
# Go through Results_oncoming_SA folder aand Results_rear_end_SA folder and create combined analysis files
# In those folders, find Analysis_settings_*.csv files and combine them into a single Analysis_settings_*.csv file
oncoming_files = os.listdir("Results_oncoming_SA")
rear_end_files = os.listdir("Results_rear_end_SA")
intersection_files = os.listdir("Results_intersection_SA")
# Get usable files
oncoming_files = [f for f in oncoming_files if f.startswith("Analysis_settings_") and f.endswith(".csv")]
rear_end_files = [f for f in rear_end_files if f.startswith("Analysis_settings_") and f.endswith(".csv")]
intersection_files = [f for f in intersection_files if f.startswith("Analysis_settings_") and f.endswith(".csv")]
# Get the corresponding parameter names
oncoming_param_names = [f[len("Analysis_settings_"):-len(".csv")] for f in oncoming_files]
rear_end_param_names = [f[len("Analysis_settings_"):-len(".csv")] for f in rear_end_files]
intersection_param_names = [f[len("Analysis_settings_"):-len(".csv")] for f in intersection_files]
# Get combined unique parameter names
all_param_names = list(set(oncoming_param_names) | set(rear_end_param_names) | set(intersection_param_names))
# Go through each parameter name and combine files. If one experiment is not available, use NaNs
# For oncoming, the column names should be ['JSD_5', 'JSD_25', 'JSD_50', 'JSD_75', 'JSD_95', 'WD_5', 'WD_25', 'WD_50', 'WD_75', 'WD_95', param]
# For rear_end, the column names should be ['IT_5', 'IT_25', 'IT_50', 'IT_75', 'IT_95', 'IA_5', 'IA_25', 'IA_50', 'IA_75', 'IA_95', param]
# Index should be the same as for the other existing files
for param in all_param_names:
# get param values
if param == 'a_tar_min_intensity':
continue
# Oncoming
if not param in oncoming_param_names:
oncoming_df = pd.DataFrame(-1.0, index=[], columns=['param', 'JSD_5', 'JSD_25', 'JSD_50', 'JSD_75', 'JSD_95', 'WD_5', 'WD_25', 'WD_50', 'WD_75', 'WD_95'])
else:
oncoming_file = "Results_oncoming_SA" + os.sep + "Analysis_settings_" + param + ".csv"
oncoming_df = pd.read_csv(oncoming_file, index_col=0)
# Rear end
if not param in rear_end_param_names:
rear_end_df = pd.DataFrame(-1.0, index=[], columns=['param', 'IT_5', 'IT_25', 'IT_50', 'IT_75', 'IT_95', 'IA_5', 'IA_25', 'IA_50', 'IA_75', 'IA_95'])
else:
rear_end_file = "Results_rear_end_SA" + os.sep + "Analysis_settings_" + param + ".csv"
rear_end_df = pd.read_csv(rear_end_file, index_col=0)
# Intersection
if not param in intersection_param_names:
intersection_df = pd.DataFrame(-1.0, index=[], columns=['param', 'JSDI_5', 'JSDI_25', 'JSDI_50', 'JSDI_75', 'JSDI_95', 'WDI_5', 'WDI_25', 'WDI_50', 'WDI_75', 'WDI_95'])
else:
intersection_file = "Results_intersection_SA" + os.sep + "Analysis_settings_" + param + ".csv"
intersection_df = pd.read_csv(intersection_file, index_col=0)
# Make param the index for both dataframes
oncoming_df = oncoming_df.set_index('param')
rear_end_df = rear_end_df.set_index('param')
intersection_df = intersection_df.set_index('param')
# Combine dataframes
combined_df = pd.concat([oncoming_df, rear_end_df, intersection_df], axis=1)
# Make param a column again
combined_df = combined_df.reset_index()
# Sort by param
combined_df = combined_df.sort_values(by='param')
# Update for lambda
if param == 'EA_fac':
combined_df['param'] = 10 ** (combined_df['param'] + 5)
if param in ['road_leave_cost', 'collision_cost']:
combined_df['param'] = combined_df['param'] * 0.01
# Make Nans into -1
combined_df = combined_df.fillna(-1.0)
# Save combined dataframe
os.makedirs("Results_combined_SA", exist_ok=True)
combined_df.to_csv("Results_combined_SA" + os.sep + 'Analysis_settings_' + param + ".csv")