rust 0.7 → 0.9

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.
@@ -1,5 +1,4 @@
1
- require_relative 'rust-core'
2
- require_relative 'rust-calls'
1
+ require_relative '../core'
3
2
 
4
3
  module Rust::Plots
5
4
  class BasePlot
@@ -134,173 +133,6 @@ module Rust::Plots
134
133
  end
135
134
  end
136
135
 
137
- class ScatterPlot < BasePlot
138
- def initialize(x = nil, y = nil, **options)
139
- super()
140
- @series = []
141
- if x && y
142
- self.series(x, y, options)
143
- end
144
- end
145
-
146
- def series(x, y, **options)
147
- @series << [x, y, options]
148
-
149
- return self
150
- end
151
-
152
- def thickness(t)
153
- self['lwd'] = t
154
-
155
- return self
156
- end
157
-
158
- def lines()
159
- self['type'] = "l"
160
-
161
- return self
162
- end
163
-
164
- def points()
165
- self['type'] = "p"
166
-
167
- return self
168
- end
169
-
170
- def lines_and_points()
171
- self['type'] = "b"
172
-
173
- return self
174
- end
175
-
176
- protected
177
- def _show()
178
- first = true
179
- palette = self.palette(@series.size)
180
- i = 0
181
-
182
- base_options = {}
183
- unless @options['xlim']
184
- x_values = @series.map { |v| v[0] }.flatten
185
- y_values = @series.map { |v| v[1] }.flatten
186
-
187
- base_options[:xlim] = [x_values.min, x_values.max]
188
- base_options[:ylim] = [y_values.min, y_values.max]
189
- end
190
-
191
- @series.each do |x, y, options|
192
- options = options.merge(base_options)
193
- Rust["plotter.x"] = x
194
- Rust["plotter.y"] = y
195
-
196
- function = nil
197
- if first
198
- function = Rust::Function.new("plot")
199
- first = false
200
- else
201
- function = Rust::Function.new("lines")
202
- end
203
-
204
- augmented_options = {}
205
- augmented_options['col'] = options[:color] || palette[i]
206
- augmented_options['xlim'] = options[:xlim] if options[:xlim]
207
- augmented_options['ylim'] = options[:ylim] if options[:ylim]
208
-
209
- function.options = self._augmented_options(augmented_options)
210
- function.arguments << Rust::Variable.new("plotter.x")
211
- function.arguments << Rust::Variable.new("plotter.y")
212
-
213
- function.call
214
-
215
- i += 1
216
- end
217
-
218
- return self
219
- end
220
- end
221
-
222
- class BarPlot < BasePlot
223
- def initialize(bars)
224
- super()
225
- @bars = bars
226
- end
227
-
228
- protected
229
- def _show()
230
- Rust["plotter.bars"] = @bars.values
231
- Rust["plotter.labels"] = @bars.keys
232
-
233
- Rust._eval("names(plotter.bars) <- plotter.labels")
234
-
235
- function = Rust::Function.new("barplot")
236
- function.options = self._augmented_options
237
- function.arguments << Rust::Variable.new("plotter.bars")
238
-
239
- function.call
240
-
241
- return self
242
- end
243
- end
244
-
245
- class DistributionPlot < BasePlot
246
- def initialize
247
- super()
248
- @series = []
249
- end
250
-
251
- def series(data, **options)
252
- @series << [data, options]
253
-
254
- return self
255
- end
256
- end
257
-
258
- class DensityPlot < DistributionPlot
259
- protected
260
- def _show()
261
- first = true
262
- @series.each do |data, options|
263
- Rust["plotter.series"] = data
264
-
265
- if first
266
- first = false
267
- command = "plot"
268
- else
269
- command = "lines"
270
- end
271
-
272
- function = Rust::Function.new(command)
273
- function.options = self._augmented_options({"col" => options[:color]})
274
- function.arguments << Rust::Variable.new("density(plotter.series)")
275
- function.call
276
- end
277
-
278
- return self
279
- end
280
- end
281
-
282
- class BoxPlot < DistributionPlot
283
- protected
284
- def _show()
285
- function = Rust::Function.new("boxplot")
286
-
287
- names = []
288
- @series.each_with_index do |data, i|
289
- series, options = *data
290
- varname = "plotter.series#{i}"
291
- Rust[varname] = series
292
- function.arguments << Rust::Variable.new(varname)
293
- names << (options[:name] || (i+1).to_s)
294
- end
295
-
296
- function.options = self._augmented_options({'names' => names})
297
-
298
- function.call
299
-
300
- return self
301
- end
302
- end
303
-
304
136
  class Renderable
