Skip to content

Commit

Permalink
Enable Score subclassing (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakesare committed Aug 16, 2021
1 parent 42f7aa1 commit b67c62a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sciunit/scores/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def compute(cls, observation: dict, prediction: dict) -> "BooleanScore":
Returns:
BooleanScore: Boolean score of the observation equals the prediction.
"""
return BooleanScore(observation == prediction)
return cls(observation == prediction)

@property
def norm_score(self) -> float:
Expand Down Expand Up @@ -127,7 +127,7 @@ def compute(cls, observation: dict, prediction: dict) -> "ZScore":
if np.isnan(value):
error = "One of the input values was NaN"
return InsufficientDataScore(error)
score = ZScore(value)
score = cls(value)
return score

@property
Expand Down Expand Up @@ -180,7 +180,7 @@ def compute(cls, observation: dict, prediction: dict) -> "CohenDScore":
s = (p_std ** 2 + o_std ** 2) ** 0.5
value = (p_mean - o_mean) / s
value = utils.assert_dimensionless(value)
return CohenDScore(value)
return cls(value)

def __str__(self) -> str:
return "D = %.2f" % self.score
Expand Down Expand Up @@ -227,7 +227,7 @@ def compute(cls, observation: dict, prediction: dict, key=None) -> "RatioScore":
obs, pred = cls.extract_means_or_values(observation, prediction, key=key)
value = pred / obs
value = utils.assert_dimensionless(value)
return RatioScore(value)
return cls(value)

@property
def norm_score(self) -> float:
Expand Down Expand Up @@ -313,7 +313,7 @@ def compute(
)
value = np.abs(pred - obs) / scale
value = utils.assert_dimensionless(value)
return RelativeDifferenceScore(value)
return cls(value)

@property
def norm_score(self) -> float:
Expand Down Expand Up @@ -405,7 +405,7 @@ def compute_ssd(cls, observation: dict, prediction: dict) -> Score:
"""
# The sum of the squared differences.
value = ((observation - prediction) ** 2).sum()
score = FloatScore(value)
score = cls(value)
return score

def __str__(self) -> str:
Expand Down Expand Up @@ -457,7 +457,7 @@ def _check_score(self, score):
@classmethod
def compute(cls, observation, prediction):
"""Compute whether the observation equals the prediction."""
return CorrelationScore(float(np.corrcoef(observation, prediction)[0, 1]))
return cls(float(np.corrcoef(observation, prediction)[0, 1]))

def __str__(self):
return "%.3g" % self.score

0 comments on commit b67c62a

Please sign in to comment.