-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized the imports to make it cleaner
- Loading branch information
1 parent
4457a49
commit a2b75fc
Showing
24 changed files
with
372 additions
and
327 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
"""Solidago library, robust and secure algorithms for the Tournesol platform""" | ||
|
||
from .__version__ import __version__ | ||
|
||
from .privacy_settings import PrivacySettings | ||
from .judgments import Judgments | ||
from .scoring_model import ScoringModel |
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,40 +1,8 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
import pandas as pd | ||
|
||
from solidago.voting_rights import VotingRights | ||
from solidago.scoring_model import ScoringModel | ||
|
||
|
||
class Aggregation: | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
voting_rights: VotingRights, | ||
user_models: dict[int, ScoringModel], | ||
users: pd.DataFrame, | ||
entities: pd.DataFrame | ||
) -> tuple[dict[int, ScoringModel], ScoringModel]: | ||
""" Returns scaled user models | ||
Parameters | ||
---------- | ||
voting_rights: VotingRights | ||
voting_rights[user, entity]: float | ||
user_models: dict[int, ScoringModel] | ||
user_models[user] is user's scoring model | ||
users: DataFrame with columns | ||
* user_id (int, index) | ||
* trust_score (float) | ||
entities: DataFrame with columns | ||
* entity_id (int, ind) | ||
Returns | ||
------- | ||
updated_user_models[user]: ScoringModel | ||
Returns a scaled user model | ||
global_model: ScoringModel | ||
Returns a global scoring model | ||
""" | ||
raise NotImplementedError | ||
|
||
""" Step 5 of the pipeline. | ||
Aggregation combines the different user models to construct a global model. | ||
The aggregation may also adjust the user models to the learned global model. | ||
""" | ||
|
||
from .base import Aggregation | ||
from .standardized_qrmed import QuantileStandardizedQrMedian |
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,40 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
import pandas as pd | ||
|
||
from solidago.voting_rights import VotingRights | ||
from solidago.scoring_model import ScoringModel | ||
|
||
|
||
class Aggregation: | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
voting_rights: VotingRights, | ||
user_models: dict[int, ScoringModel], | ||
users: pd.DataFrame, | ||
entities: pd.DataFrame | ||
) -> tuple[dict[int, ScoringModel], ScoringModel]: | ||
""" Returns scaled user models | ||
Parameters | ||
---------- | ||
voting_rights: VotingRights | ||
voting_rights[user, entity]: float | ||
user_models: dict[int, ScoringModel] | ||
user_models[user] is user's scoring model | ||
users: DataFrame with columns | ||
* user_id (int, index) | ||
* trust_score (float) | ||
entities: DataFrame with columns | ||
* entity_id (int, ind) | ||
Returns | ||
------- | ||
updated_user_models[user]: ScoringModel | ||
Returns a scaled user model | ||
global_model: ScoringModel | ||
Returns a global scoring model | ||
""" | ||
raise NotImplementedError | ||
|
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
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,25 +1,8 @@ | ||
from abc import ABC, abstractmethod | ||
""" Step 6 of the pipeline. | ||
Post-process modifies the user and global models, typically with the goal | ||
of yielding more human-readible scores. | ||
""" | ||
|
||
from solidago.scoring_model import ScoringModel | ||
|
||
class PostProcess(ABC): | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
user_models: dict[int, ScoringModel], | ||
global_model: ScoringModel | ||
) -> tuple[dict[int, ScoringModel], ScoringModel]: | ||
""" Post-processes user models and global models, | ||
typically to yield human-readible scores | ||
Parameters | ||
---------- | ||
user_models: user_model[user] should be a ScoringModel to post-process | ||
global_model: ScoringModel to post-process | ||
Returns | ||
------- | ||
user_models: post-processed user models | ||
global_model: post-processed global model | ||
""" | ||
raise NotImplementedError | ||
from .base import PostProcess | ||
from .squash import Squash |
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,25 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from solidago.scoring_model import ScoringModel | ||
|
||
class PostProcess(ABC): | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
user_models: dict[int, ScoringModel], | ||
global_model: ScoringModel | ||
) -> tuple[dict[int, ScoringModel], ScoringModel]: | ||
""" Post-processes user models and global models, | ||
typically to yield human-readible scores | ||
Parameters | ||
---------- | ||
user_models: user_model[user] should be a ScoringModel to post-process | ||
global_model: ScoringModel to post-process | ||
Returns | ||
------- | ||
user_models: post-processed user models | ||
global_model: post-processed global model | ||
""" | ||
raise NotImplementedError |
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,55 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Optional | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
from solidago.scoring_model import ScoringModel | ||
|
||
|
||
class PreferenceLearning(ABC): | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
user_judgments: dict[str, pd.DataFrame], | ||
entities: pd.DataFrame | ||
) -> ScoringModel: | ||
""" Learns a scoring model, given user judgments of entities | ||
Parameters | ||
---------- | ||
user_judgments: dict[str, pd.DataFrame] | ||
May contain different forms of judgments, | ||
but most likely will contain "comparisons" and/or "assessments" | ||
entities: DataFrame with columns | ||
* entity_id: int, index | ||
* May contain others, such as vector representation | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class ComparisonBasedPreferenceLearning(PreferenceLearning): | ||
@abstractmethod | ||
def comparison_learning(self, comparisons, entities) -> ScoringModel: | ||
""" Learns only based on comparisons | ||
Parameters | ||
---------- | ||
comparisons: DataFrame with columns | ||
* entity_a: int | ||
* entity_b: int | ||
* score: float | ||
entities: DataFrame with columns | ||
* entity_id: int, index | ||
* May contain others, such as vector representation | ||
""" | ||
raise NotImplementedError | ||
|
||
def __call__( | ||
self, | ||
user_judgments: dict[str, pd.DataFrame], | ||
entities: pd.DataFrame | ||
) -> ScoringModel: | ||
return self.comparison_learning(user_judgments["comparisons"], entities) | ||
|
||
""" Step 3 of the pipeline. | ||
Preference learning infers, for each user and based on their data, | ||
a model of the user's preferences. | ||
This corresponds to the idea of "algorithmic representatives", | ||
which will participate in the digital democracy | ||
to remedy users' lack of activity and reactivity. | ||
""" | ||
|
||
from .base import PreferenceLearning | ||
from .generalized_bradley_terry import UniformGBT |
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,55 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Optional | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
from solidago.scoring_model import ScoringModel | ||
|
||
|
||
class PreferenceLearning(ABC): | ||
@abstractmethod | ||
def __call__( | ||
self, | ||
user_judgments: dict[str, pd.DataFrame], | ||
entities: pd.DataFrame | ||
) -> ScoringModel: | ||
""" Learns a scoring model, given user judgments of entities | ||
Parameters | ||
---------- | ||
user_judgments: dict[str, pd.DataFrame] | ||
May contain different forms of judgments, | ||
but most likely will contain "comparisons" and/or "assessments" | ||
entities: DataFrame with columns | ||
* entity_id: int, index | ||
* May contain others, such as vector representation | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class ComparisonBasedPreferenceLearning(PreferenceLearning): | ||
@abstractmethod | ||
def comparison_learning(self, comparisons, entities) -> ScoringModel: | ||
""" Learns only based on comparisons | ||
Parameters | ||
---------- | ||
comparisons: DataFrame with columns | ||
* entity_a: int | ||
* entity_b: int | ||
* score: float | ||
entities: DataFrame with columns | ||
* entity_id: int, index | ||
* May contain others, such as vector representation | ||
""" | ||
raise NotImplementedError | ||
|
||
def __call__( | ||
self, | ||
user_judgments: dict[str, pd.DataFrame], | ||
entities: pd.DataFrame | ||
) -> ScoringModel: | ||
return self.comparison_learning(user_judgments["comparisons"], entities) | ||
|
||
|
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.