classPiiSom
#include <PiiSom.h>
An implementation of the self-organizing map (Kohonen map).
Inherits PiiVectorQuantizer< SampleSet >, PiiLearningAlgorithm< SampleSet >
Description
Typically, SOM is trained in two phases. First, a "rough" training is made with a relatively large learning rate (~0.05), a relatively large radius (e.g. 10, depending on the size of the map), and a relatively low number of iterations (depending on the number of training samples). Then, fine-tuning is performed with a smaller learning rate (~0.02), a smaller radius (e.g. 3), and a larger number of iterations.
Each training sample is fed to the SOM sequentially. The same samples can be (and usually are) used multiple times until a sufficient number of iterations (e.g. 10000) has been performed. Each sample tunes the code book according to the then current learning parameters. The class modifies a code book that is given upon construction of the class.
In classification, the SOM works as a vector quantizer.
Public types
|
typedef PiiSampleSet::Traits< SampleSet
>::ConstFeatureIterator
|
Constructors and destructor
|
(
Create a new SOM with the number of nodes in horizontal and vertical directions. |
Public member functions
|
virtual PiiClassification::LearnerCapabilities
|
( )
Returns the capabilities of the learning algorithm as a combination of LearnerCapability flags. |
|
int
|
|
|
virtual bool
|
( )
Returns |
|
double
|
Get the current learning rate. |
|
double
|
( )
Get the current learning radius. |
|
double
|
(
|
|
QVector<
double >
|
(
|
|
int
|
( )
Get the height of the SOM. |
|
double
|
Get the initial learning rate. |
|
double
|
( )
Get the initial learning radius. |
|
( )
Get the initialization mode. |
|
|
int
|
( )
Get the current iteration number. |
|
virtual void
|
Train the SOM with a batch of samples. |
|
Get the learning algorithm. |
|
|
int
|
( )
Get the estimated number of iterations in training. |
|
virtual double
|
(
Train the SOM with the given feature vector. |
|
( )
Get the type of learning rate change in training. |
|
|
void
|
(
Set the height of the som. |
|
void
|
(
Set the initial learning rate. |
|
void
|
(
Set the initial learning radius. |
|
void
|
Set the initialization mode to |
|
void
|
(
Set the current iteration number. |
|
void
|
Set the learning algorithm. |
|
void
|
(
Set the estimated number of iterations in training. |
|
void
|
Set the type of learning rate change in training. |
|
void
|
(
Set the size of the SOM. |
|
void
|
Set the topology of the network. |
|
void
|
(
Set the width of the som. |
|
( )
Get the topology of the network. |
|
|
int
|
( )
Get the width of the SOM. |
Function details
-
PiiSom
(- int width = 10
- int height = 0
Create a new SOM with the number of nodes in horizontal and vertical directions.
Parameters
- width
-
the number of nodes in horizontal direction
- height
-
the number of nodes in vertical direction. If set to a value less than one, a width-by-width map will be created.
-
virtual PiiClassification::LearnerCapabilities capabilities
()[virtual]Returns the capabilities of the learning algorithm as a combination of LearnerCapability flags.
Reimplemented from PiiLearningAlgorithm.
-
int codeBookCollectionIndex
() -
virtual bool converged
()[virtual]Returns
trueif the algorithm has converged (found an optimal solution) andfalseotherwise.Reimplemented from PiiLearningAlgorithm.
-
double currentLearningRate
()Get the current learning rate.
-
double currentRadius
()Get the current learning radius.
-
double findMostDistantNeighbor
(- int row
- int * vector2Index = 0
-
QVector< double > findMostDistantNeighbors
(- int * vector1Index = 0
- int * vector2Index = 0
-
int height
()Get the height of the SOM.
-
double initialLearningRate
()Get the initial learning rate.
-
double initialRadius
()Get the initial learning radius.
-
PiiClassification::SomInitMode initMode
()Get the initialization mode.
-
int iterationNumber
()Get the current iteration number.
-
virtual void learn
(- const SampleSet & samples
- const QVector< double > & labels
- const QVector< double > & weights = < double >()
[virtual]Train the SOM with a batch of samples.
Parameters
- samples
-
a batch of training samples
- labels
-
ignored. The SOM is a supervised algorithm.
- weights
-
ignored.
Returns
the index of the closest code vector
Reimplemented from PiiLearningAlgorithm.
-
PiiClassification::SomLearningAlgorithm learningAlgorithm
()Get the learning algorithm.
-
int learningLength
()Get the estimated number of iterations in training.
-
virtual double learnOne
(- ConstFeatureIterator features
- int length
- double label = NAN
- double weight = 1.0
[virtual]Train the SOM with the given feature vector.
Parameters
- features
-
the feature vector of a training sample
- length
-
the number of features to consider. Must match the current dimensionality of stored feature vectors.
- label
-
ignored. The SOM is a supervised algorithm.
- weight
-
ignored.
Returns
the index of the closest code vector
Reimplemented from PiiLearningAlgorithm.
-
PiiClassification::SomRateFunction rateFunction
()Get the type of learning rate change in training.
-
void setHeight
(- int height
Set the height of the som.
This will invalidate the internal code book.
-
void setInitialLearningRate
(- double rate
Set the initial learning rate.
The default value is 0.05. The learning rate decreases on each training iteration depending on the learning rate function. The current value is retrieved with currentLearningRate().
-
void setInitialRadius
(- double radius
Set the initial learning radius.
The radius affects the number of code vectors that are adapted in the neighborhood of the winning node. The default value is 10. The radius decreases depending on the learning rate function on each training iteration. The current radius can be retrieved with currentRadius(). The initial size of the adapted neighborhood should always be smaller than or equal to the width and height of the map. In other words, if you set the map size to, say, 6x6, set the radius to at most 3.
-
void setInitMode
Set the initialization mode to
mode.The default initialization mode is SomSampleInit.
-
void setIterationNumber
(- int iteration
Set the current iteration number.
This number affects the learning rate and the size of the neighborhood. Set this value to zero to restart learning.
Note. If you want to restart learning at an index other than zero, set the iteration number to zero first to ensure all necessary initialization is done.
-
void setLearningAlgorithm
Set the learning algorithm.
-
void setLearningLength
(- int length
Set the estimated number of iterations in training.
The SOM does not know the number of training iterations in advance. However, an estimate needs to be given because of the linearly changing learning parameters (radius and learning rate). The default value is 10000. If more iterations are taken, the learning parameters will be fixed. With a linearly decreasing learning rate this effectively stops the learning process after the estimated number of iterations have been pefrormed. Thus, one needs to make sure the value is large enough.
-
void setRateFunction
Set the type of learning rate change in training.
-
void setSize
(- int width
- int height
Set the size of the SOM.
When the size is changed, the old code book may not be usable. One should ensure that the number of code vectors always matches the size of the map (width*height).
-
void setTopology
Set the topology of the network.
-
void setWidth
(- int width
Set the width of the som.
This will invalidate the internal code book.
-
PiiClassification::SomTopology topology
()Get the topology of the network.
-
int width
()Get the width of the SOM.
Add a note
Not a single note added yet. Be the first, add yours.