| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<!-- $Id: statistics.html 313 2009-06-11 05:44:13Z thomasoa $ --> |
| 6 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 7 |
<LINK REL="SHORTCUT ICON" HREF="/icon/bridge.ico"> |
| 8 |
<link rev="made" href="mailto:deal@thomasoandrews.com (Thomas Andrews)"> |
| 9 |
<link rel="stylesheet" type="text/css" href="look.css"> |
| 10 |
<title>Statistics in Deal and iDeal</title> |
| 11 |
|
| 12 |
</head> |
| 13 |
<body> |
| 14 |
<div class="toplevel"> |
| 15 |
<h1>Statistics in Deal</h1> |
| 16 |
<p> |
| 17 |
One can, of course, implement statistical functions in pure Tcl, but |
| 18 |
the number crunching of Tcl is not particularly fast, so I've implemented |
| 19 |
two methods in C which do some rudimentary statistics. |
| 20 |
<p> |
| 21 |
The two procedures are <span class="code">sdev</span> and <span class="code">correlate</span>. |
| 22 |
<p> |
| 23 |
<h1>The <span class="code">sdev</span> declaration</h1> |
| 24 |
The call: |
| 25 |
<pre class="codesample"> |
| 26 |
sdev fitstats |
| 27 |
</pre> |
| 28 |
defines a new procedure, <span class="code">fitstats</span>, which is used to accumulate |
| 29 |
data. After it is defined, we can add data to it: |
| 30 |
<pre class="codesample"> |
| 31 |
fitstats add 4 |
| 32 |
fitstats add 5 |
| 33 |
fitstats add 6 |
| 34 |
</pre> |
| 35 |
Then we can dump the data with: |
| 36 |
<pre class="codesample"> |
| 37 |
set average [fitstats average] |
| 38 |
set deviation [fitstats sdev] |
| 39 |
</pre> |
| 40 |
|
| 41 |
In Deal 3.1 you might write: |
| 42 |
<pre class="codesample"> |
| 43 |
# Determine the avearge spade length of north if south has |
| 44 |
# five spades. |
| 45 |
|
| 46 |
# |
| 47 |
# Use "format/none" because we are not interested in specific |
| 48 |
# deals. |
| 49 |
# |
| 50 |
source format/none |
| 51 |
|
| 52 |
# |
| 53 |
# Declare the statistical collector |
| 54 |
# |
| 55 |
sdev fitstats |
| 56 |
|
| 57 |
main { |
| 58 |
reject unless {[spades south]==5} |
| 59 |
|
| 60 |
fitstats add [spades north] |
| 61 |
|
| 62 |
accept |
| 63 |
} |
| 64 |
|
| 65 |
deal_finished { |
| 66 |
puts "Count=[fitstats count]" |
| 67 |
puts "Average=[fitstats average]" |
| 68 |
puts "Deviation=[fitstats sdev]" |
| 69 |
} |
| 70 |
</pre> |
| 71 |
|
| 72 |
The code in <span class="code">deal_finished</span> is executed once, after the appropriate |
| 73 |
set of deals are generated. Saving this code to the file "fit.tcl" we |
| 74 |
can run it: |
| 75 |
<pre class="codesample"> |
| 76 |
\deal30> deal -i fit.tcl 100000 |
| 77 |
Count=100000 |
| 78 |
Average=2.67254 |
| 79 |
Deviation=1.20679325006 |
| 80 |
</pre> |
| 81 |
<h1>The <span class="code">correlation</span> declaration</h1> |
| 82 |
The <span class="code">correlation</span> declaration defines a routine much like |
| 83 |
the <span class="code">sdev</span> correlation. It computes the linear correlation |
| 84 |
between two data bits. In tclsh, with iDeal: |
| 85 |
<pre class="codesample"> |
| 86 |
% correlation baz |
| 87 |
% baz add 10 20 |
| 88 |
% baz add 20 30 |
| 89 |
% baz add 30 40 |
| 90 |
% baz add 40 50 |
| 91 |
% baz correlate |
| 92 |
1.0 |
| 93 |
% |
| 94 |
</pre> |
| 95 |
|
| 96 |
<hr> |
| 97 |
<table><tr><td><a href="http://bridge.thomasoandrews.com/" class="image"> |
| 98 |
<img style="border:0;width:40px;height:56px" alt="Silhouette" src="graphics/StampSm.gif"></a><td> |
| 99 |
Thomas Andrews |
| 100 |
(<a href="mailto:deal@thomasoandrews.com">deal@thomasoandrews.com</a>) |
| 101 |
Copyright 1996-2010. Deal is covered by the |
| 102 |
<a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License.</a> |
| 103 |
<p> |
| 104 |
<a href="graphics/falling.jpg"><em>Plane Dealing</em></a> graphic |
| 105 |
above created using |
| 106 |
<a href="http://www.povray.org/">POV-Ray.</a> |
| 107 |
</tr></table> |
| 108 |
</div> |
| 109 |
</body> |
| 110 |
</html> |