Skip to content

Commit

Permalink
intermediate save
Browse files Browse the repository at this point in the history
  • Loading branch information
hoomanzabeti committed Apr 4, 2021
1 parent aef84fd commit 760655b
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 138 deletions.
74 changes: 74 additions & 0 deletions PaperPlotTable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import pandas as pd
import orloge as ol
import copy
import yaml
from utils import config_decoder


def best_parameter_distribution(dir_path, file_condition='best_params_', output_file_name='best_params.csv',
save_output=True, noise_level=0):
file_list = [f_name for f_name in os.listdir(dir_path) if f_name.startswith(file_condition)]
path_list = [[os.path.join(dir_path, f_name), f_name] for f_name in file_list
if os.path.isfile(os.path.join(dir_path, f_name))]
combined_csv = []
for f in path_list:
temp_csv = pd.read_csv(f[0], index_col=0)
temp_info = pd.DataFrame(dict(zip(['N', 'group_size', 'm', 's', 'seed'], f[1].strip('.csv').split('_')[2:])), index=[0])
temp_info['noise_level'] = noise_level
temp_csv = pd.concat([temp_info, temp_csv], axis=1)
combined_csv.append(copy.copy(temp_csv))
combined_csv = pd.concat(combined_csv).reset_index().drop(['index'], axis=1)

if save_output:
combined_csv.to_csv(os.path.join(dir_path, output_file_name), index=False, encoding='utf-8-sig')
else:
return combined_csv

def cplex_log_files(dir_path, file_condition='log_', output_file_name='parsed_log.csv',
save_output=True):
file_list = [f_name for f_name in os.listdir(dir_path) if f_name.startswith(file_condition)]
path_list = [[os.path.join(dir_path, f_name), f_name] for f_name in file_list
if os.path.isfile(os.path.join(dir_path, f_name))]
combined_csv = []
for f in path_list:
temp_info = pd.DataFrame(dict(zip(['N', 'group_size', 'm', 's', 'seed'], f[1].strip('.txt').split('_')[1:])), index=[0])
flist = open(os.path.join(f[0])).readlines()
print(flist[-1])
temp_info['time(sec)'] = flist[-1].split(' ')[-4].strip('(')
temp_info['ticks'] = flist[-1].split(' ')[-2].strip('(')
combined_csv.append(copy.copy(temp_info))
combined_csv = pd.concat(combined_csv).reset_index().drop(['index'], axis=1)
if save_output:
combined_csv.to_csv(os.path.join(dir_path, output_file_name), index=False, encoding='utf-8-sig')
else:
return combined_csv

# dir_path = '/Users/hoomanzabeti/Desktop/GTResults/Noisy/Threshold'
# dir_list = [i for i in os.walk(dir_path)][0][1]
#
# # print(pd.concat([best_parameter_distribution(os.path.join(dir_path,i,'Logs'),save_output=False) for i in dir_list]).reset_index())
# pd.concat([best_parameter_distribution(os.path.join(dir_path, i, 'Logs'), save_output=False)
# for i in dir_list]).reset_index().to_csv(os.path.join(dir_path, 'best_params.csv'),
# index=False, encoding='utf-8-sig')

# dir_path = '/Users/hoomanzabeti/Desktop/GTResults/LP_IT'
# dir_list = [i for i in os.walk(dir_path)][0][1]
# pd.concat([cplex_log_files(os.path.join(dir_path, i, 'Logs'), save_output=False)
# for i in dir_list]).reset_index().to_csv(os.path.join(dir_path, 'parsed_lp_logs.csv'),
# index=False, encoding='utf-8-sig')

