chris_lib 1.1.10 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7af77d04c120dacf88cc6d208c51e31c7d8eb35b280cfba48b93f0815329053c
4
- data.tar.gz: 276f996bd4f5bd2a81b00c6ece959cf4bb26206e70970087022beea1d49eb3a0
3
+ metadata.gz: 0aa6a70c43d3a1eb61de63a1512ebb5d923ad1b7ef9c7b696a6756d6a54ab43d
4
+ data.tar.gz: aca4e314380f79a159a1392ab5d14e8d9a6a5c7bbe3b294f0b55d4157552b0e2
5
5
  SHA512:
6
- metadata.gz: b4ff3203d46941297016836351413c0116e19a288514b32cd2febb4bc1913fe4d679be202da0296cefe6c570ceb77238c932742e002c73cff33e76c1c0111914
7
- data.tar.gz: 1c046877f6451c2b144f8f2dfded4d148eb2cbc2d00ec2e0b2d9cc73d5d19af52add06b6c8347a82a35f43e977cc041a6752000054ce748dd43e8c1ef0b36e8f
6
+ metadata.gz: 7b3dad798054cf7d62ddca361c33f5718e1fc91a977ac64109a763adb1e27d39fc291e145e063ddfb514df2b275d1cc006717930769c0db782ea27335782bd8a
7
+ data.tar.gz: '068762bb346e73ee1ff196778a9e3386620743d238c871cfdd72c1ea89c26869ec09a97e36b1a8f1e8241929f053c51361b01efdc8c6bea4b22481053ac54c61'
@@ -1,8 +1,9 @@
1
+ require 'matrix'
1
2
  Integer.class_eval do
2
3
  def factorial
3
4
  n = self
4
5
  if n > 20
5
- fail 'Number too large'
6
+ raise 'Number too large'
6
7
  else
7
8
  (1..n).inject {|prod, i| prod * i}
8
9
  end
@@ -10,25 +11,36 @@ Integer.class_eval do
10
11
  end
11
12
 
12
13
  Matrix.class_eval do
14
+ # right pseudo-inverse for linearly independent rows
13
15
  def pinv
14
16
  full_rank = (rank == [row_count, column_count].min)
15
17
  raise ExceptionForMatrix::ErrNotRegular unless full_rank
16
18
  transpose * (self * transpose).inv
17
19
  end
20
+
21
+ # for linearly independent rows
22
+ def pinv_right
23
+ full_rank = (rank == [row_count, column_count].min)
24
+ raise ExceptionForMatrix::ErrNotRegular unless full_rank
25
+ transpose * (self * transpose).inv
26
+ end
27
+
28
+ # for linearly independent columns
29
+ def pinv_left
30
+ (transpose * self).inv * transpose
31
+ end
18
32
  end
19
33
 
20
34
  Array.class_eval do
21
35
  # mean of array
22
36
  def mean
23
- # s=c(7.08195525827783, 10.831582068121444, 9.288611270369554, 9.054684238411918, 12.268532229606647)
24
- # returns 9.705073
25
- fail 'Length must be greater than 0.' if length < 1
37
+ raise 'Length must be greater than 0.' if length < 1
26
38
  sum.to_f / length
27
39
  end
28
40
 
29
41
  # unbiased sample variance of array
30
42
  def var
31
- fail 'Length must be greater than 1' if length < 2
43
+ raise 'Length must be greater than 1' if length < 2
32
44
  mu = mean
33
45
  map { |v| (v**2 - mu**2) }.sum.to_f / (length - 1)
34
46
  end
@@ -55,12 +67,6 @@ Array.class_eval do
55
67
  end
56
68
  end
57
69
 
58
- def histogram
59
- k = Hash.new(0)
60
- self.each { |x| k[x] += 1 }
61
- k
62
- end
63
-
64
70
  # deep dup, takes about 20 microseconds for scores arrays
65
71
  # https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
66
72
  def deep_dup
@@ -122,7 +128,7 @@ module ChrisMath
122
128
 
123
129
  def std(values)
124
130
  n = values.length
125
- fail 'n = #{n} but must be greater than 1' if n < 2
131
+ raise 'n = #{n} but must be greater than 1' if n < 2
126
132
  m = mean(values)
127
133
  sum = values.inject { |s,v| s + (v**2 - m**2)}
128
134
  sqrt(sum.to_f/(n - 1))
@@ -139,7 +145,7 @@ module ChrisMath
139
145
  end
