One can, of course, implement statistical functions in pure Tcl, but the number crunching of Tcl is not particularly fast, so I've implemented two methods in C which do some rudimentary statistics.
The two procedures are sdev and correlate.
sdev fitstatsdefines a new procedure, fitstats, which is used to accumulate data. After it is defined, we can add data to it:
fitstats add 4 fitstats add 5 fitstats add 6Then we can dump the data with:
set average [fitstats average] set deviation [fitstats sdev]In Deal 3.1 you might write:
# Determine the avearge spade length of north if south has # five spades. # # Use "format/none" because we are not interested in specific # deals. # source format/none # # Declare the statistical collector # sdev fitstats main { reject unless {[spades south]==5} fitstats add [spades north] accept } deal_finished { puts "Count=[fitstats count]" puts "Average=[fitstats average]" puts "Deviation=[fitstats sdev]" }The code in deal_finished is executed once, after the appropriate set of deals are generated. Saving this code to the file "fit.tcl" we can run it:
\deal30> deal -i fit.tcl 100000 Count=100000 Average=2.67254 Deviation=1.20679325006
% correlation baz % baz add 10 20 % baz add 20 30 % baz add 30 40 % baz add 40 50 % baz correlate 1.0 %
Thomas Andrews
(deal@thomasoandrews.com)
Copyright 1996-2005. Deal is covered by the
GNU General Public License.
Plane Dealing graphic above created using POV-Ray. |