Parent

Included Modules

Files

Ai4r::Som::Layer

responsible for the implementation of the algorithm's decays currently has methods for the decay of the radius, influence and learning rate. Has only one phase, which ends after the number of epochs is passed by the Som-class.

Parameters

you pass to the SOM. Has to be an integer

Public Class Methods

new(nodes, radius, epochs = 100, learning_rate = 0.7) click to toggle source
# File lib/ai4r/som/layer.rb, line 34
def initialize(nodes, radius, epochs = 100, learning_rate = 0.7)
  raise("Too few nodes") if nodes < 3
  
  @nodes = nodes
  @epochs = epochs
  @radius = radius
  @time_for_epoch = @epochs / Math.log(nodes / 4.0)
  @time_for_epoch = @epochs + 1.0 if @time_for_epoch < @epochs

  @initial_learning_rate = learning_rate
end

Public Instance Methods

influence_decay(distance, radius) click to toggle source

calculates the influnce decay for a certain distance and the current radius of the epoch

# File lib/ai4r/som/layer.rb, line 48
def influence_decay(distance, radius)
  Math.exp(- (distance.to_f**2 / 2.0 / radius.to_f**2))
end
learning_rate_decay(epoch) click to toggle source

calculates the learning rate decay. uses @time_for_epoch again and same rule applies: @time_for_epoch has to be higher than the number of epochs, otherwise the decay will be - Infinity

# File lib/ai4r/som/layer.rb, line 60
def learning_rate_decay(epoch)
  @initial_learning_rate * ( 1 - epoch / @time_for_epoch)
end
radius_decay(epoch) click to toggle source

calculates the radius decay for the current epoch. Uses @time_for_epoch which has to be higher than the number of epochs, otherwise the decay will be - Infinity

# File lib/ai4r/som/layer.rb, line 54
def radius_decay(epoch)
  (@radius * ( 1 - epoch/ @time_for_epoch)).round
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.