140
146
  sum
141
147
  else
142
- fail 'Error, #{r} must be >= 0 and <= #{n}'
148
+ raise 'Error, #{r} must be >= 0 and <= #{n}'
143
149
  end
144
150
  end
145
151
 
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "1.1.10"
2
+ VERSION = "2.0.2"
3
3
  end
data/lib/chris_lib.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'matrix'
1
2
  require "chris_lib/version"
2
3
  require "chris_lib/date_ext"
3
4
  require "chris_lib/test_access"
metadata CHANGED
@@ -1,197 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chris_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.10
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.2'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 2.2.1
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.2'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.2.1
33
- - !ruby/object:Gem::Dependency
34
- name: actionview
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '5.1'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 5.2.4.3
43
- type: :development
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '5.1'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 5.2.4.3
53
- - !ruby/object:Gem::Dependency
54
- name: actionpack
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '5.2'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 5.2.4.6
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '5.2'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 5.2.4.6
73
- - !ruby/object:Gem::Dependency
74
- name: loofah
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: '2.3'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 2.3.1
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.3'
90
24
  - - ">="
91
25
  - !ruby/object:Gem::Version
92
- version: 2.3.1
26
+ version: '0'
93
27
  - !ruby/object:Gem::Dependency
94
28
  name: rails
95
29
  requirement: !ruby/object:Gem::Requirement
96
30
  requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '5.1'
100
31
  - - ">="
101
32
  - !ruby/object:Gem::Version
102
- version: 5.1.4.6
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '5.1'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 5.1.4.6
113
- - !ruby/object:Gem::Dependency
114
- name: rspec-rails
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '3.7'
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 3.7.2
123
- type: :development
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '3.7'
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: 3.7.2
133
- - !ruby/object:Gem::Dependency
134
- name: sqlite3
135
- requirement: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: '1.3'
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: 1.3.11
143
- type: :development
144
- prerelease: false
145
- version_requirements: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - "~>"
148
- - !ruby/object:Gem::Version
149
- version: '1.3'
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: 1.3.11
153
- - !ruby/object:Gem::Dependency
154
- name: nokogiri
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '1.10'
160
- - - ">="
161
- - !ruby/object:Gem::Version
162
- version: 1.11.4
163
- type: :development
164
- prerelease: false
165
- version_requirements: !ruby/object:Gem::Requirement
166
- requirements:
167
- - - "~>"
168
- - !ruby/object:Gem::Version
169
- version: '1.10'
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- version: 1.11.4
173
- - !ruby/object:Gem::Dependency
174
- name: rack
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - "~>"
178
- - !ruby/object:Gem::Version
179
- version: '2.0'
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: 2.2.3
183
- type: :development
33
+ version: '0'
34
+ type: :runtime
184
35
  prerelease: false
185
36
  version_requirements: !ruby/object:Gem::Requirement
186
37
  requirements:
187
- - - "~>"
188
- - !ruby/object:Gem::Version
189
- version: '2.0'
190
38
  - - ">="
191
39
  - !ruby/object:Gem::Version
192
- version: 2.2.3
40
+ version: '0'
193
41
  - !ruby/object:Gem::Dependency
194
- name: sass-rails
42
+ name: rspec
195
43
  requirement: !ruby/object:Gem::Requirement
196
44
  requirements:
197
45
  - - ">="
@@ -205,7 +53,7 @@ dependencies:
205
53
  - !ruby/object:Gem::Version
206
54
  version: '0'
207
55
  - !ruby/object:Gem::Dependency
208
- name: uglifier
56
+ name: nokogiri
209
57
  requirement: !ruby/object:Gem::Requirement
210
58
  requirements:
211
59
  - - ">="
@@ -219,7 +67,7 @@ dependencies:
219
67
  - !ruby/object:Gem::Version
220
68
  version: '0'
221
69
  - !ruby/object:Gem::Dependency
222
- name: jquery-rails
70
+ name: pry
223
71
  requirement: !ruby/object:Gem::Requirement
224
72
  requirements:
225
73
  - - ">="
@@ -269,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
117
  - !ruby/object:Gem::Version
270
118
  version: '0'
271
119
  requirements: []
272
- rubygems_version: 3.1.2
120
+ rubygems_version: 3.1.6
273
121
  signing_key:
274
122
  specification_version: 4
275
123
  summary: This an eclectic collection of methods. It include maths, datetime, and rspec