Class: Newral::Functions::Gaussian

Inherits:
Base
  • Object
show all
Defined in:
lib/newral/functions/gaussian.rb

Direct Known Subclasses

RickerWavelet

Instance Attribute Summary collapse

Attributes inherited from Base

#center

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#calculate_descent, #calculate_error, #error_gradient_approximation, #find_minimum, #move_random, #move_several, #move_with_gradient

Constructor Details

#initialize(center: [0], factor: 1) ⇒ Gaussian

Returns a new instance of Gaussian.



5
6
7
8
# File 'lib/newral/functions/gaussian.rb', line 5

def initialize(  center:[0], factor:1 )
  @factor = factor
  @center = center.dup
end

Instance Attribute Details

#factorsObject (readonly)

Returns the value of attribute factors.



4
5
6
# File 'lib/newral/functions/gaussian.rb', line 4

def factors
  @factors
end

Class Method Details

.create_random(low_range: -9,, high_range: 9) ⇒ Object



19
20
21
# 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

Instance Method Details

#calculate(input) ⇒ Object



10
11
12
# File 'lib/newral/functions/gaussian.rb', line 10

def calculate( input ) 
 calculate_for_center_distance( [input])
end

#calculate_for_center_distance(vector1) ⇒ Object



14
15
16
17
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# 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_directionsObject



23
24
25
# File 'lib/newral/functions/gaussian.rb', line 23

def number_of_directions
  1+@center.size
end