Skip to content

Commit

Permalink
Merge pull request #31 from scidash/dev
Browse files Browse the repository at this point in the history
Merge from Dev
  • Loading branch information
JustasB committed Jul 4, 2016
2 parents 75880e2 + 20234f0 commit 67a51e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
22 changes: 17 additions & 5 deletions sciunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def __init__(self, name=None, **params):
name = self.__class__.__name__
self.name = name
self.params = params
if params is None:
params = {}

name = None
"""The name of the model. Defaults to the class name."""
Expand Down Expand Up @@ -77,8 +79,9 @@ def __init__(self, observation, name=None, **params):
if self.description is None:
self.description = self.__class__.__doc__

if params:
self.params = params
self.params = params
if params is None:
params = {}

self.observation = observation
self.validate_observation(observation)
Expand Down Expand Up @@ -169,11 +172,12 @@ def _bind_score(self,score,model,observation,prediction):
score.observation = observation
score.related_data = score.related_data.copy() # Don't let scores
# share related_data.
score = self.bind_score(score,model,observation,prediction)
return score

def bind_score(self,score,model,observation,prediction):
"""
For the user to bind addition features to the score.
For the user to bind additional features to the score.
"""
return score

Expand All @@ -199,8 +203,7 @@ def _judge(self, model, verbose=False):
score.__class__.__name__)))
# 5.
score = self._bind_score(score,model,observation,prediction)
score = self.bind_score(score,model,observation,prediction)


return score

def judge(self, model, stop_on_error=True, deep_error=False, verbose=False):
Expand Down Expand Up @@ -433,6 +436,12 @@ def _describe(self):
def describe(self):
print(self._describe())

def raw(self):
string = '%.4g' % self.value
if hasattr(self.value,'magnitude'):
string += ' %s' % str(self.value.units)[4:]
return string

def __str__(self):
return '%s' % self.score

Expand Down Expand Up @@ -587,6 +596,9 @@ def rank(self, test, model):
rank = 1 + vals.index(self[test,model].sort_key)
return rank

def view(self):
return self


class ScoreMatrix(pd.DataFrame):
"""
Expand Down
18 changes: 12 additions & 6 deletions sciunit/scores.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math

import quantities as pq

import sciunit
import sciunit.utils as utils

Expand Down Expand Up @@ -216,8 +218,8 @@ def __init__(self, score, related_data={}):
if not isinstance(score, Exception) and not isinstance(score, float):
raise sciunit.InvalidScoreError("Score must be a float.")
elif score < 0.0 or score > 100.0:
raise sciunit.InvalidScoreError("Score of %f must be in \
range 0.0-100.0" % score)
raise sciunit.InvalidScoreError(("Score of %f must be in "
"range 0.0-100.0" % score))
else:
super(PercentScore,self).__init__(score, related_data=related_data)

Expand All @@ -242,7 +244,9 @@ class FloatScore(sciunit.Score):
"""

def __init__(self, score, related_data={}):
if not isinstance(score, Exception) and not isinstance(score, float):
if not isinstance(score, Exception) and \
not isinstance(score, float) and \
not (isinstance(score, pq.Quantity) and score.size==1):
raise sciunit.InvalidScoreError("Score must be a float.")
else:
super(FloatScore,self).__init__(score, related_data=related_data)
Expand All @@ -257,9 +261,11 @@ def compute_ssd(cls, observation, prediction):
"""
Computes a sum-squared difference from an observation and a prediction.
"""
value = sum((observation - prediction)**2) # The sum of the
# squared differences.
return FloatScore(value)
value = ((observation - prediction)**2).sum() # The sum of the
# squared differences.
score = FloatScore(value)
score.value = value
return score

def __str__(self):
return '%.3g' % self.score
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='sciunit',
version='0.1.5.1',
version='0.1.5.2',
author='Rick Gerkin',
author_email='rgerkin@asu.edu',
packages=['sciunit', 'sciunit.tests'],
Expand Down

0 comments on commit 67a51e1

Please sign in to comment.