File: statistics.html

package info (click to toggle)
deal 3.1.9-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,576 kB
  • sloc: ansic: 5,224; cpp: 4,186; tcl: 3,125; makefile: 203; javascript: 21; sh: 10
file content (110 lines) | stat: -rw-r--r-- 3,077 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- $Id: statistics.html 313 2009-06-11 05:44:13Z thomasoa $ -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="SHORTCUT ICON" HREF="/icon/bridge.ico">
<link rev="made" href="mailto:deal&#64;thomasoandrews.com (Thomas Andrews)">
<link rel="stylesheet" type="text/css" href="look.css">
<title>Statistics in Deal and iDeal</title>

</head>
<body>
<div class="toplevel">
<h1>Statistics in Deal</h1>
<p>
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.
<p>
The two procedures are <span class="code">sdev</span> and <span class="code">correlate</span>.
<p>
<h1>The <span class="code">sdev</span> declaration</h1>
The call:
<pre class="codesample">
sdev fitstats
</pre>
defines a new procedure, <span class="code">fitstats</span>, which is used to accumulate
data.  After it is defined, we can add data to it:
<pre class="codesample">
fitstats add 4
fitstats add 5
fitstats add 6
</pre>
Then we can dump the data with:
<pre class="codesample">
set average [fitstats average]
set deviation [fitstats sdev]
</pre>

In Deal 3.1 you might write:
<pre class="codesample">
# 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]"
}
</pre>

The code in <span class="code">deal_finished</span> is executed once, after the appropriate
set of deals are generated.  Saving this code to the file "fit.tcl" we
can run it:
<pre class="codesample">
\deal30> deal -i fit.tcl 100000
Count=100000
Average=2.67254
Deviation=1.20679325006
</pre>
<h1>The <span class="code">correlation</span> declaration</h1>
The <span class="code">correlation</span> declaration defines a routine much like
the <span class="code">sdev</span> correlation.  It computes the linear correlation
between two data bits.  In tclsh, with iDeal:
<pre class="codesample">
% correlation baz
% baz add 10 20
% baz add 20 30
% baz add 30 40
% baz add 40 50
% baz correlate
1.0
%
</pre>

<hr>
<table><tr><td><a href="http://bridge.thomasoandrews.com/" class="image">
<img style="border:0;width:40px;height:56px" alt="Silhouette" src="graphics/StampSm.gif"></a><td>
Thomas Andrews
(<a href="mailto:deal&#64;thomasoandrews.com">deal&#64;thomasoandrews.com</a>)
Copyright 1996-2010.  Deal is covered by the 
<a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License.</a>
<p>
<a href="graphics/falling.jpg"><em>Plane Dealing</em></a> graphic
above created using
<a href="http://www.povray.org/">POV-Ray.</a>
</tr></table>
</div>
</body>
</html>