Skip to content

Commit

Permalink
tweak how ties are broken, fixes a bug. #2254
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoslicki committed Apr 24, 2024
1 parent cc9aaf7 commit b2cd8e9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
44 changes: 44 additions & 0 deletions code/ARAX/ARAXQuery/ARAX_query.py
Expand Up @@ -1841,6 +1841,50 @@ def main():
"resultify(ignore_edge_direction=true)",
"return(message=true, store=false)"
]}}
elif params.example_number == 2263:
query = {
"message": {
"query_graph": {
"edges": {
"t_edge": {
"attribute_constraints": [],
"knowledge_type": "inferred",
"object": "on",
"predicates": [
"biolink:treats"
],
"qualifier_constraints": [],
"subject": "sn"
}
},
"nodes": {
"on": {
"categories": [
"biolink:Disease"
],
"constraints": [],
"ids": [
"MONDO:0015564"
],
"is_set": False
},
"sn": {
"categories": [
"biolink:ChemicalEntity"
],
"constraints": [],
"is_set": False
}
}
}
},
"submitter": "ARAX GUI",
"stream_progress": True,
"query_options": {
"kp_timeout": "30",
"prune_threshold": "50"
}
}
else:
eprint(f"Invalid test number {params.example_number}. Try 1 through 17")
return
Expand Down
31 changes: 16 additions & 15 deletions code/ARAX/ARAXQuery/ARAX_ranker.py
Expand Up @@ -174,24 +174,23 @@ def _break_ties_and_preserve_order(scores):
# if there are more than 1,000 scores, apply the fix to the first 1000 scores and ignore the rest
if n > 1000:
n = 1000
# set all scores below the 1000th to 0
for i in range(n, len(adjusted_scores)):
adjusted_scores[i] = 0

for i in range(n):
if i > 0 and adjusted_scores[i] >= adjusted_scores[i - 1]:
# Calculate the decrement such that it makes this score slightly less than the previous,
# maintaining the descending order.
decrement = round(adjusted_scores[i - 1] - adjusted_scores[i], 3) - 0.001
adjusted_scores[i] = adjusted_scores[i - 1] - max(decrement, 0.001)
# round all scores to 3 decimal places initially to make adjustment easier
adjusted_scores = [round(score, 3) for score in adjusted_scores]

# Ensure the adjusted score doesn't become lower than the next score
if i < n - 1 and adjusted_scores[i] <= adjusted_scores[i + 1]:
# Adjust the next score to be slightly less than the current score
increment = round(adjusted_scores[i] - adjusted_scores[i + 1], 3) - 0.001
adjusted_scores[i + 1] = adjusted_scores[i] - max(increment, 0.001)
# Adjust scores in descending order to ensure no tie or inversion
for i in range(1, n):
if adjusted_scores[i] >= adjusted_scores[i - 1]:
# Decrease the current score to make it strictly less than the previous score
new_score = adjusted_scores[i - 1] - 0.001
adjusted_scores[i] = max(new_score, 0) # Prevent going below 0

# Final check to ensure all scores are within bounds
adjusted_scores = [round(max(min(score, 1), 0), 3) for score in adjusted_scores]

# round all scores to 3 decimal places
adjusted_scores = [round(score, 3) for score in adjusted_scores]
# make sure no scores are below 0
adjusted_scores = [max(score, 0) for score in adjusted_scores]
return adjusted_scores


Expand Down Expand Up @@ -730,6 +729,8 @@ def aggregate_scores_dmk(self, response):
# break ties and preserve order, round to 3 digits and make sure none are < 0
scores_with_ties = [result.analyses[0].score for result in message.results]
scores_without_ties = _break_ties_and_preserve_order(scores_with_ties)
print(scores_with_ties)
print(scores_without_ties)
# reinsert these scores into the results
for result, score in zip(message.results, scores_without_ties):
result.analyses[0].score = score
Expand Down

0 comments on commit b2cd8e9

Please sign in to comment.