setIoByModule

PURPOSE ^

SETIOBYMODULE set input and output neurons in separated modules

SYNOPSIS ^

function [ network, inputList, outputList ] = setIoByModule( network, nInput, nOutput )

DESCRIPTION ^

 SETIOBYMODULE set input and output neurons in separated modules

   [network, inputList, outputList] = setIoByModule(network, nInput, nOutput)
   First, this function randomly determined in which modules input neurons
   should be. Output neurons would be in the other modules. Then, we randomly
   select nInput neurons from input modules and nOutput neurons from output
   modules.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ network, inputList, outputList ] = setIoByModule( network, nInput, nOutput )
0002 % SETIOBYMODULE set input and output neurons in separated modules
0003 %
0004 %   [network, inputList, outputList] = setIoByModule(network, nInput, nOutput)
0005 %   First, this function randomly determined in which modules input neurons
0006 %   should be. Output neurons would be in the other modules. Then, we randomly
0007 %   select nInput neurons from input modules and nOutput neurons from output
0008 %   modules.
0009 
0010 
0011 %   ---------
0012 %   Yen-Nan Lin, NTHU, 2010-2014, Matlab 2012a
0013 
0014 moduleId = modularity_dir(full(network.matrix))';
0015 network.moduleId = moduleId;
0016 uniModuleId = unique(moduleId);
0017 nModule = numel(uniModuleId);
0018 for iModule = 1:nModule
0019     tmpModuleId = uniModuleId(iModule);
0020     tmpIx = find(moduleId == tmpModuleId);
0021     neuronIdEachModule{tmpModuleId} = network.label(tmpIx);
0022 end
0023 
0024 isValid = false;
0025 while isValid == false
0026     nModuleInput = randi(nModule - 1);
0027     nModuleOutput = nModule - nModuleInput;
0028 
0029     uniModuleId = uniModuleId(randperm(numel(uniModuleId)));
0030     inputModuleId = uniModuleId(1:nModuleInput);
0031     outputModuleId = uniModuleId((nModuleInput + 1):end);
0032 
0033     inputModuleNeuronId = [neuronIdEachModule{inputModuleId}];
0034     outputModuleNeuronId = [neuronIdEachModule{outputModuleId}];
0035     if (numel(inputModuleNeuronId) < nInput) || ...
0036         (numel(outputModuleNeuronId) < nOutput)
0037         continue;
0038     end
0039 
0040     inputModuleNeuronId = ...
0041         inputModuleNeuronId(randperm(numel(inputModuleNeuronId)));
0042     outputModuleNeuronId = ...
0043         outputModuleNeuronId(randperm(numel(outputModuleNeuronId)));
0044     inputList = inputModuleNeuronId(1:nInput);
0045     outputList = outputModuleNeuronId(1:nOutput);
0046     isValid = true;
0047 end
0048 network = sortByIO(network, [inputList, outputList]);
0049 network.inputList = inputList;
0050 network.outputList = outputList;
0051 network.inputNumber = nInput;
0052 network.outputNumber = nOutput;
0053 
0054 function [ network ] = sortByIO( network, ioList )
0055 for ix = 1:length(ioList)
0056     wantNode = ioList(ix);
0057     if isnumeric(ioList)
0058         wantNodeIndex = find(network.label == wantNode, 1);
0059     elseif ischar(ioList)
0060         error('Still cannot access string label');
0061     end
0062     network.matrix = swapCol(network.matrix, ix, wantNodeIndex);
0063     network.matrix = swapRow(network.matrix, ix, wantNodeIndex);
0064     network.label = swapCol(network.label, ix, wantNodeIndex);
0065     network.moduleId = swapCol(network.moduleId, ix, wantNodeIndex);
0066 end
0067 
0068 function [ matrix ] = swapCol( matrix, col1, col2 )
0069 matrix(:, [col1, col2]) = matrix(:, [col2, col1]);
0070 
0071 function [ matrix ] = swapRow( matrix, col1, col2 )
0072 matrix([col1, col2], :) = matrix([col2, col1], :);

Generated on Thu 30-Jan-2014 00:00:07 by m2html © 2005