Skip to content

Commit

Permalink
fix some returned scores
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Aug 2, 2024
1 parent 710e0dc commit 2510a98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/inat_inferrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ def combine_results(self, raw_vision_scores, raw_geo_scores, filter_taxon, debug
# multipliedby the normalized geo score
leaf_scores["combined_score"] = leaf_scores["normalized_vision_score"] * \
leaf_scores["normalized_geo_score"]

sum_of_root_node_aggregated_combined_scores = leaf_scores["combined_score"].sum()
if sum_of_root_node_aggregated_combined_scores > 0:
leaf_scores["normalized_combined_score"] = leaf_scores[
"combined_score"] / sum_of_root_node_aggregated_combined_scores
else:
leaf_scores["normalized_combined_score"] = 0

if debug:
print("Score Combining Time: %0.2fms" % ((time.time() - start_time) * 1000.))
leaf_scores.reset_index(drop=True, inplace=True)
Expand Down
27 changes: 19 additions & 8 deletions lib/inat_vision_api_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def object_response(leaf_scores, inferrer):
common_ancestor = inferrer.common_ancestor_from_leaf_scores(leaf_scores, debug=True)
if common_ancestor is not None:
common_ancestor_frame = pd.DataFrame([common_ancestor])
common_ancestor_frame = InatVisionAPIResponses.update_aggregated_scores_scaling(
common_ancestor_frame = InatVisionAPIResponses.update_common_ancestor_scores_scaling(
common_ancestor_frame
)
common_ancestor = InatVisionAPIResponses.array_response_common_ancestor_columns(
Expand Down Expand Up @@ -135,7 +135,7 @@ def limit_leaf_scores_for_response(leaf_scores):
@staticmethod
def update_leaf_scores_scaling(leaf_scores):
score_columns = [
"combined_score",
"normalized_combined_score",
"geo_score",
"normalized_vision_score",
"geo_threshold"
Expand All @@ -145,6 +145,16 @@ def update_leaf_scores_scaling(leaf_scores):
].multiply(100, axis="index")
return leaf_scores

@staticmethod
def update_common_ancestor_scores_scaling(aggregated_scores):
score_columns = [
"normalized_aggregated_combined_score"
]
aggregated_scores[score_columns] = aggregated_scores[
score_columns
].multiply(100, axis="index")
return aggregated_scores

@staticmethod
def update_aggregated_scores_scaling(aggregated_scores):
score_columns = [
Expand All @@ -162,7 +172,7 @@ def update_aggregated_scores_scaling(aggregated_scores):
@staticmethod
def array_response_columns(leaf_scores):
columns_to_return = [
"combined_score",
"normalized_combined_score",
"geo_score",
"taxon_id",
"name",
Expand All @@ -171,25 +181,26 @@ def array_response_columns(leaf_scores):
]
column_mapping = {
"taxon_id": "id",
"normalized_vision_score": "vision_score"
"normalized_vision_score": "vision_score",
"normalized_combined_score": "combined_score"
}
return leaf_scores[columns_to_return].rename(columns=column_mapping)

@staticmethod
def array_response_common_ancestor_columns(common_ancestor_dataframe):
columns_to_return = [
"aggregated_combined_score",
"normalized_aggregated_combined_score",
"aggregated_geo_score",
"taxon_id",
"name",
"normalized_aggregated_vision_score",
"aggregated_vision_score",
"aggregated_geo_threshold"
]
column_mapping = {
"aggregated_combined_score": "combined_score",
"normalized_aggregated_combined_score": "combined_score",
"aggregated_geo_score": "geo_score",
"taxon_id": "id",
"normalized_aggregated_vision_score": "vision_score",
"aggregated_vision_score": "vision_score",
"aggregated_geo_threshold": "geo_threshold"
}
return common_ancestor_dataframe[columns_to_return].rename(columns=column_mapping)
Expand Down

0 comments on commit 2510a98

Please sign in to comment.