Skip to content

Commit

Permalink
Rename suppress_output -> verbose, and verbose -> renorm_warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mwshinn committed May 28, 2020
1 parent 9e114c9 commit 9f107ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions ddm/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def fit_model(sample,
method=None,
overlay=OverlayNone(),
lossfunction=LossLikelihood,
suppress_output=False,
verbose=True,
name="fit_model",
verify=False):
"""Fit a model to reaction time data.
Expand Down Expand Up @@ -146,8 +146,8 @@ def fit_model(sample,
may prevent crashes. If verification is already disabled, this
does not re-enable it.
`suppress_output` disables out-of-boundaries warnings and suppresses
printing the model information at each evaluation of the fitness function.
`verbose` enables out-of-boundaries warnings and prints the model
information at each evaluation of the fitness function.
Returns a "Model()" object with the specified `drift`, `noise`,
`bound`, `IC`, and `overlay`.
Expand All @@ -172,11 +172,11 @@ def fit_model(sample,
# of the model.
m = copy.deepcopy(Model(name=name, drift=drift, noise=noise, bound=bound, IC=IC, overlay=overlay, T_dur=T_dur, dt=dt, dx=dx))
return fit_adjust_model(sample, m, fitparams=fitparams, fitting_method=fitting_method,
method=method, lossfunction=lossfunction, suppress_output=suppress_output)
method=method, lossfunction=lossfunction, verbose=verbose)


def fit_adjust_model(sample, model, fitparams=None, fitting_method="differential_evolution",
lossfunction=LossLikelihood, verify=False, method=None, suppress_output=False):
lossfunction=LossLikelihood, verify=False, method=None, verbose=True):
"""Modify parameters of a model which has already been fit.
The data `sample` should be a Sample object of the reaction times
Expand Down Expand Up @@ -215,8 +215,8 @@ def fit_adjust_model(sample, model, fitparams=None, fitting_method="differential
`method` gives the method used to solve the model, and can be
"analytical", "numerical", "cn", "implicit", or "explicit".
`suppress_output` disables out-of-boundaries warnings and suppresses
printing the model information at each evaluation of the fitness function.
`verbose` enables out-of-boundaries warnings and prints the model
information at each evaluation of the fitness function.
Returns the same model object that was passed to it as an
argument. However, the parameters will be modified. The model is
Expand All @@ -233,10 +233,10 @@ def fit_adjust_model(sample, model, fitparams=None, fitting_method="differential
"""
# Disable paranoid if `verify` is False.
paranoid_state = paranoid_settings.get('enabled')
verbose_state = param.verbose
renorm_warnings_state = param.renorm_warnings
if paranoid_state and not verify:
paranoid_settings.set(enabled=False)
param.verbose = False
param.renorm_warnings = False
# Loop through the different components of the model and get the
# parameters that are fittable. Save the "Fittable" objects in
# "params". Create a list of functions to set the value of these
Expand Down Expand Up @@ -318,16 +318,16 @@ def _fit_model(xs):
# they will give 1.000000000001. This fixes that problem
# to make sure the model is within its domain.
if x > p.maxval:
if not suppress_output:
if verbose:
print("Warning: optimizer went out of bounds. Setting %f to %f" % (x, p.maxval))
x = p.maxval
if x < p.minval:
if not suppress_output:
if verbose:
print("Warning: optimizer went out of bounds. Setting %f to %f" % (x, p.minval))
x = p.minval
s(m, x)
lossf = lf.loss(m)
if not suppress_output:
if verbose:
print(repr(m), "loss="+ str(lossf))
return lossf
# Cast to a dictionary if necessary
Expand Down Expand Up @@ -359,7 +359,7 @@ def _fit_model(xs):
s(m, x)
if not verify:
paranoid_settings.set(enabled=paranoid_state)
param.verbose = verbose_state
param.renorm_warnings = renorm_warnings_state
return m

def evolution_strategy(fitness, x_0, mu=1, lmbda=3, copyparents=True, mutate_var=.002, mutate_prob=.5, evals=100):
Expand Down
12 changes: 6 additions & 6 deletions ddm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def solve_analytical(self, conditions={}):
# Fix numerical errors
pdfsum = (np.sum(anal_pdf_corr) + np.sum(anal_pdf_err))*self.dt
if pdfsum > 1:
if pdfsum > 1.01 and param.verbose:
if pdfsum > 1.01 and param.renorm_warnings:
print("Warning: renormalizing probability density from", pdfsum, "to 1. " \
"Try decreasing dt. If that doesn't eliminate this warning, it may be due to " \
"extreme parameter values and/or bugs in your model speficiation.")
Expand Down Expand Up @@ -646,11 +646,11 @@ def solve_numerical(self, method="cn", conditions={}, return_evolution=False):
if minval < 0:
sum_negative_strength = np.sum(pdf_corr[pdf_corr<0]) + np.sum(pdf_err[pdf_err<0])
sum_negative_strength_undec = np.sum(pdf_undec[pdf_undec<0])
if sum_negative_strength < -.01 and param.verbose:
if sum_negative_strength < -.01 and param.renorm_warnings:
print("Warning: probability density included values less than zero "
"(minimum=%f, total=%f). " \
"Please decrease dt and/or avoid extreme parameter values." % (minval, sum_negative_strength))
if sum_negative_strength_undec < -.01 and param.verbose:
if sum_negative_strength_undec < -.01 and param.renorm_warnings:
print("Warning: remaining FP distribution included values less than zero " \
"(minimum=%f, total=%f). " \
"Please decrease dt and/or avoid extreme parameter values." % (minval, sum_negative_strength_undec))
Expand All @@ -660,7 +660,7 @@ def solve_numerical(self, method="cn", conditions={}, return_evolution=False):
# Fix numerical errors
pdfsum = np.sum(pdf_corr) + np.sum(pdf_err) + np.sum(pdf_undec)
if pdfsum > 1:
if pdfsum > 1.01 and param.verbose:
if pdfsum > 1.01 and param.renorm_warnings:
print("Warning: renormalizing probability density from", pdfsum, "to 1. " \
"Try decreasing dt or using the implicit (backward Euler) method instead. " \
"If that doesn't eliminate this warning, it may be due to " \
Expand Down Expand Up @@ -870,7 +870,7 @@ def solve_numerical_cn(self, conditions={}):
if minval < 0:
sum_negative_strength = np.sum(pdf_corr[pdf_corr<0]) + np.sum(pdf_err[pdf_err<0])
# For small errors, don't bother alerting the user
if sum_negative_strength < -.01 and param.verbose:
if sum_negative_strength < -.01 and param.renorm_warnings:
print("Warning: probability density included values less than zero "
"(minimum=%f, total=%f). " \
"Please decrease dt and/or avoid extreme parameter values." % (minval, sum_negative_strength))
Expand All @@ -880,7 +880,7 @@ def solve_numerical_cn(self, conditions={}):
pdfsum = np.sum(pdf_corr) + np.sum(pdf_err)
if pdfsum > 1:
# If it is only a small renormalization, don't bother alerting the user.
if pdfsum > 1.01 and param.verbose:
if pdfsum > 1.01 and param.renorm_warnings:
print("Warning: renormalizing probability density from", pdfsum, "to 1. " \
"Try decreasing dt. If that doesn't eliminate this warning, it may be due to " \
"extreme parameter values and/or bugs in your model speficiation.")
Expand Down
2 changes: 1 addition & 1 deletion ddm/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
dt = .005 #0.005 # [s] Time-step.

# Display warnings
verbose = True
renorm_warnings = True

0 comments on commit 9f107ab

Please sign in to comment.