Skip to content

Commit

Permalink
Model fit information in repr output
Browse files Browse the repository at this point in the history
  • Loading branch information
mwshinn committed Mar 5, 2020
1 parent d4e903d commit ded491f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ddm/fitresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def __init__(self, fitting_method, method, loss, value, **kwargs):
self.loss = loss
self.properties = kwargs
self.fitting_method = fitting_method
def __repr__(self):
components = ["fitting_method=%s" % repr(self.fitting_method),
"method=%s" % repr(self.method),
"loss=%s" % repr(self.loss),
"value=%s" % repr(self.val)]
components += ["%s=%s" % (k,repr(v)) for k,v in self.properties.items()]
return type(self).__name__ + "(" + ", ".join(components) + ")"
@accepts(Self)
@returns(ExtendedReal)
def value(self):
Expand All @@ -72,6 +79,8 @@ def value(self):

class FitResultEmpty(FitResult):
"""A default Fit object before a model has been fit."""
def __repr__(self):
return type(self).__name__ + "()"
def __init__(self):
self.val = None
self.properties = {}
Expand Down
2 changes: 2 additions & 0 deletions ddm/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ def solve_all_conditions(model, sample, conditions={}, method=None):
meth = model.solve_numerical_implicit
elif method == "explicit":
meth = model.solve_numerical_explicit
else:
raise ValueError("Invalid method "+method)

cache = {}
if _parallel_pool is None: # No parallelization
Expand Down
5 changes: 5 additions & 0 deletions ddm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def __repr__(self, pretty=False):
params += ",\n" + " "*(len(type(self).__name__)+1)
else:
params += ", "
if not isinstance(self.fitresult, FitResultEmpty):
if pretty:
params += ",\n " + repr(self.fitresult)
else:
params += ", " + repr(self.fitresult)
return type(self).__name__ + "(" + params + ")"
def __str__(self):
return self.__repr__(pretty=True)
Expand Down

0 comments on commit ded491f

Please sign in to comment.