Class KohonenUpdateAction
- java.lang.Object
-
- org.apache.commons.math3.ml.neuralnet.sofm.KohonenUpdateAction
-
- All Implemented Interfaces:
UpdateAction
public class KohonenUpdateAction extends java.lang.Object implements UpdateAction
Update formula for Kohonen's Self-Organizing Map.
Theupdate
method modifies the featuresw
of the "winning" neuron and its neighbours according to the following rule:wnew = wold + α e(-d / σ) * (sample - wold)
where- α is the current learning rate,
- σ is the current neighbourhood size, and
d
is the number of links to traverse in order to reach the neuron from the winning neuron.
This class is thread-safe as long as the arguments passed to theconstructor
are instances of thread-safe classes.
Each call to theupdate
method will increment the internal counter used to compute the current values for- the learning rate, and
- the neighbourhood size.
- Since:
- 3.3
-
-
Field Summary
Fields Modifier and Type Field Description private DistanceMeasure
distance
Distance function.private LearningFactorFunction
learningFactor
Learning factor update function.private NeighbourhoodSizeFunction
neighbourhoodSize
Neighbourhood size update function.private java.util.concurrent.atomic.AtomicLong
numberOfCalls
Number of calls toupdate(Network,double[])
.
-
Constructor Summary
Constructors Constructor Description KohonenUpdateAction(DistanceMeasure distance, LearningFactorFunction learningFactor, NeighbourhoodSizeFunction neighbourhoodSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
attemptNeuronUpdate(Neuron n, double[] features, double learningRate)
Tries to update a neuron.private double[]
computeFeatures(double[] current, double[] sample, double learningRate)
Computes the new value of the features set.private Neuron
findAndUpdateBestNeuron(Network net, double[] features, double learningRate)
Searches for the neuron whose features are closest to the given sample, and atomically updates its features.long
getNumberOfCalls()
Retrieves the number of calls to theupdate
method.void
update(Network net, double[] features)
Updates the network in response to the samplefeatures
.private void
updateNeighbouringNeuron(Neuron n, double[] features, double learningRate)
Atomically updates the given neuron.
-
-
-
Field Detail
-
distance
private final DistanceMeasure distance
Distance function.
-
learningFactor
private final LearningFactorFunction learningFactor
Learning factor update function.
-
neighbourhoodSize
private final NeighbourhoodSizeFunction neighbourhoodSize
Neighbourhood size update function.
-
numberOfCalls
private final java.util.concurrent.atomic.AtomicLong numberOfCalls
Number of calls toupdate(Network,double[])
.
-
-
Constructor Detail
-
KohonenUpdateAction
public KohonenUpdateAction(DistanceMeasure distance, LearningFactorFunction learningFactor, NeighbourhoodSizeFunction neighbourhoodSize)
- Parameters:
distance
- Distance function.learningFactor
- Learning factor update function.neighbourhoodSize
- Neighbourhood size update function.
-
-
Method Detail
-
update
public void update(Network net, double[] features)
Updates the network in response to the samplefeatures
.- Specified by:
update
in interfaceUpdateAction
- Parameters:
net
- Network.features
- Training data.
-
getNumberOfCalls
public long getNumberOfCalls()
Retrieves the number of calls to theupdate
method.- Returns:
- the current number of calls.
-
attemptNeuronUpdate
private boolean attemptNeuronUpdate(Neuron n, double[] features, double learningRate)
Tries to update a neuron.- Parameters:
n
- Neuron to be updated.features
- Training data.learningRate
- Learning factor.- Returns:
true
if the update succeeded,true
if a concurrent update has been detected.
-
updateNeighbouringNeuron
private void updateNeighbouringNeuron(Neuron n, double[] features, double learningRate)
Atomically updates the given neuron.- Parameters:
n
- Neuron to be updated.features
- Training data.learningRate
- Learning factor.
-
findAndUpdateBestNeuron
private Neuron findAndUpdateBestNeuron(Network net, double[] features, double learningRate)
Searches for the neuron whose features are closest to the given sample, and atomically updates its features.- Parameters:
net
- Network.features
- Sample data.learningRate
- Current learning factor.- Returns:
- the winning neuron.
-
computeFeatures
private double[] computeFeatures(double[] current, double[] sample, double learningRate)
Computes the new value of the features set.- Parameters:
current
- Current values of the features.sample
- Training data.learningRate
- Learning factor.- Returns:
- the new values for the features.
-
-