Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4190

Strange behaviour of NMinimize when doing curve fitting

From Hovhannes Babayan <bhovhannes@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Strange behaviour of NMinimize when doing curve fitting
Date 2011-08-06 06:14 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j1im4n$cni$1@smc.vnet.net> (permalink)

Show all headers | View raw


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.



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};

f[r_, z_, u_, a_, b_] :=
  z*(r^(-a/110)*(1 + r/u)^(b/100)); (* Here z,u,a,b are parameters *)

x = points[[All, 1]];
y = points[[All, 2]];
n = Length[points];
bestFitVals = NMinimize[
  	Sum[
   		((f[x[[i]], z, u, a, b] - y[[i]])^2)*weights[[i]],
   		{i, n}
   	],
  	{z, u, a, b}
  ]
Show[
 	Plot[
  		Tooltip[f[r, z, u, a, b] /. bestFitVals[[2]]],
  		{r, Max[xdata], Max[ydata]}
  	],
 	ListPlot[points],
 	PlotRange -> {{0, Automatic}, {0, 0.2}},
 	AxesLabel -> {"r", "f[r]"}
 ]

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Strange behaviour of NMinimize when doing curve fitting Hovhannes Babayan <bhovhannes@gmail.com> - 2011-08-06 06:14 +0000
  Re: Strange behaviour of NMinimize when doing curve fitting Peter Pein <petsie@dordos.net> - 2011-08-07 10:16 +0000
  Re: Strange behaviour of NMinimize when doing curve fitting "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-07 10:21 +0000

csiph-web