Repository navigation
Refactor constraints - #1243
Refactor constraints#1243
Conversation
There was a problem hiding this comment.
I realize this is more consistent with other classes in this module, but I'm not entirely clear why **cons is used rather than naming the constraint arguments explicitly. Subclasses could use **cons for brevity, but I thought it made sense to have them explicit at least in the base class.
If nothing else, I would raise a TypeError if any unrecognized constraints are passed in. Currently if one mistyped a constraint argument it would just be ignored...
There was a problem hiding this comment.
I used **constraints in the subclasses so that it's clear what goes in the dictionary. And I want to attach a common docstring to all models which support constraints explaining the details.
But you make a very good point about unrecognised constraints, I'll make a check.
|
This looks great--I had a feeling the As for a value to reset the bounds to a default I think something like As for the question of appending to a docstring the easiest way (though not terribly pretty) is to just do it after the class definition: But a nicer way might be to do it in a metaclass. |
|
@iguananaut Thanks for looking at this and for the suggestion about docstrings. I'll finish the changes and push them. |
|
The one failing test here is in |
|
@nden - I agree that it should use |
|
Maybe @iguananaut could give this a final review since he has already looked at an earlier version? |
|
@astrofrog thanks |
There was a problem hiding this comment.
There isn't really any reason to copy the array b here, but it's a small list so it doesn't really matter much.
… classes to using the new Parameter object (somehow missed this the first time).
|
Can anyone restart travis? I'd like to merge this soon. |
|
@nden - I've just restarted it |
|
I think that the failing test has now been fixed by @mdboom in master. Either way, once this is ready to merge, let's just ignore the Travis status. |
|
@astrofrog Thanks! There's a separate PR #1312 which attempts to to fix the current failing test but it's failing as well. I think this is ready to merge unless @embray has other comments. |
This is a somewhat larger PR as it touches almost every module but the goal is to simplify and improve handling of constraints. The added tests hopefully will make it easier to further refactor the code or provide alternate implementations.
The biggest change is that the
Constraintsclass was eliminated. As before constraints are properties of parameters. Fitters have a copy / list of different types of constraints (bounds,fixed, ...). These lists are created once but used in fitting iterations. Before starting a fit, fitters update their lists of constraints to pick up any changes made to the model. Models have a convenience getter property for each type of constraint which returns the current constraints on a model. For example:This required a change to the
Parameterclass which doesn't inherit fromlistany more. A new attributeParameter.valuewas added and is mostly transparent to end users.This change fixed the problem with losing the constraints after a fit. In the previous implementation, when a fitter updated the parameters, it did not update the previously set constraints and they were lost. Now a fitter updates the
valueattribute only and all other attributes are kept.This PR addresses problems raised in issues #1064 , #1218. #1078
I also have a few questions on how to proceed
minandmaxattributes of a parameter. Suppose a model was initialized with some bounds. What is the best way to reset them. For example, usinggauss.mean.max = 10**12to reset the value seems not very intuitive. Isgauss.mean.max = Noneacceptable?The constraints docstrings are currently included in
ParametricModeland are not visible as individual models's docstrings. If I separate them as a standalone string, is there a way to attach them to a class docstring (all my attempts to append them to doc failed)?