rust 0.3 → 0.4
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/lib/rust-basics.rb +9 -3
- data/lib/rust-core.rb +4 -0
- data/lib/rust-descriptive.rb +10 -2
- data/lib/rust-plots.rb +55 -21
- 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: ca9e5aaa6bcfff9d1b261c5a3ced5cf74b7731085b4b094dba55df72884aca9a
|
4
|
+
data.tar.gz: 8c90363b44a0c95abc9610fb78c3c632c6ae4265ad2260ff7e9740777245f63e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ca17e2c0dda2188138f11e1ae4becaa8a5c4b0d2cc12273775b9ade1fefbc860f3ccee2251fbe353b9dbde55eded960e8cf26642af042070d979ed192b332e3
|
7
|
+
data.tar.gz: 28dacd36f814acf51d222c8e746f65b94ef53ab5f24902ba6f654b05267c926e8db03cca82a876ca1183f55293da96d60ec862c5bfa26f6abd430d1f5e998709
|
data/lib/rust-basics.rb
CHANGED
@@ -10,13 +10,14 @@ module Rust:: Correlation
|
|
10
10
|
Rust['correlation.a'] = d1
|
11
11
|
Rust['correlation.b'] = d2
|
12
12
|
|
13
|
-
Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')")
|
13
|
+
_, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')", true)
|
14
14
|
|
15
15
|
result = Result.new
|
16
16
|
result.name = "Pearson's product-moment correlation"
|
17
17
|
result.statistics['t'] = Rust._pull('correlation.result$statistic')
|
18
18
|
result.pvalue = Rust._pull('correlation.result$p.value')
|
19
19
|
result.correlation = Rust._pull('correlation.result$estimate')
|
20
|
+
result.exact = !warnings.include?("Cannot compute exact p-value with ties")
|
20
21
|
|
21
22
|
return result
|
22
23
|
end
|
@@ -36,13 +37,14 @@ module Rust:: Correlation
|
|
36
37
|
Rust['correlation.a'] = d1
|
37
38
|
Rust['correlation.b'] = d2
|
38
39
|
|
39
|
-
Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='s')")
|
40
|
+
_, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='s')", true)
|
40
41
|
|
41
42
|
result = Result.new
|
42
43
|
result.name = "Spearman's rank correlation rho"
|
43
44
|
result.statistics['S'] = Rust._pull('correlation.result$statistic')
|
44
45
|
result.pvalue = Rust._pull('correlation.result$p.value')
|
45
46
|
result.correlation = Rust._pull('correlation.result$estimate')
|
47
|
+
result.exact = !warnings.include?("Cannot compute exact p-value with ties")
|
46
48
|
|
47
49
|
return result
|
48
50
|
end
|
@@ -62,13 +64,14 @@ module Rust:: Correlation
|
|
62
64
|
Rust['correlation.a'] = d1
|
63
65
|
Rust['correlation.b'] = d2
|
64
66
|
|
65
|
-
Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')")
|
67
|
+
_, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')", true)
|
66
68
|
|
67
69
|
result = Result.new
|
68
70
|
result.name = "Kendall's rank correlation tau"
|
69
71
|
result.statistics['T'] = Rust._pull('correlation.result$statistic')
|
70
72
|
result.pvalue = Rust._pull('correlation.result$p.value')
|
71
73
|
result.correlation = Rust._pull('correlation.result$estimate')
|
74
|
+
result.exact = !warnings.include?("Cannot compute exact p-value with ties")
|
72
75
|
|
73
76
|
return result
|
74
77
|
end
|
@@ -84,11 +87,13 @@ module Rust:: Correlation
|
|
84
87
|
attr_accessor :statistics
|
85
88
|
attr_accessor :pvalue
|
86
89
|
attr_accessor :correlation
|
90
|
+
attr_accessor :exact
|
87
91
|
|
88
92
|
alias :estimate :correlation
|
89
93
|
|
90
94
|
def initialize
|
91
95
|
@statistics = {}
|
96
|
+
@exact = true
|
92
97
|
end
|
93
98
|
|
94
99
|
def [](name)
|
@@ -101,6 +106,7 @@ module Rust:: Correlation
|
|
101
106
|
|
102
107
|
def to_s
|
103
108
|
return "#{name}. Correlation = #{correlation}, P-value = #{pvalue} " +
|
109
|
+
(!@exact ? "P-value is not exact. " : "") +
|
104
110
|
"#{ statistics.map { |k, v| k.to_s + " -> " + v.to_s }.join(", ") }."
|
105
111
|
end
|
106
112
|
end
|
data/lib/rust-core.rb
CHANGED
data/lib/rust-descriptive.rb
CHANGED
@@ -13,15 +13,17 @@ module Rust::Descriptive
|
|
13
13
|
def standard_deviation(data)
|
14
14
|
raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
|
15
15
|
|
16
|
-
|
16
|
+
return Math.sqrt(variance(data))
|
17
17
|
end
|
18
18
|
alias :sd :standard_deviation
|
19
19
|
alias :stddev :standard_deviation
|
20
20
|
|
21
21
|
def variance(data)
|
22
22
|
raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
|
23
|
+
return Float::NAN if data.size < 2
|
23
24
|
|
24
|
-
|
25
|
+
mean = mean(data)
|
26
|
+
return data.map { |v| (v - mean) ** 2 }.sum.to_f / (data.size - 1)
|
25
27
|
end
|
26
28
|
alias :var :variance
|
27
29
|
|
@@ -39,6 +41,12 @@ module Rust::Descriptive
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
44
|
+
def sum(data)
|
45
|
+
raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
|
46
|
+
|
47
|
+
return data.sum
|
48
|
+
end
|
49
|
+
|
42
50
|
def quantile(data, percentiles=[0.0, 0.25, 0.5, 0.75, 1.0])
|
43
51
|
raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
|
44
52
|
raise TypeError, "Expecting Array of numerics" if !percentiles.is_a?(Array) || !percentiles.all? { |e| e.is_a?(Numeric) }
|
data/lib/rust-plots.rb
CHANGED
@@ -4,8 +4,9 @@ require_relative 'rust-calls'
|
|
4
4
|
module Rust::Plots
|
5
5
|
class BasePlot
|
6
6
|
def initialize
|
7
|
-
@
|
7
|
+
@renderables = []
|
8
8
|
@options = Rust::Options.new
|
9
|
+
@override_options = true
|
9
10
|
end
|
10
11
|
|
11
12
|
def x_label(label)
|
@@ -36,7 +37,13 @@ module Rust::Plots
|
|
36
37
|
@options['xaxt'] = 'n'
|
37
38
|
@options['yaxt'] = 'n'
|
38
39
|
|
39
|
-
self.
|
40
|
+
self._add_renderable(axis)
|
41
|
+
|
42
|
+
return self
|
43
|
+
end
|
44
|
+
|
45
|
+
def grid(grid)
|
46
|
+
self._add_renderable(grid)
|
40
47
|
|
41
48
|
return self
|
42
49
|
end
|
@@ -53,21 +60,25 @@ module Rust::Plots
|
|
53
60
|
return self
|
54
61
|
end
|
55
62
|
|
56
|
-
def
|
57
|
-
raise TypeError, "Expected
|
58
|
-
@
|
63
|
+
def _add_renderable(renderable)
|
64
|
+
raise TypeError, "Expected Renderable" unless renderable.is_a?(Renderable)
|
65
|
+
@renderables << renderable
|
59
66
|
|
60
67
|
return self
|
61
68
|
end
|
62
69
|
|
63
70
|
def []=(option, value)
|
64
|
-
@options[option] = value
|
71
|
+
@options[option.to_s] = value
|
72
|
+
end
|
73
|
+
|
74
|
+
def _do_not_override_options!
|
75
|
+
@override_options = false
|
65
76
|
end
|
66
77
|
|
67
78
|
def show()
|
68
79
|
Rust.exclusive do
|
69
80
|
self._show
|
70
|
-
self.
|
81
|
+
self._render_others
|
71
82
|
end
|
72
83
|
|
73
84
|
return self
|
@@ -82,7 +93,7 @@ module Rust::Plots
|
|
82
93
|
Rust.exclusive do
|
83
94
|
pdf_function.call
|
84
95
|
self._show
|
85
|
-
self.
|
96
|
+
self._render_others
|
86
97
|
Rust._eval("dev.off()")
|
87
98
|
end
|
88
99
|
|
@@ -94,9 +105,9 @@ module Rust::Plots
|
|
94
105
|
raise "You are trying to show a BasePlot"
|
95
106
|
end
|
96
107
|
|
97
|
-
def
|
98
|
-
@
|
99
|
-
|
108
|
+
def _render_others()
|
109
|
+
@renderables.each do |renderable|
|
110
|
+
renderable._render()
|
100
111
|
end
|
101
112
|
|
102
113
|
return self
|
@@ -106,7 +117,7 @@ module Rust::Plots
|
|
106
117
|
result = @options.clone
|
107
118
|
|
108
119
|
options.each do |key, value|
|
109
|
-
result[key] = value
|
120
|
+
result[key] = value if !result[key] || @override_options
|
110
121
|
end
|
111
122
|
|
112
123
|
result.select! { |k, v| v != nil }
|
@@ -221,7 +232,7 @@ module Rust::Plots
|
|
221
232
|
end
|
222
233
|
end
|
223
234
|
|
224
|
-
class
|
235
|
+
class Renderable
|
225
236
|
def initialize
|
226
237
|
@options = Rust::Options.new
|
227
238
|
end
|
@@ -233,12 +244,12 @@ module Rust::Plots
|
|
233
244
|
end
|
234
245
|
|
235
246
|
protected
|
236
|
-
def
|
237
|
-
raise "You are trying to run an abstract
|
247
|
+
def _render()
|
248
|
+
raise "You are trying to run an abstract Renderable"
|
238
249
|
end
|
239
250
|
end
|
240
251
|
|
241
|
-
class Axis <
|
252
|
+
class Axis < Renderable
|
242
253
|
BELOW = 1
|
243
254
|
LEFT = 2
|
244
255
|
ABOVE = 3
|
@@ -276,7 +287,7 @@ module Rust::Plots
|
|
276
287
|
return self
|
277
288
|
end
|
278
289
|
|
279
|
-
def
|
290
|
+
def _render()
|
280
291
|
function = Rust::Function.new("axis")
|
281
292
|
function.options = @options
|
282
293
|
|
@@ -286,7 +297,7 @@ module Rust::Plots
|
|
286
297
|
end
|
287
298
|
end
|
288
299
|
|
289
|
-
class Grid <
|
300
|
+
class Grid < Renderable
|
290
301
|
def initialize
|
291
302
|
super()
|
292
303
|
|
@@ -330,7 +341,7 @@ module Rust::Plots
|
|
330
341
|
return self
|
331
342
|
end
|
332
343
|
|
333
|
-
def
|
344
|
+
def _render()
|
334
345
|
function = Rust::Function.new("grid")
|
335
346
|
|
336
347
|
function.arguments << @x
|
@@ -345,7 +356,30 @@ module Rust::Plots
|
|
345
356
|
end
|
346
357
|
|
347
358
|
module Rust::RBindings
|
348
|
-
def plot(x, y)
|
349
|
-
Rust::Plots::ScatterPlot.new(x, y)
|
359
|
+
def plot(x, y=(1..x.size).to_a, **options)
|
360
|
+
result = Rust::Plots::ScatterPlot.new(x, y)
|
361
|
+
|
362
|
+
options.each do |k, v|
|
363
|
+
result[k] = v
|
364
|
+
end
|
365
|
+
|
366
|
+
result._do_not_override_options!
|
367
|
+
|
368
|
+
result.show
|
369
|
+
end
|
370
|
+
|
371
|
+
def boxplot(*args, **options)
|
372
|
+
result = Rust::Plots::BoxPlot.new
|
373
|
+
options.each do |k, v|
|
374
|
+
result[k] = v
|
375
|
+
end
|
376
|
+
|
377
|
+
result._do_not_override_options!
|
378
|
+
|
379
|
+
args.each do |s|
|
380
|
+
result.series(s)
|
381
|
+
end
|
382
|
+
|
383
|
+
result.show
|
350
384
|
end
|
351
385
|
end
|
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.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simone Scalabrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rinruby
|