visualdatatools.com Forum Index visualdatatools.com
Discussion for DataTank and DataGraph
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Arbitrary Fit Algorithm...

 
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Request Fit Function
View previous topic :: View next topic  
Author Message
paploo



Joined: 27 Nov 2006
Posts: 25
Location: Spokane, WA

PostPosted: Mon Nov 27, 2006 7:37 pm    Post subject: Arbitrary Fit Algorithm... Reply with quote

I'm an active one on these boards today. I guess I'm just excited by a program that does a lot of what I do in Excel, all the while wishing I had something geared towards scientific data analysis and not financial data analysis. :)

You have covered the bulk of the fit functions that a scientist would want to use for the bulk of situations. However the theory often predicts a function of a shape that is well-known but isn't one of these simple fit curves, or the theory puts restrictions on these curves such as that they are quadratic but the constant term must be zero.

In these cases, it is desireable to know the best fit function to your theoretical function.

The general way of handling this is to allow the input of a fit function expression (such as A*cos(w*x-b)+c), and then to note that the input parameter is x, and that the free parameters that need to be fit are A, w, b, and c.

Now ideally the program could go off and find the set of parameters that minimizes the standard deviation, but this is a bit tricky. Therefore it is often good enough to allow the user to put in guesses that start off an iterative solving algorithm that is capable of seeking out a local minima in the n-dimensional space.

There are plenty of good references on how to solve problems of this kind (though I cannot think of any off hand), and it is not too difficult to employ one of the simpler minima finding algorithms.

Thank you once again for your time. :)
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1938
Location: Chapel Hill, NC

PostPosted: Mon Nov 27, 2006 8:49 pm    Post subject: Reply with quote

Agree, and my big program - DataTank does this type of non-linear least squares fit. You definitely have to give initial guesses and success is often very dependent on good guesses.

I am planning on adding this, for sure, but first I want to get a good list of functions that might be non-linear but I can generate good initial guesses.

Things like
a/(1+b*x)

a*x/(1+b*x)

a - b*exp(-c*x)


I am for example going to add a method that allows you to specify only even powers etc. When that is ready, DataPlot will notify you of the new version.

David
Back to top
View user's profile Send private message Send e-mail
paploo



Joined: 27 Nov 2006
Posts: 25
Location: Spokane, WA

PostPosted: Mon Nov 27, 2006 9:02 pm    Post subject: I figured... Reply with quote

I figured that you might have had that feature on your list, but now you know that someone like me is anxiously awaiting it. :)
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1938
Location: Chapel Hill, NC

PostPosted: Mon Jan 15, 2007 10:20 pm    Post subject: Reply with quote

OK.

Finally, it's in the beta, and planned for 1.2.1

http://www.visualdatatools.com/DataPlot/DataPlotBeta.dmg

You can specify any expression, and specify which coefficients should be optimized. The problem with non-linear least squares is that it's not always possible to find a local minima let alone the global minima. To work around that, I draw the initial guess (you can specify the line style).

That means that you might need to tweak the coefficients before the drawing command finds the minima.

If you have specific functions, such as a - b*exp(-c*x) it is often possible to come up with a good initial guess programmatically. Therefore, if there are standard functions that you want to fit and think should be in the menu, please discuss that on this forum.

Also, if the routine doesn't find the minima, even though the initial guess looks to be in the ballbark, let me know.

David
Back to top
View user's profile Send private message Send e-mail
paploo



Joined: 27 Nov 2006
Posts: 25
Location: Spokane, WA

PostPosted: Mon Jan 15, 2007 11:24 pm    Post subject: Pokin' at it now... Reply with quote

Cool. My most desired feature. :)

I'm poking at it now, and it seems to be having some problems with some trig function fittting, though this may be highly related to not knowing exactly how the algorithm works.


I generated some data by making my x column be the integer values 0 through 10 inclusive, and making my y column be the function sin(0.628*x). (This, of course, plots a sine wave whose period is 10.)

I then went in and had it fit the function: a*cos(k*x-phi)
Note that I chose cosine instead of sine on purpose, knowing that by setting phi to an appropriate value (such as about 1.571), it would give me a sine wave.

With all three variables having "Optimize" on, trying a=0.905, k=0.60, and q=1.55 didn't output anything. If I un-check optimize on any of the three, then I get a fit, though in two of the situations my inital guess is even better than the fit!

The other thing that makes this difficult is that if it cannot find a fit at all, the initial guess curve isn't drawn at all. Since fitting a cosine to a sine only works in special occassions, it makes it really hard to visually make a guess without plotting the function and using global parameter sliders to find a good guess first, and then input those values into the fitting function.

For the record, I had better luck with fitting a sine onto the sine, but with oscillations you don't usually know the phase to be able to get away with that luxury. :)



Anyway, that is what I see thus far.

:)
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1938
Location: Chapel Hill, NC

PostPosted: Tue Jan 16, 2007 10:44 am    Post subject: Reply with quote

I uploaded a new version. This version does display the initial guess when nothing is found (the reason why it is there).

But it still doesn't do a good job of finding the minima. I will adjust the method so that it does better in cases like this where there is a lot of local minima and things tend to bounce around.

David
Back to top
View user's profile Send private message Send e-mail
paploo



Joined: 27 Nov 2006
Posts: 25
Location: Spokane, WA

PostPosted: Tue Jan 16, 2007 3:08 pm    Post subject: Reply with quote

Thanks and good luck. :) (Stupid periodic functions making a mess out of things.) :)
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1938
Location: Chapel Hill, NC

PostPosted: Tue Apr 03, 2007 9:31 pm    Post subject: Finally Reply with quote

Well, after a false start, I implemented the arbitrary fit function in 1.2.3. This will work a lot better than in the earlier beta. I also tweaked the UI to display the initial guess if the fit fails.

I am still interested in knowing if there are other types of fits (double exponential, gaussian, etc) that people want and might need some tweaking to get a good enough initial guess.
Back to top
View user's profile Send private message Send e-mail
paploo



Joined: 27 Nov 2006
Posts: 25
Location: Spokane, WA

PostPosted: Wed Apr 04, 2007 2:42 pm    Post subject: Reply with quote

It's been quiet around here lately. :)

My primary vote is for a quick way to do a gaussian bell curve. Note that when working with pre-normalized data, the constant out in front is a function of the standard deviation, but that if the data isn't pre-normalized, another behavior needs to be done (of which maybe it should just auto-normalize, or maybe it should find the best-fit with the constant in front being an independent variable... I don't know which is right off the top of my head--I can't think before coffee!)

I, of course, would like a way to do a simple periodic (A*cos(w*x-a), with A, x, and a as independent variables), but one thing I find happening often, is wanting to find a fit of a linear combination of periodic functions that fit the data. This, of course, moves into the realm of fourier analysis, which gets complicated, but so far I've yet to find a product that attempts to give me a cos/sin based real-valued function that fits the data I give to it. (Maybe I'm asking too much.) :)

Outside of that, my fitting needs tend to be non-repeatable, as I am trying to best-fit against some equation that I've theoretically derived.
Back to top
View user's profile Send private message
pariah99



Joined: 06 Mar 2014
Posts: 2

PostPosted: Mon Oct 06, 2014 2:10 pm    Post subject: Reply with quote

Is there any way currently, or plans in the future to restrict the fitted parameters to a certain range? i.e. if we want to optimize parameters for an arbitrary function, I would like to be able to specify the range to optimize the parameter (>0, <0, or in between -1 and 1, etc)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Request Fit Function All times are GMT - 3 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group