darkhelmet-darkext 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/darkext/statistics.rb +16 -7
- metadata +1 -1
data/lib/darkext/statistics.rb
CHANGED
@@ -38,16 +38,25 @@ class Array
|
|
38
38
|
map.keys.select { |x| map[x] == max }
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
42
|
-
def
|
43
|
-
self.sum_of_squares.to_f /
|
41
|
+
# Population variance
|
42
|
+
def pvariance
|
43
|
+
self.sum_of_squares.to_f / self.size.to_f
|
44
44
|
end
|
45
45
|
|
46
|
-
#
|
47
|
-
def
|
48
|
-
self.
|
46
|
+
# Sample variance
|
47
|
+
def svariance
|
48
|
+
self.sum_of_squares.to_f / (self.size - 1).to_f
|
49
|
+
end
|
50
|
+
|
51
|
+
# Population standard deviation
|
52
|
+
def pdeviation
|
53
|
+
self.pvariance.abs.sqrt
|
54
|
+
end
|
55
|
+
|
56
|
+
# Sample standard deviation
|
57
|
+
def sdeviation
|
58
|
+
self.svariance.abs.sqrt
|
49
59
|
end
|
50
|
-
alias :stddev :deviation
|
51
60
|
|
52
61
|
# Randomly samples n elements
|
53
62
|
def sample(n = 1)
|