Class: ML::Data::Generator
- Inherits:
-
Object
- Object
- ML::Data::Generator
- Defined in:
- lib/data/generator.rb
Overview
General generator for n-dimentional space
Class Method Summary collapse
-
.generate_vector(dim, scale = 1) ⇒ Array
Generating a random vector.
Instance Method Summary collapse
-
#initialize(dim) ⇒ Generator
constructor
Initial generator.
-
#points(points, coef) ⇒ Hash
Generate two groups of points.
Constructor Details
#initialize(dim) ⇒ Generator
Initial generator
59 60 61 |
# File 'lib/data/generator.rb', line 59 def initialize dim @dim = dim end |
Class Method Details
.generate_vector(dim, scale = 1) ⇒ Array
Generating a random vector
91 92 93 94 |
# File 'lib/data/generator.rb', line 91 def self.generate_vector dim, scale = 1 result = Array.new(dim) { (rand - 0.5) * scale } result << 1.0 end |
Instance Method Details
#points(points, coef) ⇒ Hash
Generate two groups of points
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/data/generator.rb', line 68 def points points, coef result = {} # for each group [1, -1].each do |grp| points.times do while true point = Generator.generate_vector(@dim, 100) 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 |