From e05ead4a56d8cd856f416a86e8393df66c45fa52 Mon Sep 17 00:00:00 2001 From: appukuttan-shailesh Date: Fri, 19 Aug 2022 12:19:47 +0200 Subject: [PATCH] Remove duplicate `RelativeDifferenceScore` There seems two be two similar copies of `RelativeDifferenceScore`. Keeping the second instance which seems to be more consistent with other scores. --- sciunit/scores/complete.py | 75 -------------------------------------- 1 file changed, 75 deletions(-) diff --git a/sciunit/scores/complete.py b/sciunit/scores/complete.py index 8d6046c..f3faadf 100644 --- a/sciunit/scores/complete.py +++ b/sciunit/scores/complete.py @@ -244,81 +244,6 @@ def __str__(self): return 'Ratio = %.2f' % self.score -class RelativeDifferenceScore(Score): - """A relative difference between prediction and observation. - - The absolute value of the difference between the prediction and the - observation is divided by a reference value with the same units. This - reference scale should be chosen for each test such that normalization - produces directly comparable scores across tests. For example, if 5 volts - represents a medium size difference for TestA, and 10 seconds represents a - medium size difference for TestB, then 5 volts and 10 seconds should be - used for this reference scale in TestA and TestB, respectively. The - attribute `scale` can be passed to the compute method or set for the whole - class in advance. Otherwise, a scale of 1 (in the units of the - observation and prediction) will be used. - """ - - _allowed_types = (float,) - - _description = ('The relative difference between the prediction and the observation') - - _best = 0.0 # A RelativeDifferenceScore of 0.0 is best - - _worst = np.inf - - scale = None - - def _check_score(self, score): - if score < 0.0: - raise errors.InvalidScoreError(("RelativeDifferenceScore was initialized with " - "a score of %f, but a RelativeDifferenceScore " - "must be non-negative.") % score) - - @classmethod - def compute(cls, observation: Union[dict, float, int, pq.Quantity], - prediction: Union[dict, float, int, pq.Quantity], - key=None, - scale: Union[float, int, pq.Quantity, None] = None) -> 'RelativeDifferenceScore': - """Compute the relative difference between the observation and a prediction. - - Returns: - RelativeDifferenceScore: A relative difference between an observation and a prediction. - """ - assert isinstance(observation, (dict, float, int, pq.Quantity)) - assert isinstance(prediction, (dict, float, int, pq.Quantity)) - - obs, pred = cls.extract_means_or_values(observation, prediction, - key=key) - - scale = scale or cls.scale or (obs/float(obs)) - assert type(obs) is type(scale) - assert type(obs) is type(pred) - if isinstance(obs, pq.Quantity): - assert obs.units == pred.units, \ - "Prediction must have the same units as the observation" - assert obs.units == scale.units, \ - "RelativeDifferenceScore.Scale must have the same units as the observation" - assert scale > 0, \ - "RelativeDifferenceScore.scale must be positive (not %g)" % scale - value = np.abs(pred - obs) / scale - value = utils.assert_dimensionless(value) - return RelativeDifferenceScore(value) - - @property - def norm_score(self) -> float: - """Return 1.0 for a ratio of 0.0, falling to 0.0 for extremely large values. - - Returns: - float: The value of the norm score. - """ - x = self.score - return 1 / (1+x) - - def __str__(self): - return 'Relative Difference = %.2f' % self.score - - class RelativeDifferenceScore(Score): """A relative difference between prediction and observation.