# [SciPy-User] multidimensional polynomial fit

David Goldsmith d.l.goldsmith@gmail....
Sun Jun 13 17:18:27 CDT 2010

```On Sun, Jun 13, 2010 at 3:15 PM, David Goldsmith <d.l.goldsmith@gmail.com>wrote:

> On Sun, Jun 13, 2010 at 2:29 PM, Oscar Gerardo Lazo Arjona <
> algebraicamente@gmail.com> wrote:
>
>> David Goldsmith <d.l.goldsmith <at> gmail.com> writes:
>>
>> > Whatever you do, before submission, please ensure that your function has
>> a
>> complete, Standard-conforming docstring (and, though this is not "my
>> department," so to speak, most would probably join me in also asking that
>> it be
>> accompanied by a pretty complete suite of unit tests, esp. something as
>> mathematically complicated as this - my off-the-cuff would be that it
>> should
>> have at least three, preferably at least five non-trivial or semi-trivial
>> tests,
>> by which I mean tests which pass when a non-trivial solution consisting of
>> simple, e.g., integer, values is produced exactly [to within, say, 9
>> sigfigs],
>> for at least two degrees above 2, one even and one odd - just my \$0.02).DG
>>
>>
>> I implemented the function so that it returns a sage[1] symbolic
>> expression.
>>
>
In general I don't think we "support" sage objects, so whatever you submit
will have to suppress that output in favor, exclusively, of the list (numpy
array preferred, I think) of coefficients (if I'm wrong about this, someone
will correct me).

DG

> Although it could also return a list of coefficients. Within sage's command
>> propt, it can be used like this:
>>
>> sage: var('x y z')
>> (x, y, z)
>> sage: G=-2*y^3*x +x^2 + x*y  -5*z -1
>> sage: pg=[(i,j,k,G.subs(x=i,y=j,z=k)) for i in srange(-1,1.5,0.5) for j in
>> srange(-1,1.5,0.5) for k in srange(-1,1.5,0.5)]
>> sage: Pg=polynomial_fit(pg,[2,3,1],[x,y,z],depreciation=True)
>> -2.0*x*y^3 + x^2 + x*y - 5.0*z - 1.0
>>
>> It reconstructs the original polynomial without *any error*.
>
>
> So the number of data _must_ equal the number of terms in the polynomial?
> (Anything else will be over- or under-determined and require either some
> sort of error minimizing fit.)  What's your use case; just curious.
>
> DG
>
>> Notice the
>> depreciation option which depreciates coefficients that are smaller than
>> 10e-10
>> so that they do not appear in the resulting polynomial.
>>
>> So, if I understood you correctly, this passes your propposed requirement
>> ;) .I
>> haven't written a docstring, but in the mean time, how do I make my
>> submission?
>>
>> I also did not understand what you meant by unit tests...
>>
>> Oscar
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
>
>

--
Mathematician: noun, someone who disavows certainty when their uncertainty
set is non-empty, even if that set has measure zero.

Hope: noun, that delusive spirit which escaped Pandora's jar and, with her
lies, prevents mankind from committing a general suicide.  (As interpreted
by Robert Graves)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100613/3aa78f6a/attachment.html
```