dir_path = '/Users/hoomanzabeti/Desktop/GTResults/Noisy/Permutation/'
dir_list = [i for i in os.walk(dir_path)][0][1]
noise_level = []
for f in dir_list:
with open(os.path.join(dir_path,f,'config.yml'), 'r') as config_file:
config_dict = yaml.load(config_file, Loader=yaml.FullLoader)
opts = config_decoder(config_dict['opts'])[0]
noise_level.append(opts['permutation_noise_prob'])
print(noise_level)
print(dir_list)
# print(pd.concat([best_parameter_distribution(os.path.join(dir_path,i,'Logs'),save_output=False) for i in dir_list]).reset_index())
pd.concat([best_parameter_distribution(os.path.join(dir_path, i, 'Logs'), save_output=False,noise_level=noise_level[idx])
for idx, i in enumerate(dir_list)]).reset_index().to_csv(os.path.join(dir_path, 'best_params.csv'),
index=False, encoding='utf-8-sig')
121 changes: 66 additions & 55 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
---
opts:
'run_ID': 'debugging'
'verbose': False
'plotting': False
'saving': True
'graph_gen_method': 'no_multiple'
'test_noise_methods': ['permutation']
'permutation_noise_prob':
'mode': 'scalar'
'values': [0.01]
'theta_l':
'mode': 'scalar'
'values': [0.00]
'theta_u':
'mode': 'scalar'
'values': [0.0625]
'binary_symmetric_noise_prob':
'mode': 'scalar'
'values': [0.26]
'seed':
'mode': 'range'
'values': [0,10,1]
'N':
'mode': 'scalar'
'values': [1000]
's':
'mode': 'scalar'
'values': [50]
'group_size':
'mode': 'scalar'
'values': [16]
'm':
'mode': 'range'
'values': [10,1010,10]
'max_tests_per_individual':
'mode': 'scalar'
'values': [16]
design_param:
'general':
'seed':
'mode': 'range'
'values': [0,1,1]
'N':
'mode': 'scalar'
'values': [1000]
'm':
'mode': 'range'
'values': [10,30,10]
'verbose': False
'generate_groups':
'run_ID': 'debugging'
'plotting': False
'saving': True
'graph_gen_method': 'no_multiple'
'group_size':
'mode': 'scalar'
'values': [16]
'max_tests_per_individual':
'mode': 'scalar'
'values': [16]
'generate_individual_status':
's':
'mode': 'scalar'
'values': [50]
'generate_test_results':
'test_noise_methods': ['permutation']
'permutation_noise_prob':
'mode': 'scalar'
'values': [0.01]
'theta_l':
'mode': 'scalar'
'values': [0.00]
'theta_u':
'mode': 'scalar'
'values': [0.0625]
'binary_symmetric_noise_prob':
'mode': 'scalar'
'values': [0.26]

decoder_param:
'decode':
'lambda_w': 1
'lambda_e':
'mode': 'scalar'
'values': [0.125,0.25,0.5,1,2,4,8]
'defective_num_lower_bound': null
'sensitivity_threshold': null
'specificity_threshold': null
'is_it_noiseless': False
'lp_relaxation': False
'solver_name': 'CPLEX_PY'
'solver_options':
'mode': 'exact'
'timeLimit': 1800
'lambda_selection':
'cross_validation': False
'number_of_folds': 2
'cv_param':
'mode': 'exact'
'lambda_e': [0.125,0.25,0.5,1,2,4,8]
#'mip':True
'evaluation':
'eval_metric': 'balanced_accuracy'

lambda_selection:
'cross_validation': False
'number_of_folds': 5
'param':
'lambda_e': [0.125,0.25,0.5,1,2,4,8]
param:
'lambda_w': 1
'lambda_p': 100
'lambda_n': 100
'defective_num_lower_bound': null
'sensitivity_threshold': null
'specificity_threshold': null
'is_it_noiseless': False
'lp_relaxation': False
'solver_name': 'CPLEX_PY'
'solver_options':
'mode': 'exact'
'timeLimit': 1800
2 changes: 1 addition & 1 deletion generate_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def gen_test_vector(A, u, opts):
elif method == 'threshold':

# find the group sizes
Asum = np.sum(A, axis = 1)
Asum = np.sum(A, axis=1)

print('sum is ' + str(Asum.shape))

Expand Down
Loading

0 comments on commit 760655b

Please sign in to comment.