Skip to content

Commit

Permalink
fix global variable creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmramor committed Mar 28, 2024
1 parent bfbe096 commit 75d37d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
26 changes: 11 additions & 15 deletions outrank/core_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
def prior_combinations_sample(combinations: list[tuple[Any, ...]], args: Any) -> list[tuple[Any, ...]]:
"""Make sure only relevant subspace of combinations is selected based on prior counts"""

if len(GLOBAL_PRIOR_COMB_COUNTS) == 0:
for combination in combinations:
GLOBAL_PRIOR_COMB_COUNTS[combination] += 1
missing_combinations = set(set(combinations)).difference(GLOBAL_PRIOR_COMB_COUNTS.keys())
if len(missing_combinations) > 0:
for combination in missing_combinations:
GLOBAL_PRIOR_COMB_COUNTS[combination] = 0
tmp = combinations[:args.combination_number_upper_bound]
else:
tmp = list(x[0] for x in sorted(GLOBAL_PRIOR_COMB_COUNTS.items(), key=lambda x:x[1], reverse=False))[:args.combination_number_upper_bound]
Expand Down Expand Up @@ -121,16 +122,9 @@ def mixed_rank_graph(
if is_prior_heuristic(args):
reference_model_features = [(" AND ").join(tuple(sorted(item.split(",")))) for item in extract_features_from_reference_JSON(args.reference_model_JSON, all_features=True)]
combinations = [comb for comb in combinations if comb[0] not in reference_model_features and comb[1] not in reference_model_features]
print(combinations)
print("\n\n")

combinations = prior_combinations_sample(combinations, args)
print(GLOBAL_PRIOR_COMB_COUNTS)
print(combinations)
print("\n\n")
random.shuffle(combinations)
print(combinations)
print("\n\n")

if args.heuristic == 'Constant':
final_constant_imp = []
Expand Down Expand Up @@ -206,17 +200,19 @@ def compute_combined_features(
model_combinations = []
full_combination_space = []

if args.reference_model_JSON != '':
model_combinations = extract_features_from_reference_JSON(args.reference_model_JSON, combined_features_only = True)
model_combinations = [tuple(sorted(combination.split(','))) for combination in model_combinations]
full_combination_space = model_combinations

if args.interaction_order > 1:
full_combination_space = list(
itertools.combinations(all_columns, interaction_order),
)
full_combination_space = prior_combinations_sample(full_combination_space, args)

if args.reference_model_JSON != '':
model_combinations = extract_features_from_reference_JSON(args.reference_model_JSON, combined_features_only = True)
model_combinations = [tuple(sorted(combination.split(','))) for combination in model_combinations]
if not is_prior_heuristic(args):
full_combination_space = model_combinations

if is_prior_heuristic(args):
full_combination_space = full_combination_space + [tuple for tuple in model_combinations if tuple not in full_combination_space]

Expand All @@ -243,7 +239,7 @@ def compute_combined_features(
pbar.set_description('Concatenating into final frame ..')
input_dataframe = pd.concat([input_dataframe, tmp_df], axis=1)
del tmp_df

return input_dataframe


Expand Down
4 changes: 2 additions & 2 deletions outrank/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ def summarize_rare_counts(
)


def is_prior_heuristic(args: Any):
if "-prior" in args.heuristic and args.reference_model_JSON and args.reference_model_JSON != "":
def is_prior_heuristic(args: Any) -> bool:
if "-prior" in args.heuristic and args.reference_model_JSON:
return True
return False

7 changes: 4 additions & 3 deletions outrank/task_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def outrank_task_result_summary(args):

min_score = np.min(final_df[f'Score {args.heuristic}'].values)
max_score = np.max(final_df[f'Score {args.heuristic}'].values)
final_df[f'Score {args.heuristic}'] = (
final_df[f'Score {args.heuristic}'] - min_score
) / (max_score - min_score)
if "MI" in args.heuristic:
final_df[f'Score {args.heuristic}'] = (
final_df[f'Score {args.heuristic}'] - min_score
) / (max_score - min_score)
logging.info(f'Storing summary files to {args.output_folder}')
pd.set_option('display.max_rows', None, 'display.max_columns', None)
singles_path = os.path.join(args.output_folder, 'feature_singles.tsv')
Expand Down

0 comments on commit 75d37d2

Please sign in to comment.