Polyfit with scaling

Ben Abbott bpabbott at mac.com
Thu Jan 31 06:47:24 CST 2008


On Jan 31, 2008, at 3:40 AM, Thomas Weber wrote:

>
> Am Mittwoch, den 30.01.2008, 17:48 -0600 schrieb Dmitri A. Sergatskov:
>> On Jan 30, 2008 11:19 AM, Thomas Weber  
>> <thomas.weber.mail at gmail.com> wrote:
>>> I'd like to propose the attached patch for polyfit.m
>>> It introduces an optional fourth bool parameter 'scale'. If not  
>>> set, or
>>> if it's set to 'false', nothing changes.
>>>
>>> If it's set to true, the x values are scaled by their maximal  
>>> absolute
>>> value prior to calculating the polynomial coefficients. This has a
>>> stabilizing effect on the calculation.
>>>
>>
>> I do not understand why this change had not been made a long time ago
>> -- we had few reports of faulty fits. I think the better
>> scaling is:
>>
>> x = (x-mean(x))/std(x).
>>
>> wpolyfit from octave-forge does the scaling like that.
>
> Tarball with a test directory attached. Output of the script in it:
>
> norm difference with normal polyfit: 	 6.330024
> norm difference with wpolyfit: 		 0.465359
> norm difference with new polyfit:	 0.082466
>
> There are warnings from dgelsd, though. The data is taken from the  
> unit
> test, which in turn was taken from a bug report in Debian.
>
> I don't use polynomial approximations often, so it would be nice if a
> few people tested it with their data.
>
> 	Thomas
>
> <polyfits.tar.gz>


The test script uses a set of data for which there is a very small  
variation in both x and y. As a result, if I make the non-sensical  
change below;

   ## scale the x values
   if (scale)
  #  xmax = max(abs(x));
     xmax = min(abs(x));
     x = x/xmax;
   endif

I still get impressive results

warning: dgelsd: rank deficient 13x11 matrix, rank = 3
warning: dgelsd: rank deficient 13x11 matrix, rank = 7
norm difference with normal polyfit: 	6.330024
norm difference with wpolyfit: 		0.150155
norm difference with new polyfit: 	0.082631

It doesn't appear that the example has much comparative value.

I suspect that using max(abs(x)) to normalized the x-data will also  
result in difficulties when that value is substantially large than the  
other x-data values.

I suggest some tests be designed to break both wpolyfit as well as  
your new version, and see how the three fair comparatively.

I'll have some time over the next few days, and will take a shot at  
writing a few tests myself.

Ben


-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080131/efb0245f/attachment-0001.html 


More information about the Octave-maintainers mailing list