Class: ML::Data::Generator2D
- Inherits:
-
Object
- Object
- ML::Data::Generator2D
- Defined in:
- lib/data/generator.rb
Overview
Generating sample points on 2D plane
Class Method Summary collapse
-
.point_from_line(coef, x) ⇒ Array
Generate point from line.
Instance Method Summary collapse
-
#initialize(x_range = 100, y_range = 100) ⇒ Generator2D
constructor
Initialize a generator.
-
#points_2d(points, coef = [-1.0, 1.0, 0.0]) ⇒ Hash
Generate two groups of points on 2d plain.
Constructor Details
#initialize(x_range = 100, y_range = 100) ⇒ Generator2D
Initialize a generator
20 21 22 23 |
# File 'lib/data/generator.rb', line 20 def initialize x_range = 100, y_range = 100 @x_range = x_range @y_range = y_range end |
Class Method Details
.point_from_line(coef, x) ⇒ Array
Generate point from line
12 13 14 |
# File 'lib/data/generator.rb', line 12 def self.point_from_line coef, x [x, (-coef[2]-(coef[0] * x))/coef[1]] end |
Instance Method Details
#points_2d(points, coef = [-1.0, 1.0, 0.0]) ⇒ Hash
Generate two groups of points on 2d plain
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/data/generator.rb', line 30 def points_2d points, coef = [-1.0, 1.0, 0.0] result = {} # for each group [1, -1].each do |grp| points.times do while true point = generate_point prod = Matrix.column_vector(point).transpose * Matrix.column_vector(coef) if (prod[0,0] <=> 0) == grp result[point] = grp break end end end end result end |