|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object comirva.mlearn.SOM
public class SOM
This class implements a Self-Organizing Map and some useful algorithms for initializing and training.
Field Summary | |
---|---|
protected Vector<String> |
altLabels
|
protected boolean |
circular
|
protected DataMatrix |
codebook
|
protected DataMatrix |
coOccMatrix
|
protected Vector<String> |
coOccMatrixLabels
|
DataMatrix |
data
|
static int |
INIT_GRADIENT
|
static int |
INIT_LINEAR
|
static int |
INIT_RANDOM
|
static int |
INIT_SLC
|
protected int |
intMUCols
|
protected int |
intMURows
|
protected Vector<String> |
labels
|
protected int |
method
|
JLabel |
statusBar
statusBar represents the status bar of the calling MainUI-instance and is used to update the status bar while performing training |
static int |
TRAIN_BATCH
|
static int |
TRAIN_SEQ
|
protected int |
trainingLength
|
Vector<Vector<Integer>> |
voronoiSet
|
Constructor Summary | |
---|---|
SOM(DataMatrix trainData)
Creates a SOM-instance with the training data contained in the DataMatrix trainData . |
|
SOM(DataMatrix trainData,
int rows,
int cols)
Creates a SOM-instance with the training data contained in the DataMatrix trainData . |
Method Summary | |
---|---|
void |
clearAltLabels()
|
void |
clearLabels()
Clears all labels assigned to the SOM. |
void |
createVoronoiSet()
Calculates the Voronoi-Set of the SOM and stored the result in the internal voronoiSet Vector
which contains a nested Vector containig Integers of mapped data item indices for each map unit. |
static double |
euclideanDistance(Vector<Double> item1,
Vector<Double> item2)
Calculates and returns the Euclidean distance between the data vectors item1 and item2 . |
String |
getAltLabel(int dataItemIndex)
|
Vector<String> |
getAltLabels()
|
int |
getBMU(Vector<Double> dataItem)
Calculates the best matching unit for the data vector dataItem and
returns its index in the codebook. |
DataMatrix |
getCodebook()
|
DataMatrix |
getCoOccMatrix()
|
Vector<String> |
getCoOccMatrixLabels()
|
DataMatrix |
getDataset()
Returns the data set of the SOM (that is used for training). |
Color[] |
getGridcolors()
|
String |
getLabel(int dataItemIndex)
Returns the label for the data item whose index is dataItemIndex . |
Vector<String> |
getLabels()
|
MDM |
getMDM()
|
int |
getNumberOfColumns()
Returns the number of map units of the SOM in horizontal direction. |
int |
getNumberOfDataItems()
Returns the number of data items in the training set. |
int |
getNumberOfRows()
Returns the number of map units of the SOM in vertical direction. |
TreeMap<Double,Integer> |
getOrderedBMUs(Vector<Double> dataItem)
Calculates a set of best matching units for the data vector dataItem and
returns the codebook-indices of these units. |
Vector<String> |
getPrototypesForMU(int idxMU,
int maxNumber)
Calculates for the given map unit its most "representative" data items. |
boolean[][] |
getVoronoiMatrix()
Calculates a boolean matrix containing, for each map unit, the data items which are mapped to the unit. |
void |
gradientInit()
Initializes the SOM based on a gradient from min to max. |
void |
init(int initMethod)
|
protected void |
initWithCorners(Vector<Double> upperLeft,
Vector<Double> upperRight,
Vector<Double> lowerLeft,
Vector<Double> lowerRight)
The SOM is initiated by giving specific values to the corner units of the map. |
boolean |
isColorByPCA()
|
void |
linearInit()
Initializes the SOM with the linear initialization algorithm as proposed by T. |
protected double |
mapunitDistance(int mu1,
int mu2)
Calculates and returns the Euclidean distance between two map units in the output space, i.e. its distance on the SOM-grid. |
void |
printVoronoiSet()
Prints the Voronoi-set of all map units to java.lang.System.out . |
void |
randomInit()
Initializes the SOM based on random values. |
void |
setAltLabels(Vector<String> labels)
|
void |
setCircular(boolean circular)
|
void |
setCoOccMatrix(DataMatrix coOccMatrix)
|
void |
setCoOccMatrixLabels(Vector<String> coOccMatrixLabels)
|
void |
setLabels(Vector<String> labels)
Sets the labels, i.e. the descriptions for the data items, of the SOM. |
void |
setMDM(MDM mdm)
|
void |
setSOMSize(int mapUnitsInRow,
int mapUnitsInColumn)
Sets the number of map units in each row and each column to the argument values. |
void |
setTrainingLength(int trainingLength)
|
void |
showCurrentFeatureState()
This method does the same as showCurrentFeatureState(int feature), but it prints all available features. |
void |
showCurrentFeatureState(int feature)
This method is useful for debugging SOM-initialisation-algorithms. |
void |
slcInit()
Initializes the SOM with the algorithm proposed by Su, Liu and Chang in "Improving the Self-Organizing Feature Map Algorithm Using an Efficient Initialization Scheme" created by MSt |
void |
train(int method,
int length)
Trains the SOM using the method given in the parameter method . |
protected void |
trainBatch()
Performs batch training. |
protected void |
trainSequential()
Performs a very simple sequential training based on the equation: mi(t+1) = mi(t) + alpha(t)*hbmu,i(t)*[x-mi(t)] . |
Vector<Double> |
vectorDistance(Vector<Double> item1,
Vector<Double> item2)
Calculates and returns a Vector containing the pairwise distances between the data vectors item1 and item2 . |
Vector<Double> |
vectorDistanceMultiply(Vector<Double> item1,
Vector<Double> item2,
double multi)
Calculates a Vector containing the pairwise distances between the data vectors item1 and item2 . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INIT_RANDOM
public static final int INIT_GRADIENT
public static final int INIT_LINEAR
public static final int INIT_SLC
public static final int TRAIN_SEQ
public static final int TRAIN_BATCH
public DataMatrix data
protected DataMatrix codebook
protected Vector<String> labels
protected Vector<String> altLabels
protected DataMatrix coOccMatrix
protected Vector<String> coOccMatrixLabels
protected int intMURows
protected int intMUCols
public Vector<Vector<Integer>> voronoiSet
protected int trainingLength
protected int method
protected boolean circular
public JLabel statusBar
statusBar
represents the status bar of the calling MainUI-instance and is used to update the status bar while performing training
Constructor Detail |
---|
public SOM(DataMatrix trainData)
trainData
.
trainData
- a DataMatrix containing the data for training the SOMpublic SOM(DataMatrix trainData, int rows, int cols)
trainData
.rows
and cols
.
trainData
- a DataMatrix containing the data for training the SOMrows
- the number of map units in vertical directioncols
- the number of map units in horizontal directionMethod Detail |
---|
public int getNumberOfRows()
public int getNumberOfColumns()
public int getNumberOfDataItems()
public void setSOMSize(int mapUnitsInRow, int mapUnitsInColumn)
mapUnitsInRow
- the number of map units per rowmapUnitsInColumn
- the number of map units per columnpublic void setLabels(Vector<String> labels) throws SizeMismatchException
labels
must contain as many String-instances as
there are data items in the training set.
labels
- a Vector containing one String for every data item in the traing set
SizeMismatchException
public void clearLabels()
public String getAltLabel(int dataItemIndex)
public Vector<String> getAltLabels()
public void setAltLabels(Vector<String> labels) throws SizeMismatchException
SizeMismatchException
public void clearAltLabels()
public String getLabel(int dataItemIndex)
dataItemIndex
.
If not labels were specified, the dataItemIndex
is returned as String.
dataItemIndex
- the index of the data item for which the label is requested
public DataMatrix getDataset()
public void init(int initMethod)
public void randomInit()
min
, max
).
public void gradientInit()
minVec
which contains all min-values and is written to the upper left;maxVec
which contains all max-values and is written to the lower right;
public void linearInit()
protected void initWithCorners(Vector<Double> upperLeft, Vector<Double> upperRight, Vector<Double> lowerLeft, Vector<Double> lowerRight)
public void slcInit()
public void train(int method, int length)
method
.
method
- the training method usedlength
- the training length in epochsTRAIN_SEQ
,
TRAIN_BATCH
protected void trainSequential()
Performs a very simple sequential training based on the equation:
mi(t+1) = mi(t) + alpha(t)*hbmu,i(t)*[x-mi(t)]
.
alpha(t)
the formula 1 - current_iteration/iterations
is taken.
The neighborhood-radius is calculated according to the formula:
hbmu,i(t) = exp(- ||rbmu, ri|| / 2*sigma(t)^2)
where the learning rate alpha
is used for sigma
.
protected void trainBatch()
mi(t+1) = sum(j=1..N, hbmu,i(t)*xi) / sum(j=1..N, hbmu,i(t))
The neighborhood-radius is calculated according to the formula:
hbmu,i(t) = exp(- ||rbmu, ri|| / 2*sigma(t)^2)
public int getBMU(Vector<Double> dataItem)
dataItem
and
returns its index in the codebook.
dataItem
- the Vector containing the data item for which the BMU should be determined
dataItem
public TreeMap<Double,Integer> getOrderedBMUs(Vector<Double> dataItem)
dataItem
and
returns the codebook-indices of these units.
dataItem
- the Vector containing the data item for which the BMUs should be determined
dataItem
public Vector<String> getPrototypesForMU(int idxMU, int maxNumber)
idxMU
- the index of the map unitmaxNumber
- the maximum number of returned data items
public static double euclideanDistance(Vector<Double> item1, Vector<Double> item2) throws SizeMismatchException
item1
and item2
.item1
and item2
must contain the same number of Double-instances,
otherwise a SizeMismatchException
is thrown.
item1
- a Vector representing the first data vectoritem2
- a Vector representing the second data vector
item1
and item2
SizeMismatchException
public Vector<Double> vectorDistance(Vector<Double> item1, Vector<Double> item2) throws SizeMismatchException
item1
and item2
.
item1
- a Vector representing the first data vectoritem2
- a Vector representing the second data vector
item1
- item2
SizeMismatchException
public Vector<Double> vectorDistanceMultiply(Vector<Double> item1, Vector<Double> item2, double multi) throws SizeMismatchException
item1
and item2
.
The result is multiplied with multi
before it is returned.
item1
- a Vector representing the first data vectoritem2
- a Vector representing the second data vectormulti
- the multiplier for (item1
and item2
)
item1
- item2
) * multi
SizeMismatchException
protected double mapunitDistance(int mu1, int mu2)
mu1
- the codebook-index of the first map unitmu2
- the codebook-index of the second map unit
mu1
and mu2
in the output spacepublic void createVoronoiSet()
voronoiSet
Vector
which contains a nested Vector containig Integers of mapped data item indices for each map unit.
public boolean[][] getVoronoiMatrix()
true
, otherwise false
.public void printVoronoiSet()
java.lang.System.out
.
This set contains all data items that are mapped to a specific map unit.
public void showCurrentFeatureState()
public void showCurrentFeatureState(int feature)
feature
from the codebook.
The visualised array shows the values of exactly this feature.
created by MSt
public Vector<String> getLabels()
public DataMatrix getCodebook()
public MDM getMDM()
public void setMDM(MDM mdm)
public boolean isColorByPCA()
public Color[] getGridcolors()
public void setTrainingLength(int trainingLength)
public void setCircular(boolean circular)
public DataMatrix getCoOccMatrix()
public void setCoOccMatrix(DataMatrix coOccMatrix)
public Vector<String> getCoOccMatrixLabels()
public void setCoOccMatrixLabels(Vector<String> coOccMatrixLabels)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |