public
Description: New development on the Ruby bindings for the GNU Scientific Library
Clone URL: git://github.com/codahale/ruby-gsl.git
Added Array#mean, #variance, and #sd.
codahale (author)
Mon Feb 25 18:02:24 -0800 2008
commit  1d3e5d9ad6a87e2efad4e668f4ac3af21d07a662
tree    7b3c9da1746e946f4288d12afdf1be50b95c1ee4
parent  942e9702e5f992c77f0ea595f373dc8ea274cb05
...
9
10
11
 
 
 
 
 
 
 
 
 
 
 
12
13
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -9,4 +9,15 @@ class Array
0
     end
0
   end
0
   
0
+ def mean
0
+ return GSL::Stats.mean1(self)
0
+ end
0
+
0
+ def variance
0
+ return GSL::Stats.variance1(self)
0
+ end
0
+
0
+ def sd
0
+ return GSL::Stats::sd1(self)
0
+ end
0
 end
0
\ No newline at end of file
...
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
...
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
0
@@ -7,5 +7,27 @@ describe Array do
0
     it "should return a real number" do
0
       [1, 2, 3].correlation([1, 2, 3]).should be_close(1.0, 0.001)
0
     end
0
+
0
+ it "should raise an ArgumentError if the two arrays are of different sizes" do
0
+ lambda { [1, 2, 3].correlation([1, 2]) }.should raise_error(ArgumentError)
0
+ end
0
+ end
0
+
0
+ describe "calculating the mean" do
0
+ it "should return a real number" do
0
+ [1, 2, 3].mean.should be_close(2.0, 0.0001)
0
+ end
0
+ end
0
+
0
+ describe "calculating the variance" do
0
+ it "should return a real number" do
0
+ [1, 2, 3].variance.should be_close(1.0, 0.0001)
0
+ end
0
+ end
0
+
0
+ describe "calculating the standard deviation" do
0
+ it "should return a real number" do
0
+ [2, 2, 2].sd.should be_close(0.0, 0.0001)
0
+ end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.