-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9b13e4
commit 8fa4e51
Showing
7 changed files
with
239 additions
and
102 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from hakeem.core.aggregation.base import WeightedAggregator | ||
from hakeem.core.utils.inventory import COLUMNS, DEFAULT_RELIABILITY_BOUNDS | ||
|
||
|
||
class CondorcetAggregator(WeightedAggregator): | ||
def __init__( | ||
self, | ||
lower_reliability_bound: float = DEFAULT_RELIABILITY_BOUNDS.lower, | ||
upper_reliability_bound: float = DEFAULT_RELIABILITY_BOUNDS.upper, | ||
task_column: str = COLUMNS.question, | ||
worker_column: str = COLUMNS.voter, | ||
): | ||
super().__init__(task_column, worker_column) | ||
self.lower_reliability_bound = lower_reliability_bound | ||
self.upper_reliability_bound = upper_reliability_bound | ||
|
||
def compute_weights(self, annotations: pd.DataFrame) -> pd.Series: | ||
vote_size = annotations.sum(axis=1) | ||
reliabilities = (len(annotations.columns) - vote_size - 1) / ( | ||
len(annotations.columns) - 2 | ||
) | ||
reliabilities = reliabilities.clip( | ||
self.lower_reliability_bound, self.upper_reliability_bound | ||
) | ||
weights = np.log(reliabilities / (1 - reliabilities)) | ||
|
||
return weights |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from hakeem.core.aggregation.base import WeightedAggregator | ||
|
||
|
||
class StandardApprovalAggregator(WeightedAggregator): | ||
@staticmethod | ||
def compute_weights(annotations: pd.DataFrame) -> pd.Series: | ||
return pd.Series(1, index=annotations.index) | ||
|
||
|
||
class EuclidAggregator(WeightedAggregator): | ||
@staticmethod | ||
def compute_weights(annotations: pd.DataFrame) -> pd.Series: | ||
vote_size = annotations.sum(axis=1) | ||
return np.sqrt(vote_size + 1) - np.sqrt(vote_size - 1) | ||
|
||
|
||
class JaccardAggregator(WeightedAggregator): | ||
@staticmethod | ||
def compute_weights(annotations: pd.DataFrame) -> pd.Series: | ||
vote_size = annotations.sum(axis=1) | ||
return 1 / vote_size | ||
|
||
|
||
class DiceAggregator(WeightedAggregator): | ||
@staticmethod | ||
def compute_weights(annotations: pd.DataFrame) -> pd.Series: | ||
vote_size = annotations.sum(axis=1) | ||
return 2 / (vote_size + 1) |
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.