expcalc 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/Rakefile +13 -6
- data/expcalc.gemspec +3 -1
- data/lib/expcalc/array_expansion.rb +26 -15
- data/lib/expcalc/numo_expansion.rb +140 -27
- data/lib/expcalc/version.rb +1 -1
- metadata +34 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f9eaab6610ec89aa3fe75d983c79963bff16043e7edeb3d895dd48f55f7e76
|
4
|
+
data.tar.gz: 3833329850de9158991c40841f1da6fa2eae9b9a9475c7bb1c7e2f64ca7b328e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e5c14c32bde7e0f6d7805f6fe9c9d39da59e438c4665b025806634721f012e5c68c359ecea257c7543815661c4345519a17c74440ae258c958ba40b326349cd
|
7
|
+
data.tar.gz: 7568bd056703c2992192da9b09e3c311ce542e337806b2b347fa35450cc6a7ef9a8e7eaeed6655227c4556234b33a0420654e0ee411657d7e1cc9fd2cf16132b
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Expcalc
|
2
2
|
|
3
|
+
DEPRECATED PROJECT. MIGRATED TO [python expcalc](https://github.com/seoanezonjic/py_exp_calc)
|
4
|
+
|
3
5
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/expcalc`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
6
|
|
5
7
|
TODO: Delete this and the text above, and describe your gem
|
data/Rakefile
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "
|
4
|
+
require "rake/testtask"
|
5
|
+
require 'rdoc/task'
|
5
6
|
|
6
|
-
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.libs << "lib"
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
11
|
+
end
|
7
12
|
|
8
|
-
|
13
|
+
RDoc::Task.new do |rdoc|
|
14
|
+
rdoc.main = "README.doc"
|
15
|
+
rdoc.rdoc_files.include("README.md", "lib/*.rb", "lib/semtools/*.rb")
|
16
|
+
rdoc.options << "--all"
|
17
|
+
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
task default: %i[spec rubocop]
|
19
|
+
task :default => :test
|
data/expcalc.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["seoanezonjic@hotmail.com"]
|
10
10
|
|
11
11
|
spec.summary = "Gem to expand ruby math capabilities"
|
12
|
-
spec.description = "
|
12
|
+
spec.description = "DEPRECATED PROJECT. MIGRATED TO PYTHON: https://github.com/seoanezonjic/py_exp_calc.\nTo expand ruby math operations this gem call to others such as Numo:narray and others and implements methods onto them to deal with our needs"
|
13
13
|
spec.homepage = "https://github.com/seoanezonjic/expcalc"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
@@ -36,6 +36,8 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_dependency "pycall", ">= 1.3.1"
|
37
37
|
spec.add_dependency "npy", ">= 0.2.0"
|
38
38
|
|
39
|
+
spec.add_development_dependency "rake"
|
40
|
+
spec.add_development_dependency "rspec"
|
39
41
|
# For more information and examples about making a new gem, checkout our
|
40
42
|
# guide at: https://bundler.io/guides/creating_gem.html
|
41
43
|
end
|
@@ -4,21 +4,32 @@ class Array
|
|
4
4
|
return self.inject(0){|sum, n | sum + n}.fdiv(self.length)
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def variance(population=false)
|
8
|
+
x_mean = self.mean
|
9
|
+
size = self.length
|
10
|
+
size -= 1 if !population
|
11
|
+
variance = self.inject(0){|sum, n | sum + (n - x_mean)**2 }.fdiv(size)
|
12
|
+
return variance
|
13
|
+
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
-
n_items = self.size
|
16
|
-
quantile_coor = n_items * position - 1
|
17
|
-
if n_items % 2 == 0
|
18
|
-
quantile_value = (self[quantile_coor.to_i] + self[quantile_coor.to_i + 1]).fdiv(2)
|
19
|
-
else
|
20
|
-
quantile_value = self[quantile_coor.ceil]
|
21
|
-
end
|
22
|
-
return quantile_value
|
15
|
+
def standard_deviation(population = false)
|
16
|
+
return Math.sqrt(self.variance(population))
|
23
17
|
end
|
18
|
+
|
19
|
+
def get_quantiles(position=0.5, decreasing_sort = false)
|
20
|
+
sorted_array = self.sort
|
21
|
+
sorted_array.reverse! if decreasing_sort
|
22
|
+
quantile_value = nil
|
23
|
+
|
24
|
+
n_items = self.length
|
25
|
+
quantile_coor = (n_items - 1) * position
|
26
|
+
f_qcoor = quantile_coor.floor.to_i
|
27
|
+
c_qcoor = quantile_coor.ceil.to_i
|
28
|
+
if f_qcoor == c_qcoor
|
29
|
+
quantile_value = sorted_array[f_qcoor]
|
30
|
+
else
|
31
|
+
quantile_value = (sorted_array[f_qcoor] + sorted_array[c_qcoor]).fdiv(2)
|
32
|
+
end
|
33
|
+
return quantile_value
|
34
|
+
end
|
24
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#require 'nmatrix'
|
2
|
-
#require 'nmatrix/lapacke
|
2
|
+
#require 'nmatrix/lapacke
|
3
3
|
require 'numo/narray'
|
4
4
|
require 'numo/linalg'
|
5
5
|
require 'cmath'
|
@@ -13,8 +13,9 @@ class Hash
|
|
13
13
|
x_names_indx = {}
|
14
14
|
i = 0
|
15
15
|
self.each do |k, values|
|
16
|
-
values.each do |val_id|
|
17
|
-
|
16
|
+
values.each do |val_id|
|
17
|
+
val_id = val_id.first if val_id.class == Array
|
18
|
+
query = x_names_indx[val_id]
|
18
19
|
if query.nil?
|
19
20
|
x_names_indx[val_id] = i
|
20
21
|
i += 1
|
@@ -24,8 +25,8 @@ class Hash
|
|
24
25
|
return x_names_indx
|
25
26
|
end
|
26
27
|
|
27
|
-
def to_bmatrix
|
28
|
-
x_names_indx = self.get_hash_values_idx
|
28
|
+
def to_bmatrix
|
29
|
+
x_names_indx = self.get_hash_values_idx
|
29
30
|
y_names = self.keys
|
30
31
|
x_names = x_names_indx.keys
|
31
32
|
# row (y), cols (x)
|
@@ -41,25 +42,55 @@ class Hash
|
|
41
42
|
end
|
42
43
|
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
45
|
+
def to_wmatrix(squared: true, symm: true)
|
46
|
+
if squared
|
47
|
+
matrix, element_names = to_wmatrix_squared(symm: symm)
|
48
|
+
return matrix, element_names
|
49
|
+
else
|
50
|
+
matrix, y_names, x_names = to_wmatrix_rectangular(symm: symm)
|
51
|
+
return matrix, y_names, x_names
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_wmatrix_squared(symm: true)
|
56
|
+
element_names = self.keys
|
57
|
+
matrix = Numo::DFloat.zeros(element_names.length, element_names.length)
|
58
|
+
i = 0
|
59
|
+
self.each do |elementA, relations|
|
60
|
+
element_names.each_with_index do |elementB, j|
|
61
|
+
if elementA != elementB
|
62
|
+
query = relations[elementB]
|
63
|
+
if !query.nil?
|
64
|
+
matrix[i, j] = query
|
65
|
+
elsif symm
|
66
|
+
matrix[i, j] = self[elementB][elementA]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
i += 1
|
71
|
+
end
|
72
|
+
return matrix, element_names
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_wmatrix_rectangular(symm: true)
|
76
|
+
y_names = self.keys
|
77
|
+
x_names = self.get_hash_values_idx.keys
|
78
|
+
p x_names
|
79
|
+
matrix = Numo::DFloat.zeros(y_names.length, x_names.length)
|
80
|
+
i = 0
|
81
|
+
self.each do |elementA, relations|
|
82
|
+
x_names.each_with_index do |elementB, j|
|
83
|
+
query = relations[elementB]
|
84
|
+
if !query.nil?
|
85
|
+
matrix[i, j] = query
|
86
|
+
elsif symm
|
87
|
+
query = self.dig(elementB, elementA)
|
88
|
+
matrix[i, j] = query if !query.nil?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
i += 1
|
92
|
+
end
|
93
|
+
return matrix, y_names, x_names
|
63
94
|
end
|
64
95
|
end
|
65
96
|
|
@@ -95,6 +126,89 @@ module Numo
|
|
95
126
|
Npy.save(matrix_filename, self)
|
96
127
|
end
|
97
128
|
|
129
|
+
def bmatrix_squared_to_hash(elements_names)
|
130
|
+
hash = {}
|
131
|
+
elements_names.each_with_index do |x_name, x_pos|
|
132
|
+
elements_names.each_with_index do |y_name, y_pos|
|
133
|
+
associationValue = self[x_pos, y_pos]
|
134
|
+
if associationValue > 0
|
135
|
+
query = hash[x_name]
|
136
|
+
if query.nil?
|
137
|
+
hash[x_name] = [y_name]
|
138
|
+
else
|
139
|
+
hash[x_name] << y_name
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
return hash
|
145
|
+
end
|
146
|
+
|
147
|
+
def bmatrix_rectangular_to_hash(x_names, y_names)
|
148
|
+
hash = {}
|
149
|
+
x_names.each_with_index do |x_name, x_pos|
|
150
|
+
y_names.each_with_index do |y_name, y_pos|
|
151
|
+
associationValue = self[x_pos, y_pos]
|
152
|
+
if associationValue > 0
|
153
|
+
query = hash[x_name]
|
154
|
+
if query.nil?
|
155
|
+
hash[x_name] = [y_name]
|
156
|
+
else
|
157
|
+
hash[x_name] << y_name
|
158
|
+
end
|
159
|
+
query = hash[y_name]
|
160
|
+
if query.nil?
|
161
|
+
hash[y_name] = [x_name]
|
162
|
+
else
|
163
|
+
hash[y_name] << x_name
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
return hash
|
169
|
+
end
|
170
|
+
|
171
|
+
def wmatrix_squared_to_hash(layers)
|
172
|
+
hash = {}
|
173
|
+
layers.each_with_index do |x_name, x_pos|
|
174
|
+
layers.each_with_index do |y_name, y_pos|
|
175
|
+
associationValue = self[x_pos, y_pos]
|
176
|
+
if associationValue > 0
|
177
|
+
query = hash[x_name]
|
178
|
+
if query.nil?
|
179
|
+
hash[x_name] = {y_name => associationValue}
|
180
|
+
else
|
181
|
+
hash[x_name][y_name] = associationValue
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
return hash
|
187
|
+
end
|
188
|
+
|
189
|
+
def wmatrix_rectangular_to_hash(x_names, y_names)
|
190
|
+
hash = {}
|
191
|
+
x_names.each_with_index do |x_name, x_pos|
|
192
|
+
y_names.each_with_index do |y_name, y_pos|
|
193
|
+
associationValue = self[x_pos, y_pos].to_f
|
194
|
+
if associationValue > 0
|
195
|
+
query = hash[x_name]
|
196
|
+
if query.nil?
|
197
|
+
hash[x_name] = {y_name => associationValue}
|
198
|
+
else
|
199
|
+
hash[x_name][y_name] = associationValue
|
200
|
+
end
|
201
|
+
query = hash[y_name]
|
202
|
+
if query.nil?
|
203
|
+
hash[y_name] = {x_name => associationValue}
|
204
|
+
else
|
205
|
+
hash[y_name][x_name] = associationValue
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
return hash
|
211
|
+
end
|
98
212
|
|
99
213
|
def div(second_mat) #Matrix division A/B => A.dot(B.pinv) #https://stackoverflow.com/questions/49225693/matlab-matrix-division-into-python
|
100
214
|
return self.dot(second_mat.pinv)
|
@@ -256,9 +370,8 @@ module Numo
|
|
256
370
|
end
|
257
371
|
|
258
372
|
def cosine_normalization
|
259
|
-
normalized_matrix =
|
260
|
-
|
261
|
-
self.each_with_indices do |val, i, j|
|
373
|
+
normalized_matrix = Numo::DFloat.zeros(self.shape)
|
374
|
+
self.each_with_index do |val, i, j|
|
262
375
|
norm = val/CMath.sqrt(self[i, i] * self[j,j])
|
263
376
|
#abort("#{norm} has non zero imaginary part" ) if norm.imag != 0
|
264
377
|
normalized_matrix[i, j] = norm#.real
|
data/lib/expcalc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expcalc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seoanezonjic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmath
|
@@ -94,8 +94,37 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.2.0
|
97
|
-
|
98
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: |-
|
126
|
+
DEPRECATED PROJECT. MIGRATED TO PYTHON: https://github.com/seoanezonjic/py_exp_calc.
|
127
|
+
To expand ruby math operations this gem call to others such as Numo:narray and others and implements methods onto them to deal with our needs
|
99
128
|
email:
|
100
129
|
- seoanezonjic@hotmail.com
|
101
130
|
executables:
|
@@ -143,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
172
|
- !ruby/object:Gem::Version
|
144
173
|
version: '0'
|
145
174
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.3.7
|
147
176
|
signing_key:
|
148
177
|
specification_version: 4
|
149
178
|
summary: Gem to expand ruby math capabilities
|