305
137
  def initialize
306
138
  @options = Rust::Options.new
@@ -0,0 +1,62 @@
1
+ require_relative 'core'
2
+
3
+ module Rust::Plots
4
+ class DistributionPlot < BasePlot
5
+ def initialize
6
+ super()
7
+ @series = []
8
+ end
9
+
10
+ def series(data, **options)
11
+ @series << [data, options]
12
+
13
+ return self
14
+ end
15
+ end
16
+
17
+ class DensityPlot < DistributionPlot
18
+ protected
19
+ def _show()
20
+ first = true
21
+ @series.each do |data, options|
22
+ Rust["plotter.series"] = data
23
+
24
+ if first
25
+ first = false
26
+ command = "plot"
27
+ else
28
+ command = "lines"
29
+ end
30
+
31
+ function = Rust::Function.new(command)
32
+ function.options = self._augmented_options({"col" => options[:color]})
33
+ function.arguments << Rust::Variable.new("density(plotter.series)")
34
+ function.call
35
+ end
36
+
37
+ return self
38
+ end
39
+ end
40
+
41
+ class BoxPlot < DistributionPlot
42
+ protected
43
+ def _show()
44
+ function = Rust::Function.new("boxplot")
45
+
46
+ names = []
47
+ @series.each_with_index do |data, i|
48
+ series, options = *data
49
+ varname = "plotter.series#{i}"
50
+ Rust[varname] = series
51
+ function.arguments << Rust::Variable.new(varname)
52
+ names << (options[:name] || (i+1).to_s)
53
+ end
54
+
55
+ function.options = self._augmented_options({'names' => names})
56
+
57
+ function.call
58
+
59
+ return self
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ self_path = File.expand_path(__FILE__)
2
+ Dir.glob(File.dirname(self_path) + "/*.rb").each do |lib|
3
+ require_relative lib unless lib == self_path
4
+ end
@@ -1,4 +1,4 @@
1
- require_relative 'rust-core'
1
+ require_relative '../core'
2
2
 
3
3
  module Rust::Correlation
4
4
  class Pearson
@@ -64,7 +64,7 @@ module Rust::Correlation
64
64
  Rust['correlation.a'] = d1
65
65
  Rust['correlation.b'] = d2
66
66
 
67
- _, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')", true)
67
+ _, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='k')", true)
68
68
 
69
69
  result = Result.new
70
70
  result.name = "Kendall's rank correlation tau"
@@ -1,6 +1,4 @@
1
- require 'code-assertions'
2
-
3
- require_relative 'rust-core'
1
+ require_relative '../core'
4
2
 
5
3
  module Rust::Descriptive
6
4
  class << self
@@ -47,7 +45,7 @@ module Rust::Descriptive
47
45
  return data.sum
48
46
  end
49
47
 
50
- def quantile(data, percentiles=[0.0, 0.25, 0.5, 0.75, 1.0])
48
+ def quantile(data, percentiles = [0.0, 0.25, 0.5, 0.75, 1.0])
51
49
  raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
52
50
  raise TypeError, "Expecting Array of numerics" if !percentiles.is_a?(Array) || !percentiles.all? { |e| e.is_a?(Numeric) }
53
51
  raise "Percentiles outside the range: #{percentiles}" if percentiles.any? { |e| !e.between?(0, 1) }
@@ -106,3 +104,25 @@ module Rust::Descriptive
106
104
  end
107
105
  end
108
106
  end
