You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow min / max / tie constraint removal for modeling Parameter #1078
I think currently it is not possible to un-tie a parameter?
At the moment when I try to set model.parameter.tied = False indicate it should be un-tied I get an AssertionError:
@tied.setter
def tied(self, val):
> assert callable(val), "Tied must be a callable"
E AssertionError: Tied must be a callable
The same applies to trying to remove a min or max constraint from a Parameter, i.e. setting model.parameter.min = None gives an
@min.setter
def min(self, val):
> assert isinstance(val, numbers.Number), "Min value must be a number"
E AssertionError: Min value must be a number
Another minor thing: the constructor arguments minvalue and maxvalue should be changed to min and max to make them consistent with and easier to remember with the min and max properties.
@iguananaut mentioned he is currently working on the Parameter and Model class, so we should wait for #980 before fixing these issues (if they aren't resolved there).
Hmm. First of all if this is going to throw an error at all it should be a TypeError, not an AssertionError. Second of all, does it make sense to be able to modify these constraints, or does it make more sense to create a new model instance with different constraints?
I haven't paid much attention to this issue until recently so I'm not clear on whether it's preferable for Model objects to be very tweakable, or what. Though I suppose, as long as you can modify the parameter values I guess you should be able to modify these constraints as well. And in that case I agree it should be possible to 'unset' them with None or False. (in the meantime you could just override them with a noop like lambda v: v).
I think this feature request has been implemented by @nden in the meantime.
Everyone happy how it works now?
The only think left would be to change the AssertionError into a TypeError and to add some documentation for this feature?
Do we want more unit tests with some complicated setting / fitting / unsetting / fitting / ... sequences to make sure the system can't get into a bad state?
If that's all that's missing to close this issue I can make a PR.
In [1]: from astropy.modeling.models import Gaussian1DModel
In [2]: gauss = Gaussian1DModel(amplitude=1, stddev=2, mean=3)
In [3]: gauss.bounds
Out[3]: {'amplitude': (None, None), 'mean': (None, None), 'stddev': (None, None)}
In [4]: gauss.tied
Out[4]: {'amplitude': False, 'mean': False, 'stddev': False}
In [5]: gauss.amplitude
Out[5]: 1.0
In [6]: gauss.amplitude.min
In [7]: gauss.amplitude.min = 10
In [8]: gauss.amplitude.min = None
In [9]: gauss.amplitude.tied
Out[9]: False
In [10]: gauss.amplitude.tied = True
ERROR: AssertionError: Tied must be a callable [astropy.modeling.parameters]
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-10-0810b990d983> in <module>()
----> 1 gauss.amplitude.tied = True
/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy-0.3.dev4991-py2.7-macosx-10.8-x86_64.egg/astropy/modeling/parameters.pyc in tied(self, val)
198 Tie a parameter.
199 """
--> 200 assert callable(val) or val is False, "Tied must be a callable"
201 self._tied = val
202
AssertionError: Tied must be a callable
In [11]: gauss.amplitude.tied = False
In [12]: gauss.amplitude.tied = lambda x : x
In [13]: gauss.amplitude.tied
Out[13]: <function __main__.<lambda>>
In [14]: gauss.amplitude.tied = False
In [15]: gauss.tied
Out[15]: {'amplitude': False, 'mean': False, 'stddev': False}
Activity
embray commentedon May 10, 2013
Hmm. First of all if this is going to throw an error at all it should be a
TypeError, not anAssertionError. Second of all, does it make sense to be able to modify these constraints, or does it make more sense to create a new model instance with different constraints?I haven't paid much attention to this issue until recently so I'm not clear on whether it's preferable for Model objects to be very tweakable, or what. Though I suppose, as long as you can modify the parameter values I guess you should be able to modify these constraints as well. And in that case I agree it should be possible to 'unset' them with
NoneorFalse. (in the meantime you could just override them with a noop likelambda v: v).cdeil commentedon May 10, 2013
@iguananaut It's very common to fix / free parameters in interactive fitting sessions to eventually achieve convergence for multi-parameter fits.
nden commentedon May 10, 2013
@iguananaut Yes, this is a bug in the current master
embray commentedon May 10, 2013
Yeah, okay. That makes sense.
cdeil commentedon Aug 8, 2013
I think this feature request has been implemented by @nden in the meantime.
Everyone happy how it works now?
The only think left would be to change the
AssertionErrorinto aTypeErrorand to add some documentation for this feature?Do we want more unit tests with some complicated setting / fitting / unsetting / fitting / ... sequences to make sure the system can't get into a bad state?
If that's all that's missing to close this issue I can make a PR.
nden commentedon Oct 5, 2013
This has been fixed in #1243 and tests were added to
test_constraints.