Skip to content

Commit

Permalink
Fixed error occuring when no parameter changes are generated.
Browse files Browse the repository at this point in the history
Sometimes NR (or perhaps other methods) won't actually generate
any parameter changes. If it's due to cutoffs, this may be the
intended effect. If it's not due to cutoffs, you may want to
reconsider what parameters you're optimizing, what methods you're
using, etc.

For example, if you're trying to optimize a parameter that has no
effect on the objective function, then NR won't generate changes.
You don't want to include parameters that have no affect on the
penalty function!

Anyway, if a method doesn't actually generate any parameter changes,
an error would occur when the function "cleanup" would attempt to
iterate over the changes. Now, it checks that changes exist before
attempting to iterate.
  • Loading branch information
ericchansen committed Mar 1, 2016
1 parent 5126475 commit 0cd6a70
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,15 @@ def check_radius(par_rad, max_rad):
return 1

def cleanup(ffs, ff, changes):
for method, change in changes:
opt.pretty_param_changes(
ff.params, change, method)
ffs.append(return_ff(ff, change, method))
if changes:
for method, change in changes:
opt.pretty_param_changes(
ff.params, change, method)
ffs.append(return_ff(ff, change, method))
else:
logger.warning(
' -- No changes generated! It may be wise to ensure this '
'parameter has an effect on the objective function!')

def do_method(func):
def wrapper(*args, **kwargs):
Expand Down

0 comments on commit 0cd6a70

Please sign in to comment.