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


Groups > comp.soft-sys.math.mathematica > #8557 > unrolled thread

Rationalized Fitting

Started byAntonio Alvaro Ranha Neves <aneves@gmail.com>
First post2012-02-16 08:28 +0000
Last post2012-03-14 05:37 +0000
Articles 6 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Rationalized Fitting Antonio Alvaro Ranha Neves <aneves@gmail.com> - 2012-02-16 08:28 +0000
    Re: Rationalized Fitting Antonio Alvaro Ranha Neves <aneves@gmail.com> - 2012-03-13 08:02 +0000
      Re: Rationalized Fitting Ray Koopman <koopman@sfu.ca> - 2012-03-14 05:41 +0000
        Re: Rationalized Fitting Ray Koopman <koopman@sfu.ca> - 2012-03-15 05:36 +0000
      Re: Rationalized Fitting Antonio Alvaro Ranha Neves <aneves@gmail.com> - 2012-03-19 09:56 +0000
    Re: Rationalized Fitting Darren Glosemeyer <darreng@wolfram.com> - 2012-03-14 05:37 +0000

#8557 — Rationalized Fitting

FromAntonio Alvaro Ranha Neves <aneves@gmail.com>
Date2012-02-16 08:28 +0000
SubjectRationalized Fitting
Message-ID<jhienb$b3o$1@smc.vnet.net>
Hello group members and advanced users,

Recently, I was trying to obtain the best fitting function with rational parameters, without success. I tried something like,

NoisyParabola = 
 Table[{x, (Prime[7]/Prime[8] + x Prime[9]/Prime[10] + 
      Prime[11]/Prime[12] x^2)*RandomReal[{.95, 1.05}]}, {x, 1, 10, 
   1/4}]
NLMFit = NonlinearModelFit[NoisyParabola, 
  Rationalize[a, 10^-6] + x Rationalize[b, 10^-6] + 
   Rationalize[c, 10^-6] x^2, {a, b, c}, x] 
NLMFit["ParameterTable"]

The main idea is to obtain the fitting coefficients (a,b,c) whose standard deviation (da,db,dc), would yield a fitting result of a best fit rational Rationalize[a,da]. But I fail to see how I can get this interactively.

Hope I made myself clear,
Thanks,
Antonio

[toc] | [next] | [standalone]


#8986

FromAntonio Alvaro Ranha Neves <aneves@gmail.com>
Date2012-03-13 08:02 +0000
Message-ID<jjmuv3$cen$1@smc.vnet.net>
In reply to#8557
No reply? Guess it's harder than it looks.


On Thursday, February 16, 2012 9:28:27 AM UTC+1, Antonio Alvaro Ranha Neves wrote:
> Hello group members and advanced users,
> 
> Recently, I was trying to obtain the best fitting function with rational parameters, without success. I tried something like,
> 
> NoisyParabola = 
>  Table[{x, (Prime[7]/Prime[8] + x Prime[9]/Prime[10] + 
>       Prime[11]/Prime[12] x^2)*RandomReal[{.95, 1.05}]}, {x, 1, 10, 
>    1/4}]
> NLMFit = NonlinearModelFit[NoisyParabola, 
>   Rationalize[a, 10^-6] + x Rationalize[b, 10^-6] + 
>    Rationalize[c, 10^-6] x^2, {a, b, c}, x] 
> NLMFit["ParameterTable"]
> 
> The main idea is to obtain the fitting coefficients (a,b,c) whose standard deviation (da,db,dc), would yield a fitting result of a best fit rational Rationalize[a,da]. But I fail to see how I can get this interactively.
> 
> Hope I made myself clear,
> Thanks,
> Antonio

[toc] | [prev] | [next] | [standalone]


#9024

