Skip to content

Fitting with bounds and NonLinearLSQFitter broken? #2400

Closed

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?

Activity

  1. eteq commented on May 1, 2014

    @eteq
    MemberAuthor
  2. added this to the milestone on May 1, 2014
  3. embray commented on May 1, 2014

    @embray
    Member

    Pretty sure this is effectively a duplicate of #2235 but I need to confirm.

  4. eteq commented on May 5, 2014

    @eteq
    MemberAuthor

    @embray - I think its subtly different, because it happens even if the parameter values are well within the bounds (at least initially).

  5. embray commented on May 5, 2014

    @embray
    Member

    What I mean though is that I'm pretty sure the cause is the same.

  6. modified the milestones: v0.4.1, on May 21, 2014
  7. embray commented on Jun 20, 2014

    @embray
    Member

    As I wrote in #2235 (comment), this actually appears to be more or less fixed by #2634 .

  8. modified the milestones: v0.4.0, v0.4.1 on Jun 26, 2014
  9. embray commented on Jun 26, 2014

    @embray
    Member

    This should be fixed by #2634, though if you find it isn't--or find another example where this isn't working--feel free to reopen or whatever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions