class Newral::Functions::Gaussian

Attributes

factors[R]

Public Class Methods

create_random( low_range: -9, high_range: 9 ) click to toggle source
# File lib/newral/functions/gaussian.rb, line 19
def self.create_random(  low_range: -9, high_range: 9 )
  self.new center:[low_range+rand(high_range-low_range)],factor: low_range+rand(high_range-low_range)
end
new( center:[0], factor:1 ) click to toggle source
# File lib/newral/functions/gaussian.rb, line 5
def initialize(  center:[0], factor:1 )
  @factor = factor
  @center = center.dup
end

Public Instance Methods

calculate( input ) click to toggle source
# File lib/newral/functions/gaussian.rb, line 10
def calculate( input ) 
 calculate_for_center_distance( [input])
end
calculate_for_center_distance( vector1 ) click to toggle source
# File lib/newral/functions/gaussian.rb, line 14
def calculate_for_center_distance( vector1  ) 
  distance = Newral::Tools.euclidian_distance( vector1, @center )
  Math.exp(-distance**2)*@factor
end
move( direction: 0, step:0.01, step_percentage: nil ) click to toggle source
# File lib/newral/functions/gaussian.rb, line 27
def move( direction: 0, step:0.01, step_percentage: nil )
   raise Errors::InvalidDirection if direction >= number_of_directions
   if direction == 0
     @factor = ( step_percentage ? @factor*(1+step_percentage/100) : @factor+step_percentage )
   else 
     @center = @center.dup
     @center[direction-1] =  step_percentage ?  @center[direction-1]*(1+step_percentage/100) : @center[direction-1]+step
   end
   self
 end
number_of_directions() click to toggle source
# File lib/newral/functions/gaussian.rb, line 23
def number_of_directions
  1+@center.size
end