Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute ranking for joined features in modelspec #59

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion outrank/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def main():
parser.add_argument(
'--reference_model_JSON',
type=str,
default='./ranking_outputs/reference_model.json',
default='',
help='Reference model JSON',
)

Expand Down
16 changes: 10 additions & 6 deletions outrank/core_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,15 @@ def compute_combined_features(
join_string = ' AND_REL ' if is_3mr else ' AND '
interaction_order = 2 if is_3mr else args.interaction_order

full_combination_space = list(
itertools.combinations(all_columns, interaction_order),
)

if args.combination_number_upper_bound:
if args.reference_model_JSON != "":
miha-jenko marked this conversation as resolved.
Show resolved Hide resolved
combined_features = extract_features_from_reference_JSON(args.reference_model_JSON, combined_features_only = True)
full_combination_space = [combination.split(',') for combination in combined_features]
else:
full_combination_space = list(
itertools.combinations(all_columns, interaction_order),
)

if args.combination_number_upper_bound and args.reference_model_JSON != "":
random.shuffle(full_combination_space)
full_combination_space = full_combination_space[
: args.combination_number_upper_bound
Expand Down Expand Up @@ -517,7 +521,7 @@ def compute_batch_ranking(
input_dataframe, logger, args, pbar,
)

if args.interaction_order > 1:
if args.interaction_order > 1 or args.reference_model_JSON:
pbar.set_description('Constructing new features')
input_dataframe = compute_combined_features(
input_dataframe, logger, args, pbar,
Expand Down
7 changes: 5 additions & 2 deletions outrank/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def parse_csv_raw(data_path) -> DatasetInformationStorage:
)


def extract_features_from_reference_JSON(json_path: str) -> set[Any]:
def extract_features_from_reference_JSON(json_path: str, combined_features_only = False) -> set[Any]:
"""Given a model's JSON, extract unique features"""

with open(json_path) as jp:
Expand All @@ -402,7 +402,10 @@ def extract_features_from_reference_JSON(json_path: str) -> set[Any]:
unique_features = set()
feature_space = content['desc'].get('features', [])
fields_space = content['desc'].get('fields', [])
joint_space = feature_space + fields_space
joint_space = feature_space + fields_space

if combined_features_only:
return set([feature for feature in feature_space if len(feature.split(","))>1])
miha-jenko marked this conversation as resolved.
Show resolved Hide resolved

for feature_tuple in joint_space:
for individual_feature in feature_tuple.split(','):
Expand Down
1 change: 1 addition & 0 deletions tests/ranking_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class args:
combination_number_upper_bound: int = 1024
disable_tqdm: bool = False
mi_stratified_sampling_ratio: float = 1.0
reference_model_JSON: str = ""


class CompareStrategiesTest(unittest.TestCase):
Expand Down