107
+
108
+ module Rust::RBindings
109
+ def mean(series)
110
+ Rust::Descriptive.mean(series)
111
+ end
112
+
113
+ def median(series)
114
+ Rust::Descriptive.median(series)
115
+ end
116
+
117
+ def var(series)
118
+ Rust::Descriptive.variance(series)
119
+ end
120
+
121
+ def sd(series)
122
+ Rust::Descriptive.standard_deviation(series)
123
+ end
124
+
125
+ def quantile(series, percentiles = [0.0, 0.25, 0.5, 0.75, 1.0])
126
+ Rust::Descriptive.quantile(series, percentiles)
127
+ end
128
+ end
@@ -1,8 +1,6 @@
1
- require 'code-assertions'
1
+ require_relative '../core'
2
2
 
3
- Rust.exclusive do
4
- Rust._eval("library(effsize)")
5
- end
3
+ Rust.prerequisite('effsize')
6
4
 
7
5
  module Rust::EffectSize
8
6
  class Result
@@ -16,11 +14,9 @@ module Rust::EffectSize
16
14
  return "#{name} = #{estimate} (#{magnitude}) [#{confidence_interval.min}, #{confidence_interval.max}]"
17
15
  end
18
16
  end
19
- end
20
17
 
21
- module Rust::EffectSize::CliffDelta
22
- class << self
23
- def compute(d1, d2)
18
+ class CliffDelta
19
+ def self.compute(d1, d2)
24
20
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
25
21
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
26
22
 
@@ -45,11 +41,9 @@ module Rust::EffectSize::CliffDelta
45
41
  end
46
42
  end
47
43
  end
48
- end
49
-
50
- module Rust::EffectSize::CohenD
51
- class << self
52
- def compute(d1, d2)
44
+
45
+ class CohenD
46
+ def self.compute(d1, d2)
53
47
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
54
48
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
55
49
 
@@ -1,4 +1,4 @@
1
- require_relative 'rust-core'
1
+ require_relative '../core'
2
2
 
3
3
  class Numeric
4
4
  def distance(other)
@@ -1,4 +1,4 @@
1
- require_relative 'rust-core'
1
+ require_relative '../core'
2
2
 
3
3
  module Rust::StatisticalTests
4
4
  class Result
@@ -85,85 +85,9 @@ module Rust::StatisticalTests
85
85
  end
86
86
  end
87
87
  end
88
- end
89
88
 
90
- module Rust::StatisticalTests::PValueAdjustment
91
- def self.method(name)
92
- name = name.to_s
93
- case name.downcase
94
- when "bonferroni", "b"
95
- return Bonferroni
96
- when "holm", "h"
97
- return Holm
98
- when "hochberg"
99
- return Hochberg
100
- when "hommel"
101
- return Hommel
102
- when "benjaminihochberg", "bh"
103
- return BenjaminiHochberg
104
- when "benjaminiyekutieli", "by"
105
- return BenjaminiYekutieli
106
- end
107
- end
108
-
109
- class Bonferroni
110
- def self.adjust(*p_values)
111
- Rust.exclusive do
112
- Rust['adjustment.p'] = p_values
113
- return Rust._pull("p.adjust(adjustment.p, method=\"bonferroni\")")
114
- end
115
- end
116
- end
117
-
118
- class Holm
119
- def self.adjust(*p_values)
120
- Rust.exclusive do
121
- Rust['adjustment.p'] = p_values
122
- return Rust._pull("p.adjust(adjustment.p, method=\"holm\")")
123
- end
124
- end
125
- end
126
-
127
- class Hochberg
128
- def self.adjust(*p_values)
129
- Rust.exclusive do
130
- Rust['adjustment.p'] = p_values
131
- return Rust._pull("p.adjust(adjustment.p, method=\"hochberg\")")
132
- end
133
- end
134
- end
135
-
136
- class Hommel
137
- def self.adjust(*p_values)
138
- Rust.exclusive do
139
- Rust['adjustment.p'] = p_values
140
- return Rust._pull("p.adjust(adjustment.p, method=\"hommel\")")
141
- end
142
- end
143
- end
144
-
145
- class BenjaminiHochberg
146
- def self.adjust(*p_values)
147
- Rust.exclusive do
148
- Rust['adjustment.p'] = p_values
149
- return Rust._pull("p.adjust(adjustment.p, method=\"BH\")")
150
- end
151
- end
152
- end
153
-
154
- class BenjaminiYekutieli
155
- def self.adjust(*p_values)
156
- Rust.exclusive do
157
- Rust['adjustment.p'] = p_values
158
- return Rust._pull("p.adjust(adjustment.p, method=\"BY\")")
159
- end
160
- end
161
- end
162
- end
163
-
164
- module Rust::StatisticalTests::Wilcoxon
165
- class << self
166
- def paired(d1, d2, alpha = 0.05, **options)
89
+ class Wilcoxon
90
+ def self.paired(d1, d2, alpha = 0.05, **options)
167
91
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
168
92
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
169
93
  raise "The two distributions have different size" if d1.size != d2.size
