Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hoomanzabeti committed Apr 16, 2021
1 parent c67953f commit fa4a6b9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ design:
'mode': 'list'
'values': [16]
'save_to_file': True
s: 50
'individual_status':
#input: 'individual_status.csv'
params:
Expand Down
2 changes: 1 addition & 1 deletion generate_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def gen_measurement_matrix(opts, seed=0, N=1000, m=100, group_size=4, max_tests_
# out-degree corresponds to the group tests, here we set the last m
# entries of the out-degree sequence to specify the groups
outdeg = np.zeros(N + m)
outdeg[N:N + m] = group_size
outdeg[N:(N + m)] = group_size

# keep track of vertex types for final graph vertex coloring
vtypes = np.zeros(N + m)
Expand Down
1 change: 0 additions & 1 deletion group_testing_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def fit(self, A, label):
p += lpSum([w[i] for i in range(n)]) >= self.defective_num_lower_bound
solver = pl.get_solver(self.solver_name, **self.solver_options)
p.solve(solver)
# TODO: Check this
if not self.lp_relaxation:
p.roundSolution()
# ----------------
Expand Down
1 change: 1 addition & 0 deletions group_testing_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def decoder_evaluation(w_true, sln, ev_metric='balanced_accuracy'):


if __name__ == '__main__':
# TODO: update this part
current_directory = os.getcwd()
file_path = os.path.join(current_directory, r'problem.mps')
u = [1, 0, 0, 1, 0, 1]
Expand Down
32 changes: 16 additions & 16 deletions group_testing_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def multi_process_group_testing(design_param, decoder_param):
try:
single_run_start = time.time()
# generate the measurement matrix from the given options

if design_param['generate_groups'] == 'alternative_module':
generate_groups_alt_module = __import__(design_param['groups_alternative_module'][0], globals(), locals(),
[], 0)
Expand All @@ -44,8 +43,7 @@ def multi_process_group_testing(design_param, decoder_param):
design_param['m'], design_param['N'] = A.shape
design_param['group_size'] = int(max(A.sum(axis=1)))
design_param['max_tests_per_individual'] = int(max(A.sum(axis=0)))
# elif design_param['generate_groups'] == 'generate':
else:
elif design_param['generate_groups'] == 'generate':
A = gen_measurement_matrix(opts=design_param)
# generate the infected status of the individuals
if design_param['generate_individual_status'] == 'input':
Expand All @@ -59,7 +57,7 @@ def multi_process_group_testing(design_param, decoder_param):
individual_status_alt_function = getattr(individual_status_alt_module,
design_param['individual_status_alternative_module'][1])
u = individual_status_alt_function(opts=design_param)
else:
elif design_param['generate_individual_status'] == 'generate':
u = gen_status_vector(design_param)
u = [i[0] for i in u]
# generate the data corresponding to the group tests
Expand All @@ -73,20 +71,21 @@ def multi_process_group_testing(design_param, decoder_param):
test_results_alt_function = getattr(test_results_alt_module,
design_param['test_results_alternative_module'][1])
b = test_results_alt_function(opts=design_param)
else:
elif design_param['generate_test_results'] == 'generate':
b = gen_test_vector(A, u, design_param)
if 'save_to_file' in design_param.keys() and design_param['save_to_file']:
design_path = inner_path_generator(result_path, 'Design')
design_matrix_path = inner_path_generator(design_path, 'Design_Matrix')
pd.DataFrame(A).to_csv(report_file_path(design_matrix_path, 'design_matrix', design_param),
header=None, index=None)
individual_status_path = inner_path_generator(design_path,'Individual_Status')
pd.DataFrame(u).to_csv(report_file_path(individual_status_path, 'individual_status', design_param),
header=None, index=None)
test_results_path = inner_path_generator(design_path,'Test_Results')
pd.DataFrame(b).to_csv(report_file_path(test_results_path, 'test_results', design_param),
header=None, index=None)

if design_param['generate_individual_status']:
individual_status_path = inner_path_generator(design_path,'Individual_Status')
pd.DataFrame(u).to_csv(report_file_path(individual_status_path, 'individual_status', design_param),
header=None, index=None)
if design_param['generate_test_results']:
test_results_path = inner_path_generator(design_path,'Test_Results')
pd.DataFrame(b).to_csv(report_file_path(test_results_path, 'test_results', design_param),
header=None, index=None)
except Exception as design_error:
print(design_error)
decoder_param['decoding']=False
Expand Down Expand Up @@ -145,7 +144,7 @@ def multi_process_group_testing(design_param, decoder_param):
ev_result['time'] = round(single_run_end - single_run_start, 2)
ev_result.update({key: design_param[key] for key in ['N', 'm', 's', 'group_size', 'seed',
'max_tests_per_individual']})
return ev_result
return ev_result
except Exception as e:
print(e)
else:
Expand All @@ -168,13 +167,14 @@ def multi_process_group_testing(design_param, decoder_param):
pool.join()
else:
results = [multi_process_group_testing(i[0], i[1]) for i in itertools.product(design_param, decoder_param)]
column_names = [i for i in ['N', 'm', 's', 'group_size', 'seed', 'max_tests_per_individual', 'tn', 'fp', 'fn', 'tp',
decoder_param[0]['eval_metric'], 'Status', 'solver_time', 'time']]

# Saving files
pd.DataFrame(design_param).to_csv(os.path.join(result_path, 'opts.csv'))
#print("---------------------->", results)
if all(v is not None for v in results):
pd.DataFrame(results).reindex(columns=column_names).to_csv(os.path.join(result_path, 'CM.csv'))
column_names = ['N', 'm', 's', 'group_size', 'seed', 'max_tests_per_individual', 'tn', 'fp', 'fn', 'tp',
decoder_param[0]['eval_metric'], 'Status', 'solver_time', 'time']
pd.DataFrame(results).reindex(columns=column_names).to_csv(os.path.join(result_path, 'ConfusionMatrix.csv'))

end_time = time.time()
print(end_time - start_time)
2 changes: 1 addition & 1 deletion temp_for_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml
from utils import config_decoder

path = '/Users/hoomanzabeti/Desktop/GTResults/Noisy/Threshold/threshold_32'
path = '/Users/hoomanzabeti/Desktop/GTResults/Noisy/Permutation_updated'
alist = [i for i in os.walk(path)]
#dir_list = [i for i in alist[0][1] if i.startswith('Jan_')]
dir_list = [i for i in alist[0][1]]
Expand Down

0 comments on commit fa4a6b9

Please sign in to comment.