
visualdatatools.com Discussion for DataTank and DataGraph

View previous topic :: View next topic 
Author 
Message 
paploo
Joined: 27 Nov 2006 Posts: 25 Location: Spokane, WA

Posted: Mon Nov 27, 2006 7:37 pm Post subject: Arbitrary Fit Algorithm... 


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 wellknown 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*xb)+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 ndimensional 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 


David Site Admin
Joined: 25 Nov 2006 Posts: 1964 Location: Chapel Hill, NC

Posted: Mon Nov 27, 2006 8:49 pm Post subject: 


Agree, and my big program  DataTank does this type of nonlinear 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 nonlinear 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 


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

Posted: Mon Nov 27, 2006 9:02 pm Post subject: I figured... 


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 


David Site Admin
Joined: 25 Nov 2006 Posts: 1964 Location: Chapel Hill, NC

Posted: Mon Jan 15, 2007 10:20 pm Post subject: 


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 nonlinear 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 


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

Posted: Mon Jan 15, 2007 11:24 pm Post subject: Pokin' at it now... 


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*xphi)
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 uncheck 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 


David Site Admin
Joined: 25 Nov 2006 Posts: 1964 Location: Chapel Hill, NC

Posted: Tue Jan 16, 2007 10:44 am Post subject: 


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 


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

Posted: Tue Jan 16, 2007 3:08 pm Post subject: 


Thanks and good luck. :) (Stupid periodic functions making a mess out of things.) :) 

Back to top 


David Site Admin
Joined: 25 Nov 2006 Posts: 1964 Location: Chapel Hill, NC

Posted: Tue Apr 03, 2007 9:31 pm Post subject: Finally 


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 


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

Posted: Wed Apr 04, 2007 2:42 pm Post subject: 


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 prenormalized data, the constant out in front is a function of the standard deviation, but that if the data isn't prenormalized, another behavior needs to be done (of which maybe it should just autonormalize, or maybe it should find the bestfit with the constant in front being an independent variable... I don't know which is right off the top of my headI can't think before coffee!)
I, of course, would like a way to do a simple periodic (A*cos(w*xa), 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 realvalued function that fits the data I give to it. (Maybe I'm asking too much.) :)
Outside of that, my fitting needs tend to be nonrepeatable, as I am trying to bestfit against some equation that I've theoretically derived. 

Back to top 


pariah99
Joined: 06 Mar 2014 Posts: 2

Posted: Mon Oct 06, 2014 2:10 pm Post subject: 


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 




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
