Self-Organizing Maps
A self-organizing feature map (SOM) is a kind of competitive neural network designed to make it easier to visualize the structure of high-dimensional data.
Start with a blank map with desired dimensions.
net = selforgmap([10 10]);
You can change the properties of the network variable.
net.epochs = 1000;
Use the train function to train the SOM on data. Remember that data is expected to be arranged such that each column is an observation and each row is a variable.
X = measurements';
net = train(net,X);
You can use the function plotsomhits to visualize the number of observations assigned to each neuron.
plotsomhits(net,X)
You can use plotsomnd to plot the neighbor distances.
Larger distances are darker, indicating two neurons are far apart in the original n-dimensional space. A band of dark segments can help identify clusters.
Mapping New Data
Given a matrix of new data XNew, you can determine how each observation is mapped to the neurons in an existing network net using the syntax:
preds = net(XNew)
For a map with an m-by-n arrangement of neurons, the output preds has m*n rows (one row for each neuron), and the same number of columns as XNew. Each column of preds represents how the corresponding observation in XNew is assigned to the m*n neurons in the map. Consequently, every element of each column is 0, except one which has the value of 1.
You can find the neuron number of each observation by finding the index of the non-zero value in each column.
predindex = vec2ind(preds)
Use Commands to Create SOMs
如下矩陣
'measurements' is arranged so that each row represents an observation.
Transpose 'measurements' so that each column represents an observation. Name the resulting matrix X.
X = measurements';
The selforgmap function creates a self-organizing map with the given dimensions.
map = selforgmap([m n])
Use the train function on the self-organizing map and training data to train the neural network.
Create a self-organizing map with dimensions [8 6] and name it 'som'
som = selforgmap([8 6]);
Use 'som' and the data X to train a neural network and name the network net.
net = train(som,X);
Visualize your network by plotting sample hits and neighbor distances.
plotsomhits plots sample hits given the neural network and input data.
plotsomhits(net,X)
plotsomnd plots the neighbor distances.