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

Sample id fix in GroupAnalysis #384

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Changes from all 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
9 changes: 5 additions & 4 deletions fuse/eval/metrics/metrics_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def get(self, ids: Optional[Sequence[Hashable]] = None) -> Tuple[Dict[str, Any]]

permutation = [original_ids_pos[sample_id] for sample_id in required_ids]

# create the permuted dictionary
data = {}
for name, values in self._collected_data.items():
data[name] = [values[i] for i in permutation]
Expand Down Expand Up @@ -741,15 +740,17 @@ def eval(
raise Exception(
"Error: group analysis is supported only when a unique identifier is specified. Add key 'id' to your data"
)
ids = np.array(ids)
# don't convert to array, this converts the tuple ids to arrays
# ids = np.array(ids)

groups = np.array(data["group"])
unique_groups = set(groups)

group_analysis_results = {}
for group_value in unique_groups:
group_ids = ids[groups == group_value]

# group_ids = ids[groups == group_value]
# use List comprehension instead of boolean filtering to support advance id types such as tuples
group_ids = [ids[i] for i in range(len(ids)) if groups[i] == group_value]
group_analysis_results[str(group_value)] = self._metric.eval(
results, group_ids
)
Expand Down
Loading