class ML::Data::Generator2D
Generating sample points on 2D plane
Public Class Methods
new(x_range = 100, y_range = 100, noise = 0, model = :random)
click to toggle source
Initialize a generator
@param [Integer] x_range x range @param [Integer] y_range y range @param [Numeric] noise the percentage of noise @param [Symbol] model the noise model, :random for flipping
all the element in a probability, while :flip only flips a portion of elements randomly
# File lib/data/generator.rb, line 91 def initialize x_range = 100, y_range = 100, noise = 0, model = :random @x_range = x_range @y_range = y_range @noise = noise @model = model end
point_from_line(coef, x)
click to toggle source
Generate point from line
@param [Array] coef [a,b,c] for ax+by+c=0 @param [Number] x x value @return [Array] point
# File lib/data/generator.rb, line 79 def self.point_from_line coef, x [x, (-coef[2]-(coef[0] * x))/coef[1]] end
Public Instance Methods
points_2d(points, coef = [-1.0, 1.0, 0.0])
click to toggle source
Generate two groups of points on 2d plain
@param [Integer] points the number of points of each set @param [Array] coef [a,b,c] for ax+by+c=0 @return [Hash] key: points, value: supervised value
# File lib/data/generator.rb, line 103 def points_2d points, coef = [-1.0, 1.0, 0.0] points(points, coef) end
Protected Instance Methods
generate_vector()
click to toggle source
# File lib/data/generator.rb, line 108 def generate_vector [@x_range * rand, @y_range * rand, 1.0] end