chris_lib 1.1.11 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chris_lib/chris_math.rb +10 -13
- data/lib/chris_lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea3447c69d66f98ca586f54400ff878b50722e96769865c9a09bc8533e94eec
|
4
|
+
data.tar.gz: 28e1df6aa9b135b88a428b5e8e0b1cd856455c7f224bfee90705c32f742590cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119b1971ba49a8c67486603910279c3e9488b384b80e63e474ec275089a0391febb68cd5ebe4a1f42b74ee968096455d982011bcc4a996c78f5b51642d8357a1
|
7
|
+
data.tar.gz: d04f7889df086aa1f3403383d767bc41877e80220d930f57d8c489deaf6ffab156905b359fd0236b861248cf551fcd8f37c5ab2b12594b5de75666b8828f5e86
|
data/lib/chris_lib/chris_math.rb
CHANGED
@@ -3,7 +3,7 @@ Integer.class_eval do
|
|
3
3
|
def factorial
|
4
4
|
n = self
|
5
5
|
if n > 20
|
6
|
-
|
6
|
+
raise 'Number too large'
|
7
7
|
else
|
8
8
|
(1..n).inject {|prod, i| prod * i}
|
9
9
|
end
|
@@ -32,17 +32,20 @@ Matrix.class_eval do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
Array.class_eval do
|
35
|
+
# round each element
|
36
|
+
def round(n)
|
37
|
+
map { |e| e.round(n) }
|
38
|
+
end
|
39
|
+
|
35
40
|
# mean of array
|
36
41
|
def mean
|
37
|
-
|
38
|
-
# returns 9.705073
|
39
|
-
fail 'Length must be greater than 0.' if length < 1
|
42
|
+
raise 'Length must be greater than 0.' if length < 1
|
40
43
|
sum.to_f / length
|
41
44
|
end
|
42
45
|
|
43
46
|
# unbiased sample variance of array
|
44
47
|
def var
|
45
|
-
|
48
|
+
raise 'Length must be greater than 1' if length < 2
|
46
49
|
mu = mean
|
47
50
|
map { |v| (v**2 - mu**2) }.sum.to_f / (length - 1)
|
48
51
|
end
|
@@ -69,12 +72,6 @@ Array.class_eval do
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
def histogram
|
73
|
-
k = Hash.new(0)
|
74
|
-
self.each { |x| k[x] += 1 }
|
75
|
-
k
|
76
|
-
end
|
77
|
-
|
78
75
|
# deep dup, takes about 20 microseconds for scores arrays
|
79
76
|
# https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
|
80
77
|
def deep_dup
|
@@ -136,7 +133,7 @@ module ChrisMath
|
|
136
133
|
|
137
134
|
def std(values)
|
138
135
|
n = values.length
|
139
|
-
|
136
|
+
raise 'n = #{n} but must be greater than 1' if n < 2
|
140
137
|
m = mean(values)
|
141
138
|
sum = values.inject { |s,v| s + (v**2 - m**2)}
|
142
139
|
sqrt(sum.to_f/(n - 1))
|
@@ -153,7 +150,7 @@ module ChrisMath
|
|
153
150
|
end
|
154
151
|
sum
|
155
152
|
else
|
156
|
-
|
153
|
+
raise 'Error, #{r} must be >= 0 and <= #{n}'
|
157
154
|
end
|
158
155
|
end
|
159
156
|
|
data/lib/chris_lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chris_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|