Hi Experts, i have changed my ID from Mola to Moladou because my Mola Id is not working
Here is my whole code:
clear;
fn=7129;
col=fn+1;
cluster=2;
num_eachClass=19;
row=num_eachClass*cluster;
fid1 = fopen('data', 'r');
txt_format='';
for t=1:col
txt_format=[txt_format '%g '];
end
data = fscanf(fid1,txt_format,[col row]);
data = data';
fclose(fid1);
%%----------- training data and test data ------------
test_num = 0;
train_num = num_eachClass-test_num;
t1=1;
t2=1;
for i=1:row
t=mod(i-1,num_eachClass);
if t<train_num
Training(t1,:)=data(i,:);
t1=t1+1;
else
Test(t2,:)=data(i,:);
t2=t2+1;
end
end
TrainingLabel = Training(:,col);
Training = Training(:,1:fn);
if(test_num~=0)
TestLabel = Test(:,col);
Test = Test(:,1:fn);
end
train_row=t1-1;
test_row=t2-1;
%---------------To scale the data----------------------------------
%---------------normalize standard deviation to 1 ----------------
% %
% % for i2=1:fn
% % mean1=mean(Training(:,i2),1);
% % std1=std(Training(:,i2),1);
% % Training(:,i2) = (Training(:,i2)-mean1)/std1;
% %
% % if(test_num~=0)
% % Test(:,i2) = (Test(:,i2)-mean1)/std1;
% % end
% %
% % end
%%-------------------initial values-------------------
map_size = 15;
neighborhood = 9 ;
learning_rate = 0.8;
lattice = 'r'; % r : rect , h : hexa
iterations = 100;
%-----------------------------------------------------
%%--- To initiate the map
[Map] = initiate_som_Su(Training,train_row,fn,map_size);
%%--- training process---
[Map] = training_Batch(Training,train_row,fn,Map,map_size,neighborhood,lattice,iterations);
%--- calibrate the Map
[Map LabelMap] = calibrateMap(Training,TrainingLabel,train_row,fn,Map,map_size);
%% read the data
sD = som_read_data('data.txt');
% filter columns by variance
%% filter columns by variance
var_values = var(sD.data,1);
var_th = 1e5; % just an example that worked for me
indexToRemove = var_values < var_th;
sD.data(:,indexToRemove) = []; % filter out
sD.comp_names(indexToRemove) = [];
sD.comp_norm(indexToRemove) = [];
%% normalize the data
sD = som_normalize(sD,'var');
%% create, initialize and train a SOM
sM = som_make(sD,'lettice','hexa');
sM = som_autolabel(sM,sD,'vote');
%% U-matrix
U=som_umat(sM,'rect');
% U1=U(1:19,1:19);
figure, som_show(sM,'umat','all')
%% P-matrix
[pheight rad_real perc] = somvis_p_matrix(sM,sD);
tit = sprintf('P-Matrix (radius = %0.2f)', rad_real);
figure, som_show (sM, 'color', {pheight, tit});
%% U*-matrix
[ustar rad_real perc] = somvis_ustar_matrix(sM, sD);
tit = sprintf('U*-Matrix (radius = %0.2f)', rad_real);
figure, som_show (sM, 'color', {ustar, tit});
%---Show the labels of map
% showMap(Map,LabelMap,map_size,data,col);
%---
LabelMap
you can check to see where the error lies and edit that part for me.
Thanks