Message Boards Message Boards

0
|
4831 Views
|
12 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

NonlinearModelFit Fails! on procedural function!

Posted 10 years ago

I defined a function through a module and then tried to fit it to the data, but it gets stuck for hours, no response even when I leave only one parameter.

I would appreciate help a lot!

Attachments:
POSTED BY: Al Guy
12 Replies
Posted 10 years ago

Perhaps try NMaximize with constraints on the range of the parameters and Method->"RandomSearch"

As with all the other N-functions, all the variables, except those you are asking it to find, must have been assigned specific concrete numerical values before it starts.

POSTED BY: Bill Simpson
Posted 10 years ago

Yes, I understand that. Parameters are within (0, Pi) which is the same as (-Pi, 0). where exactly in this region hard to say.

POSTED BY: Al Guy
Posted 10 years ago

There is always at least a dozen different ways of doing anything in Mathematica.

Do you have a reasonably good idea for the range of each parameter?

Can you write a reasonably simple expression for the magnitude of the error between a given set of parameters and the optimum?

If you could provide that sort of information then perhaps someone could try a few of the dozen different ways and see if they find one that converges at an acceptable rate.

POSTED BY: Bill Simpson
Posted 10 years ago

What is the fastest fitting method for this type of procedurally defined functions? Apparently Levenberg is not the best, too expensive. Nothing cheaper?

POSTED BY: Al Guy
Posted 10 years ago

This is really cool!

I guess the problem is it it's just slow, the fitting. Maybe it is as good as it can be, quite disappointing.

POSTED BY: Al Guy
Posted 10 years ago

A little experiment.

Insert up near the top of your code

counter = 0;

Insert immediately before the last line of your Module, which returns the value of intensity,

LinkWrite[$ParentLink, SetNotebookStatusLine[FrontEnd`EvaluationNotebook[], ToString[{counter++, pw, h0, \[Sigma]0, Qw, intensity}]]];

That is going to write little messages onto the status line in the lower right corner of your window. You will be able to see the counter incrementing, the contents of your arguments to your module and the resulting intensity.

I have chosen the order of those so that the ones which will almost always have the same number of characters to be displayed each time come first. That way we can hopefully see pattern in the flood of messages.

Notice how many thousands of calls are made to your module have without any change to pw, h0 and sigma0.

POSTED BY: Bill Simpson
Posted 10 years ago

In your Module in your local variable list there is b,,Qv and that worries me.

If I insert

Print[{Qw, pw, h0, \[Sigma]0, intensity}];

immediately prior to the last line of your module, where it returns the value of intensity, and run your code then there is a vast long list of lines printed which show me that your function is being evaluated for a variety of different parameters and different values of intensities are being returned. Note: you may need to kill the math kernel to get control over the machine again because of the stream of output swamping the machine.

I was hoping that seeing the parameters and result from your int function might provide a clue.

POSTED BY: Bill Simpson
Posted 10 years ago

The function itself seems to be correct and gives correct results. I just don't understand what's happening in the NonlinearModelFit.

POSTED BY: Al Guy
Posted 10 years ago

StepMonitor just returns p1 and that's it.

 fitm = FindFit[
      datint, {k1*int[q, {p1, p2, p3, p4}, h, \[Sigma]] + c}, {{\[Sigma], 
        0.0086}, {p1, -0.487}, {p2, 1.07}, {p3, 
        0.211}, {p4, -0.1264}, {k1, (2*10^6)^-1}, {h, 17}, {c, 0.001}}, 
      q , Method -> "LevenbergMarquardt", StepMonitor -> Print[p1]]
POSTED BY: Al Guy
Posted 10 years ago

Can you use StepMonitor or EvaluationMonitor in NonlinearModelFit to observe the progress and get a better idea where it is hanging up?

POSTED BY: Bill Simpson
Posted 10 years ago

Tiny probable typo:

dat3 = Import["Non-annealed data.txt", "Data"];
fitm = NonlinearModelFit[datint,...

I'm guessing datint should be dat3. True?

Any other typos if you carefully look over the files you posted?

Thanks

POSTED BY: Bill Simpson
Posted 10 years ago

Yes, you are right, it's dat3 instead of datint. But that's not the issue. The procedure in Module is correct, no doubt about it.

POSTED BY: Al Guy
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract