MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Strange behaviour of NMinimize when doing curve fitting

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120743] Re: Re: Strange behaviour of NMinimize when doing curve fitting
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 8 Aug 2011 04:21:23 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

The error sum has a large constant denominator (use Together to see it),  
so you might do this:

Clear[f, error, errorSum]
f[z_, u_, a_, b_][x_] := z x^-a (1 + x/u)^b;
error[z_, u_, a_, b_][x_, y_] := (f[z, u, a, b]@x - y)^2;
points = {{4.68, 0.156}, {7.63, 0.100}, {10.56, 0.074}, {13.48,
     0.061}, {16.55, 0.048}, {20.33, 0.029}, {25.39, 0.023}, {30.28,
     0.018}, {36.05, 0.016}, {42.60, 0.016}, {55.49, 0.028}};
weights = {0.2523, 0.4007, 0.5801, 0.6193, 0.6798, 1, 0.7957, 0.5144,
    0.37030, 0.1079, 0.0189};
errorSum[z_, u_, a_, b_] =
   Numerator@Total[(error[z, u, a, b] @@@ points)*weights];
bestFitVals =
   NMinimize[{errorSum[z, u, a, b], Thread[0 < {u, z, a, b}]}, {z, u,
     a, b}];
soln[x_] = f[z, u, a, b]@x /. bestFitVals[[2]]

(0.818574 (1 + 2.53907 x)^2.72706*10^-26)/x^1.04706

limits = Flatten@{x, Through[{Min, Max}@points[[All, 1]]]};
Show@{Plot[soln@x, Evaluate@limits, PlotRange -> All],
   ListPlot[points, PlotStyle -> Red]}

Bobby

On Sun, 07 Aug 2011 05:15:03 -0500, Peter Pein <petsie at dordos.net> wrote:

> Am 06.08.2011 08:14, schrieb Hovhannes Babayan:
>> Hello,
>>
>> I want to fit a set of points with some curve, which form I know, but  
>> coefficients have to be determined to make the best possible fit. Also,  
>> for the each point a weight (a number ranging from 0 to 1) is defined.  
>> Point with greater weight is more important and point with lower weight  
>> is not so important. Point with weight=0 doesn't matter at all, point  
>> with weight=1 is extremely important.
>> The code below uses NMinimize and draw the best fit graphic.
>> The function f[r_, z_, u_, a_, b_] is a fitting function, where z,u,a,b  
>> are parameters.
>> The question is following. Notice that I've used a/110 and b/100,  
>> instead of just a and b. When I use just a and b, produced curve  
>> doesn't fit at all my points. When I use a/50 and b/50 result is  
>> better, with a/70 and b/70 even better, and so on. The best seems to be  
>> a/110 and b/100 combination. Why it is so important for NMinimize??
>>> From theoretical point of view it absolutely doesn't matter what is  
>>> used: a/100 or a/1000 or just a. Parameter "a" should be found in  
>>> every case.
>> Please, if you have met such behavior, let me know, because currently I  
>> am doing NMinimize of NMinimize just to find good values to divide a  
>> and b, and it has no sense :)
>> In order to try the code below, just copy/paste it into Mathematica, it  
>> should print best fit result (first element is error, second element is  
>> array with values of parameters z,u,a,b), should plot points and  
>> fitting curve. Use a/1 and b/1 to have the worst result and a/110 and  
>> b/100 to have good result.
>> Thanks forehand for any suggestions, remarks and/or ideas.
>>
>>
> ...
>
> Hi,
>
>  as you can see in this notebook [1], there is no more difference in the
> results, when rationalizing the input and restricting u to be positive
> and the other variables to be nonnegative.
>
> hth,
>   Peter
>
>
> [1] http://dl.dropbox.com/u/3030567/Mathematica/hovhannes.nb
>


-- 
DrMajorBob at yahoo.com




  • Prev by Date: Re: NMinimize eats all memory b/c of unnecessary symbolic work
  • Next by Date: Re: NMinimize eats all memory b/c of unnecessary symbolic work
  • Previous by thread: Re: Strange behaviour of NMinimize when doing curve fitting
  • Next by thread: Getting TraditionalForm to put in a multiplication sign.