[Date Index]
[Thread Index]
[Author Index]
NonlinearFit not reaching convergence, even after spoon-feeding it with initial parameters.
*To*: mathgroup at smc.vnet.net
*Subject*: [mg45875] NonlinearFit not reaching convergence, even after spoon-feeding it with initial parameters.
*From*: gilmar.rodriguez at nwfwmd.state.fl.us (Gilmar Rodr?guez Pierluissi)
*Date*: Wed, 28 Jan 2004 05:19:16 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
Dear Friends:
Please; copy the following lines into a new Mathematica
notebook in order to evaluate them:
(**I have the following tide data: **)
data={{1, 0}, {2, -0.015}, {3, -0.07}, {4, -0.102}, {5, -0.152}, {6,
-0.221}, {
7, -0.259}, {8, -0.303}, {9, -0.361}, {10, -0.407}, {
11, -0.456}, {12, -0.496}, {13, -0.547}, {14, -0.613}, {15,
-0.65}, {16, \
-0.662}, {17, -0.691}, {18, -0.733}, {19, -0.763}, {
20, -0.807}, {21, -0.814}, {22, -0.822}, {23, -0.784}, {
24, -0.762}, {25, -0.756}, {26, -0.755}, {27, -0.743}, {
28, -0.714}, {29, -0.688}, {30, -0.672}, {31, -0.632}, {32, -0.609},
{33, \
-0.552}, {34, -0.475}, {35, -0.443}, {36, -0.373}, {37, -0.34}, {38,
-0.293}, \
{39, -0.232}, {40, -0.214}, {41, -0.152}, {42, -0.112}, {43, -0.082},
{44, \
-0.072}, {45, -0.075}, {46, -0.073}, {47, -0.071}, {48, -0.072}, {49,
\
-0.078}, {50, -0.109}, {51, -0.113}, {52, -0.144}, {53, -0.165}, {54,
\
-0.181}, {55, -0.202}, {56, -0.21}, {57, -0.248}, {
58, -0.284}, {59, -0.327}, {60, -0.363}, {61, -0.403}, {
62, -0.432}, {63, -0.477}, {64, -0.522}, {65, -0.569}, {
66, -0.584}, {67, -0.617}, {68, -0.631}, {69, -0.63}, {70, -0.626},
{71, \
-0.611}, {72, -0.622}, {73, -0.593}, {
74, -0.567}, {75, -0.549}, {76, -0.525}, {
77, -0.503}, {78, -0.48}, {79, -0.445}, {80, -0.406}, {81,
-0.363}, {82, \
-0.326}, {83, -0.279}, {84, -0.246}, {85, -0.197}, {86, -0.145}, {
87, -0.119}, {88, -0.061}, {89, -0.021}, {90, 0.026}, {91,
0.032}, {92, 0.059}, {93, 0.068}, {94, 0.059}, {95, 0.08}, {96,
0.084}, {
97, 0.065}, {98, 0.044}, {99, -0.021}, {100, -0.014}, {101, -0.053},
{102, \
-0.068}, {103, -0.101}, {104, -0.145}, {105, -0.212}, {106, -0.26},
{107, \
-0.319}, {108, -0.346}, {
109, -0.378}, {110, -0.438}, {111, -0.496}, {112, -0.55}, {113,
-0.599}, \
{114, -0.64}, {115, -0.684}, {116, -0.708}, {
117, -0.735}, {118, -0.757}, {119, -0.785}, {120, -0.797}, {
121, -0.786}, {122, -0.781}, {123, -0.767}, {124, -0.746}, {
125, -0.72}, {126, -0.686}, {127, -0.672}, {128, -0.648}, {
129, -0.634}, {130, -0.593}, {131, -0.54}, {132, -0.512}, {133,
-0.466}, \
{134, -0.425}, {135, -0.371}, {136, -0.308}, {137, -0.266}, {138,
-0.219}, \
{139, -0.182}, {140, -0.149}, {141, -0.114}, {142, -0.107}, {143,
-0.102}, \
{144, -0.08}, {145, -0.1}, {146, -0.127}, {147, -0.143}, {
148, -0.179}, {149, -0.175}, {150, -0.181}, {151, -0.215}, {
152, -0.231}, {153, -0.264}, {154, -0.323}, {155, -0.373}, {
156, -0.431}, {157, -0.481}, {158, -0.525}, {159, -0.58}, {
160, -0.629}, {161, -0.674}, {162, -0.726}, {163, -0.766}, {
164, -0.825}, {165, -0.845}, {166, -0.864}, {167, -0.891}, {
168, -0.889}, {169, -0.895}, {170, -0.883}, {171, -0.876}, {
172, -0.821}, {173, -0.818}, {174, -0.802}, {175, -0.76}, {
176, -0.731}, {177, -0.696}, {178, -0.672}, {179, -0.631}, {
180, -0.592}, {181, -0.548}, {182, -0.495}, {183, -0.441}, {
184, -0.38}, {185, -0.333}, {186, -0.265}, {187, -0.185}, {
188, -0.155}, {189, -0.116}, {190, -0.101}, {191, -0.074}, {
192, -0.029}, {193, -0.005}, {194, 0.001}, {195, 0.029}, {196,
0.001}, \
{197, -0.019}, {198, -0.053}, {199, -0.081}, {200, -0.097}, {201,
-0.152}, {
202, -0.185}, {203, -0.206}, {204, -0.219}, {205, -0.261}, {
206, -0.282}, {207, -0.331}, {208, -0.378}, {209, -0.455}, {210,
-0.495}, \
{211, -0.556}, {212, -0.599}, {213, -0.639}, {214, -0.637}, {215,
-0.667}, \
{216, -0.673}, {217, -0.695}, {218, -0.7}, {219, -0.687}, {220,
-0.687}, \
{221, -0.683}, {222, -0.656}, {223, -0.631}, {224, -0.616}, {225,
-0.578}, \
{226, -0.534}, {227, -0.482}, {228, -0.428}, {229, -0.345}, {230,
-0.313}, \
{231, -0.282}, {232, -0.25}, {233, -0.218}, {234, -0.187}, {235,
-0.155}, \
{236, -0.139}, {237, -0.099}, {238, -0.083}, {239, -0.076}, {240,
-0.054}, \
{241, -0.047}, {242, -0.064}, {243, -0.038}, {244, -0.043}, {245,
-0.06}, \
{246, -0.056}, {247, -0.077}, {248, -0.106}, {249, -0.134}, {250,
-0.212}, \
{251, -0.269}, {252, -0.327}, {253, -0.386}, {254, -0.443}, {255,
-0.476}, \
{256, -0.525}, {257, -0.608}, {258, -0.665}, {259, -0.71}, {260,
-0.723}, \
{261, -0.756}, {262, -0.784}, {263, -0.807}, {264, -0.845}};
(**The length of the data is 264 values:**)
L = Length[data]
(** Plot the tide data: **)
ListPlot[data, PlotJoined -> True]
(** I define the following model: **)
\!\(model\ = \ a\_0 + Sum[a\_i*
Sin[v\_i*t - b\_i], {i, 1, 4}] + Sum[c\_i*Sin[w\_i*t - d\_i], {i,
1, 4}]\)
(** I view the 25 parameters involved: **)
\!\(params = \ Join[{a\_0},
Table[a\_i, {i, 1, 4}], Table[b\_i, {i,
1, 4}], Table[c\_i, {i, 1, 4}], Table[d\_i, {i,
1, 4}], Table[v\_i, {i, 1, 4}], Table[w\_i, {i, 1, 4}]]\)
(** Next, I plot the data using red color, to plot it against the
above model: **)
g1 = ListPlot[data, PlotJoined -> True, PlotStyle -> RGBColor[1, 0,
0]]
(** I call the NonlinearFit program: **)
<< Statistics`NonlinearFit`
(** Next, I attempt a non-linear fit : **)
B[t_] = Chop[NonlinearFit[data, model, t, params]]
(** I get a message: ""FindFit::cvmit: Failed to converge to the
requested accuracy or precision
within 100 iterations". **)
(** Still; a model is released by the program and I plot it in color
green: **)
g2 = Plot[B[t], {t, 1, 264}, PlotStyle -> RGBColor[0, 1, 0]]
(** When I compare the data with the model, I see the discrepancy
between the data and the first fit: **)
Show[{g1, g2}, ImageSize -> 540]
(** To correct this situation, I introduce initial parameters that I
have obtained by other means... : **)
\!\(\(initparams = {{a\_0, \(-0.31278\)}, {a\_1, \(-0.21078\)}, {a\_2,
\
\(-0.12503\)}, {a\_3, \(-0.03388\)}, {a\_4, \(-0.34959\)}, {b\_1,
8.093077}, \
{b\_2, 10.51904}, {b\_3,
2.014087}, {
b\_4, 7.077294}, {c\_1, \(-0.05472\)}, {c\_2, \(-0.05678\)},
{c\_3, \
\(-0.1125\)}, {c\_4, \(-0.06463\)}, {d\_1, \(-5.01326\)}, {d\_2, \
\(-6.27323\)}, {d\_3, \(-1.67511\)}, {d\_4, \(-10.6115\)}, {v\_1,
0.126851}, \
{v\_2, 0.135713}, {v\_3,
0.089487}, {v\_4, 0.130158}, {w\_1, 0.049697}, {w\_2,
0.049183}, {
w\_3, \(-0.00844\)}, {w\_4, 0.046353}};\)\)
(** Next; I attempt a second non-linear fit, in terms of the above
initial parameters: **)
B[t_] = Chop[NonlinearFit[data, model, t, initparams]];
(** This time I get a message: "FindFit::cvit: Failed to converge to
the requested accuracy or precision
within 100 iterations." **)
(** I plot B[t_] again: **)
g3 = Plot[B[t], {t, 1, 264}, PlotStyle -> RGBColor[0, 1, 0]]
(** When I compare the data with B[t_]; I find that the match is
excellent: **)
Show[{g1, g3}, ImageSize -> 540]
(** I calculate the correlation between the data, and the model, and
indeed I see that the correlation
is excellent: **)
tidevals = Table[data[[i]][[2]], {i, 1, L}];
modvals = Table[B[t], {t, 1, L}];
<< Statistics`MultiDescriptiveStatistics`
r = Correlation[tidevals, modvals]
(**The correlation is 0.997555 **)
My questions are:
(1.) How can I control the NUMBER OF ITERATIONS in NonlinearFit?
(2.) How can I control the STEPSIZE in NonlinearFit?
(3.) How can I control the TOLERANCE in NonlinearFit?
(4.) Notice that I "spoon fed" NonlinearFit the above initial
parameters (which I know work fine), and I still
get a warning message! How can I remedy this situation?
Thank you for your help!
Prev by Date:
**RE: GridPlot**
Next by Date:
**unpartition**
Previous by thread:
**Re: Difference of numbers in the list**
Next by thread:
**Re: NonlinearFit not reaching convergence, even after spoon-feeding it with initial parameters.**
| |