-
-
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.
- Loading branch information
1 parent
cd7e9c3
commit 67e21b4
Showing
43 changed files
with
3,692 additions
and
5,300 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
40 changes: 16 additions & 24 deletions
40
solidago/src/solidago/generative_model/assessment/base.py
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,32 +1,24 @@ | ||
import numpy as np | ||
|
||
from solidago.state import * | ||
from solidago.pipeline import StateFunction | ||
|
||
|
||
class AssessmentGenerator: | ||
def __call__(self, | ||
users: Users, | ||
entities: Entities, | ||
criteria: Criteria, | ||
made_public: MadePublic, | ||
assessments: Assessments | ||
) -> Assessments: | ||
class AssessmentGenerator(StateFunction): | ||
def __call__(self, state: State) -> None: | ||
""" Fills in the assessments """ | ||
for (username, entity_name, criterion_name), _ in assessments: | ||
user = users.get(username) | ||
entity = entities.get(entity_name) | ||
criterion = criteria.get(criterion_name) | ||
public=made_public[user, entity] | ||
a_min, a_max, a = self.sample(user, entity, criterion, public) | ||
assessments[user, entity, criterion] |= { "assessment_min": a_min, "assessment_max": a_max, "assessment": a } | ||
return assessments | ||
for (username, entity_name), assessment_list in state.assessments: | ||
for index, assessment in enumerate(assessment_list): | ||
user = state.users.get(username) | ||
entity = state.entities.get(entity_name) | ||
public = state.made_public[user, entity] | ||
a, a_min, a_max = self.sample(state, assessment, user, entity, public) | ||
state.assessments[user, entity][index] |= { | ||
"assessment": a, | ||
"assessment_min": a_min, | ||
"assessment_max": a_max, | ||
} | ||
|
||
def sample(self, user: User, entity: Entity, criterion: Criterion, public: bool) -> tuple[float, float, float]: | ||
def sample(self, state: State, assessment: Assessment, user: User, entity: Entity, public: bool) -> tuple[float, float, float]: | ||
""" Returns assessment min, max and value """ | ||
return 0, 1, np.random.random() | ||
|
||
def __str__(self): | ||
return type(self).__name__ | ||
|
||
def to_json(self): | ||
return (type(self).__name__, ) | ||
return np.random.random(), 0, 1 |
12 changes: 3 additions & 9 deletions
12
solidago/src/solidago/generative_model/assessment/normal.py
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,17 +1,11 @@ | ||
from numpy import sqrt | ||
from numpy.random import normal | ||
|
||
from solidago.state import VectorUser, VectorEntity, Criterion | ||
from solidago.state import * | ||
from .base import AssessmentGenerator | ||
|
||
|
||
class NormalAssessmentGenerator(AssessmentGenerator): | ||
def sample(self, user: VectorUser, entity: VectorEntity, criterion: Criterion, public: bool) -> tuple[float, float, float]: | ||
def sample(self, state: State, assessment: Assessment, user: VectorUser, entity: VectorEntity, public: bool) -> tuple[float, float, float]: | ||
score = user.vector @ entity.vector / sqrt(user.vector.size) | ||
return -float("inf"), float("inf"), score + normal() | ||
|
||
def __str__(self): | ||
return type(self).__name__ | ||
|
||
def to_json(self): | ||
return (type(self).__name__, ) | ||
return score + normal(), -float("inf"), float("inf") |
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,17 +1,18 @@ | ||
from solidago.state import Criterion, Criteria | ||
from solidago.state import * | ||
|
||
|
||
class CriterionGenerator: | ||
def __call__(self, n_criteria: int) -> Criteria: | ||
return Criteria([ self.sample(criterion_name) for criterion_name in range(n_criteria) ]) | ||
criteria_cls: type=Criteria | ||
|
||
def sample(self, criterion_name): | ||
return Criterion(name=criterion_name) | ||
|
||
def __str__(self): | ||
return type(self).__name__ | ||
def __init__(self, n_criteria: int=0): | ||
assert isinstance(n_criteria, int) and n_criteria >= 0 | ||
self.n_criteria = n_criteria | ||
|
||
def to_json(self): | ||
return (type(self).__name__, ) | ||
|
||
|
||
def __call__(self, state: State) -> None: | ||
if n_criteria == 0: | ||
return None | ||
state.criteria = self.criteria_cls([ self.sample(c) for c in range(n_criteria) ]) | ||
|
||
def sample(self, criterion): | ||
return self.criteria_cls.series_cls(name=criterion) | ||
|
Oops, something went wrong.