Created
November 11, 2009 23:05
-
-
Save muddana/232411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Neural Netowrks Project | |
% srinivas muddana | |
% 9561 - 2909 | |
% self organizing maps | |
function [initMap, map, elapsedTime, winNeurons] = testsomap(mapSize,ipData,epoochs) | |
initTime = clock; | |
mapDim = mapSize ; %array of two variables indicating the length and width of map | |
etaInit=0.1; | |
if (size(mapSize,1)~=1) | |
error 'The map size must be a vector' | |
end %end if for checking map is a two dim | |
ipDim = size(ipData,2); | |
ipLength = size(ipData,1); | |
%initializing the nodes assuming the map size is two D | |
totalNodes = mapSize(1) * mapSize(2); | |
rndWgts = rand(totalNodes,ipDim); | |
nodeCell = cell(mapSize(1),mapSize(2)); | |
perm = randperm(ipLength); | |
for i=1:mapSize(1) | |
for j=1:mapSize(2) | |
nodeCell{i,j}=ipData(perm((i-1)*mapSize(2)+j),:); | |
%nodeCell{i,j}=rndWgts((i-1)*mapSize(2)+j,:); | |
%nodeCell{i,j}=somNode(i,j,rndWgts((i-1)*mapSize(2)+j,:)); | |
end | |
end | |
initMap = nodeCell; | |
sigmaInit = max(mapSize(1),mapSize(2))/2; | |
winNeurons = []; | |
%traigning start | |
for numEpooch=1:epoochs %number of iterations...numEpooch is the n term | |
perm = randperm(ipLength); | |
numEpooch | |
for nIp=1:ipLength | |
minVal=inf; | |
%minPos; % showing x and y of the node .. like [2 4] 2nd row and 4th column | |
tempIp=ipData(perm(nIp),:); | |
%[minVal, minPos] = compete(obj,tempIp,minVal); | |
for i=1:mapDim(1) | |
for j=1:mapDim(2) | |
tempNode = nodeCell{i,j}; | |
tempMinVal = norm(tempNode); | |
%tempMinVal = tempNode.FindArgMin(tempIp); | |
if(tempMinVal<minVal) | |
minVal = tempMinVal; | |
minPos=[i j]; | |
end | |
end %end for scaning the columns in nodeCell | |
end %end for scaning the rows in nodeCell | |
var = find(winNeurons==(mapDim(1)-1)*minPos(1)+minPos(2)); | |
if(size(var,1)>0) | |
else | |
winNeurons(size(winNeurons,1)+1) = (mapDim(1)-1)*minPos(1)+minPos(2); | |
end | |
testh=[]; | |
%minPos | |
%co-operative process stats | |
for i=1:mapDim(1) | |
for j=1:mapDim(2) | |
tempWgts = nodeCell{i,j}; | |
%tempNode.updateWgts(tempIp,minPos(1),minPos(2),numEpooch,sigmaInit,etaInit); | |
eucDisSq = sqrt(sum(([i j]-[minPos(1) minPos(2)]).^2)); | |
t1=1000/log(sigmaInit); | |
sigma = sigmaInit * exp((-1*numEpooch)/t1); | |
if(sigma >= eucDisSq) | |
h=exp((-1*eucDisSq)/(2*sigma*sigma)); | |
testh(size(testh,2)+1) = h; | |
t2=1000; | |
eta = etaInit * exp((-1*numEpooch)/t2); | |
if eta < 0.01 | |
eta = 0.01; | |
end | |
delWgts = (tempIp-tempWgts).*eta * h; | |
nodeCell{i,j} = nodeCell{i,j} + delWgts; | |
else | |
minPos | |
end | |
end %end for scaning the columns in nodeCell | |
end %end for scaning the rows in nodeCell | |
%end of co-opertaive process | |
end %end for input order | |
end %end for | |
map = nodeCell; | |
finalTime = clock; | |
elapsedTime = etime(finalTime, initTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment