Class: Ai4r::Som::Layer
- Inherits:
-
Object
- Object
- Ai4r::Som::Layer
- Includes:
- Data::Parameterizable
- Defined in:
- lib/ai4r/som/layer.rb
Overview
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
-
nodes => number of nodes in the SOM (nodes x nodes). Has to be the same number
you pass to the SOM. Has to be an integer
-
radius => the initial radius for the neighborhood
-
epochs => number of epochs the algorithm runs, has to be an integer. By default it is set to 100
-
learning_rate => sets the initial learning rate
Direct Known Subclasses
Instance Method Summary collapse
-
#influence_decay(distance, radius) ⇒ Object
calculates the influnce decay for a certain distance and the current radius of the epoch.
- #initialize(nodes, radius, epochs = 100, learning_rate = 0.7, options = {}) ⇒ Object constructor
-
#learning_rate_decay(epoch) ⇒ Object
calculates the learning rate decay.
-
#radius_decay(epoch) ⇒ Object
calculates the radius decay for the current epoch.
Methods included from Data::Parameterizable
#get_parameters, included, #set_parameters
Constructor Details
#initialize(nodes, radius, epochs = 100, learning_rate = 0.7, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ai4r/som/layer.rb', line 40 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 @distance_metric = [:distance_metric] || :chebyshev end |
Instance Method Details
#influence_decay(distance, radius) ⇒ Object
calculates the influnce decay for a certain distance and the current radius of the epoch
58 59 60 |
# File 'lib/ai4r/som/layer.rb', line 58 def influence_decay(distance, radius) Math.exp(- ((distance.to_f**2) / 2.0 / (radius.to_f**2))) end |
#learning_rate_decay(epoch) ⇒ Object
calculates the learning rate decay. uses @time_for_epoch again and same rule applies:
74 75 76 |
# File 'lib/ai4r/som/layer.rb', line 74 def learning_rate_decay(epoch) @initial_learning_rate * (1 - (epoch / @time_for_epoch)) end |
#radius_decay(epoch) ⇒ Object
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
66 67 68 |
# File 'lib/ai4r/som/layer.rb', line 66 def radius_decay(epoch) (@radius * (1 - (epoch / @time_for_epoch))).round end |