Re: Rationalized Fitting

• To: mathgroup at smc.vnet.net
• Subject: [mg125562] Re: Rationalized Fitting
• From: Antonio Alvaro Ranha Neves <aneves at gmail.com>
• Date: Mon, 19 Mar 2012 04:55:10 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <jhienb\$b3o\$1@smc.vnet.net> <jjmuv3\$cen\$1@smc.vnet.net>

```On Thursday, March 15, 2012 6:36:56 AM UTC+1, Ray Koopman wrote:
> On Mar 13, 10:41 pm, Ray Koopman <koop... at sfu.ca> wrote:
> > First, the data you generate has multiplicative error,
> > so you should specify Weights->(1/#&) in NonlinearModelFit.
>
> With multiplicative error, the error variance is proportional
> to the square of the expected value, so the weight function
> should be (#^-2&), because the weights should be inversely
> proportional to the error variance.

Dear Darren and Ray,

I've tried,
del = 10^-3;
NoisyParabola =
Table[{x, (Prime[7]/Prime[8] + x Prime[9]/Prime[10] +
Prime[11]/Prime[12] x^2)*RandomReal[{98/100, 102/100}]}, {x, 1,
10, 1/4}];
NLMFit = NonlinearModelFit[NoisyParabola,
Rationalize[a, del] + x Rationalize[b, del] +
Rationalize[c, del] x^2, {a, b, c}, x,
Weights -> (Rationalize[#^-2, del] &),
VarianceEstimatorFunction -> (Mean[Abs[Rationalize[#, del]]] &)];
NLMFit["ParameterTable"]
Rationalize[NLMFit["ParameterTable"], del]

As suggested with no success. Here I'm trying to find the best fit rational ized coefficients. The function is linear, but just an example since I would latter need a NonlinerModelFit. The brute-force solution would be something like,

PossibleList = Prepend[Table[Prime[i], {i, 1, 26}], 1];
CheatedList = {Prime[7], Prime[8], Prime[9], Prime[10], Prime[11],
Prime[12]};
PossibleList = CheatedList; (* Here I cheated, so it'll be fast *)
PossibleCoef = Tuples[PossibleList, 2];
{xData, yData} = Transpose[NoisyParabola];
Error = 99999999;
For[Coef1 = 1, Coef1 <= Length[PossibleCoef], Coef1++,
For[Coef2 = 1, Coef2 <= Length[PossibleCoef], Coef2++,
For[Coef3 = 1, Coef3 <= Length[PossibleCoef], Coef3++,
temp =
Total[Abs[(yData -
ParallelMap[(PossibleCoef[[Coef1, 1]]/
PossibleCoef[[Coef1, 2]] + # PossibleCoef[[Coef2, 1]]/
PossibleCoef[[Coef2, 2]] +
PossibleCoef[[Coef3, 1]]/PossibleCoef[[Coef3, 2]] #^2) &,
xData])]^2];
If[temp < Error, Error = temp;
BestCoef = {PossibleCoef[[Coef1, 1]]/PossibleCoef[[Coef1, 2]],
PossibleCoef[[Coef2, 1]]/PossibleCoef[[Coef2, 2]],
PossibleCoef[[Coef3, 1]]/PossibleCoef[[Coef3, 2]]}]
]
]
]

Now BestCoef holds the desired coefficients that satisfies least square fitting. I was hopping to obtain such a result via NonlinearModelFit, but had no success so far. Also, the brute force method takes too long, when considering other ensemble of rationals.

```

• Prev by Date: Re: Export Data and Decimal Separator
• Next by Date: Re: Mathematica results different on different computers !
• Previous by thread: Re: Rationalized Fitting
• Next by thread: Re: Trouble Getting Graphic Primitives in a Module to Display with Show Command