FromRay Koopman <koopman@sfu.ca>
Date2012-03-14 05:41 +0000
Message-ID<jjpb32$p6b$1@smc.vnet.net>
In reply to#8986
On Mar 13, 1:02 am, Antonio Alvaro Ranha Neves <ane...@gmail.com>
wrote:
> No reply? Guess it's harder than it looks.
>
> On Thursday, February 16, 2012 9:28:27 AM UTC+1,
> Antonio Alvaro Ranha Neves wrote:
>
>> Hello group members and advanced users,
>>
>> Recently, I was trying to obtain the best fitting function with
>> rational parameters, without success. I tried something like,
>>
>> NoisyParabola =
>>  Table[{x, (Prime[7]/Prime[8] + x Prime[9]/Prime[10] +
>>       Prime[11]/Prime[12] x^2)*RandomReal[{.95, 1.05}]}, {x, 1, 10,
>>    1/4}]
>> NLMFit = NonlinearModelFit[NoisyParabola,
>>   Rationalize[a, 10^-6] + x Rationalize[b, 10^-6] +
>>    Rationalize[c, 10^-6] x^2, {a, b, c}, x]
>> NLMFit["ParameterTable"]
>>
>> The main idea is to obtain the fitting coefficients (a,b,c)
>> whose standard deviation (da,db,dc), would yield a fitting
>> result of a best fit rational Rationalize[a,da]. But I fail
>> to see how I can get this interactively.
>>
>> Hope I made myself clear,
>> Thanks,
>> Antonio

Two things. First, the data you generate has multiplicative error,
so you should specify Weights->(1/#&) in NonlinearModelFit.

Second, it's not clear what you want or how the standard errors of
the parameter estimates relate to it.

[toc] | [prev] | [next] | [standalone]


#9058

FromRay Koopman <koopman@sfu.ca>
Date2012-03-15 05:36 +0000
Message-ID<jjrv5o$9f8$1@smc.vnet.net>
In reply to#9024
On Mar 13, 10:41 pm, Ray Koopman <koop...@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.

[toc] | [prev] | [next] | [standalone]


#9140

FromAntonio Alvaro Ranha Neves <aneves@gmail.com>
Date2012-03-19 09:56 +0000
Message-ID<jk6vsi$s0$1@smc.vnet.net>
In reply to#8986
On Thursday, March 15, 2012 6:36:56 AM UTC+1, Ray Koopman wrote:
> On Mar 13, 10:41 pm, Ray Koopman <koop...@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.

[toc] | [prev] | [next] | [standalone]


#9008

FromDarren Glosemeyer <darreng@wolfram.com>
Date2012-03-14 05:37 +0000
Message-ID<jjpaqd$p21$1@smc.vnet.net>
In reply to#8557
On 3/13/2012 3:01 AM, Antonio Alvaro Ranha Neves wrote:
> No reply? Guess it's harder than it looks.
>
>
> On Thursday, February 16, 2012 9:28:27 AM UTC+1, Antonio Alvaro Ranha Neves wrote:
>> Hello group members and advanced users,
>>
>> Recently, I was trying to obtain the best fitting function with rational parameters, without success. I tried something like,
>>
>> NoisyParabola =
>>   Table[{x, (Prime[7]/Prime[8] + x Prime[9]/Prime[10] +
>>        Prime[11]/Prime[12] x^2)*RandomReal[{.95, 1.05}]}, {x, 1, 10,
>>     1/4}]
>> NLMFit = NonlinearModelFit[NoisyParabola,
>>    Rationalize[a, 10^-6] + x Rationalize[b, 10^-6] +
>>     Rationalize[c, 10^-6] x^2, {a, b, c}, x]
>> NLMFit["ParameterTable"]
>>
>> The main idea is to obtain the fitting coefficients (a,b,c) whose standard deviation (da,db,dc), would yield a fitting result of a best fit rational Rationalize[a,da]. But I fail to see how I can get this interactively.
>>
>> Hope I made myself clear,
>> Thanks,
>> Antonio
>

You could rationalize the end result, e.g.

Rationalize[NLMFit["ParameterTable"], 10^-6]

a, b and c in the model are inexact numbers which get rationalized in 
the formula. Since the model is actually linear in the parameters, you 
could use LinearModelFit with WorkingPrecision->Infinity to get an exact 
result but that will include huge Root object expressions, so you would 
still need to rationalize an inexact numeric approximation of the result 
like in the following to get rationals.

lm = LinearModelFit[NoisyParabola, {x, x^2}, x,
    WorkingPrecision -> Infinity];
Rationalize[N[lm["ParameterTable"], 20], 10^-6]


Darren Glosemeyer
Wolfram Research

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web