chris_lib 1.1.11 → 2.0.0
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 +5 -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: 55f439aa3d9c69f76fe0d8e71ca2792d54a86371403c24e48a8b364216f3d1f3
|
4
|
+
data.tar.gz: aa416d12ca0916cf34d54985ad185e1bf4a49ed39befbc39b146f4c9002f1494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08c41d77e18cd3cb849f65feab716370cf0a1d5ac91bdd9a0292c82fe76e0abfa18d352ac3222472b37584fb7fc1e2d25d8e5c37f5468f08b31a562f11cee53
|
7
|
+
data.tar.gz: 17fffc4641e04f756ea8444fcc9e2234d83dc8f46c7c8c56a87fd70d73f320947e5ec1c65645ebb2e739a01736893038e2d453a0c76d41f5ad7274e8a953187f
|
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
|
@@ -34,15 +34,13 @@ end
|
|
34
34
|
Array.class_eval do
|
35
35
|
# mean of array
|
36
36
|
def mean
|
37
|
-
|
38
|
-
# returns 9.705073
|
39
|
-
fail 'Length must be greater than 0.' if length < 1
|
37
|
+
raise 'Length must be greater than 0.' if length < 1
|
40
38
|
sum.to_f / length
|
41
39
|
end
|
42
40
|
|
43
41
|
# unbiased sample variance of array
|
44
42
|
def var
|
45
|
-
|
43
|
+
raise 'Length must be greater than 1' if length < 2
|
46
44
|
mu = mean
|
47
45
|
map { |v| (v**2 - mu**2) }.sum.to_f / (length - 1)
|
48
46
|
end
|
@@ -69,12 +67,6 @@ Array.class_eval do
|
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
|
-
def histogram
|
73
|
-
k = Hash.new(0)
|
74
|
-
self.each { |x| k[x] += 1 }
|
75
|
-
k
|
76
|
-
end
|
77
|
-
|
78
70
|
# deep dup, takes about 20 microseconds for scores arrays
|
79
71
|
# https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
|
80
72
|
def deep_dup
|
@@ -136,7 +128,7 @@ module ChrisMath
|
|
136
128
|
|
137
129
|
def std(values)
|
138
130
|
n = values.length
|
139
|
-
|
131
|
+
raise 'n = #{n} but must be greater than 1' if n < 2
|
140
132
|
m = mean(values)
|
141
133
|
sum = values.inject { |s,v| s + (v**2 - m**2)}
|
142
134
|
sqrt(sum.to_f/(n - 1))
|
@@ -153,7 +145,7 @@ module ChrisMath
|
|
153
145
|
end
|
154
146
|
sum
|
155
147
|
else
|
156
|
-
|
148
|
+
raise 'Error, #{r} must be >= 0 and <= #{n}'
|
157
149
|
end
|
158
150
|
end
|
159
151
|
|
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.0
|
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-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|