@@ -185,7 +109,7 @@ module Rust::StatisticalTests::Wilcoxon
185
109
  end
186
110
  end
187
111
 
188
- def unpaired(d1, d2, alpha = 0.05, **options)
112
+ def self.unpaired(d1, d2, alpha = 0.05, **options)
189
113
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
190
114
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
191
115
 
@@ -206,11 +130,9 @@ module Rust::StatisticalTests::Wilcoxon
206
130
  end
207
131
  end
208
132
  end
209
- end
210
-
211
- module Rust::StatisticalTests::T
212
- class << self
213
- def paired(d1, d2, alpha = 0.05, **options)
133
+
134
+ class T
135
+ def self.paired(d1, d2, alpha = 0.05, **options)
214
136
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
215
137
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
216
138
  raise "The two distributions have different size" if d1.size != d2.size
@@ -232,7 +154,7 @@ module Rust::StatisticalTests::T
232
154
  end
233
155
  end
234
156
 
235
- def unpaired(d1, d2, alpha = 0.05, **options)
157
+ def self.unpaired(d1, d2, alpha = 0.05, **options)
236
158
  raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
237
159
  raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
238
160
 
@@ -253,11 +175,9 @@ module Rust::StatisticalTests::T
253
175
  end
254
176
  end
255
177
  end
256
- end
257
178
 
258
- module Rust::StatisticalTests::Shapiro
259
- class << self
260
- def compute(vector, alpha = 0.05, **options)
179
+ class Shapiro
180
+ def self.compute(vector, alpha = 0.05, **options)
261
181
  raise TypeError, "Expecting Array of numerics" if !vector.is_a?(Array) || !vector.all? { |e| e.is_a?(Numeric) }
262
182
  Rust.exclusive do
263
183
  Rust['shapiro.v'] = vector
@@ -275,6 +195,80 @@ module Rust::StatisticalTests::Shapiro
275
195
  end
276
196
  end
277
197
  end
198
+
199
+ module PValueAdjustment
200
+ def self.method(name)
201
+ name = name.to_s
202
+ case name.downcase
203
+ when "bonferroni", "b"
204
+ return Bonferroni
205
+ when "holm", "h"
206
+ return Holm
207
+ when "hochberg"
208
+ return Hochberg
209
+ when "hommel"
210
+ return Hommel
211
+ when "benjaminihochberg", "bh"
212
+ return BenjaminiHochberg
213
+ when "benjaminiyekutieli", "by"
214
+ return BenjaminiYekutieli
215
+ end
216
+ end
217
+
218
+ class Bonferroni
219
+ def self.adjust(*p_values)
220
+ Rust.exclusive do
221
+ Rust['adjustment.p'] = p_values
222
+ return Rust._pull("p.adjust(adjustment.p, method=\"bonferroni\")")
223
+ end
224
+ end
225
+ end
226
+
227
+ class Holm
228
+ def self.adjust(*p_values)
229
+ Rust.exclusive do
230
+ Rust['adjustment.p'] = p_values
231
+ return Rust._pull("p.adjust(adjustment.p, method=\"holm\")")
232
+ end
233
+ end
234
+ end
235
+
236
+ class Hochberg
237
+ def self.adjust(*p_values)
238
+ Rust.exclusive do
239
+ Rust['adjustment.p'] = p_values
240
+ return Rust._pull("p.adjust(adjustment.p, method=\"hochberg\")")
241
+ end
242
+ end
243
+ end
244
+
245
+ class Hommel
246
+ def self.adjust(*p_values)
247
+ Rust.exclusive do
248
+ Rust['adjustment.p'] = p_values
249
+ return Rust._pull("p.adjust(adjustment.p, method=\"hommel\")")
250
+ end
251
+ end
252
+ end
253
+
254
+ class BenjaminiHochberg
255
+ def self.adjust(*p_values)
256
+ Rust.exclusive do
257
+ Rust['adjustment.p'] = p_values
258
+ return Rust._pull("p.adjust(adjustment.p, method=\"BH\")")
259
+ end
260
+ end
261
+ end
262
+
263
+ class BenjaminiYekutieli
264
+ def self.adjust(*p_values)
265
+ Rust.exclusive do
266
+ Rust['adjustment.p'] = p_values
267
+ return Rust._pull("p.adjust(adjustment.p, method=\"BY\")")
268
+ end
269
+ end
270
+ end
271
+ end
278
272
  end
