darkhelmet-darkext 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +0 -1
- data/lib/darkext/statistics.rb +10 -11
- metadata +2 -4
- data/PostInstall.txt +0 -7
data/Manifest.txt
CHANGED
data/lib/darkext/statistics.rb
CHANGED
@@ -35,18 +35,19 @@ class Array
|
|
35
35
|
def mode
|
36
36
|
map = self.histogram
|
37
37
|
max = map.values.max
|
38
|
-
map.keys.select{ |x| map[x] == max}
|
38
|
+
map.keys.select { |x| map[x] == max }
|
39
39
|
end
|
40
40
|
|
41
41
|
# Finds the variance of the array
|
42
|
-
def variance
|
43
|
-
|
42
|
+
def variance(dof = self.size)
|
43
|
+
self.sum_of_squares.to_f / dof.to_f
|
44
44
|
end
|
45
45
|
|
46
46
|
# Finds the standard deviation of the array
|
47
|
-
def deviation
|
48
|
-
self.variance.sqrt
|
47
|
+
def deviation(dof = self.size)
|
48
|
+
self.variance(dof).abs.sqrt
|
49
49
|
end
|
50
|
+
alias :stddev :deviation
|
50
51
|
|
51
52
|
# Randomly samples n elements
|
52
53
|
def sample(n = 1)
|
@@ -57,7 +58,7 @@ class Array
|
|
57
58
|
# Percent must be 0 < percent < 1 for this to work properly
|
58
59
|
def ci(percent = 0.95, rho = 1)
|
59
60
|
m = self.mean
|
60
|
-
i = ((Statistics
|
61
|
+
i = ((Darkext::Statistics::zscore((1 - percent) / 2) * rho) /
|
61
62
|
self.size.sqrt).abs
|
62
63
|
[m - i, m + i]
|
63
64
|
end
|
@@ -78,16 +79,14 @@ class Array
|
|
78
79
|
|
79
80
|
def sum_of_squares
|
80
81
|
m = self.mean
|
81
|
-
self.map
|
82
|
-
(v - m).square
|
83
|
-
end.sum
|
82
|
+
self.map { |v| v - m }.map(&:square).sum
|
84
83
|
end
|
85
84
|
end
|
86
85
|
module Darkext
|
87
86
|
module Darkext::Statistics
|
88
87
|
# Finds the probability of a z-score
|
89
88
|
def self.prob(z)
|
90
|
-
p = Math
|
89
|
+
p = Math::erf(z.abs/2.sqrt) / 2
|
91
90
|
return 0.5 + p if 0 < z
|
92
91
|
return 0.5 - p
|
93
92
|
end
|
@@ -111,7 +110,7 @@ module Darkext
|
|
111
110
|
probs = r.map do |x|
|
112
111
|
(x - mu) / (rho / n.sqrt)
|
113
112
|
end.map do |x|
|
114
|
-
Statistics
|
113
|
+
Statistics::prob(x)
|
115
114
|
end
|
116
115
|
return 1 - (probs[1] - probs[0])
|
117
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darkhelmet-darkext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Huckstep
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- /home/helmet/.gem/gem-public_cert.pem
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-07 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,11 +39,9 @@ extensions: []
|
|
39
39
|
|
40
40
|
extra_rdoc_files:
|
41
41
|
- Manifest.txt
|
42
|
-
- PostInstall.txt
|
43
42
|
- README.rdoc
|
44
43
|
files:
|
45
44
|
- Manifest.txt
|
46
|
-
- PostInstall.txt
|
47
45
|
- README.rdoc
|
48
46
|
- Rakefile
|
49
47
|
- lib/darkext.rb
|