Borrar filtros
Borrar filtros

How to get neurons positions from net

2 visualizaciones (últimos 30 días)
Jorge Curto Martín
Jorge Curto Martín el 28 de Oct. de 2021
Editada: Malay Agarwal el 23 de Feb. de 2024
Hey, I have trained many times a som network (neural net clustering), to find clusters from data(green points), and I got this plot.
The code I used to train 10 times the same neuronal network to see different results was:
h = genvarname({'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1', 'trainALL1'});
for i = 11:20
x = transpose(AmplitudTemperaturaPeso);
net = selforgmap([25,25],100,3,'hextop','linkdist');
net = train(net,x);
%view(net)
y = net(x);
classes = vec2ind(y);
figure(i), plotsompos(net,x), daspect auto;
saveas(figure(i),genvarname(h{i-10}),'fig')
close all
end
My question is How can I get the position of each neuron in the space (x,y,z) ? (using commands)
I got it manipulating the plot (View> Plot Browser show only the neurons and Tool>Brush I select the neurons and clicking rigth button, I select cretate a new variable), but I want to automate the process, so I want a way to do it with commands.
I supose that the solution will be manipulating the variable net, but I don't know how to do it.
Thank you very much!!

Respuestas (1)

Malay Agarwal
Malay Agarwal el 23 de Feb. de 2024
Editada: Malay Agarwal el 23 de Feb. de 2024
Hi Jorge,
I understand that you want the (x, y, z) coordinates of each neuron as they appear in the plot generated by “plotsompos”.
The weights of the SOM network are stored in the property “IW” as a cell array. You can execute the following to access the property:
net.IW
The (x, y, z) coordinates of each neuron are taken directly from the weight matrix, depending on the dimensionality of the data:
  • If the data is one-dimensional (and thus, the weights are one-dimensional), the x-coordinate of the weight positions are taken from the only column of the weight matrix, the y-coordinate is 0 and the z-coordinate is set to 1.
  • If the data is two-dimensional, the x-coordinate and y-coordinates are taken from the two columns of the weight matrix and the z-coordinate is set to 1.
  • If the data is three-dimensional, the x-, y- and z-coordinates are taken from the three columns of the weight matrix.
  • For higher dimensional data, the x- and y-coordinates are taken from the first two columns of the weight matrix and the z-coordinate is set to 1.
The above behaviour is not documented but can be verified. For example, considering the case of one-dimensional data:
% Create one-dimensional dataset
angles = 0:0.5*pi/99:0.5*pi;
X = sin(angles);
% Create the net
net = selforgmap(10);
% Train the net for 10 epochs
net.trainParam.epochs = 10;
net = train(net, X);
% Plot the net
% TODO: Brush the data from the plot and store it in a variable called brushedData
plotsompos(net, X);
Now you can confirm the above behaviour as follows:
% Check x-coordinate matches first column of weight matrix
all(brushedData(:, 1) == net.IW{1}(:, 1))
% Check y-coordinate is 0
all(brushedData(:, 2) == 0)
% Check z-coordinate is 1
all(brushedData(:, 3) == 1)
All the “all” function calls return "logical" 1, which is the expected behaviour for one-dimensional data.
In your case, assuming the data is three-dimensional, the coordinates can be obtained as follows:
neuronCoords = net.IW{1}(:, [1 2 3]);
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by