[SciPy-user] Curve fitting and LaTeX output

Ryan Krauss ryanlists@gmail....
Wed Aug 27 21:27:05 CDT 2008


You can use optimize.fmin to fit a curve of an arbitrary form.  You have to
be careful to specify the output of your cost function correctly - you
probably want the sum of the squared error.  The first input to the cost
function must be a vector of unknown coefficients.

Something like

import scipy

y = #some data here
x = #some other array here

def mycost(c):
    y_model = c[0] + c[1]**x
    error_vect = y - y_model
    return sum(error_vect**2)

c_initial_guess = [123412.1234, 1203740.0123984]

c_final = scipy.optimize.fmin(mycost, c_initial_guess)

I didn't test that code, but am 90% confident in it.

I have written my own latex output code for lots of stuff, but it is messy.
I don't know what exists that is well conceived :)

Ryan

On Wed, Aug 27, 2008 at 9:09 PM, David Lonie <loniedavid@gmail.com> wrote:

> I'm using the scipy package to analyze data from my research. I'm
> running into a couple problems I'd like some help with. 2 questions:
>
> 1) Curve fitting -- I have found linregress for linear functions,
> polyfit for polynomial fits, and a description of using lstsq to fit
> data that linearly depends on x. Is there a way to fit a curve of the
> form, for example, y = a + b^x? I don't mind a RTFM response to this,
> just please let me know which FM to R, because I can't find anything
> :)
>
> 2) LaTeX output -- I remember using R for stats before, but I'd like
> to avoid going back to it if possible. IIRC it had the ability to
> output latex tables, etc. that could be inserted into a document via
> \input{} (I think). Is there a python module that provides a similar
> output interface?
>
> Thanks in advance,
>
> Dave
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080827/38c90836/attachment.html 


More information about the SciPy-user mailing list