-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Update doc strings (#109)
Update all doc strings
1 parent
b29b464
commit 3b514cf
Showing
69 changed files
with
3,435 additions
and
2,095 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,55 @@ | ||
from typing import Optional, Sequence, Tuple | ||
|
||
import numpy as np | ||
|
||
from .util import compute_ignore_mask, contigency_table | ||
from .rand_index import compute_rand_scores | ||
from .variation_of_information import compute_vi_scores | ||
|
||
|
||
def cremi_score(segmentation, groundtruth, ignore_seg=None, ignore_gt=None): | ||
""" Computes cremi scores between two segmentations | ||
def cremi_score( | ||
segmentation: np.ndarray, | ||
groundtruth: np.ndarray, | ||
ignore_seg: Optional[Sequence[int]] = None, | ||
ignore_gt: Optional[Sequence[int]] = None, | ||
) -> Tuple[float, float, float, float]: | ||
"""Compute cremi score of two segmentations. | ||
This score was used as the evaluation metric for the CREMI challenge. | ||
It is defined as the geometric mean of the variation of information and the adapted rand score. | ||
Args: | ||
segmentation: Candidate segmentation to evaluate. | ||
groundtruth: Groundtruth segmentation. | ||
ignore_seg: Ignore ids for the segmentation. | ||
ignore_gt: Ignore ids for the groundtruth. | ||
Arguments: | ||
segmentation [np.ndarray] - candidate segmentation to evaluate | ||
groundtruth [np.ndarray] - groundtruth | ||
ignore_seg [listlike] - ignore ids for segmentation (default: None) | ||
ignore_gt [listlike] - ignore ids for groundtruth (default: None) | ||
Retuns: | ||
float - vi-split | ||
float - vi-merge | ||
float - adapted rand error | ||
float - cremi score | ||
The variation of information split score. | ||
The variation of information merge score. | ||
The adapted rand error. | ||
The cremi score. | ||
""" | ||
|
||
ignore_mask = compute_ignore_mask(segmentation, groundtruth, | ||
ignore_seg, ignore_gt) | ||
ignore_mask = compute_ignore_mask(segmentation, groundtruth, ignore_seg, ignore_gt) | ||
if ignore_mask is not None: | ||
segmentation = segmentation[ignore_mask] | ||
groundtruth = groundtruth[ignore_mask] | ||
else: | ||
# if we don't have a mask, we need to make sure the segmentations are | ||
segmentation = segmentation.ravel() | ||
groundtruth = groundtruth.ravel() | ||
|
||
# compute ids, counts and overlaps making up the contigency table | ||
# Compute ids, counts and overlaps making up the contigency table. | ||
a_dict, b_dict, p_ids, p_counts = contigency_table(groundtruth, segmentation) | ||
n_points = segmentation.size | ||
|
||
# compute vi scores | ||
vis, vim = compute_vi_scores(a_dict, b_dict, p_ids, p_counts, n_points, | ||
use_log2=True) | ||
# Compute VI scores. | ||
vis, vim = compute_vi_scores(a_dict, b_dict, p_ids, p_counts, n_points, use_log2=True) | ||
|
||
# compute and rand scores | ||
# Compute rand score. | ||
ari, _ = compute_rand_scores(a_dict, b_dict, p_counts, n_points) | ||
|
||
# compute the cremi score = geometric mean of voi and ari | ||
# Compute the cremi score = geometric mean of voi and ari. | ||
cs = np.sqrt(ari * (vis + vim)) | ||
|
||
return vis, vim, ari, cs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.