[SciPy-User] multidimensional polynomial fit

Oscar Gerardo Lazo Arjona algebraicamente@gmail....
Sun Jun 13 16:29:51 CDT 2010

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.
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: load('/myhome/polynomial_fit.py')
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*. 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...


More information about the SciPy-User mailing list