279
273
 
280
274
  module Rust::RBindings
data/lib/rust.rb CHANGED
@@ -1,9 +1,4 @@
1
- require_relative 'rust-core'
2
- require_relative 'rust-basics'
3
- require_relative 'rust-csv'
4
- require_relative 'rust-tests'
5
- require_relative 'rust-effsize'
6
- require_relative 'rust-descriptive'
7
- require_relative 'rust-plots'
8
- require_relative 'rust-calls'
9
- require_relative 'rust-probabilities'
1
+ require_relative 'rust/core'
2
+ require_relative 'rust/models/all'
3
+ require_relative 'rust/plots/all'
4
+ require_relative 'rust/stats/all'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rust
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2022-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rinruby
@@ -52,20 +52,38 @@ dependencies:
52
52
  version: 1.1.2
53
53
  description: Ruby advanced statistical library based on RinRuby
54
54
  email: s.scalabrino9@gmail.com
55
- executables: []
55
+ executables:
56
+ - ruby-rust
56
57
  extensions: []
57
58
  extra_rdoc_files: []
58
59
  files:
59
- - lib/rust-basics.rb
60
- - lib/rust-calls.rb
61
- - lib/rust-core.rb
62
- - lib/rust-csv.rb
63
- - lib/rust-descriptive.rb
64
- - lib/rust-effsize.rb
65
- - lib/rust-plots.rb
66
- - lib/rust-probabilities.rb
67
- - lib/rust-tests.rb
60
+ - bin/ruby-rust
68
61
  - lib/rust.rb
62
+ - lib/rust/core.rb
63
+ - lib/rust/core/csv.rb
64
+ - lib/rust/core/rust.rb
65
+ - lib/rust/core/types/all.rb
66
+ - lib/rust/core/types/dataframe.rb
67
+ - lib/rust/core/types/datatype.rb
68
+ - lib/rust/core/types/factor.rb
69
+ - lib/rust/core/types/language.rb
70
+ - lib/rust/core/types/list.rb
71
+ - lib/rust/core/types/matrix.rb
72
+ - lib/rust/core/types/s4class.rb
73
+ - lib/rust/core/types/utils.rb
74
+ - lib/rust/models/all.rb
75
+ - lib/rust/models/anova.rb
76
+ - lib/rust/models/regression.rb
77
+ - lib/rust/plots/all.rb
78
+ - lib/rust/plots/basic-plots.rb
79
+ - lib/rust/plots/core.rb
80
+ - lib/rust/plots/distribution-plots.rb
81
+ - lib/rust/stats/all.rb
82
+ - lib/rust/stats/correlation.rb
83
+ - lib/rust/stats/descriptive.rb
84
+ - lib/rust/stats/effsize.rb
85
+ - lib/rust/stats/probabilities.rb
86
+ - lib/rust/stats/tests.rb
69
87
  homepage: https://github.com/intersimone999/ruby-rust
70
88
  licenses:
71
89
  - GPL-3.0-only
@@ -85,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
103
  - !ruby/object:Gem::Version
86
104
  version: '0'
87
105
  requirements: []
88
- rubygems_version: 3.2.7
106
+ rubygems_version: 3.3.15
89
107
  signing_key:
90
108
  specification_version: 4
91
109
  summary: Ruby advanced statistical library