chris_lib 1.1.9 → 2.0.1

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: 351bd475350c86c89f42a50911ed12805b40dbc259d27144e76ffdd24b64e97c
4
- data.tar.gz: '05915975544fc81f61616f9c736af823c422316b352bc976ac9af570dfa8fc76'
3
+ metadata.gz: a49b1a56101739eda525ada550a7ac6d142bfae37daa8cab662ad1da8e2081fa
4
+ data.tar.gz: 585607c18aa8cdebbfc56fa8f85afa999a10554f64dec38cd0a34492d2a3f4bb
5
5
  SHA512:
6
- metadata.gz: 224d872803a9ba27bb2356cb11b3c1434dce8321b1481f334c3570ee9294f45a19863ccc6f7bea37463a641e52afb7ef44113872f15d17a11e9cab7dd0973ff1
7
- data.tar.gz: d6d0692c4d354b9dabed8099db5f3e4f77afa75a02352f7e41dc0aba943a9f9ec986c8bfc0e7ec19f27c05d305ca163e112c0c65151a864f29240a6bd221562b
6
+ metadata.gz: 2ccbee869659d8937a609458d799902899c13fb6abdd168d3235e0e0713bb52ef6a673778ccbd0a265475e035e7bf75e0cb0634209027dcac47fb023632318e4
7
+ data.tar.gz: caaf85adaca705933ffa161441aba021c69c42d74e36ac201723f6d4b939d4b838ebf06a7a7b87a697e242e832c76e177546eccdce122330cfdec382e09b7894
@@ -1,25 +1,46 @@
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
9
10
  end
10
11
  end
12
+
13
+ Matrix.class_eval do
14
+ # right pseudo-inverse for linearly independent rows
15
+ def pinv
16
+ full_rank = (rank == [row_count, column_count].min)
17
+ raise ExceptionForMatrix::ErrNotRegular unless full_rank
18
+ transpose * (self * transpose).inv
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
32
+ end
33
+
11
34
  Array.class_eval do
12
35
  # mean of array
13
36
  def mean
14
- # s=c(7.08195525827783, 10.831582068121444, 9.288611270369554, 9.054684238411918, 12.268532229606647)
15
- # returns 9.705073
16
- fail 'Length must be greater than 0.' if length < 1
37
+ raise 'Length must be greater than 0.' if length < 1
17
38
  sum.to_f / length
18
39
  end
19
40
 
20
41
  # unbiased sample variance of array
21
42
  def var
22
- fail 'Length must be greater than 1' if length < 2
43
+ raise 'Length must be greater than 1' if length < 2
23
44
  mu = mean
24
45
  map { |v| (v**2 - mu**2) }.sum.to_f / (length - 1)
25
46
  end
@@ -46,12 +67,6 @@ Array.class_eval do
46
67
  end
47
68
  end
48
69
 
49
- def histogram
50
- k = Hash.new(0)
51
- self.each { |x| k[x] += 1 }
52
- k
53
- end
54
-
55
70
  # deep dup, takes about 20 microseconds for scores arrays
56
71
  # https://www.thoughtco.com/making-deep-copies-in-ruby-2907749
57
72
  def deep_dup
@@ -113,7 +128,7 @@ module ChrisMath
113
128
 
114
129
  def std(values)
115
130
  n = values.length
116
- 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
117
132
  m = mean(values)
118
133
  sum = values.inject { |s,v| s + (v**2 - m**2)}
119
134
  sqrt(sum.to_f/(n - 1))
@@ -130,7 +145,7 @@ module ChrisMath
130
145
  end
131
146
  sum
132
147
  else
133
- fail 'Error, #{r} must be >= 0 and <= #{n}'
148
+ raise 'Error, #{r} must be >= 0 and <= #{n}'
134
149
  end
135
150
  end
136
151
 
@@ -1,3 +1,3 @@
1
1
  module ChrisLib
2
- VERSION = "1.1.9"
2
+ VERSION = "2.0.1"
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,177 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chris_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-24 00:00:00.000000000 Z
11
+ date: 2021-08-28 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
24
  - - ">="
41
25
  - !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: loofah
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '2.3'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 2.3.1
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '2.3'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 2.3.1
26
+ version: '0'
73
27
  - !ruby/object:Gem::Dependency
74
28
  name: rails
75
29
  requirement: !ruby/object:Gem::Requirement
76
30
  requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: '5.1'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 5.1.4.3
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '5.1'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 5.1.4.3
93
- - !ruby/object:Gem::Dependency
94
- name: rspec-rails
95
- requirement: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '3.7'
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 3.7.2
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '3.7'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 3.7.2
113
- - !ruby/object:Gem::Dependency
114
- name: sqlite3
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '1.3'
120
31
  - - ">="
121
32
  - !ruby/object:Gem::Version
122
- version: 1.3.11
123
- type: :development
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '1.3'
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: 1.3.11
133
- - !ruby/object:Gem::Dependency
134
- name: nokogiri
135
- requirement: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: '1.10'
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: 1.10.8
143
- type: :development
144
- prerelease: false
145
- version_requirements: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - "~>"
148
- - !ruby/object:Gem::Version
149
- version: '1.10'
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: 1.10.8
153
- - !ruby/object:Gem::Dependency
154
- name: rack
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '2.0'
160
- - - ">="
161
- - !ruby/object:Gem::Version
162
- version: 2.2.3
163
- type: :development
33
+ version: '0'
34
+ type: :runtime
164
35
  prerelease: false
165
36
  version_requirements: !ruby/object:Gem::Requirement
166
37
  requirements:
167
- - - "~>"
168
- - !ruby/object:Gem::Version
169
- version: '2.0'
170
38
  - - ">="
171
39
  - !ruby/object:Gem::Version
172
- version: 2.2.3
40
+ version: '0'
173
41
  - !ruby/object:Gem::Dependency
174
- name: sass-rails
42
+ name: rspec
175
43
  requirement: !ruby/object:Gem::Requirement
176
44
  requirements:
177
45
  - - ">="
@@ -185,7 +53,7 @@ dependencies:
185
53
  - !ruby/object:Gem::Version
186
54
  version: '0'
187
55
  - !ruby/object:Gem::Dependency
188
- name: uglifier
56
+ name: nokogiri
189
57
  requirement: !ruby/object:Gem::Requirement
190
58
  requirements:
191
59
  - - ">="
@@ -199,7 +67,7 @@ dependencies:
199
67
  - !ruby/object:Gem::Version
200
68
  version: '0'
201
69
  - !ruby/object:Gem::Dependency
202
- name: jquery-rails
70
+ name: pry
203
71
  requirement: !ruby/object:Gem::Requirement
204
72
  requirements:
205
73
  - - ">="
@@ -234,7 +102,7 @@ licenses:
234
102
  metadata:
235
103
  source_code_uri: https://github.com/obromios/chris_lib
236
104
  changelog_uri: https://github.com/obromios/chris_lib/blob/master/CHANGELOG.md
237
- post_install_message:
105
+ post_install_message:
238
106
  rdoc_options: []
239
107
  require_paths:
240
108
  - lib
@@ -249,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
117
  - !ruby/object:Gem::Version
250
118
  version: '0'
251
119
  requirements: []
252
- rubygems_version: 3.1.2
253
- signing_key:
120
+ rubygems_version: 3.1.6
121
+ signing_key:
254
122
  specification_version: 4
255
123
  summary: This an eclectic collection of methods. It include maths, datetime, and rspec
256
124
  access test libraries.