|
From: James R. V. Z. <jr...@co...> - 2009-02-14 02:38:01
|
My new fitting code is working.
I had proposed these formats:
>>> v:x:y:z:s
>>> u:v:x:y:z:s
>>> t:u:v:x:y:z:s
Peter and Ethan objected to the ordering. I eventually changed my
mind, deciding the following set of formats was easier to implement,
to explain, and to remember:
z
x:z
x:z:s
x:y:z:s
x:y:t:z:s
x:y:t:u:z:s
x:y:t:u:v:z:s
If you have three or more using specs, then the last one is for
standard deviation, the next to last is for Z values (dependent
variable), and all the preceding ones are for independent variables.
And the first two dummy variables are always 'x' and 'y'.
Here are some examples:
fit a*x + b*y + c*t 'foo.dat' using 1:2:3:4:(1) via a,b,c
h(x,y,t,u,v) = a*x + b*y + c*t + d*u + e*v
fit h(x,y,t,u,v) 'foo.dat' using 1:2:3:4:5:6:(1) via a,b,c,d,e
You can also use ranges, including those that change the dummy
variable names:
g(x,yaks,tulips) = a*x+b*yaks+c*tulips
fit [*:9][yaks=*:*][tulips=*:*] g(x,yaks,tulips) 'surface.dat' u 1:2:3:(1) via a,b,c
I have uploaded a patch and a set of data files and demo scripts here:
http://jrv.oddones.org/fit-patch
http://jrv.oddones.org/fit-demo.tar.gz
The only code I touched was in fit.c. However, it involved a lot of
things I have not worked with before, so I would rather other
developers would check out the patch before I commit the changes.
For example:
I'm using the T, U, and V axes to store range information. Are there
side effects? Would it be better to set those entries in df_axis to
NO_AXIS and store range information separately?
You can still do a one- or two-variable fit with a function using
"t" as a regular user-defined variable. However, if your fit
function includes "t" but you haven't defined it, you don't get an
"undefined variable" error. That's because while gnuplot is parsing
the expression, it assumes "t" is an independent variable, and
doesn't discover differently until later. How can this be fixed?
I don't think there are any new memory leaks. Is there a way to
automatically check for leaks?
I think any of the new columns can have time formats. However, I
don't use time data myself, and haven't tested it.
Though this code allows up to five independent variables, I would
really rather there was no fixed limit. There are at least a couple
of challenges in removing the limit:
- df_readascii is set up to read a maximum of seven columns.
- For an arbitrary number of variables, we would also need a set of
dummy variable names that can be extended. For example:
z
x:z
x:z:s
x:y:z:s
x:y:t1:z:s
x:y:t1:t2:z:s
x:y:t1:t2:t3:z:s
x:y:t1:t2:t3:t4:z:s
...
This would be incompatible with the names I have used.
Or, we could decide that any user who wants more than five independent
variables would have to supply their own dummy variable names in range
specs.
I noticed Z ranges were implemented in the code, but were not
documented or reported in the log file. The log file reported "using"
specs and the fit function. Also, if some range spec changed a dummy
variable name, the new name was not reported, making it hard to
interpret the reported range and fit function. I have fixed those
bugs.
Every now and then while fitting, I have gotten an error message "No
data to fit" which brings me up short. So while I was working in the
area, I expanded the report like this:
fit [-4:4][yaks=-2:2][4:4][0:22] a*x+b*yaks+c*t 'lin3.dat' u 1:2:3:4:5 via a,b,c
Read 64 points
Skipped 32 points outside range [x=-4:4]
Skipped 24 points outside range [yaks=-2:2]
Skipped 6 points outside range [t=4:4]
Skipped 2 points outside range [z=0:22]
No data to fit
(If there are points to fit, nothing new is printed.)
So, let me know what you think.
- Jim Van Zandt
|