Re: Curve fitting to data



Alex Fenton wrote:
Phil Rhoades wrote:

On Sun, 2007-12-16 at 23:55 +0000, Thomas Adam wrote:
On 16/12/2007, Phil Rhoades <phil@xxxxxxxxxxxxx> wrote:
People,

Does anyone know of a Ruby app that will fit a curve to data eg fitting
a curve to:

-10 0
-9 19
This looks like a prime candidate for GNUPlot -- which ruby has
bindings for.


I think GNUPlot requires the knowledge of the type of fn you are trying
to fit - I want the software to TELL me what sort of fn it is eg for the
data:

You can access the "R" statistical package via Ruby, which seems to have
curve fitting capabilities. But this would involve learning R, which
I've found to have a steeper curve than I cared to climb.

More generally, I think for most scientific purposes, it's a good idea
to have an idea of the type of curve (power, quadratic, cubic etc) that
might underlie the observed data. Most applications enforce this. If you
know the general form of the equation that's being fitted ( eg ax^2 + bx
+ c for a quadratic), it would be possible to get estimates for a, b and
c by using eg ordinary least squares to find a solution that minimises
the difference between observed and predicted values. How you get to
that with acceptable time is an algorithmic question...

But nothing I know of exactly in Ruby. You might take a look at the
source code for the website you linked to:
http://pythonequations.cvs.sourceforge.net/pythonequations/PythonEquations/DESolver/DESolver.py?revision=1.2&view=markup


Maybe a fun one for a Ruby Quiz sometime?

alex

Well ... let's see:

1. There's no such thing as a "universal curve fitting algorithm", in
the sense that you give it a set of points and it spits out a formula.
The main reason is that given any *finite* set of points, there are an
*infinite* number of possible curves that can be drawn through them
exactly. Some of these are fairly well behaved outside the range of the
input points, and some of them exhibit bizarre behavior.

2. There's no such thing as a curve-fitting problem in a total vacuum,
without any context whatsoever. In other words, a request to fit a curve
to a set of points is meaningless without knowledge of how you will use
that fit.

3. Many of the "naive" techniques, like polynomial regression, behave
very badly. By "behave very badly", I mean "much worse than plotting the
points in Excel and making a wild guess."

Given all that, I don't see much hope of finding or writing a Ruby
program to do this. Conversely, if the original poster has a model that
the points should have come from, based on some theory, writing Ruby
code (or R or Python code) to fit the data to the model is easy. Just
about every reasonable fitting algorithm is already coded in R, so if
you just want an answer without all that pesky learning stuff, it's
probably easier to do it in R.





.



Relevant Pages

  • Re: Curve fitting to data
    ... Does anyone know of a Ruby app that will fit a curve to data eg fitting ... You can access the "R" statistical package via Ruby, ...
    (comp.lang.ruby)
  • Re: Sample code of Gamma Variate Fitting
    ... I was actually looking for something that can curve fit a gampdf. ... Gamma Variate fitting is very common in biomedical applications. ... saw the gamfit tool in Matlab but I just can't seems to figure out ...
    (comp.soft-sys.matlab)
  • Re: fitting data
    ... i have to fit experimental data to a model given by the ... The upper constraint on b implies that you are fitting based only on data on the declining half of the log-normal curve, and that would seem to doom you to poor estimates because the parameters would seem to be "approximately aliased", in the sense that if you have no information to tell you where the peak is, then there's no way to tell how how high it is and how far down the curve your data are. ...
    (comp.soft-sys.matlab)
  • Re: Curve fitting to data
    ... Does anyone know of a Ruby app that will fit a curve to data eg fitting ... This looks like a prime candidate for GNUPlot -- which ruby has bindings for. ...
    (comp.lang.ruby)
  • Re: How to get the equation of a curve fitting experimental data?
    ... > I would like to fit a curve to this set of data and get the equation ... > of this curve in order to reach the primitive function Y of y. ... > provide any equation for the fitting curve. ... Model fitting to experimental data requires the user to choose ...
    (comp.soft-sys.matlab)