Skip to content

Filtering

FilteringBase

Bases: ABC

Base class for annotation filtering.

Source code in src/annotation/filtering.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class FilteringBase(ABC):
    """
    Base class for annotation filtering.
    """
    @abstractmethod
    def filter(self, distribution: np.array) -> bool:
        """
        Given a numpy array representing a distribution, return a boolean on whether the annotation
        is filtered or not.
        :param distribution:
        :return:
        """
        pass

filter(distribution) abstractmethod

Given a numpy array representing a distribution, return a boolean on whether the annotation is filtered or not.

Parameters:

Name Type Description Default
distribution array
required

Returns:

Type Description
bool
Source code in src/annotation/filtering.py
11
12
13
14
15
16
17
18
19
@abstractmethod
def filter(self, distribution: np.array) -> bool:
    """
    Given a numpy array representing a distribution, return a boolean on whether the annotation
    is filtered or not.
    :param distribution:
    :return:
    """
    pass

JSDFiltering

Bases: FilteringBase

Filters the annotation using the JSD between it and a uniform distribution. If the score is lower than a threshold (noisy annotation), the annotation is filtered.

Source code in src/annotation/filtering.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class JSDFiltering(FilteringBase):
    """
    Filters the annotation using the JSD between it and a uniform distribution.
    If the score is lower than a threshold (noisy annotation), the annotation is filtered.
    """
    def __init__(self, threshold: float):
        """

        :param threshold: JSD threshold used to filter the file
        """
        self.threshold = threshold

    def filter(self, distribution: np.array) -> bool:
        n = len(distribution)
        uniform_vec = np.ones(n) / n

        if np.linalg.norm(distribution) == 0 or jensenshannon(distribution, uniform_vec) <= self.threshold:
            return True

        return False

__init__(threshold)

Parameters:

Name Type Description Default
threshold float

JSD threshold used to filter the file

required
Source code in src/annotation/filtering.py
27
28
29
30
31
32
def __init__(self, threshold: float):
    """

    :param threshold: JSD threshold used to filter the file
    """
    self.threshold = threshold

ThresholdFiltering

Bases: FilteringBase

Filter based on the probability of the most likely class. If is not high enough, then the annotation is filtered.

Source code in src/annotation/filtering.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class ThresholdFiltering(FilteringBase):
    """
    Filter based on the probability of the most likely class.
    If is not high enough, then the annotation is filtered.
    """
    def __init__(self, threshold: float):
        """

        :param threshold: Noise threshold used to filter the file
        """
        self.threshold = threshold

    def filter(self, distribution: np.array) -> bool:
        if np.linalg.norm(distribution) == 0 or np.max(distribution) <= self.threshold:
            return False

        return True

__init__(threshold)

Parameters:

Name Type Description Default
threshold float

Noise threshold used to filter the file

required
Source code in src/annotation/filtering.py
49
50
51
52
53
54
def __init__(self, threshold: float):
    """

    :param threshold: Noise threshold used to filter the file
    """
    self.threshold = threshold