Skip to content

Fitting with bounds and NonLinearLSQFitter broken? #2400

Description

@eteq

I've noticed some odd behavior on the current master that seems like a bug.

class MyModel(modeling.Fittable1DModel):
    a = modeling.Parameter(default=1)
    b = modeling.Parameter(default=0)
    @staticmethod
    def eval(x, a, b):
        return a*x + b

m_real = MyModel(a=1.5, b= -3)
x = np.arange(100)
y = m_real(x)

With that model defined, I see the following:

>>> m = MyModel()
>>> f=modeling.fitting.NonLinearLSQFitter()
>>> f(m,x,y)
<MyModel(a=Parameter('a', value=1.5), b=Parameter('b', value=-3.0), param_dim=1)>

>>> m2 = MyModel()
>>> m2.a.bounds = (-2,2)  # same if I do e.g. m2.a.bounds = (0, None)
>>> f2=modeling.fitting.NonLinearLSQFitter()
>>> f2(m2,x,y)
<MyModel(a=Parameter('a', value=1.0), b=Parameter('b', value=0.0), param_dim=1)>

That looks wrong. It seems like adding the bounds to m2 has caused it to stop trying to fit. And indeed, here's what the fitter says:

>>>f2.fit_info['message']
'The cosine of the angle between func(x) and any column of the\n  Jacobian is at most 0.000000 in absolute value'
>>>f2.fit_info['fjac']
array([[-0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
        [ 0., -0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
          0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])

So apparently the jacobian is coming out to be all zeros?? Why would setting bounds do this despite the initial value being well inside the bounds?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions