ruby-mext 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mext/math/stepwise.rb +98 -0
- data/lib/mext/math.rb +1 -0
- data/lib/tasks/gruff/gruff.rake +1 -1
- data/lib/tasks/gruff/stepwise.rake +19 -0
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f86e7d87ee04f60b780f4a82f982239fffe311475bb0553c9072ef4aaf1340e
|
4
|
+
data.tar.gz: 476180537e18d2f41fad5cb6ea86c78db5a7d0beabb245385455b3a67d0a946a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894b67cfa2db0c20a59ddf9fff63bcc88671eebe1eab681f712656b8bc0c588e65e5a40417d72750d297ac5c34bfe7068e61f15ce95781fc23c3f17d19962ee2
|
7
|
+
data.tar.gz: 8b072063935a3b6be99092e9fc935c0236ee081fdc22b750b5c19710cd571dbd05e585d60ff020de5b0b68878549947964313d03a556b02e1c82a63d087fcdb0
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Math
|
2
|
+
|
3
|
+
class Stepwise < Function
|
4
|
+
|
5
|
+
class Point
|
6
|
+
attr_reader :x, :y
|
7
|
+
|
8
|
+
def initialize(x, y)
|
9
|
+
@x = x
|
10
|
+
@y = y
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# +:values+
|
16
|
+
#
|
17
|
+
# is an array of pairs (+x+, +y+)
|
18
|
+
#
|
19
|
+
attr_reader :values
|
20
|
+
|
21
|
+
#
|
22
|
+
# +Math::Stepwise.new(values = [])+
|
23
|
+
#
|
24
|
+
# stepwise function
|
25
|
+
#
|
26
|
+
# Arguments are:
|
27
|
+
#
|
28
|
+
# +values+: an array of (+x+, +y+) pairs
|
29
|
+
#
|
30
|
+
#:nodoc:
|
31
|
+
def initialize(vs = [])
|
32
|
+
setup(vs)
|
33
|
+
end
|
34
|
+
|
35
|
+
#:doc:
|
36
|
+
#
|
37
|
+
# +y(x)+:
|
38
|
+
#
|
39
|
+
# Returns a value for any given x
|
40
|
+
#
|
41
|
+
#:nodoc:
|
42
|
+
def y(x)
|
43
|
+
lookup(x)
|
44
|
+
end
|
45
|
+
|
46
|
+
def label
|
47
|
+
'stepwise function'
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
|
52
|
+
#
|
53
|
+
# +from_yaml(yaml_hash)+:
|
54
|
+
#
|
55
|
+
# creates a Math::Stepwise class from a yaml file which must have the
|
56
|
+
# relevant fields:
|
57
|
+
#
|
58
|
+
# +values+: an array of duples [x, y]
|
59
|
+
#
|
60
|
+
def from_yaml(yh)
|
61
|
+
new(yh['values'])
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def lookup(x)
|
69
|
+
last = nil
|
70
|
+
self.values.each do
|
71
|
+
|p|
|
72
|
+
break if p.x > x
|
73
|
+
last = p.y
|
74
|
+
end
|
75
|
+
last
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# +setup+
|
80
|
+
#
|
81
|
+
# setup basically sorts the input array in time creating points
|
82
|
+
#
|
83
|
+
#:nodoc:
|
84
|
+
def setup(vs)
|
85
|
+
@values = []
|
86
|
+
sorted = vs.sort { |a, b| a[0] <=> b[0] }
|
87
|
+
sorted.each { |duple| self.values << Point.new(duple[0], duple[1]) }
|
88
|
+
#
|
89
|
+
# keep in mind that vs might be empty
|
90
|
+
#
|
91
|
+
@x_start = self.values.first ? self.values.first.x : self.values.first
|
92
|
+
@x_end = self.values.last ? self.values.last.x : self.values.last
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
data/lib/mext/math.rb
CHANGED
data/lib/tasks/gruff/gruff.rake
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require File.expand_path(File.join(['..'] * 4, 'spec', 'fixtures', 'stepwise_dataset'), __FILE__)
|
3
|
+
require File.expand_path(File.join('..', 'gruff_plot'), __FILE__)
|
4
|
+
|
5
|
+
require 'byebug'
|
6
|
+
|
7
|
+
namespace :plot do
|
8
|
+
|
9
|
+
desc 'plot the Stepwise dataset'
|
10
|
+
task :stepwise => :create_output_dir do
|
11
|
+
ranges = [ Range.new(0, 1) ]
|
12
|
+
p = Mext::Gruff::Plotter.new('stepwise_dataset', 800, Mext::Spec::Fixtures::Math::STEPWISE_DATASETS, ranges)
|
13
|
+
p.plot do
|
14
|
+
|args|
|
15
|
+
Math::Stepwise.new(args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Bernardini
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/mext/math/expon.rb
|
123
123
|
- lib/mext/math/function.rb
|
124
124
|
- lib/mext/math/line.rb
|
125
|
+
- lib/mext/math/stepwise.rb
|
125
126
|
- lib/mext/numeric.rb
|
126
127
|
- lib/mext/numeric/ampdb.rb
|
127
128
|
- lib/mext/numeric/cpspch.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- lib/tasks/gruff/gruff.rake
|
144
145
|
- lib/tasks/gruff/gruff_plot.rb
|
145
146
|
- lib/tasks/gruff/line.rake
|
147
|
+
- lib/tasks/gruff/stepwise.rake
|
146
148
|
- lib/version.rb
|
147
149
|
- ruby-mext.gemspec
|
148
150
|
homepage: https://github.com/nicb/ruby-mext
|