Mercurial > forge
changeset 11214:9112a2b6f2d6 octave-forge
nnet: made __foo functions properly private
line wrap: on
line diff
--- a/main/nnet/NEWS Thu Nov 08 00:27:30 2012 +0000 +++ b/main/nnet/NEWS Thu Nov 08 01:51:04 2012 +0000 @@ -1,4 +1,24 @@ Summary of important user-visible changes for Neural Networks package 0.2.0: ---------------------------------------------------------------------------- + ** The following functions have been made private: + + __analyzerows.m __printBiasConnect.m __printNumLayerDelays.m + __calcjacobian.m __printBiases.m __printNumLayers.m + __calcperf.m __printB.m __printNumOutputs.m + __checknetstruct.m __printInitFcn.m __printNumTargets.m + __copycoltopos1.m __printInitParam.m __printOutputConnect.m + __dlogsig.m __printInputConnect.m __printOutputs.m + __dpurelin.m __printInputs.m __printPerformFcn.m + __dradbas.m __printInputWeights.m __printPerformParam.m + __dtansig.m __printIW.m __printTargetConnect.m + __getx.m __printLayerConnect.m __printTargets.m + __init.m __printLayers.m __printTrainFcn.m + __mae.m __printLayerWeights.m __printTrainParam.m + __mse.m __printLW.m __randomisecols.m + __newnetwork.m __printMLPHeader.m __rerangecolumns.m + __optimizedatasets.m __printNetworkType.m __setx.m + __printAdaptFcn.m __printNumInputDelays.m __trainlm.m + __printAdaptParam.m __printNumInputs.m + ** Package is no longer automatically loaded.
--- a/main/nnet/inst/__analyzerows.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{retmatrix} = __analyzerows(@var{matrix}) -## @code{__analyzerows} takes a matrix as input argument and checks what kind of -## data are contained in the rows. -## a.) binary values? Means the row contains only 0 and 1 -## b.) unique values? -## c.) Min values are several times contained in the row -## d.) Max values are several times contained in the row -## @end deftypefn - -## Author: mds - -function retmatrix = __analyzerows(matrix) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - nRows = size(matrix,1); # get number or rows - retmatrix = zeros(nRows,4); - doneVec = zeros(nRows,1); - - ## now let's check which rows are binary - i = 1; - while (i <= nRows) - vec = matrix(i,:); - n1 = find(vec==1); - n0 = find(vec==0); - if (length(n1)==0 || length(n0)==0) - #do nothing - else - if (length(vec)==(length(n1)+length(n0))) - # in this case, the vector contains only ones and zeros - retmatrix(i,1) = 1; - doneVec(i) = 1; - endif - endif - i += 1; - endwhile - - ## now let's check which rows are unique - i = 1; - while (i <= nRows) - if (doneVec(i)==0) - vec = matrix(i,:); - n1 = find(vec==vec(1)); - if (length(vec)==(length(n1))) - # in this case, the vector contains only unique data - retmatrix(i,2) = 1; - doneVec(i) = 1; - endif - endif - i += 1; - endwhile - - - ## now let's check how often we can find the min value - i = 1; - while (i <= nRows) - if (doneVec(i)==0) - vec = matrix(i,:); - n1 = min(vec); - retmatrix(i,3) = length(find(n1==vec)); - endif - i += 1; - endwhile - - ## now let's check how often we can find the max value - i = 1; - while (i <= nRows) - if (doneVec(i)==0) - vec = matrix(i,:); - n1 = max(vec); - retmatrix(i,4) = length(find(n1==vec)); - endif - i += 1; - endwhile - -endfunction - -%!shared b, retmat -%! disp("testing __analyzerows") -%! b = [1 0 0 1; 1 0 0 0; 1 2 0 1]; -%! retmat = __analyzerows(b); -%!assert(retmat(1,1)==1);#%!assert(retmat(1,1)==1); -%!assert(retmat(2,1)==1); -%!assert(retmat(3,1)==0); -%! b = [1 0 0 2; 1 0 0 0; 1 1 1 1]; -%! retmat = __analyzerows(b); -%!assert(retmat(1,2)==0); -%!assert(retmat(2,2)==0); -%!assert(retmat(3,2)==1); -%! b = [1 0 0 2; 1 0 0 0; 1 1 1 1]; -%! retmat = __analyzerows(b); -%!assert(retmat(1,3)==2); -%!assert(retmat(2,3)==0); -%!assert(retmat(3,3)==0); -%! retmat = __analyzerows(b); -%!assert(retmat(1,4)==1); -%!assert(retmat(2,4)==0); -%!assert(retmat(3,4)==0);
--- a/main/nnet/inst/__calcjacobian.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,283 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}@var{Jj} = __calcjacobian (@var{net},@var{Im},@var{Nn},@var{Aa},@var{vE}) -## This function calculates the jacobian matrix. It's used inside the -## Levenberg-Marquardt algorithm of the neural network toolbox. -## PLEASE DO NOT USE IT ELSEWEHRE, it proparly will not work! -## @end deftypefn - -## Author: Michel D. Schmid - - -function [Jj] = __calcjacobian(net,Im,Nn,Aa,vE) - - ## comment: - ## - return value Jj is jacobi matrix - ## for this calculation, see "Neural Network Design; Hagan, Demuth & Beale page 12-45" - - - ## check range of input arguments - error(nargchk(5,5,nargin)) - - ## get signals from inside the network - bias = net.b; - - ## calculate some help matrices - mInputWeight = net.IW{1} * Im; - nLayers = net.numLayers; - for i=2:nLayers - mLayerWeight{i,1} = net.LW{i,i-1} * Aa{i-1,1}; - endfor - - ## calculate number of columns and rows in jacobi matrix - ## firstly, number of columns - a = ones(nLayers+1,1); # +1 is for the input - a(1) = net.inputs{1}.size; - for iLayers = 1:nLayers - a(iLayers+1) = net.layers{iLayers}.size; - endfor - nColumnsJacobiMatrix = 0; - for iLayers = 1:nLayers - nColumnsJacobiMatrix = (a(iLayers)+1)*a(iLayers+1) + nColumnsJacobiMatrix; - endfor - ## secondly, number of rows - ve = vE{nLayers,1}; - nRowsJacobiMatrix = length(ve(:)); - - - ## FIRST STEP ----------------------------------------------------- - ## calculate the neuron outputs without the transfer function - ## - n1_1 = W^1*a_1^0+b^1: the ^x factor defined the xth train data set - ## the _x factor defines the layer - ## ********** this datas should be hold in Nn - ## ********** should be calculated in "__calcperf" - ## ********** so Nn{1} means hidden layer - ## ********** so Nn{2} means second hidden layer or output layer - ## ********** and so on ... - ## END FIRST STEP ------------------------------------------------- - - ## now we can rerange the signals ... this will be done only for - ## matrix calculation ... - [nRowsError nColumnsError] = size(ve); - errorSize = size(ve(:),1); # this will calculate, if only one row - # of errors exist... in other words... two rows will be reranged to - # one row with the same number of elements. - rerangeIndex = floor([0:(errorSize-1)]/nRowsError)+1; - nLayers = net.numLayers; - - for i = 1:nLayers - Nn{i,1} = Nn{i,1}(:,rerangeIndex); - Aa{i,1} = Aa{i,1}(:,rerangeIndex); - [nRows nColumns] = size(Nn{i,1}); - bTemp = bias{i,1}; - bias{i,1} = repmat(bTemp,1,nColumns); - bias{i,1} = bias{i,1}(:,rerangeIndex); - endfor - mInputWeight = mInputWeight(:,rerangeIndex); - for i=2:nLayers - mLayerWeight{i,1} = mLayerWeight{i,1}(:,rerangeIndex); - endfor - Im = Im(:,rerangeIndex); - - ## define how the errors are connected - ## ATTENTION! this happens in row order... - numTargets = net.numTargets; - mIdentity = -eye(numTargets); - cols = size(mIdentity,2); - mIdentity = mIdentity(:,rem(0:(cols*nColumnsError-1),cols)+1); - errorConnect = cell(net.numLayers,1); - startPos = 0; - for i=net.numLayers - targSize = net.layers{i}.size; - errorConnect{i} = mIdentity(startPos+[1:targSize],:); - startPos = startPos + targSize; - endfor - - ## SECOND STEP ---------------------------------------------- - ## define and calculate the derivative matrix dF - ## - this is "done" by the two first derivative functions - ## of the transfer functions - ## e.g. __dpureline, __dtansig, __dlogsig and so on ... - - ## calculate the sensitivity matrix tildeS - ## start at the end layer, this means of course the output layer, - ## the transfer function is selectable - - ## for calculating the last layer - ## this should happen like following: - ## tildeSx = -dFx(n_x^x) - ## use mIdentity to calculate the number of targets correctly - ## for all other layers, use instead: - ## tildeSx(-1) = dF1(n_x^(x-1))(W^x)' * tildeSx; - - for iLayers = nLayers:-1:1 # this will count from the last - # layer to the first layer ... - n = Nn{iLayers}; # nLayers holds the value of the last layer... - ## which transfer function should be used? - if (iLayers==nLayers) - switch(net.layers{iLayers}.transferFcn) - case "radbas" - tildeSxTemp = __dradbas(n); - case "purelin" - tildeSxTemp = __dpurelin(n); - case "tansig" - n = tansig(n); - tildeSxTemp = __dtansig(n); - case "logsig" - n = logsig(n); - tildeSxTemp = __dlogsig(n); - otherwise - error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"]) - endswitch - tildeSx{iLayers,1} = tildeSxTemp .* mIdentity; - n = bias{nLayers,1}; - switch(net.layers{iLayers}.transferFcn) - case "radbas" - tildeSbxTemp = __dradbas(n); - case "purelin" - tildeSbxTemp = __dpurelin(n); - case "tansig" - n = tansig(n); - tildeSbxTemp = __dtansig(n); - case "logsig" - n = logsig(n); - tildeSbxTemp = __dlogsig(n); - otherwise - error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"]) - endswitch - tildeSbx{iLayers,1} = tildeSbxTemp .* mIdentity; - endif - - if (iLayers<nLayers) - dFx = ones(size(n)); - switch(net.layers{iLayers}.transferFcn) ######## new lines ... - case "radbas" - nx = radbas(n); - dFx = __dradbas(nx); - case "purelin" - nx = purelin(n); - dFx = __dpurelin(nx); - case "tansig" ######## new lines ... - nx = tansig(n); - dFx = __dtansig(nx); - case "logsig" ######## new lines ... - nx = logsig(n); ######## new lines ... - dFx = __dlogsig(nx); ######## new lines ... - otherwise ######## new lines ... - error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"])######## new lines ... - endswitch ############# new lines .... - LWtranspose = net.LW{iLayers+1,iLayers}; - if iLayers<(nLayers-1) - mIdentity = -ones(net.layers{iLayers}.size,size(mIdentity,2)); - endif - - mTest = tildeSx{iLayers+1,1}; - LWtranspose = LWtranspose' * mTest; - tildeSx{iLayers,1} = dFx .* LWtranspose; - tildeSxTemp = dFx .* LWtranspose; - tildeSbx{iLayers,1} = ones(size(nx)).*tildeSxTemp; - endif - - endfor # if iLayers = nLayers:-1:1 - ## END SECOND STEP ------------------------------------------------- - - ## THIRD STEP ------------------------------------------------------ - ## some problems occur if we have more than only one target... so how - ## does the jacobi matrix looks like? - - ## each target will cause an extra row in the jacobi matrix, for - ## each training set.. this means, 2 targets --> double of rows in the - ## jacobi matrix ... 3 targets --> three times the number of rows like - ## with one target and so on. - - ## now calculate jacobi matrix - ## to do this, define first the transposed of it - ## this makes it easier to calculate on the "batch" way, means all inputs - ## at the same time... - ## and it makes it easier to use the matrix calculation way.. - - JjTrans = zeros(nRowsJacobiMatrix,nColumnsJacobiMatrix)'; # transposed jacobi matrix - - ## Weight Gradients - for i=1:net.numLayers - if i==1 - newInputs = Im; - newTemps = tildeSx{i,1}; - gIW{i,1} = copyRows(newTemps,net.inputs{i}.size) .* copyRowsInt(newInputs,net.layers{i}.size); - endif - if i>1 - Ad = cell2mat(Aa(i-1,1)'); - newInputs = Ad; - newTemps = tildeSx{i,1}; - gLW{i,1} = copyRows(newTemps,net.layers{i-1}.size) .* copyRowsInt(newInputs,net.layers{i}.size); - endif - endfor - - for i=1:net.numLayers - [nRows, nColumns] = size(Im); - if (i==1) - nWeightElements = a(i)*a(i+1); # n inputs * n hidden neurons - JjTrans(1:nWeightElements,:) = gIW{i}(1:nWeightElements,:); - nWeightBias = a(i+1); - start = nWeightElements; - JjTrans(start+1:start+nWeightBias,:) = tildeSbx{i,1}; - start = start+nWeightBias; - endif - if (i>1) - nLayerElements = a(i)*a(i+1); # n hidden neurons * n output neurons - JjTrans(start+1:start+nLayerElements,:)=gLW{i}(1:nLayerElements,:); - start = start + nLayerElements; - nLayerBias = a(i+1); - JjTrans(start+1:start+nLayerBias,:) = tildeSbx{i,1}; - start = start + nLayerBias; - endif - endfor - Jj = JjTrans'; - ## END THIRD STEP ------------------------------------------------- - - -#======================================================= -# -# additional functions -# -#======================================================= - - function k = copyRows(k,m) - # make copies of the ROWS of Aa matrix - - mRows = size(k,1); - k = k(rem(0:(mRows*m-1),mRows)+1,:); - endfunction - -# ------------------------------------------------------- - - function k = copyRowsInt(k,m) - # make copies of the ROWS of matrix with elements INTERLEAVED - - mRows = size(k,1); - k = k(floor([0:(mRows*m-1)]/m)+1,:); - endfunction - -# ===================================================================== -# -# END additional functions -# -# ===================================================================== - -endfunction
--- a/main/nnet/inst/__calcperf.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <email: michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}[@var{perf}, @var{Ee}, @var{Aa}, @var{Nn}] = __calcperf (@var{net},@var{xx},@var{Im},@var{Tt}) -## @code{__calcperf} calculates the performance of a multi-layer neural network. -## PLEASE DON'T USE IT ELSEWHERE, it proparly won't work. -## @end deftypefn - -## Author: Michel D. Schmid - - -function [perf,Ee,Aa,Nn] = __calcperf(net,xx,Im,Tt) - - ## comment: - ## perf, net performance.. from input to output through the hidden layers - ## Aa, output values of the hidden and last layer (output layer) - ## is used for NEWFF network types - - ## calculate bias terms - ## must have the same number of columns like the input matrix Im - [nRows, nColumns] = size(Im); - Btemp = cell(net.numLayers,1); # Btemp: bias matrix - ones1xQ = ones(1,nColumns); - for i= 1:net.numLayers - Btemp{i} = net.b{i}(:,ones1xQ); - endfor - - ## shortcuts - IWtemp = cell(net.numLayers,net.numInputs,1);# IW: input weights ... - LWtemp = cell(net.numLayers,net.numLayers,1);# LW: layer weights ... - Aa = cell(net.numLayers,1);# Outputs hidden and output layer - Nn = cell(net.numLayers,1);# outputs before the transfer function - IW = net.IW; # input weights - LW = net.LW; # layer weights - - ## calculate the whole network till outputs are reached... - for iLayers = 1:net.numLayers - - ## calculate first input weights to weighted inputs.. - ## this can be done with matrix calculation... - ## called "dotprod" - ## to do this, there must be a special matrix ... - ## e.g. IW = [1 2 3 4 5; 6 7 8 9 10] * [ 1 2 3; 4 5 6; 7 8 9; 10 11 12; 1 2 3]; - if (iLayers==1) - IWtemp{iLayers,1} = IW{iLayers,1} * Im; - onlyTempVar = [IWtemp(iLayers,1) Btemp(iLayers)]; - else - IWtemp{iLayers,1} = []; - endif - - ## now calculate layer weights to weighted layer outputs - if (iLayers>1) - Ad = Aa{iLayers-1,1}; - LWtemp{iLayers,1} = LW{iLayers,iLayers-1} * Ad; - onlyTempVar = [LWtemp(iLayers,1) Btemp(iLayers)]; - else - LWtemp{iLayers,1} = []; - endif - - Nn{iLayers,1} = onlyTempVar{1}; - for k=2:length(onlyTempVar) - Nn{iLayers,1} = Nn{iLayers,1} + onlyTempVar{k}; - endfor - - ## now calculate with the transfer functions the layer output - switch net.layers{iLayers}.transferFcn - case "purelin" - Aa{iLayers,1} = purelin(Nn{iLayers,1}); - case "tansig" - Aa{iLayers,1} = tansig(Nn{iLayers,1}); - case "logsig" - Aa{iLayers,1} = logsig(Nn{iLayers,1}); - otherwise - error(["Transfer function: " net.layers{iLayers}.transferFcn " doesn't exist!"]) - endswitch - - endfor # iLayers = 1:net.numLayers - - ## now calc network error - Ee = cell(net.numLayers,1); - - for i=net.numLayers - Ee{i,1} = Tt{i,1} - Aa{i,1};# Tt: target - # Ee will be the error vector cell array - endfor - - ## now calc network performance - switch(net.performFcn) - case "mse" - perf = __mse(Ee); - otherwise - error("for performance functions, only mse is currently valid!") - endswitch - -endfunction
--- a/main/nnet/inst/__checknetstruct.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}[@var{isTrue}] = __checknetstruct (@var{net}) -## This function will check if a valid structure seems to be a neural network -## structure -## -## @noindent -## -## left side arguments: -## @noindent -## -## right side arguments: -## @noindent -## -## -## @noindent -## are equivalent. -## @end deftypefn - -## @seealso{newff,prestd,trastd} - -## Author: Michel D. Schmid - - -function isTrue = __checknetstruct(net) - - isTrue = 0; - ## first check, if it's a structure - if (isstruct(net) && isfield(net,"networkType")) - isTrue = 1; - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__copycoltopos1.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{retmatrix} = __copycoltopos1(@var{matrix},@var{colIndex}) -## @code{__copycoltopos1} copies the column of position colIndex to the first position. -## Moves the rest of the matrix one position to the right. -## @end deftypefn - -## Author: mds - -function retmatrix = __copycoltopos1(matrix,colIndex) - - ## check number of inputs - error(nargchk(2,2,nargin)); - - temp = matrix(:,colIndex); - matrix(:,colIndex) = []; # delete col - retmatrix = [temp matrix ]; - -endfunction - -%!shared a, retmat -%! disp("testing __copycoltopos1") -%! a = [0 1 2 3 4; 5 6 7 8 9]; -%! retmat = __copycoltopos1(a,3); -%!assert(retmat(1,1)==2); -%!assert(retmat(2,1)==7); -%! retmat = __copycoltopos1(a,5); -%!assert(retmat(1,1)==4); -%!assert(retmat(2,1)==9);
--- a/main/nnet/inst/__dlogsig.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -## Copyright (C) 2007 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}[@var{a} = __dlogsig (@var{n}) -## -## @end deftypefn - -## @seealso{__dpurelin,__dtansig} - -## Author: Michel D. Schmid - - -function a = __dlogsig(n) - - a = n.*(1-n); - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__dpurelin.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{a} = __dpurelin (@var{n}) -## @code{dpurelin}, first derivative of purelin -## @example -## -## purelin is a linear transfer function used by neural networks -## @end example -## -## @end deftypefn - -## Author: Michel D. Schmid - -function a = __dpurelin(n) - - [nRows, nColumns] = size(n); - a = ones(nRows,nColumns); - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__dradbas.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -## Copyright (C) 2010 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __dradbas (@var{n}) -## First derivative of the radial basis transfer function. -## -## @code{__dradbas(n) = exp(-n^2)*-2*x} -## -## @end deftypefn - -## Author: Michel D. Schmid - - -function retval = __dradbas (n) - - if (nargin != 1) - print_usage (); - else - retval = exp (-n^2)*(-2)*x; - # the derivative of exp(-n^2) must be calculated - # with help of the chain-rule! - # d/dx of e^x = e^x - # d/dx of -x^2 = -2x - # now calculate the product of both - endif -endfunction - - -#%!assert (radbas (3), exp (-3^2));
--- a/main/nnet/inst/__dtansig.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}[@var{n} = __dtansig (@var{n}) -## first derivative of @code{tansig} -## -## @example -## -## tansig is a symmetric non linear transfer function -## used by neural networks. -## Input n must be calculated with "n = tansig(n)". -## @end example -## -## @end deftypefn - -## Author: Michel D. Schmid - - -function a = __dtansig(n) - - a = 1-(n.*n); - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__getx.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program ; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{x} = __getx (@var{net}) -## @code{__getx} will rerange the weights in one columns vector. -## -## -## @noindent -## @end deftypefn - - -## Author: Michel D. Schmid - -function x = __getx(net) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - ## check input args - ## check "net", must be a net structure - if !__checknetstruct(net) - error("Structure doesn't seem to be a neural network") - endif - - ## inputs - x = net.IW{1,1}(:); - x = [x; net.b{1}(:)]; - - nNumLayers = net.numLayers; - for iLayers = 2:nNumLayers # 1 would be the input layer - - ## layers - x = [x; net.LW{iLayers,iLayers-1}(:)]; - x = [x; net.b{iLayers}(:)]; - - endfor - - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__init.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{net} = __init (@var{net}) -## @code{__init} initializes a neural network. This will be done -## with the function @code{rand} from octave. -## -## @example -## net = __init(net); -## @end example -## -## This function takes the octave function "rand" to init the -## neural network weights. -## -## @noindent -## @end deftypefn - - -## Author: Michel D. Schmid - -function net=__init(net) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - ## check input - if ( !__checknetstruct(net) ) - error("__init: wrong argument type, must be a structure!"); - endif - - - if (strcmp(net.networkType,"newff")) - - ## init with random numbers between +-1 - ## input weight layer - mRand = rand(net.layers{1}.size,net.inputs{1}.size); - net.IW{1} = mRand*2-1; - - ## hidden layers - nLayers = net.numLayers; - for i=2:nLayers - mRand = rand(net.layers{i}.size,net.layers{i-1}.size); - net.LW{i,i-1} = mRand*2-1; - endfor - for i=1:nLayers - mRand = rand(net.biases{i}.size,1); - net.b{i} = mRand*2-1; - endfor - elseif (strcmp(net.networkType,"newp")) - - ## init with zeros - inputRows = size(net.inputs{1,1}.range,1); - net.IW{1} = zeros(inputRows,1); - net.b{1} = zeros(1,1); - endif - - ## warn user of constant inputs - for i=1:net.numInputs - prange = net.inputs{i}.range; - if (any(prange(:,1) == prange(:,2))) - fprintf("\n") - fprintf("** Warning in INIT\n") - fprintf("** Network net.inputs{%g}.range has a row with equal min and max values.\n",i) - fprintf("** Constant inputs do not provide useful information.\n") - fprintf("\n") - end - end - -endfunction
--- a/main/nnet/inst/__mae.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -## Copyright (C) 2007 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn {Function File} {}@var{perf} = __mae (@var{E}) -## @code{__mse} returns the Mean-Square-Error of a vector E -## -## @example -## -## This function is used to calculate the perceptron performance -## @end example -## -## @end deftypefn - -## @seealso{__mse} - -## Author: Michel D. Schmid - -function perf = __mae(E) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - if iscell(E) - perf = 0; - elements = 0; - for i=1:size(E,1) - for j=1:size(E,2) - perf = perf + sum(sum(E{i,j}.^2)); - elements = elements + prod(size(E{i,j})); - endfor - endfor - perf = perf / elements; - else - error("Error vector should be a cell array!") - endif - - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__mse.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}@var{perf} = __mse (@var{E}) -## @code{__mse} returns the Mean-Square-Error of a vector E -## -## @example -## -## This function is used to calculate the network performance -## @end example -## -## @end deftypefn - -## @seealso{__mae} - -## Author: Michel D. Schmid - -function perf = __mse(E) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - if iscell(E) - perf = 0; - elements = 0; - for i=1:size(E,1) - for j=1:size(E,2) - perf = perf + sum(sum(E{i,j}.^2)); - elements = elements + prod(size(E{i,j})); - endfor - endfor - perf = perf / elements; - else - error("Error vector should be a cell array!") - endif - - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__newnetwork.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}{@var{net}} = __newnetwork(@var{numInputs},@var{numLayers},@var{numOutputs},@var{networkType}) -## @code{__newnetwork} create a custom 'zero'-network -## -## -## @example -## net = __newnetwork(numInputs,numLayers,numOutputs,networkType) -## -## numInputs : number of input vectors, actually only 1 allowed -## numLayers : number of layers -## numOutputs: number of output vectors, actually only 1 allowed -## networkType: e.g. feed-forward-network "newff" -## @end example -## -## @example -## net = __newnetwork(1,2,1,"newff") -## 1 input layer, two hidden layers, one output layer -## and the network type -## @end example -## -## @noindent -## @end deftypefn - -## Author: Michel D. Schmid - -function net = __newnetwork(numInputs,numLayers,numOutputs,networkType) - - ## check range of input arguments - error(nargchk(4,4,nargin)) - - ## check input args - if ( !isposint(numInputs) ) - error("network: at least 1 input must be defined! ") - # this can't happen actually, only one is allowed and this - # one is hard coded - elseif ( !isposint(numLayers) ) - error("network: at least 1 hidden- and one output layer must be defined! ") - endif - ## second check for numLayers... must be at least "2" for the - ## newff, this means at least 1 hidden and 1 output layer - if (strcmp(networkType,"newff") && (numLayers<2)) - error("network: not enough layers are defined! ") - endif - - ## define network type - net.networkType = networkType; - - ## ZERO NETWORK - net.numInputs = 0; - net.numLayers = 0; - net.numInputDelays = 0; - net.numLayerDelays = 0; - # the next five parameters aren't used till now, they are used - # only for matlab nnet type compatibility ==> saveMLPStruct - net.biasConnect = []; # not used parameter till now - net.inputConnect = []; # not used parameter till now - net.layerConnect = []; # not used parameter till now - net.outputConnect = []; # not used parameter till now - net.targetConnect = []; # not used parameter till now - net.numOutputs = 0; - net.numTargets = 0; - net.inputs = cell(0,1); - net.layers = cell(0,1); - net.biases = cell(0,1); - net.inputWeights = cell(0,0); - net.layerWeights = cell(0,0); - net.outputs = cell(1,0); - net.targets = cell(1,0); - net.performFcn = ""; - net.performParam = []; - net.trainFcn = ""; - net.trainParam = []; - net.IW = {}; - net.LW = {}; - net.b = cell(0,1); - net.userdata.note = "Put your custom network information here."; - - - ## ARCHITECTURE - - ## define everything with "inputs" - net.numInputs = numInputs; - ## actually, it's only possible to have "one" input vector - net.inputs{1,1}.range = [0 0]; - net.inputs{1,1}.size = 0; - net.inputs{1,1}.userdata = "Put your custom informations here!"; - - ## define everything with "layers" - net.numLayers = numLayers; - net = newLayers(net,numLayers); - - ## define unused variables, must be defined for saveMLPStruct - net.biasConnect = [0; 0]; - net.inputConnect = [0; 0]; - net.layerConnect = [0 0; 0 0]; - net.outputConnect = [0 0]; - net.targetConnect = [0 0]; - net.numInputDelays = 0; - net.numLayerDelays = 0; - - ## define everything with "outputs" - net.numOutputs = numOutputs; - net.outputs = cell(1,numLayers); - for i=1:numLayers - if (i==numLayers) - net.outputs{i}.size = 1; # nothing else allowed till now - net.outputs{i}.userdata = "Put your custom informations here!"; - else - net.outputs{i} = []; - endif - endfor - - ## define everything with "biases" - net = newBiases(net,numLayers); - - - -#===================================================== -# -# Additional ARCHITECTURE Functions -# -#===================================================== - function net = newLayers(net,numLayers) - - ## check range of input arguments - error(nargchk(2,2,nargin)) - - ## check type of arguments - if ( !isscalar(numLayers) || !isposint(numLayers) ) - error("second argument must be a positive integer scalar value!") - endif - if ( !__checknetstruct(net) ) - error("first argument must be a network structure!") - endif - - for iRuns=1:numLayers - net.layers{iRuns,1}.dimension = 0; - net.layers{iRuns,1}.netInputFcn = ""; - net.layers{iRuns,1}.size = 0; -### TODO: test with newff net.layers{iRuns,1}.transferFcn = "tansig"; - net.layers{iRuns,1}.transferFcn = ""; - net.layers{iRuns,1}.userdata = "Put your custom informations here!"; - endfor - - endfunction - -#----------------------------------------------------- - - function net = newBiases(net,numLayers) - - ## check range of input arguments - error(nargchk(2,2,nargin)) - - ## check type of arguments - if ( !isscalar(numLayers) || !isposint(numLayers) ) - error("second argument must be a positive integer scalar value!") - endif - if ( !isstruct(net) ) - error("first argument must be a network structure!") - endif - - for iRuns=1:numLayers - net.biases{iRuns,1}.learn = 1; - net.biases{iRuns,1}.learnFcn = ""; - net.biases{iRuns,1}.learnParam = "undefined..."; - net.biases{iRuns,1}.size = 0; - net.biases{iRuns,1}.userdata = "Put your custom informations here!"; - endfor - - endfunction - -# ================================================================ -# -# END Additional ARCHITECTURE Functions -# -# ================================================================ - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__optimizedatasets.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{retmatrix} = __optimizedatasets (@var{matrix},@var{nTrainSets},@var{nTargets},@var{bRand}) -## @code{__optimizedatasets} reranges the data sets depending on the input arguments. -## @code{matrix} is the data set matrix containing inputs and outputs (targets) in row order. -## This means for example: the first three rows are inputs and the fourth row is an output row. -## The second argument is used in the optimizing algorithm. All cols with min and max values must -## be in the range of the train data sets. The third argument defines how much rows are equal to the -## neural network targets. These rows must be at the end of the data set! -## The fourth arguemnt is optional and defines if the data sets have to be randomised before -## optimizing. -## Default value for bRand is 1, means randomise the columns. -## @end deftypefn - -## Author: mds - -function retmatrix = __optimizedatasets(matrix,nTrainSets,nTargets,bRand) - - ## check number of inputs - error(nargchk(3,4,nargin)); - - # set default values - bRandomise = 1; - - if (nargin==4) - bRandomise = bRand; - endif - - # if needed, randomise the cols - if (bRandomise) - matrix = __randomisecols(matrix); - endif - - # analyze matrix, which row contains what kind of data? - # a.) binary values? Means the row contains only 0 and 1 - # b.) unique values? - # c.) Min values are several times contained in the row - # d.) Max values are several times contained in the row - matrix1 = matrix(1:end-nTargets,:); - analyzeMatrix = __analyzerows(matrix1); - - # now sort "matrix" with help of analyzeMatrix - # following conditions must be kept: - # a.) rows containing unique values aren't sorted! - # b.) sort first rows which contains min AND max values only once - # c.) sort secondly rows which contains min OR max values only once - # d.) at last, sort binary data if still needed! - retmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); - - -endfunction - -%!shared retmatrix, matrix -%! disp("testing __optimizedatasets") -%! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \ -%! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \ -%! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \ -%! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1]; -%! ## The last row is equal to the neural network targets -%! retmatrix = __optimizedatasets(matrix,9,1); -%! ## the above statement can't be tested with assert! -%! ## it contains random values! So pass a "success" message -%!assert(1==1); -%! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \ -%! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \ -%! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \ -%! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1]; -%! ## The last row is equal to the neural network targets -%! retmatrix = __optimizedatasets(matrix,9,1,0); -%!assert(retmatrix(1,1)==5); -%!assert(retmatrix(2,1)==0); -%!assert(retmatrix(3,1)==1); -%!assert(retmatrix(4,1)==3); \ No newline at end of file
--- a/main/nnet/inst/__printAdaptFcn.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This software is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this software; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printAdaptFcn (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printAdaptFcn(fid,net) - - if isfield(net,"adaptFcn") - if isempty(net.adaptFcn) - fprintf(fid," adaptFcn: '%s'\n","empty"); - else - fprintf(fid," adaptFcn: '%s'\n",net.adaptFcn); - endif - endif - -endfunction
--- a/main/nnet/inst/__printAdaptParam.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printAdaptParam (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printAdaptParam(fid,net) - - if isfield(net,"adaptParam") - if isempty(net.adaptParam) - fprintf(fid," adaptParam: '%s'\n","not yet used item"); - else - fprintf(fid," adaptParam: '%s'\n",net.adaptParam); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printB.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printB (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printB(fid,net) - - if isfield(net,"b") - nBiases = 0; - # check if it's cell array - if iscell(net.b) - [nRows, nColumns] = size(net.b); - for i=1:nRows - for k=1:nColumns - if !isempty(net.b{i,k}) - nBiases = nBiases+1; - endif - endfor - endfor - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," b: {%dx%d cell} containing %d bias vectors\n",nRows,nColumns,nBiases); - else - fprintf(fid,"unsure if this is possible\n") - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printBiasConnect.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printBiasConnect (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printBiasConnect(fid,net) - - if isfield(net,"biasConnect") - # net.biasConnect can be a matrix..! - # check if it's a matrix - if isscalar(net.biasConnect) - error("unsure if this is possible..") - elseif isnumeric(net.biasConnect) - if ismatrix(net.biasConnect) - if issquare(net.biasConnect) - # nothing prgrammed till now - elseif isvector(net.biasConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - # print bracket for open - fprintf(fid," biasConnect: ["); - [nRows nColumns] = size(net.biasConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - fprintf(fid,"%d",net.biasConnect(i*k)); - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - endif # if issquare.. - endif #if ismatrix - endif # isscalar(net.biasConnect) - endif # if isfield(...) - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printBiases.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printBiases (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printBiases(fid,net) - - if isfield(net,"biases") - # check if it's cell array - if iscell(net.biases) - [nRows, nColumns] = size(net.biases); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," biases: {%dx%d cell} containing %d biases\n",nRows,nColumns,length(net.biases)); - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printIW.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printIW (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printIW(fid,net) - - if isfield(net,"IW") - nInputs = 0; - # check if it's cell array - if iscell(net.IW) - [nRows, nColumns] = size(net.IW); - for i=1:nRows - for k=1:nColumns - if !isempty(net.IW{i,k}) - nInputs = nInputs+1; - endif - endfor - endfor - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," IW: {%dx%d cell} containing %d input weight matrix\n",nRows,nColumns,nInputs); - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printInitFcn.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printInitFcn (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printInitFcn(fid,net) - - if isfield(net,"initFcn") - if isempty(net.initFcn) - fprintf(fid," initFcn: '%s'\n","empty"); - else - fprintf(fid," initFcn: '%s'\n",net.initFcn); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printInitParam.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printInitParam (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printInitParam(fid,net) - - if isfield(net,"initParam") - if isempty(net.initParam) - fprintf(fid," initParam: '%s'\n","not yet used item"); - else - fprintf(fid," initParam: '%s'\n",net.initParam); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printInputConnect.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printInputConnect (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printInputConnect(fid,net) - - if isfield(net,"inputConnect") - # net.inputConnect can be a matrix..! - # check if it's a matrix - if isscalar(net.inputConnect) - error("unsure if this is possible..") - elseif isnumeric(net.inputConnect) - if ismatrix(net.inputConnect) - if issquare(net.inputConnect) - # nothing prgrammed till now - elseif isvector(net.inputConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - # print bracket for open - fprintf(fid," inputConnect: ["); - [nRows nColumns] = size(net.inputConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - fprintf(fid,"%d",net.inputConnect(i*k)); - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - endif # if issquare.. - endif #if ismatrix - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printInputWeights.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printInputsWeights (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printInputWeights(fid,net) - - if isfield(net,"inputweights") - # check if it's cell array - if iscell(net.inputweights) - [nRows, nColumns] = size(net.inputweights); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," inputweights: {%dx%d cell} containing xx input weight\n",nRows,nColumns); - else - fprintf(fid,"unsure if this is possible\n"); - endif - else - fprintf(fid,"field inputweights not found & not yet used item\n"); - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printInputs.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printInputs (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printInputs(fid,net) - - if isfield(net,"inputs") - # check if it's cell array - if iscell(net.inputs) - [nRows, nColumns] = size(net.inputs); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," inputs: {%dx%d cell} of inputs\n",nRows,nColumns); - else - fprintf(fid,"unsure if this is possible\n"); - endif - - endif - -endfunction - - - - - - - - - -
--- a/main/nnet/inst/__printLW.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printLW (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printLW(fid,net) - - if isfield(net,"LW") - nLayers = 0; - # check if it's cell array - if iscell(net.LW) - [nRows, nColumns] = size(net.LW); - for i=1:nRows - for k=1:nColumns - if !isempty(net.LW{i,k}) - nLayers = nLayers+1; - endif - endfor - endfor - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," LW: {%dx%d cell} containing %d layer weight matrix\n",nRows,nColumns,nLayers); - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printLayerConnect.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printLayerConnect (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printLayerConnect(fid,net) - - if isfield(net,"layerConnect") - # net.layerConnect can be a matrix..! - # check if it's a matrix - if isscalar(net.layerConnect) - error("unsure if this is possible..") - elseif isnumeric(net.layerConnect) - if ismatrix(net.layerConnect) - if issquare(net.layerConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," layerConnect: ["); - [nRows nColumns] = size(net.layerConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - if i<nColumns - fprintf(fid,"%d ",net.layerConnect(i*k)); - else - fprintf(fid,"%d",net.layerConnect(i*k)); - endif - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - elseif isvector(net.layerConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - # print bracket for open - fprintf(fid," layerConnect: ["); - [nRows nColumns] = size(net.layerConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - fprintf(fid,"%d",net.layerConnect(i*k)); - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - endif # if issquare.. - endif #if ismatrix - endif - else - fprintf(fid," ERROR..."); - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printLayerWeights.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printLayerWeights (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printLayerWeights(fid,net) - - if isfield(net,"layerweights") - # check if it's cell array - if iscell(net.layerweights) - [nRows, nColumns] = size(net.layerweights); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," layerweights: {%dx%d cell} containing xx layer weight\n",nRows,nColumns); - else - fprintf(fid,"layerweights:unsure if this is possible\n"); - endif - else - fprintf(fid,"field layerweights not found & not yet used item\n"); - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printLayers.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printLayers (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printLayers(fid,net) - - if isfield(net,"layers") - # check if it's cell array - if iscell(net.layers) - [nRows, nColumns] = size(net.layers); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," layers: {%dx%d cell} of layers\n",nRows,nColumns); - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printMLPHeader.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printMLPHeader (@var{fid}) -## @code{__printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printMLPHeader(fid) - - # one empty row - fprintf(fid,"\n"); - # write "net=" - fprintf(fid,"net=\n"); - # next empty row - fprintf(fid,"\n"); - # write "Neural Network object:", insert two spaces.. - fprintf(fid," Neural Network object:\n"); - # next empty row - fprintf(fid,"\n"); - # write "architecture:", insert two spaces.. - fprintf(fid," architecture:\n"); - # one more time an empty row - fprintf(fid,"\n"); - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNetworkType.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printMLPHeader (@var{fid}) -## @code{__printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printNetworkType(fid,net) - - if isfield(net,"networkType") - if strcmp(net.networkType,"newff") - fprintf(fid," Network type: '%s'\n","Feed forward multi-layer network"); - else - fprintf(fid," Network type: '%s'\n","error: undefined network type"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumInputDelays.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumInputDelays (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printNumInputDelays(fid,net) - - ## now check the structure fields.. - cellNetFields = fieldnames(net); - # search for numInputDelays - if isfield(net,"numInputDelays") - # test on scalar - if isscalar(net.numInputDelays) - fprintf(fid," numInputDelays: %d (read-only)\n",net.numInputDelays); - # net.numInputDelays must be an integer... till now, 11-01-2006 - else - error("numInputDelays must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumInputs.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumInputs (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printNumInputs(fid,net) - - ## now check the structure fields.. - cellNetFields = fieldnames(net); - # search for numInputs - if isfield(net,"numInputs") - # test on scalar - if isscalar(net.numInputs) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," numInputs: %d\n",net.numInputs); - # net.numInputs must be an integer... till now, 11-01-2006 - else - error("numInputs must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumLayerDelays.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumLayerDelays (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printNumLayerDelays(fid,net) - - ## now check the structure fields.. - cellNetFields = fieldnames(net); - # search for numLayerDelays - if isfield(net,"numLayerDelays") - # test on scalar - if isscalar(net.numLayerDelays) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," numLayerDelays: %d (read-only)\n",net.numLayerDelays); - # net.numLayerDelays must be an integer... till now, 11-01-2006 - else - error("numLayerDelays must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumLayers.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumLayers (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printNumLayers(fid,net) - - if isfield(net,"numLayers") - if isscalar(net.numLayers) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," numLayers: %d\n",net.numLayers); - # net.numLayers must be an integer... till now, 11-01-2006 - else - error("numLayers must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumOutputs.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumOutputs (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printNumOutputs(fid,net) - - ## now check the structure fields.. - cellNetFields = fieldnames(net); - # search for numOutputs - if isfield(net,"numOutputs") - # test on scalar - if isscalar(net.numOutputs) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," numOutputs: %d (read-only)\n",net.numOutputs); - # net.numOutputs must be an integer... till now, 11-01-2006 - else - error("numOutputs must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printNumTargets.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printNumTargets (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printNumTargets(fid,net) - - ## now check the structure fields.. - cellNetFields = fieldnames(net); - # search for numTargets - if isfield(net,"numTargets") - # test on scalar - if isscalar(net.numTargets) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," numTargets: %d (read-only)\n",net.numTargets); - # net.numTargets must be an integer... till now, 11-01-2006 - else - error("numTargets must be a scalar value!"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printOutputConnect.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printOutputConnect (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printOutputConnect(fid,net) - - if isfield(net,"outputConnect") - # net.outputConnect can be a matrix..! - # check if it's a matrix - if isscalar(net.outputConnect) - error("unsure if this is possible..") - elseif isnumeric(net.outputConnect) - if ismatrix(net.outputConnect) - if issquare(net.outputConnect) - fprintf(fid," outputConnect: ["); - [nRows nColumns] = size(net.outputConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - if i<nColumns - fprintf(fid,"%d ",net.outputConnect(i*k)); - else - fprintf(fid,"%d",net.outputConnect(i*k)); - endif - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"]\n"); - elseif isvector(net.outputConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - # print bracket for open - fprintf(fid," outputConnect: ["); - [nRows nColumns] = size(net.outputConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - if (i<nColumns) - fprintf(fid,"%d ",net.outputConnect(i*k)); - else - fprintf(fid,"%d",net.outputConnect(i*k)); - endif - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - endif # if issquare.. - endif #if ismatrix - endif - else - fprintf(fid," ERROR..."); - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printOutputs.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printOutputs (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printOutputs(fid,net) - - if isfield(net,"outputs") - # check if it's cell array - if iscell(net.outputs) - [nRows, nColumns] = size(net.outputs); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - if (net.numOutputs>1) - fprintf(fid," outputs: {%dx%d cell} containing %d output\n",nRows,nColumns,net.numOutputs); - else - fprintf(fid," outputs: {%dx%d cell} containing %d output\n",nRows,nColumns,net.numOutputs); - endif - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printPerformFcn.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printPerformFcn (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printPerformFcn(fid,net) - - if isfield(net,"performFcn") - if isempty(net.performFcn) - fprintf(fid," performFcn: '%s'\n","empty"); - else - fprintf(fid," performFcn: '%s'\n",net.performFcn); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printPerformParam.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} printInputs (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printPerformParam(fid,net) - - if isfield(net,"performParam") - if isempty(net.performParam) - fprintf(fid," performParam: '%s'\n","not yet used item"); - else - fprintf(fid," performParam: '%s'\n",net.performParam); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printTargetConnect.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printTargetConnect (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printTargetConnect(fid,net) - - if isfield(net,"targetConnect") - # net.targetConnect can be a matrix..! - # check if it's a matrix - if isscalar(net.targetConnect) - error("unsure if this is possible..") - elseif isnumeric(net.targetConnect) - if ismatrix(net.targetConnect) - if issquare(net.targetConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," targetConnect: ["); - [nRows nColumns] = size(net.targetConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - if i<nColumns - fprintf(fid,"%d ",net.targetConnect(i*k)); - else - fprintf(fid,"%d",net.targetConnect(i*k)); - endif - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"]\n"); - elseif isvector(net.targetConnect) - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - # print bracket for open - fprintf(fid," targetConnect: ["); - [nRows nColumns] = size(net.targetConnect); - for k = 1:1:nRows - for i = 1:1:nColumns - if (i<nColumns) - fprintf(fid,"%d ",net.targetConnect(i*k)); - else - fprintf(fid,"%d",net.targetConnect(i*k)); - endif - endfor - if k!=nRows - #print ; for newline in matrix - fprintf(fid,";"); - endif - endfor - # print last bracket - fprintf(fid,"] not yet used item\n"); - endif # if issquare.. - endif #if ismatrix - endif - else - fprintf(fid," ERROR..."); - endif - - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printTargets.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printTargets (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printTargets(fid,net) - - if isfield(net,"targets") - # check if it's cell array - if iscell(net.targets) - [nRows, nColumns] = size(net.targets); - # insert enough spaces to put ":" to position 20 - # insert 2 spaces for distance between ":" and "%" - fprintf(fid," targets: {%dx%d cell} containing %d targets\n",nRows,nColumns,net.numTargets); - else - fprintf(fid,"unsure if this is possible\n"); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printTrainFcn.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printTrainFcn (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - - -function __printTrainFcn(fid,net) - - if isfield(net,"trainFcn") - if isempty(net.trainFcn) - fprintf(fid," trainFcn: '%s'\n","empty"); - else - fprintf(fid," trainFcn: '%s'\n",net.trainFcn); - endif - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__printTrainParam.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} __printTrainParam (@var{fid}) -## @code{printMLPHeader} saves the header of a neural network structure -## to a *.txt file with identification @code{fid}. -## @end deftypefn - -## Author: Michel D. Schmid - -function __printTrainParam(fid,net) - - if isfield(net,"trainParam") - str2 = ""; - str3 = ""; - if isempty(net.trainParam) - fprintf(fid," trainParam: '%s'\n","not yet used item"); - else - cellFieldNames = fieldnames(net.trainParam); - [nRows, nColumns] = size(cellFieldNames); - if (nRows<4) - else - for iRuns = 1:nRows - if (iRuns==1) - str1 = ["." char(cellFieldNames(iRuns,1)) ", "]; - endif - if (iRuns<=4 & iRuns>1) - str1 = [str1 "." char(cellFieldNames(iRuns,1)) ", "]; - endif - if (iRuns>4 & iRuns<=8) - str2 = [str2 "." char(cellFieldNames(iRuns,1)) ", "]; - endif - if (iRuns>8) - str3 = [str3 "." char(cellFieldNames(iRuns,1)) ", "]; - endif - endfor - fprintf(fid," trainParam: %s\n",str1); - fprintf(fid," %s\n",str2); - fprintf(fid," %s\n",str3); - endif - endif - else - fprintf(fid,"field trainparam not found\n"); - endif - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__randomisecols.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{retmatrix} = __randomisecols (@var{matrix}) -## @code{__randomisecols} takes a matrix as input argument and changes the order -## of the columns. The rows aren't affected. -## @end deftypefn - -## Author: mds - -function [retmatrix] = __randomisecols(matrix) - - ## check number of inputs - error(nargchk(1,1,nargin)); - - # get number of cols - nCols = size(matrix,2); - - # now create random column order - colOrder = randperm(nCols); - - # now sort the matrix new - retmatrix = matrix(:,[colOrder]); - - -endfunction - -%!# no test possible, contains randperm which is using -%!# some randome functions
--- a/main/nnet/inst/__rerangecolumns.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{retmatrix} = __rerangecolumns (@var{matrix},@var{analyzeMatrix},@var{nTrainSets}) -## @code{__rerangecolumns} reranges the data sets depending on the input arguments. -## @code{matrix} is the data set matrix containing inputs and outputs (targets) in row order. -## This means for example: the first three rows are inputs and the fourth row is an output row. -## The second argument is used in the optimizing algorithm. This matrix contains informations about -## the description of the rows data of matrix. -## The third argument is used to be sure, rerange all the columns to the correct position. -## @end deftypefn - -## Author: mds - -function retmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets) - - ## check number of inputs - error(nargchk(3,3,nargin)); - - # set default values - - # now sort "matrix" with help of analyzeMatrix - # following conditions must be kept: - # a.) rows containing unique values aren't sorted! - # b.) sort first rows which contains min AND max values only once - # c.) sort secondly rows which contains min OR max values only once - # d.) at last, sort binary data if still needed! - - nRows = size(analyzeMatrix,1); # get number of rows - - ## create i-vector - i = 1; - iVec = []; - while (i <= nRows) - if ( (analyzeMatrix(i,3)==1) && (analyzeMatrix(i,4)==1) ) - iVec = [iVec i]; - endif - i += 1; - endwhile - i = 1; - while (i <= nRows) - if ( (analyzeMatrix(i,3)>1) || (analyzeMatrix(i,4)>1) ) - iVec = [iVec i]; - endif - i += 1; - endwhile - i = 1; - while (i <= nRows) - if (analyzeMatrix(i,1)==1) - iVec = [iVec i]; - endif - i += 1; - endwhile - - - ## now do main loop - j = 1; - i = iVec(j); - nRows = length(iVec); - while (j < nRows) - if (analyzeMatrix(i,2)==1) - # easiest case, nothing to do - else - - # now let's see if min AND max values are only once in the row - if ( (analyzeMatrix(i,3)==1) && (analyzeMatrix(i,4)==1) ) - # search at which index the min value is - minVal = min(matrix(i,:)); - [rowInd, colInd] = find(matrix(i,:)==minVal);# colInd is searched - if (colInd >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd); - endif - # search at which index the max value is - maxVal = max(matrix(i,:)); - [rowInd, colInd] = find(matrix(i,:)==maxVal);# colInd is searched - if (colInd >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd); - endif - - else - - # now here, we have to copy the rows, if min OR max values are more than once in a row - if ( (analyzeMatrix(i,3)>=1) || (analyzeMatrix(i,4)>=1) ) - - # search at which index the min value is - minVal = min(matrix(i,:)); - [rowInd, colInd] = find(matrix(i,:)==minVal);# colInd is searched - if (colInd(1) >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd(1)); - endif - - # search at which index the max value is - maxVal = max(matrix(i,:)); - [rowInd, colInd] = find(matrix(i,:) == maxVal);# colInd is searched - if (colInd(1) >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd(1)); - endif - - else - # now sort binary data, if needed - - # search at which index the 0-value is - [rowInd, colInd] = find(matrix(i,:)==0);# colInd is searched - if (colInd(1) >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd(1)); - endif - # search at which index the 1-value is - [rowInd, colInd] = find(matrix(i,:)==1);# colInd is searched - if (colInd(1) >= nTrainSets ) # move column - matrix = __copycoltopos1(matrix,colInd(1)); - endif - - endif# END OF if ( (analyzeMatrix(i,3)>=1) || (analyzeMatrix(i,4)>=1) ) - - endif # END OF if ( (analyzeMatrix(i,3)==1) AND (analyzeMatrix(i,4)==1) ) - - endif # END OF if (analyzeMatrix(i,2)==1) - j += 1; - i = iVec(j); - endwhile - retmatrix = matrix; -endfunction - -%!shared matrix,analyzeMatrix,nTrainSets, returnmatrix -%! disp("testing __rerangecolumns") -%! matrix = [0 1 0 0 0 0 1 0 1 1; \ -%! 4 4 4 4 4 4 4 4 4 4; \ -%! -1.1 -1.1 2 3 4 3.2 1 8 9 10; \ -%! 0 1.1 3 4 5 2 10 10 2 3; \ -%! -1 1 1 1 1 2 3 4 1 5]; -%! analyzeMatrix = [1 0 0 0; 0 1 0 0; 0 0 2 1; 0 0 1 2; 0 0 1 1]; -%! nTrainSets = 8; -%! returnmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); -%!assert(returnmatrix(1,1)==1); -%!assert(returnmatrix(2,1)==4); -%!assert(returnmatrix(3,1)==1); -%!assert(returnmatrix(4,1)==10); -%!assert(returnmatrix(5,1)==3); -%! matrix = [0 1 0 0 0 0 1 0 1 1; \ -%! 4 4 4 4 4 4 4 4 4 4; \ -%! -1.1 -1.1 2 3 4 3.2 1 8 9 10; \ -%! 0 1.1 3 4 5 2 10 10 2 3; \ -%! -1 1 1 1 1 2 3 4 1 5; \ -%! 0 1 2 1 2 1 2 3 4 5;]; # the last row is euqal to the nnet targets -%! analyzeMatrix = [1 0 0 0; 0 1 0 0; 0 0 2 1; 0 0 1 2; 0 0 1 1]; -%! nTrainSets = 8; -%! returnmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); -%!assert(returnmatrix(1,1)==1); -%!assert(returnmatrix(2,1)==4); -%!assert(returnmatrix(3,1)==1); -%!assert(returnmatrix(4,1)==10); -%!assert(returnmatrix(5,1)==3); -%!assert(returnmatrix(6,1)==2); \ No newline at end of file
--- a/main/nnet/inst/__setx.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {} @var{net} = __setx (@var{net},@var{X2}) -## @code{__setx} sets the new weights to the neural network structure -## @end deftypefn - -## @seealso{getx} - -## Author: Michel D. Schmid - -function net = __setx(net,xx) - - ## check number of inputs - error(nargchk(2,2,nargin)); - - ## check input args - ## check "net", must be a net structure - if !__checknetstruct(net) - error("Structure doesn't seem to be a neural network") - endif - - ## inputs - [nRows, nColumns] = size(net.IW{1,1}); - nElementsIW = nRows*nColumns; - net.IW{1,1}(:) = xx(1:nElementsIW); - - [nRows, nColumns] = size(net.b{1,1}); - nElementsB1 = nRows*nColumns; - net.b{1,1}(:) = xx(1+nElementsIW:nElementsIW+nElementsB1); - start = nElementsIW + nElementsB1; - - ## layers - nLayers = net.numLayers; - for i = 2:nLayers - [nRows, nColumns] = size(net.LW{i,i-1}); - nElementsLW = nRows*nColumns; - net.LW{i,i-1}(:) = xx(1+start:start+nElementsLW); - - [nRows, nColumns] = size(net.b{i,1}); - nElementsBx = nRows*nColumns; - net.b{i,1}(:) = xx(1+start+nElementsLW:start+nElementsLW+nElementsBx); - start = start + nElementsLW + nElementsBx; - endfor - -endfunction \ No newline at end of file
--- a/main/nnet/inst/__trainlm.m Thu Nov 08 00:27:30 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,361 +0,0 @@ -## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> -## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, see -## <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {}[@var{netOut}] = __trainlm (@var{net},@var{mInputN},@var{mOutput},@var{[]},@var{[]},@var{VV}) -## A neural feed-forward network will be trained with @code{__trainlm} -## -## @example -## [netOut,tr,out,E] = __trainlm(net,mInputN,mOutput,[],[],VV); -## @end example -## @noindent -## -## left side arguments: -## @example -## netOut: the trained network of the net structure @code{MLPnet} -## tr : -## out: -## E : Error -## @end example -## @noindent -## -## right side arguments: -## @example -## net : the untrained network, created with @code{newff} -## mInputN: normalized input matrix -## mOutput: output matrix -## [] : unused parameter -## [] : unused parameter -## VV : validize structure -## out: -## E : Error -## @end example -## @noindent -## -## -## @noindent -## are equivalent. -## @end deftypefn - -## @seealso{newff,prestd,trastd} - -## Author: Michel D. Schmid - -## Comments: see in "A neural network toolbox for Octave User's Guide" [4] -## for variable naming... there have inputs or targets only one letter, -## e.g. for inputs is P written. To write a program, this is stupid, you can't -## search for 1 letter variable... that's why it is written here like Pp, or Tt -## instead only P or T. - -function [net] = __trainlm(net,Im,Pp,Tt,VV) - - ## check range of input arguments - error(nargchk(5,5,nargin)) - - ## Initialize - ##------------ - - ## get parameters for training - epochs = net.trainParam.epochs; - goal = net.trainParam.goal; - maxFail = net.trainParam.max_fail; - minGrad = net.trainParam.min_grad; - mu = net.trainParam.mu; - muInc = net.trainParam.mu_inc; - muDec = net.trainParam.mu_dec; - muMax = net.trainParam.mu_max; - show = net.trainParam.show; - time = net.trainParam.time; - - ## parameter checking - checkParameter(epochs,goal,maxFail,minGrad,mu,\ - muInc,muDec,muMax,show,time); - - ## Constants - shortStr = "TRAINLM"; # TODO: shortStr is longer as TRAINLM !!!!!!!!!!! - doValidation = !isempty(VV); - stop = ""; - - - #startTime = clock(); # TODO: maybe this row can be placed - # some rows later - - ## the weights are used in column vector format - xx = __getx(net); # x is the variable with respect to, but no - # variables with only one letter!! - ## define identity matrix - muI = eye(length(xx)); - - startTime = clock(); # if the next some tests are OK, I can delete - # startTime = clock(); 9 rows above.. - - ## calc performance of the actual net - [perf,vE,Aa,Nn] = __calcperf(net,xx,Im,Tt); - if (doValidation) - ## calc performance if validation is used - VV.net = net; # save the actual net in the validate - # structure... if no train loop will show better validate - # performance, this will be the returned net - vperf = __calcperf(net,xx,VV.Im,VV.Tt); - VV.perf = vperf; - VV.numFail = 0; # one of the stop criterias - endif - - nLayers = net.numLayers; - for iEpochs = 0:epochs # longest loop & one of the stop criterias - ve = vE{nLayers,1}; - ## calc jacobian - ## Jj is jacobian matrix - [Jj] = __calcjacobian(net,Im,Nn,Aa,vE); - - ## rerange error vector for jacobi matrix - ve = ve(:); - - Jjve = (Jj' * ve); # will be used to calculate the gradient - - normGradX = sqrt(Jjve'*Jjve); - - ## record training progress for later plotting - ## if requested - trainRec.perf(iEpochs+1) = perf; - trainRec.mu(iEpochs+1) = mu; - if (doValidation) - trainRec.vperf(iEpochs+1) = VV.perf; - endif - - ## stoping criteria - [stop,currentTime] = stopifnecessary(stop,startTime,perf,goal,\ - iEpochs,epochs,time,normGradX,minGrad,mu,muMax,\ - doValidation,VV,maxFail); - - ## show train progress - showtrainprogress(show,stop,iEpochs,epochs,time,currentTime, \ - goal,perf,minGrad,normGradX,shortStr,net); - - ## show performance plot, if needed - if !isnan(show) # if no performance plot is needed - ## now make it possible to define after how much loops the - ## performance plot should be updated - if (mod(iEpochs,show)==0) - plot(1:length(trainRec.perf),trainRec.perf); - if (doValidation) - hold on; - plot(1:length(trainRec.vperf),trainRec.vperf,"--g"); - endif - endif - endif # if !(strcmp(show,"NaN")) -# legend("Training","Validation"); - - ## stop if one of the criterias is reached. - if length(stop) - if (doValidation) - net = VV.net; - endif - break - endif - - ## calculate DeltaX - while (mu <= muMax) - ## calculate change in x - ## see [4], page 12-21 - dx = -((Jj' * Jj) + (muI*mu)) \ Jjve; - - ## add changes in x to actual x values (xx) - x1 = xx + dx; - ## now add x1 to a new network to see if performance will be better - net1 = __setx(net,x1); - ## calc now new performance with the new net - [perf1,vE1,Aa1,N1] = __calcperf(net1,x1,Im,Tt); - - if (perf1 < perf) - ## this means, net performance with new weight values is better... - ## so save the new values - xx = x1; - net = net1; - Nn = N1; - Aa = Aa1; - vE = vE1; - perf = perf1; - - mu = mu * muDec; - if (mu < 1e-20) # 1e-20 is properly the hard coded parameter in MATLAB(TM) - mu = 1e-20; - endif - break - endif - mu = mu * muInc; - endwhile - - ## validate with DeltaX - if (doValidation) - vperf = __calcperf(net,xx,VV.Im,VV.Tt); - if (vperf < VV.perf) - VV.perf = vperf; - VV.net = net; - ## if actual validation performance is better, - ## set numFail to zero again - VV.numFail = 0; - elseif (vperf > VV.perf) - VV.numFail = VV.numFail + 1; - endif - endif - - endfor #for iEpochs = 0:epochs - -#======================================================= -# -# additional functions -# -#======================================================= - function checkParameter(epochs,goal,maxFail,minGrad,mu,\ - muInc, muDec, muMax, show, time) - ## Parameter Checking - - ## epochs must be a positive integer - if ( !isposint(epochs) ) - error("Epochs is not a positive integer.") - endif - - ## goal can be zero or a positive double - if ( (goal<0) || !(isa(goal,"double")) ) - error("Goal is not zero or a positive real value.") - endif - - ## maxFail must be also a positive integer - if ( !isposint(maxFail) ) # this will be used, to see if validation can - # break the training - error("maxFail is not a positive integer.") - endif - - if (!isa(minGrad,"double")) || (!isreal(minGrad)) || (!isscalar(minGrad)) || \ - (minGrad < 0) - error("minGrad is not zero or a positive real value.") - end - - ## mu must be a positive real value. this parameter is responsible - ## for moving from stepest descent to quasi newton - if ((!isa(mu,"double")) || (!isreal(mu)) || (any(size(mu)) != 1) || (mu <= 0)) - error("mu is not a positive real value.") - endif - - ## muDec defines the decrement factor - if ((!isa(muDec,"double")) || (!isreal(muDec)) || (any(size(muDec)) != 1) || \ - (muDec < 0) || (muDec > 1)) - error("muDec is not a real value between 0 and 1.") - endif - - ## muInc defines the increment factor - if (~isa(muInc,"double")) || (!isreal(muInc)) || (any(size(muInc)) != 1) || \ - (muInc < 1) - error("muInc is not a real value greater than 1.") - endif - - ## muMax is the upper boundary for the mu value - if (!isa(muMax,"double")) || (!isreal(muMax)) || (any(size(muMax)) != 1) || \ - (muMax <= 0) - error("muMax is not a positive real value.") - endif - - ## check for actual mu value - if (mu > muMax) - error("mu is greater than muMax.") - end - - ## check if show is activated - if (!isnan(show)) - if (!isposint(show)) - error(["Show is not " "NaN" " or a positive integer."]) - endif - endif - - ## check at last the time argument, must be zero or a positive real value - if (!isa(time,"double")) || (!isreal(time)) || (any(size(time)) != 1) || \ - (time < 0) - error("Time is not zero or a positive real value.") - end - - endfunction # parameter checking - -# -# ----------------------------------------------------------------------------- -# - - function showtrainprogress(show,stop,iEpochs,epochs,time,currentTime, \ - goal,perf,minGrad,normGradX,shortStr,net) - - ## check number of inputs - error(nargchk(12,12,nargin)); - - ## show progress - if isfinite(show) && (!rem(iEpochs,show) || length(stop)) - fprintf(shortStr); # outputs the training algorithm - if isfinite(epochs) - fprintf(", Epoch %g/%g",iEpochs, epochs); - endif - if isfinite(time) - fprintf(", Time %4.1f%%",currentTime/time*100); # \todo: Time wird nicht ausgegeben - endif - if isfinite(goal) - fprintf(", %s %g/%g",upper(net.performFcn),perf,goal); # outputs the performance function - endif - if isfinite(minGrad) - fprintf(", Gradient %g/%g",normGradX,minGrad); - endif - fprintf("\n") - if length(stop) - fprintf("%s, %s\n\n",shortStr,stop); - endif - fflush(stdout); # writes output to stdout as soon as output messages are available - endif - endfunction - -# -# ----------------------------------------------------------------------------- -# - - function [stop,currentTime] = stopifnecessary(stop,startTime,perf,goal,\ - iEpochs,epochs,time,normGradX,minGrad,mu,muMax,\ - doValidation,VV,maxFail) - - ## check number of inputs - error(nargchk(14,14,nargin)); - - currentTime = etime(clock(),startTime); - if (perf <= goal) - stop = "Performance goal met."; - elseif (iEpochs == epochs) - stop = "Maximum epoch reached, performance goal was not met."; - elseif (currentTime > time) - stop = "Maximum time elapsed, performance goal was not met."; - elseif (normGradX < minGrad) - stop = "Minimum gradient reached, performance goal was not met."; - elseif (mu > muMax) - stop = "Maximum MU reached, performance goal was not met."; - elseif (doValidation) - if (VV.numFail > maxFail) - stop = "Validation stop."; - endif - endif - endfunction - -# ===================================================================== -# -# END additional functions -# -# ===================================================================== - -endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__analyzerows.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,117 @@ +## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{retmatrix} = __analyzerows(@var{matrix}) +## @code{__analyzerows} takes a matrix as input argument and checks what kind of +## data are contained in the rows. +## a.) binary values? Means the row contains only 0 and 1 +## b.) unique values? +## c.) Min values are several times contained in the row +## d.) Max values are several times contained in the row +## @end deftypefn + +## Author: mds + +function retmatrix = __analyzerows(matrix) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + nRows = size(matrix,1); # get number or rows + retmatrix = zeros(nRows,4); + doneVec = zeros(nRows,1); + + ## now let's check which rows are binary + i = 1; + while (i <= nRows) + vec = matrix(i,:); + n1 = find(vec==1); + n0 = find(vec==0); + if (length(n1)==0 || length(n0)==0) + #do nothing + else + if (length(vec)==(length(n1)+length(n0))) + # in this case, the vector contains only ones and zeros + retmatrix(i,1) = 1; + doneVec(i) = 1; + endif + endif + i += 1; + endwhile + + ## now let's check which rows are unique + i = 1; + while (i <= nRows) + if (doneVec(i)==0) + vec = matrix(i,:); + n1 = find(vec==vec(1)); + if (length(vec)==(length(n1))) + # in this case, the vector contains only unique data + retmatrix(i,2) = 1; + doneVec(i) = 1; + endif + endif + i += 1; + endwhile + + + ## now let's check how often we can find the min value + i = 1; + while (i <= nRows) + if (doneVec(i)==0) + vec = matrix(i,:); + n1 = min(vec); + retmatrix(i,3) = length(find(n1==vec)); + endif + i += 1; + endwhile + + ## now let's check how often we can find the max value + i = 1; + while (i <= nRows) + if (doneVec(i)==0) + vec = matrix(i,:); + n1 = max(vec); + retmatrix(i,4) = length(find(n1==vec)); + endif + i += 1; + endwhile + +endfunction + +%!shared b, retmat +%! disp("testing __analyzerows") +%! b = [1 0 0 1; 1 0 0 0; 1 2 0 1]; +%! retmat = __analyzerows(b); +%!assert(retmat(1,1)==1);#%!assert(retmat(1,1)==1); +%!assert(retmat(2,1)==1); +%!assert(retmat(3,1)==0); +%! b = [1 0 0 2; 1 0 0 0; 1 1 1 1]; +%! retmat = __analyzerows(b); +%!assert(retmat(1,2)==0); +%!assert(retmat(2,2)==0); +%!assert(retmat(3,2)==1); +%! b = [1 0 0 2; 1 0 0 0; 1 1 1 1]; +%! retmat = __analyzerows(b); +%!assert(retmat(1,3)==2); +%!assert(retmat(2,3)==0); +%!assert(retmat(3,3)==0); +%! retmat = __analyzerows(b); +%!assert(retmat(1,4)==1); +%!assert(retmat(2,4)==0); +%!assert(retmat(3,4)==0);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__calcjacobian.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,283 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}@var{Jj} = __calcjacobian (@var{net},@var{Im},@var{Nn},@var{Aa},@var{vE}) +## This function calculates the jacobian matrix. It's used inside the +## Levenberg-Marquardt algorithm of the neural network toolbox. +## PLEASE DO NOT USE IT ELSEWEHRE, it proparly will not work! +## @end deftypefn + +## Author: Michel D. Schmid + + +function [Jj] = __calcjacobian(net,Im,Nn,Aa,vE) + + ## comment: + ## - return value Jj is jacobi matrix + ## for this calculation, see "Neural Network Design; Hagan, Demuth & Beale page 12-45" + + + ## check range of input arguments + error(nargchk(5,5,nargin)) + + ## get signals from inside the network + bias = net.b; + + ## calculate some help matrices + mInputWeight = net.IW{1} * Im; + nLayers = net.numLayers; + for i=2:nLayers + mLayerWeight{i,1} = net.LW{i,i-1} * Aa{i-1,1}; + endfor + + ## calculate number of columns and rows in jacobi matrix + ## firstly, number of columns + a = ones(nLayers+1,1); # +1 is for the input + a(1) = net.inputs{1}.size; + for iLayers = 1:nLayers + a(iLayers+1) = net.layers{iLayers}.size; + endfor + nColumnsJacobiMatrix = 0; + for iLayers = 1:nLayers + nColumnsJacobiMatrix = (a(iLayers)+1)*a(iLayers+1) + nColumnsJacobiMatrix; + endfor + ## secondly, number of rows + ve = vE{nLayers,1}; + nRowsJacobiMatrix = length(ve(:)); + + + ## FIRST STEP ----------------------------------------------------- + ## calculate the neuron outputs without the transfer function + ## - n1_1 = W^1*a_1^0+b^1: the ^x factor defined the xth train data set + ## the _x factor defines the layer + ## ********** this datas should be hold in Nn + ## ********** should be calculated in "__calcperf" + ## ********** so Nn{1} means hidden layer + ## ********** so Nn{2} means second hidden layer or output layer + ## ********** and so on ... + ## END FIRST STEP ------------------------------------------------- + + ## now we can rerange the signals ... this will be done only for + ## matrix calculation ... + [nRowsError nColumnsError] = size(ve); + errorSize = size(ve(:),1); # this will calculate, if only one row + # of errors exist... in other words... two rows will be reranged to + # one row with the same number of elements. + rerangeIndex = floor([0:(errorSize-1)]/nRowsError)+1; + nLayers = net.numLayers; + + for i = 1:nLayers + Nn{i,1} = Nn{i,1}(:,rerangeIndex); + Aa{i,1} = Aa{i,1}(:,rerangeIndex); + [nRows nColumns] = size(Nn{i,1}); + bTemp = bias{i,1}; + bias{i,1} = repmat(bTemp,1,nColumns); + bias{i,1} = bias{i,1}(:,rerangeIndex); + endfor + mInputWeight = mInputWeight(:,rerangeIndex); + for i=2:nLayers + mLayerWeight{i,1} = mLayerWeight{i,1}(:,rerangeIndex); + endfor + Im = Im(:,rerangeIndex); + + ## define how the errors are connected + ## ATTENTION! this happens in row order... + numTargets = net.numTargets; + mIdentity = -eye(numTargets); + cols = size(mIdentity,2); + mIdentity = mIdentity(:,rem(0:(cols*nColumnsError-1),cols)+1); + errorConnect = cell(net.numLayers,1); + startPos = 0; + for i=net.numLayers + targSize = net.layers{i}.size; + errorConnect{i} = mIdentity(startPos+[1:targSize],:); + startPos = startPos + targSize; + endfor + + ## SECOND STEP ---------------------------------------------- + ## define and calculate the derivative matrix dF + ## - this is "done" by the two first derivative functions + ## of the transfer functions + ## e.g. __dpureline, __dtansig, __dlogsig and so on ... + + ## calculate the sensitivity matrix tildeS + ## start at the end layer, this means of course the output layer, + ## the transfer function is selectable + + ## for calculating the last layer + ## this should happen like following: + ## tildeSx = -dFx(n_x^x) + ## use mIdentity to calculate the number of targets correctly + ## for all other layers, use instead: + ## tildeSx(-1) = dF1(n_x^(x-1))(W^x)' * tildeSx; + + for iLayers = nLayers:-1:1 # this will count from the last + # layer to the first layer ... + n = Nn{iLayers}; # nLayers holds the value of the last layer... + ## which transfer function should be used? + if (iLayers==nLayers) + switch(net.layers{iLayers}.transferFcn) + case "radbas" + tildeSxTemp = __dradbas(n); + case "purelin" + tildeSxTemp = __dpurelin(n); + case "tansig" + n = tansig(n); + tildeSxTemp = __dtansig(n); + case "logsig" + n = logsig(n); + tildeSxTemp = __dlogsig(n); + otherwise + error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"]) + endswitch + tildeSx{iLayers,1} = tildeSxTemp .* mIdentity; + n = bias{nLayers,1}; + switch(net.layers{iLayers}.transferFcn) + case "radbas" + tildeSbxTemp = __dradbas(n); + case "purelin" + tildeSbxTemp = __dpurelin(n); + case "tansig" + n = tansig(n); + tildeSbxTemp = __dtansig(n); + case "logsig" + n = logsig(n); + tildeSbxTemp = __dlogsig(n); + otherwise + error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"]) + endswitch + tildeSbx{iLayers,1} = tildeSbxTemp .* mIdentity; + endif + + if (iLayers<nLayers) + dFx = ones(size(n)); + switch(net.layers{iLayers}.transferFcn) ######## new lines ... + case "radbas" + nx = radbas(n); + dFx = __dradbas(nx); + case "purelin" + nx = purelin(n); + dFx = __dpurelin(nx); + case "tansig" ######## new lines ... + nx = tansig(n); + dFx = __dtansig(nx); + case "logsig" ######## new lines ... + nx = logsig(n); ######## new lines ... + dFx = __dlogsig(nx); ######## new lines ... + otherwise ######## new lines ... + error(["transfer function argument: " net.layers{iLayers}.transferFcn " is not valid!"])######## new lines ... + endswitch ############# new lines .... + LWtranspose = net.LW{iLayers+1,iLayers}; + if iLayers<(nLayers-1) + mIdentity = -ones(net.layers{iLayers}.size,size(mIdentity,2)); + endif + + mTest = tildeSx{iLayers+1,1}; + LWtranspose = LWtranspose' * mTest; + tildeSx{iLayers,1} = dFx .* LWtranspose; + tildeSxTemp = dFx .* LWtranspose; + tildeSbx{iLayers,1} = ones(size(nx)).*tildeSxTemp; + endif + + endfor # if iLayers = nLayers:-1:1 + ## END SECOND STEP ------------------------------------------------- + + ## THIRD STEP ------------------------------------------------------ + ## some problems occur if we have more than only one target... so how + ## does the jacobi matrix looks like? + + ## each target will cause an extra row in the jacobi matrix, for + ## each training set.. this means, 2 targets --> double of rows in the + ## jacobi matrix ... 3 targets --> three times the number of rows like + ## with one target and so on. + + ## now calculate jacobi matrix + ## to do this, define first the transposed of it + ## this makes it easier to calculate on the "batch" way, means all inputs + ## at the same time... + ## and it makes it easier to use the matrix calculation way.. + + JjTrans = zeros(nRowsJacobiMatrix,nColumnsJacobiMatrix)'; # transposed jacobi matrix + + ## Weight Gradients + for i=1:net.numLayers + if i==1 + newInputs = Im; + newTemps = tildeSx{i,1}; + gIW{i,1} = copyRows(newTemps,net.inputs{i}.size) .* copyRowsInt(newInputs,net.layers{i}.size); + endif + if i>1 + Ad = cell2mat(Aa(i-1,1)'); + newInputs = Ad; + newTemps = tildeSx{i,1}; + gLW{i,1} = copyRows(newTemps,net.layers{i-1}.size) .* copyRowsInt(newInputs,net.layers{i}.size); + endif + endfor + + for i=1:net.numLayers + [nRows, nColumns] = size(Im); + if (i==1) + nWeightElements = a(i)*a(i+1); # n inputs * n hidden neurons + JjTrans(1:nWeightElements,:) = gIW{i}(1:nWeightElements,:); + nWeightBias = a(i+1); + start = nWeightElements; + JjTrans(start+1:start+nWeightBias,:) = tildeSbx{i,1}; + start = start+nWeightBias; + endif + if (i>1) + nLayerElements = a(i)*a(i+1); # n hidden neurons * n output neurons + JjTrans(start+1:start+nLayerElements,:)=gLW{i}(1:nLayerElements,:); + start = start + nLayerElements; + nLayerBias = a(i+1); + JjTrans(start+1:start+nLayerBias,:) = tildeSbx{i,1}; + start = start + nLayerBias; + endif + endfor + Jj = JjTrans'; + ## END THIRD STEP ------------------------------------------------- + + +#======================================================= +# +# additional functions +# +#======================================================= + + function k = copyRows(k,m) + # make copies of the ROWS of Aa matrix + + mRows = size(k,1); + k = k(rem(0:(mRows*m-1),mRows)+1,:); + endfunction + +# ------------------------------------------------------- + + function k = copyRowsInt(k,m) + # make copies of the ROWS of matrix with elements INTERLEAVED + + mRows = size(k,1); + k = k(floor([0:(mRows*m-1)]/m)+1,:); + endfunction + +# ===================================================================== +# +# END additional functions +# +# ===================================================================== + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__calcperf.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,110 @@ +## Copyright (C) 2006 Michel D. Schmid <email: michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}[@var{perf}, @var{Ee}, @var{Aa}, @var{Nn}] = __calcperf (@var{net},@var{xx},@var{Im},@var{Tt}) +## @code{__calcperf} calculates the performance of a multi-layer neural network. +## PLEASE DON'T USE IT ELSEWHERE, it proparly won't work. +## @end deftypefn + +## Author: Michel D. Schmid + + +function [perf,Ee,Aa,Nn] = __calcperf(net,xx,Im,Tt) + + ## comment: + ## perf, net performance.. from input to output through the hidden layers + ## Aa, output values of the hidden and last layer (output layer) + ## is used for NEWFF network types + + ## calculate bias terms + ## must have the same number of columns like the input matrix Im + [nRows, nColumns] = size(Im); + Btemp = cell(net.numLayers,1); # Btemp: bias matrix + ones1xQ = ones(1,nColumns); + for i= 1:net.numLayers + Btemp{i} = net.b{i}(:,ones1xQ); + endfor + + ## shortcuts + IWtemp = cell(net.numLayers,net.numInputs,1);# IW: input weights ... + LWtemp = cell(net.numLayers,net.numLayers,1);# LW: layer weights ... + Aa = cell(net.numLayers,1);# Outputs hidden and output layer + Nn = cell(net.numLayers,1);# outputs before the transfer function + IW = net.IW; # input weights + LW = net.LW; # layer weights + + ## calculate the whole network till outputs are reached... + for iLayers = 1:net.numLayers + + ## calculate first input weights to weighted inputs.. + ## this can be done with matrix calculation... + ## called "dotprod" + ## to do this, there must be a special matrix ... + ## e.g. IW = [1 2 3 4 5; 6 7 8 9 10] * [ 1 2 3; 4 5 6; 7 8 9; 10 11 12; 1 2 3]; + if (iLayers==1) + IWtemp{iLayers,1} = IW{iLayers,1} * Im; + onlyTempVar = [IWtemp(iLayers,1) Btemp(iLayers)]; + else + IWtemp{iLayers,1} = []; + endif + + ## now calculate layer weights to weighted layer outputs + if (iLayers>1) + Ad = Aa{iLayers-1,1}; + LWtemp{iLayers,1} = LW{iLayers,iLayers-1} * Ad; + onlyTempVar = [LWtemp(iLayers,1) Btemp(iLayers)]; + else + LWtemp{iLayers,1} = []; + endif + + Nn{iLayers,1} = onlyTempVar{1}; + for k=2:length(onlyTempVar) + Nn{iLayers,1} = Nn{iLayers,1} + onlyTempVar{k}; + endfor + + ## now calculate with the transfer functions the layer output + switch net.layers{iLayers}.transferFcn + case "purelin" + Aa{iLayers,1} = purelin(Nn{iLayers,1}); + case "tansig" + Aa{iLayers,1} = tansig(Nn{iLayers,1}); + case "logsig" + Aa{iLayers,1} = logsig(Nn{iLayers,1}); + otherwise + error(["Transfer function: " net.layers{iLayers}.transferFcn " doesn't exist!"]) + endswitch + + endfor # iLayers = 1:net.numLayers + + ## now calc network error + Ee = cell(net.numLayers,1); + + for i=net.numLayers + Ee{i,1} = Tt{i,1} - Aa{i,1};# Tt: target + # Ee will be the error vector cell array + endfor + + ## now calc network performance + switch(net.performFcn) + case "mse" + perf = __mse(Ee); + otherwise + error("for performance functions, only mse is currently valid!") + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__checknetstruct.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,49 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}[@var{isTrue}] = __checknetstruct (@var{net}) +## This function will check if a valid structure seems to be a neural network +## structure +## +## @noindent +## +## left side arguments: +## @noindent +## +## right side arguments: +## @noindent +## +## +## @noindent +## are equivalent. +## @end deftypefn + +## @seealso{newff,prestd,trastd} + +## Author: Michel D. Schmid + + +function isTrue = __checknetstruct(net) + + isTrue = 0; + ## first check, if it's a structure + if (isstruct(net) && isfield(net,"networkType")) + isTrue = 1; + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__copycoltopos1.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,45 @@ +## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{retmatrix} = __copycoltopos1(@var{matrix},@var{colIndex}) +## @code{__copycoltopos1} copies the column of position colIndex to the first position. +## Moves the rest of the matrix one position to the right. +## @end deftypefn + +## Author: mds + +function retmatrix = __copycoltopos1(matrix,colIndex) + + ## check number of inputs + error(nargchk(2,2,nargin)); + + temp = matrix(:,colIndex); + matrix(:,colIndex) = []; # delete col + retmatrix = [temp matrix ]; + +endfunction + +%!shared a, retmat +%! disp("testing __copycoltopos1") +%! a = [0 1 2 3 4; 5 6 7 8 9]; +%! retmat = __copycoltopos1(a,3); +%!assert(retmat(1,1)==2); +%!assert(retmat(2,1)==7); +%! retmat = __copycoltopos1(a,5); +%!assert(retmat(1,1)==4); +%!assert(retmat(2,1)==9);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__dlogsig.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,32 @@ +## Copyright (C) 2007 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}[@var{a} = __dlogsig (@var{n}) +## +## @end deftypefn + +## @seealso{__dpurelin,__dtansig} + +## Author: Michel D. Schmid + + +function a = __dlogsig(n) + + a = n.*(1-n); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__dpurelin.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,35 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{a} = __dpurelin (@var{n}) +## @code{dpurelin}, first derivative of purelin +## @example +## +## purelin is a linear transfer function used by neural networks +## @end example +## +## @end deftypefn + +## Author: Michel D. Schmid + +function a = __dpurelin(n) + + [nRows, nColumns] = size(n); + a = ones(nRows,nColumns); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__dradbas.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,44 @@ +## Copyright (C) 2010 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __dradbas (@var{n}) +## First derivative of the radial basis transfer function. +## +## @code{__dradbas(n) = exp(-n^2)*-2*x} +## +## @end deftypefn + +## Author: Michel D. Schmid + + +function retval = __dradbas (n) + + if (nargin != 1) + print_usage (); + else + retval = exp (-n^2)*(-2)*x; + # the derivative of exp(-n^2) must be calculated + # with help of the chain-rule! + # d/dx of e^x = e^x + # d/dx of -x^2 = -2x + # now calculate the product of both + endif +endfunction + + +#%!assert (radbas (3), exp (-3^2));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__dtansig.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,38 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}[@var{n} = __dtansig (@var{n}) +## first derivative of @code{tansig} +## +## @example +## +## tansig is a symmetric non linear transfer function +## used by neural networks. +## Input n must be calculated with "n = tansig(n)". +## @end example +## +## @end deftypefn + +## Author: Michel D. Schmid + + +function a = __dtansig(n) + + a = 1-(n.*n); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__getx.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,54 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program ; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{x} = __getx (@var{net}) +## @code{__getx} will rerange the weights in one columns vector. +## +## +## @noindent +## @end deftypefn + + +## Author: Michel D. Schmid + +function x = __getx(net) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + ## check input args + ## check "net", must be a net structure + if !__checknetstruct(net) + error("Structure doesn't seem to be a neural network") + endif + + ## inputs + x = net.IW{1,1}(:); + x = [x; net.b{1}(:)]; + + nNumLayers = net.numLayers; + for iLayers = 2:nNumLayers # 1 would be the input layer + + ## layers + x = [x; net.LW{iLayers,iLayers-1}(:)]; + x = [x; net.b{iLayers}(:)]; + + endfor + + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__init.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,84 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{net} = __init (@var{net}) +## @code{__init} initializes a neural network. This will be done +## with the function @code{rand} from octave. +## +## @example +## net = __init(net); +## @end example +## +## This function takes the octave function "rand" to init the +## neural network weights. +## +## @noindent +## @end deftypefn + + +## Author: Michel D. Schmid + +function net=__init(net) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + ## check input + if ( !__checknetstruct(net) ) + error("__init: wrong argument type, must be a structure!"); + endif + + + if (strcmp(net.networkType,"newff")) + + ## init with random numbers between +-1 + ## input weight layer + mRand = rand(net.layers{1}.size,net.inputs{1}.size); + net.IW{1} = mRand*2-1; + + ## hidden layers + nLayers = net.numLayers; + for i=2:nLayers + mRand = rand(net.layers{i}.size,net.layers{i-1}.size); + net.LW{i,i-1} = mRand*2-1; + endfor + for i=1:nLayers + mRand = rand(net.biases{i}.size,1); + net.b{i} = mRand*2-1; + endfor + elseif (strcmp(net.networkType,"newp")) + + ## init with zeros + inputRows = size(net.inputs{1,1}.range,1); + net.IW{1} = zeros(inputRows,1); + net.b{1} = zeros(1,1); + endif + + ## warn user of constant inputs + for i=1:net.numInputs + prange = net.inputs{i}.range; + if (any(prange(:,1) == prange(:,2))) + fprintf("\n") + fprintf("** Warning in INIT\n") + fprintf("** Network net.inputs{%g}.range has a row with equal min and max values.\n",i) + fprintf("** Constant inputs do not provide useful information.\n") + fprintf("\n") + end + end + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__mae.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,54 @@ +## Copyright (C) 2007 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, write to the Free +## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +## 02110-1301, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {}@var{perf} = __mae (@var{E}) +## @code{__mse} returns the Mean-Square-Error of a vector E +## +## @example +## +## This function is used to calculate the perceptron performance +## @end example +## +## @end deftypefn + +## @seealso{__mse} + +## Author: Michel D. Schmid + +function perf = __mae(E) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + if iscell(E) + perf = 0; + elements = 0; + for i=1:size(E,1) + for j=1:size(E,2) + perf = perf + sum(sum(E{i,j}.^2)); + elements = elements + prod(size(E{i,j})); + endfor + endfor + perf = perf / elements; + else + error("Error vector should be a cell array!") + endif + + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__mse.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,53 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}@var{perf} = __mse (@var{E}) +## @code{__mse} returns the Mean-Square-Error of a vector E +## +## @example +## +## This function is used to calculate the network performance +## @end example +## +## @end deftypefn + +## @seealso{__mae} + +## Author: Michel D. Schmid + +function perf = __mse(E) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + if iscell(E) + perf = 0; + elements = 0; + for i=1:size(E,1) + for j=1:size(E,2) + perf = perf + sum(sum(E{i,j}.^2)); + elements = elements + prod(size(E{i,j})); + endfor + endfor + perf = perf / elements; + else + error("Error vector should be a cell array!") + endif + + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__newnetwork.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,195 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}{@var{net}} = __newnetwork(@var{numInputs},@var{numLayers},@var{numOutputs},@var{networkType}) +## @code{__newnetwork} create a custom 'zero'-network +## +## +## @example +## net = __newnetwork(numInputs,numLayers,numOutputs,networkType) +## +## numInputs : number of input vectors, actually only 1 allowed +## numLayers : number of layers +## numOutputs: number of output vectors, actually only 1 allowed +## networkType: e.g. feed-forward-network "newff" +## @end example +## +## @example +## net = __newnetwork(1,2,1,"newff") +## 1 input layer, two hidden layers, one output layer +## and the network type +## @end example +## +## @noindent +## @end deftypefn + +## Author: Michel D. Schmid + +function net = __newnetwork(numInputs,numLayers,numOutputs,networkType) + + ## check range of input arguments + error(nargchk(4,4,nargin)) + + ## check input args + if ( !isposint(numInputs) ) + error("network: at least 1 input must be defined! ") + # this can't happen actually, only one is allowed and this + # one is hard coded + elseif ( !isposint(numLayers) ) + error("network: at least 1 hidden- and one output layer must be defined! ") + endif + ## second check for numLayers... must be at least "2" for the + ## newff, this means at least 1 hidden and 1 output layer + if (strcmp(networkType,"newff") && (numLayers<2)) + error("network: not enough layers are defined! ") + endif + + ## define network type + net.networkType = networkType; + + ## ZERO NETWORK + net.numInputs = 0; + net.numLayers = 0; + net.numInputDelays = 0; + net.numLayerDelays = 0; + # the next five parameters aren't used till now, they are used + # only for matlab nnet type compatibility ==> saveMLPStruct + net.biasConnect = []; # not used parameter till now + net.inputConnect = []; # not used parameter till now + net.layerConnect = []; # not used parameter till now + net.outputConnect = []; # not used parameter till now + net.targetConnect = []; # not used parameter till now + net.numOutputs = 0; + net.numTargets = 0; + net.inputs = cell(0,1); + net.layers = cell(0,1); + net.biases = cell(0,1); + net.inputWeights = cell(0,0); + net.layerWeights = cell(0,0); + net.outputs = cell(1,0); + net.targets = cell(1,0); + net.performFcn = ""; + net.performParam = []; + net.trainFcn = ""; + net.trainParam = []; + net.IW = {}; + net.LW = {}; + net.b = cell(0,1); + net.userdata.note = "Put your custom network information here."; + + + ## ARCHITECTURE + + ## define everything with "inputs" + net.numInputs = numInputs; + ## actually, it's only possible to have "one" input vector + net.inputs{1,1}.range = [0 0]; + net.inputs{1,1}.size = 0; + net.inputs{1,1}.userdata = "Put your custom informations here!"; + + ## define everything with "layers" + net.numLayers = numLayers; + net = newLayers(net,numLayers); + + ## define unused variables, must be defined for saveMLPStruct + net.biasConnect = [0; 0]; + net.inputConnect = [0; 0]; + net.layerConnect = [0 0; 0 0]; + net.outputConnect = [0 0]; + net.targetConnect = [0 0]; + net.numInputDelays = 0; + net.numLayerDelays = 0; + + ## define everything with "outputs" + net.numOutputs = numOutputs; + net.outputs = cell(1,numLayers); + for i=1:numLayers + if (i==numLayers) + net.outputs{i}.size = 1; # nothing else allowed till now + net.outputs{i}.userdata = "Put your custom informations here!"; + else + net.outputs{i} = []; + endif + endfor + + ## define everything with "biases" + net = newBiases(net,numLayers); + + + +#===================================================== +# +# Additional ARCHITECTURE Functions +# +#===================================================== + function net = newLayers(net,numLayers) + + ## check range of input arguments + error(nargchk(2,2,nargin)) + + ## check type of arguments + if ( !isscalar(numLayers) || !isposint(numLayers) ) + error("second argument must be a positive integer scalar value!") + endif + if ( !__checknetstruct(net) ) + error("first argument must be a network structure!") + endif + + for iRuns=1:numLayers + net.layers{iRuns,1}.dimension = 0; + net.layers{iRuns,1}.netInputFcn = ""; + net.layers{iRuns,1}.size = 0; +### TODO: test with newff net.layers{iRuns,1}.transferFcn = "tansig"; + net.layers{iRuns,1}.transferFcn = ""; + net.layers{iRuns,1}.userdata = "Put your custom informations here!"; + endfor + + endfunction + +#----------------------------------------------------- + + function net = newBiases(net,numLayers) + + ## check range of input arguments + error(nargchk(2,2,nargin)) + + ## check type of arguments + if ( !isscalar(numLayers) || !isposint(numLayers) ) + error("second argument must be a positive integer scalar value!") + endif + if ( !isstruct(net) ) + error("first argument must be a network structure!") + endif + + for iRuns=1:numLayers + net.biases{iRuns,1}.learn = 1; + net.biases{iRuns,1}.learnFcn = ""; + net.biases{iRuns,1}.learnParam = "undefined..."; + net.biases{iRuns,1}.size = 0; + net.biases{iRuns,1}.userdata = "Put your custom informations here!"; + endfor + + endfunction + +# ================================================================ +# +# END Additional ARCHITECTURE Functions +# +# ================================================================ + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__optimizedatasets.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,89 @@ +## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{retmatrix} = __optimizedatasets (@var{matrix},@var{nTrainSets},@var{nTargets},@var{bRand}) +## @code{__optimizedatasets} reranges the data sets depending on the input arguments. +## @code{matrix} is the data set matrix containing inputs and outputs (targets) in row order. +## This means for example: the first three rows are inputs and the fourth row is an output row. +## The second argument is used in the optimizing algorithm. All cols with min and max values must +## be in the range of the train data sets. The third argument defines how much rows are equal to the +## neural network targets. These rows must be at the end of the data set! +## The fourth arguemnt is optional and defines if the data sets have to be randomised before +## optimizing. +## Default value for bRand is 1, means randomise the columns. +## @end deftypefn + +## Author: mds + +function retmatrix = __optimizedatasets(matrix,nTrainSets,nTargets,bRand) + + ## check number of inputs + error(nargchk(3,4,nargin)); + + # set default values + bRandomise = 1; + + if (nargin==4) + bRandomise = bRand; + endif + + # if needed, randomise the cols + if (bRandomise) + matrix = __randomisecols(matrix); + endif + + # analyze matrix, which row contains what kind of data? + # a.) binary values? Means the row contains only 0 and 1 + # b.) unique values? + # c.) Min values are several times contained in the row + # d.) Max values are several times contained in the row + matrix1 = matrix(1:end-nTargets,:); + analyzeMatrix = __analyzerows(matrix1); + + # now sort "matrix" with help of analyzeMatrix + # following conditions must be kept: + # a.) rows containing unique values aren't sorted! + # b.) sort first rows which contains min AND max values only once + # c.) sort secondly rows which contains min OR max values only once + # d.) at last, sort binary data if still needed! + retmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); + + +endfunction + +%!shared retmatrix, matrix +%! disp("testing __optimizedatasets") +%! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \ +%! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \ +%! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \ +%! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1]; +%! ## The last row is equal to the neural network targets +%! retmatrix = __optimizedatasets(matrix,9,1); +%! ## the above statement can't be tested with assert! +%! ## it contains random values! So pass a "success" message +%!assert(1==1); +%! matrix = [1 2 3 2 1 2 3 0 5 4 3 2 2 2 2 2 2; \ +%! 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0; \ +%! -1 3 2 4 9 1 1 1 1 1 9 1 1 1 9 9 0; \ +%! 2 3 2 3 2 2 2 2 3 3 3 3 1 1 1 1 1]; +%! ## The last row is equal to the neural network targets +%! retmatrix = __optimizedatasets(matrix,9,1,0); +%!assert(retmatrix(1,1)==5); +%!assert(retmatrix(2,1)==0); +%!assert(retmatrix(3,1)==1); +%!assert(retmatrix(4,1)==3); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printAdaptFcn.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,35 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This software is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this software; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printAdaptFcn (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printAdaptFcn(fid,net) + + if isfield(net,"adaptFcn") + if isempty(net.adaptFcn) + fprintf(fid," adaptFcn: '%s'\n","empty"); + else + fprintf(fid," adaptFcn: '%s'\n",net.adaptFcn); + endif + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printAdaptParam.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,36 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printAdaptParam (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printAdaptParam(fid,net) + + if isfield(net,"adaptParam") + if isempty(net.adaptParam) + fprintf(fid," adaptParam: '%s'\n","not yet used item"); + else + fprintf(fid," adaptParam: '%s'\n",net.adaptParam); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printB.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,48 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printB (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printB(fid,net) + + if isfield(net,"b") + nBiases = 0; + # check if it's cell array + if iscell(net.b) + [nRows, nColumns] = size(net.b); + for i=1:nRows + for k=1:nColumns + if !isempty(net.b{i,k}) + nBiases = nBiases+1; + endif + endfor + endfor + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," b: {%dx%d cell} containing %d bias vectors\n",nRows,nColumns,nBiases); + else + fprintf(fid,"unsure if this is possible\n") + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printBiasConnect.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,60 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printBiasConnect (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printBiasConnect(fid,net) + + if isfield(net,"biasConnect") + # net.biasConnect can be a matrix..! + # check if it's a matrix + if isscalar(net.biasConnect) + error("unsure if this is possible..") + elseif isnumeric(net.biasConnect) + if ismatrix(net.biasConnect) + if issquare(net.biasConnect) + # nothing prgrammed till now + elseif isvector(net.biasConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + # print bracket for open + fprintf(fid," biasConnect: ["); + [nRows nColumns] = size(net.biasConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + fprintf(fid,"%d",net.biasConnect(i*k)); + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + endif # if issquare.. + endif #if ismatrix + endif # isscalar(net.biasConnect) + endif # if isfield(...) + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printBiases.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,40 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printBiases (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printBiases(fid,net) + + if isfield(net,"biases") + # check if it's cell array + if iscell(net.biases) + [nRows, nColumns] = size(net.biases); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," biases: {%dx%d cell} containing %d biases\n",nRows,nColumns,length(net.biases)); + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printIW.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,48 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printIW (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printIW(fid,net) + + if isfield(net,"IW") + nInputs = 0; + # check if it's cell array + if iscell(net.IW) + [nRows, nColumns] = size(net.IW); + for i=1:nRows + for k=1:nColumns + if !isempty(net.IW{i,k}) + nInputs = nInputs+1; + endif + endfor + endfor + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," IW: {%dx%d cell} containing %d input weight matrix\n",nRows,nColumns,nInputs); + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printInitFcn.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,37 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printInitFcn (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printInitFcn(fid,net) + + if isfield(net,"initFcn") + if isempty(net.initFcn) + fprintf(fid," initFcn: '%s'\n","empty"); + else + fprintf(fid," initFcn: '%s'\n",net.initFcn); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printInitParam.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,36 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printInitParam (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printInitParam(fid,net) + + if isfield(net,"initParam") + if isempty(net.initParam) + fprintf(fid," initParam: '%s'\n","not yet used item"); + else + fprintf(fid," initParam: '%s'\n",net.initParam); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printInputConnect.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,59 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printInputConnect (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printInputConnect(fid,net) + + if isfield(net,"inputConnect") + # net.inputConnect can be a matrix..! + # check if it's a matrix + if isscalar(net.inputConnect) + error("unsure if this is possible..") + elseif isnumeric(net.inputConnect) + if ismatrix(net.inputConnect) + if issquare(net.inputConnect) + # nothing prgrammed till now + elseif isvector(net.inputConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + # print bracket for open + fprintf(fid," inputConnect: ["); + [nRows nColumns] = size(net.inputConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + fprintf(fid,"%d",net.inputConnect(i*k)); + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + endif # if issquare.. + endif #if ismatrix + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printInputWeights.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,42 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printInputsWeights (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printInputWeights(fid,net) + + if isfield(net,"inputweights") + # check if it's cell array + if iscell(net.inputweights) + [nRows, nColumns] = size(net.inputweights); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," inputweights: {%dx%d cell} containing xx input weight\n",nRows,nColumns); + else + fprintf(fid,"unsure if this is possible\n"); + endif + else + fprintf(fid,"field inputweights not found & not yet used item\n"); + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printInputs.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,51 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printInputs (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printInputs(fid,net) + + if isfield(net,"inputs") + # check if it's cell array + if iscell(net.inputs) + [nRows, nColumns] = size(net.inputs); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," inputs: {%dx%d cell} of inputs\n",nRows,nColumns); + else + fprintf(fid,"unsure if this is possible\n"); + endif + + endif + +endfunction + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printLW.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,48 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printLW (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printLW(fid,net) + + if isfield(net,"LW") + nLayers = 0; + # check if it's cell array + if iscell(net.LW) + [nRows, nColumns] = size(net.LW); + for i=1:nRows + for k=1:nColumns + if !isempty(net.LW{i,k}) + nLayers = nLayers+1; + endif + endfor + endfor + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," LW: {%dx%d cell} containing %d layer weight matrix\n",nRows,nColumns,nLayers); + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printLayerConnect.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,79 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printLayerConnect (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printLayerConnect(fid,net) + + if isfield(net,"layerConnect") + # net.layerConnect can be a matrix..! + # check if it's a matrix + if isscalar(net.layerConnect) + error("unsure if this is possible..") + elseif isnumeric(net.layerConnect) + if ismatrix(net.layerConnect) + if issquare(net.layerConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," layerConnect: ["); + [nRows nColumns] = size(net.layerConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + if i<nColumns + fprintf(fid,"%d ",net.layerConnect(i*k)); + else + fprintf(fid,"%d",net.layerConnect(i*k)); + endif + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + elseif isvector(net.layerConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + # print bracket for open + fprintf(fid," layerConnect: ["); + [nRows nColumns] = size(net.layerConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + fprintf(fid,"%d",net.layerConnect(i*k)); + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + endif # if issquare.. + endif #if ismatrix + endif + else + fprintf(fid," ERROR..."); + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printLayerWeights.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,42 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printLayerWeights (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printLayerWeights(fid,net) + + if isfield(net,"layerweights") + # check if it's cell array + if iscell(net.layerweights) + [nRows, nColumns] = size(net.layerweights); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," layerweights: {%dx%d cell} containing xx layer weight\n",nRows,nColumns); + else + fprintf(fid,"layerweights:unsure if this is possible\n"); + endif + else + fprintf(fid,"field layerweights not found & not yet used item\n"); + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printLayers.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,40 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printLayers (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printLayers(fid,net) + + if isfield(net,"layers") + # check if it's cell array + if iscell(net.layers) + [nRows, nColumns] = size(net.layers); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," layers: {%dx%d cell} of layers\n",nRows,nColumns); + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printMLPHeader.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,43 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printMLPHeader (@var{fid}) +## @code{__printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printMLPHeader(fid) + + # one empty row + fprintf(fid,"\n"); + # write "net=" + fprintf(fid,"net=\n"); + # next empty row + fprintf(fid,"\n"); + # write "Neural Network object:", insert two spaces.. + fprintf(fid," Neural Network object:\n"); + # next empty row + fprintf(fid,"\n"); + # write "architecture:", insert two spaces.. + fprintf(fid," architecture:\n"); + # one more time an empty row + fprintf(fid,"\n"); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNetworkType.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,36 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printMLPHeader (@var{fid}) +## @code{__printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printNetworkType(fid,net) + + if isfield(net,"networkType") + if strcmp(net.networkType,"newff") + fprintf(fid," Network type: '%s'\n","Feed forward multi-layer network"); + else + fprintf(fid," Network type: '%s'\n","error: undefined network type"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumInputDelays.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,42 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumInputDelays (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printNumInputDelays(fid,net) + + ## now check the structure fields.. + cellNetFields = fieldnames(net); + # search for numInputDelays + if isfield(net,"numInputDelays") + # test on scalar + if isscalar(net.numInputDelays) + fprintf(fid," numInputDelays: %d (read-only)\n",net.numInputDelays); + # net.numInputDelays must be an integer... till now, 11-01-2006 + else + error("numInputDelays must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumInputs.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,44 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumInputs (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printNumInputs(fid,net) + + ## now check the structure fields.. + cellNetFields = fieldnames(net); + # search for numInputs + if isfield(net,"numInputs") + # test on scalar + if isscalar(net.numInputs) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," numInputs: %d\n",net.numInputs); + # net.numInputs must be an integer... till now, 11-01-2006 + else + error("numInputs must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumLayerDelays.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,43 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumLayerDelays (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printNumLayerDelays(fid,net) + + ## now check the structure fields.. + cellNetFields = fieldnames(net); + # search for numLayerDelays + if isfield(net,"numLayerDelays") + # test on scalar + if isscalar(net.numLayerDelays) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," numLayerDelays: %d (read-only)\n",net.numLayerDelays); + # net.numLayerDelays must be an integer... till now, 11-01-2006 + else + error("numLayerDelays must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumLayers.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,39 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumLayers (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printNumLayers(fid,net) + + if isfield(net,"numLayers") + if isscalar(net.numLayers) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," numLayers: %d\n",net.numLayers); + # net.numLayers must be an integer... till now, 11-01-2006 + else + error("numLayers must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumOutputs.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,43 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumOutputs (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printNumOutputs(fid,net) + + ## now check the structure fields.. + cellNetFields = fieldnames(net); + # search for numOutputs + if isfield(net,"numOutputs") + # test on scalar + if isscalar(net.numOutputs) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," numOutputs: %d (read-only)\n",net.numOutputs); + # net.numOutputs must be an integer... till now, 11-01-2006 + else + error("numOutputs must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printNumTargets.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,43 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printNumTargets (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printNumTargets(fid,net) + + ## now check the structure fields.. + cellNetFields = fieldnames(net); + # search for numTargets + if isfield(net,"numTargets") + # test on scalar + if isscalar(net.numTargets) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," numTargets: %d (read-only)\n",net.numTargets); + # net.numTargets must be an integer... till now, 11-01-2006 + else + error("numTargets must be a scalar value!"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printOutputConnect.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,81 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printOutputConnect (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printOutputConnect(fid,net) + + if isfield(net,"outputConnect") + # net.outputConnect can be a matrix..! + # check if it's a matrix + if isscalar(net.outputConnect) + error("unsure if this is possible..") + elseif isnumeric(net.outputConnect) + if ismatrix(net.outputConnect) + if issquare(net.outputConnect) + fprintf(fid," outputConnect: ["); + [nRows nColumns] = size(net.outputConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + if i<nColumns + fprintf(fid,"%d ",net.outputConnect(i*k)); + else + fprintf(fid,"%d",net.outputConnect(i*k)); + endif + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"]\n"); + elseif isvector(net.outputConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + # print bracket for open + fprintf(fid," outputConnect: ["); + [nRows nColumns] = size(net.outputConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + if (i<nColumns) + fprintf(fid,"%d ",net.outputConnect(i*k)); + else + fprintf(fid,"%d",net.outputConnect(i*k)); + endif + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + endif # if issquare.. + endif #if ismatrix + endif + else + fprintf(fid," ERROR..."); + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printOutputs.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,45 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printOutputs (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printOutputs(fid,net) + + if isfield(net,"outputs") + # check if it's cell array + if iscell(net.outputs) + [nRows, nColumns] = size(net.outputs); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + if (net.numOutputs>1) + fprintf(fid," outputs: {%dx%d cell} containing %d output\n",nRows,nColumns,net.numOutputs); + else + fprintf(fid," outputs: {%dx%d cell} containing %d output\n",nRows,nColumns,net.numOutputs); + endif + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printPerformFcn.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,36 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printPerformFcn (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printPerformFcn(fid,net) + + if isfield(net,"performFcn") + if isempty(net.performFcn) + fprintf(fid," performFcn: '%s'\n","empty"); + else + fprintf(fid," performFcn: '%s'\n",net.performFcn); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printPerformParam.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,36 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} printInputs (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printPerformParam(fid,net) + + if isfield(net,"performParam") + if isempty(net.performParam) + fprintf(fid," performParam: '%s'\n","not yet used item"); + else + fprintf(fid," performParam: '%s'\n",net.performParam); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printTargetConnect.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,84 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printTargetConnect (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printTargetConnect(fid,net) + + if isfield(net,"targetConnect") + # net.targetConnect can be a matrix..! + # check if it's a matrix + if isscalar(net.targetConnect) + error("unsure if this is possible..") + elseif isnumeric(net.targetConnect) + if ismatrix(net.targetConnect) + if issquare(net.targetConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," targetConnect: ["); + [nRows nColumns] = size(net.targetConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + if i<nColumns + fprintf(fid,"%d ",net.targetConnect(i*k)); + else + fprintf(fid,"%d",net.targetConnect(i*k)); + endif + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"]\n"); + elseif isvector(net.targetConnect) + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + # print bracket for open + fprintf(fid," targetConnect: ["); + [nRows nColumns] = size(net.targetConnect); + for k = 1:1:nRows + for i = 1:1:nColumns + if (i<nColumns) + fprintf(fid,"%d ",net.targetConnect(i*k)); + else + fprintf(fid,"%d",net.targetConnect(i*k)); + endif + endfor + if k!=nRows + #print ; for newline in matrix + fprintf(fid,";"); + endif + endfor + # print last bracket + fprintf(fid,"] not yet used item\n"); + endif # if issquare.. + endif #if ismatrix + endif + else + fprintf(fid," ERROR..."); + endif + + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printTargets.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,40 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printTargets (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printTargets(fid,net) + + if isfield(net,"targets") + # check if it's cell array + if iscell(net.targets) + [nRows, nColumns] = size(net.targets); + # insert enough spaces to put ":" to position 20 + # insert 2 spaces for distance between ":" and "%" + fprintf(fid," targets: {%dx%d cell} containing %d targets\n",nRows,nColumns,net.numTargets); + else + fprintf(fid,"unsure if this is possible\n"); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printTrainFcn.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,37 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printTrainFcn (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + + +function __printTrainFcn(fid,net) + + if isfield(net,"trainFcn") + if isempty(net.trainFcn) + fprintf(fid," trainFcn: '%s'\n","empty"); + else + fprintf(fid," trainFcn: '%s'\n",net.trainFcn); + endif + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__printTrainParam.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,61 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printTrainParam (@var{fid}) +## @code{printMLPHeader} saves the header of a neural network structure +## to a *.txt file with identification @code{fid}. +## @end deftypefn + +## Author: Michel D. Schmid + +function __printTrainParam(fid,net) + + if isfield(net,"trainParam") + str2 = ""; + str3 = ""; + if isempty(net.trainParam) + fprintf(fid," trainParam: '%s'\n","not yet used item"); + else + cellFieldNames = fieldnames(net.trainParam); + [nRows, nColumns] = size(cellFieldNames); + if (nRows<4) + else + for iRuns = 1:nRows + if (iRuns==1) + str1 = ["." char(cellFieldNames(iRuns,1)) ", "]; + endif + if (iRuns<=4 & iRuns>1) + str1 = [str1 "." char(cellFieldNames(iRuns,1)) ", "]; + endif + if (iRuns>4 & iRuns<=8) + str2 = [str2 "." char(cellFieldNames(iRuns,1)) ", "]; + endif + if (iRuns>8) + str3 = [str3 "." char(cellFieldNames(iRuns,1)) ", "]; + endif + endfor + fprintf(fid," trainParam: %s\n",str1); + fprintf(fid," %s\n",str2); + fprintf(fid," %s\n",str3); + endif + endif + else + fprintf(fid,"field trainparam not found\n"); + endif + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__randomisecols.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,44 @@ +## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{retmatrix} = __randomisecols (@var{matrix}) +## @code{__randomisecols} takes a matrix as input argument and changes the order +## of the columns. The rows aren't affected. +## @end deftypefn + +## Author: mds + +function [retmatrix] = __randomisecols(matrix) + + ## check number of inputs + error(nargchk(1,1,nargin)); + + # get number of cols + nCols = size(matrix,2); + + # now create random column order + colOrder = randperm(nCols); + + # now sort the matrix new + retmatrix = matrix(:,[colOrder]); + + +endfunction + +%!# no test possible, contains randperm which is using +%!# some randome functions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__rerangecolumns.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,168 @@ +## Copyright (C) 2008 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{retmatrix} = __rerangecolumns (@var{matrix},@var{analyzeMatrix},@var{nTrainSets}) +## @code{__rerangecolumns} reranges the data sets depending on the input arguments. +## @code{matrix} is the data set matrix containing inputs and outputs (targets) in row order. +## This means for example: the first three rows are inputs and the fourth row is an output row. +## The second argument is used in the optimizing algorithm. This matrix contains informations about +## the description of the rows data of matrix. +## The third argument is used to be sure, rerange all the columns to the correct position. +## @end deftypefn + +## Author: mds + +function retmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets) + + ## check number of inputs + error(nargchk(3,3,nargin)); + + # set default values + + # now sort "matrix" with help of analyzeMatrix + # following conditions must be kept: + # a.) rows containing unique values aren't sorted! + # b.) sort first rows which contains min AND max values only once + # c.) sort secondly rows which contains min OR max values only once + # d.) at last, sort binary data if still needed! + + nRows = size(analyzeMatrix,1); # get number of rows + + ## create i-vector + i = 1; + iVec = []; + while (i <= nRows) + if ( (analyzeMatrix(i,3)==1) && (analyzeMatrix(i,4)==1) ) + iVec = [iVec i]; + endif + i += 1; + endwhile + i = 1; + while (i <= nRows) + if ( (analyzeMatrix(i,3)>1) || (analyzeMatrix(i,4)>1) ) + iVec = [iVec i]; + endif + i += 1; + endwhile + i = 1; + while (i <= nRows) + if (analyzeMatrix(i,1)==1) + iVec = [iVec i]; + endif + i += 1; + endwhile + + + ## now do main loop + j = 1; + i = iVec(j); + nRows = length(iVec); + while (j < nRows) + if (analyzeMatrix(i,2)==1) + # easiest case, nothing to do + else + + # now let's see if min AND max values are only once in the row + if ( (analyzeMatrix(i,3)==1) && (analyzeMatrix(i,4)==1) ) + # search at which index the min value is + minVal = min(matrix(i,:)); + [rowInd, colInd] = find(matrix(i,:)==minVal);# colInd is searched + if (colInd >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd); + endif + # search at which index the max value is + maxVal = max(matrix(i,:)); + [rowInd, colInd] = find(matrix(i,:)==maxVal);# colInd is searched + if (colInd >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd); + endif + + else + + # now here, we have to copy the rows, if min OR max values are more than once in a row + if ( (analyzeMatrix(i,3)>=1) || (analyzeMatrix(i,4)>=1) ) + + # search at which index the min value is + minVal = min(matrix(i,:)); + [rowInd, colInd] = find(matrix(i,:)==minVal);# colInd is searched + if (colInd(1) >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd(1)); + endif + + # search at which index the max value is + maxVal = max(matrix(i,:)); + [rowInd, colInd] = find(matrix(i,:) == maxVal);# colInd is searched + if (colInd(1) >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd(1)); + endif + + else + # now sort binary data, if needed + + # search at which index the 0-value is + [rowInd, colInd] = find(matrix(i,:)==0);# colInd is searched + if (colInd(1) >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd(1)); + endif + # search at which index the 1-value is + [rowInd, colInd] = find(matrix(i,:)==1);# colInd is searched + if (colInd(1) >= nTrainSets ) # move column + matrix = __copycoltopos1(matrix,colInd(1)); + endif + + endif# END OF if ( (analyzeMatrix(i,3)>=1) || (analyzeMatrix(i,4)>=1) ) + + endif # END OF if ( (analyzeMatrix(i,3)==1) AND (analyzeMatrix(i,4)==1) ) + + endif # END OF if (analyzeMatrix(i,2)==1) + j += 1; + i = iVec(j); + endwhile + retmatrix = matrix; +endfunction + +%!shared matrix,analyzeMatrix,nTrainSets, returnmatrix +%! disp("testing __rerangecolumns") +%! matrix = [0 1 0 0 0 0 1 0 1 1; \ +%! 4 4 4 4 4 4 4 4 4 4; \ +%! -1.1 -1.1 2 3 4 3.2 1 8 9 10; \ +%! 0 1.1 3 4 5 2 10 10 2 3; \ +%! -1 1 1 1 1 2 3 4 1 5]; +%! analyzeMatrix = [1 0 0 0; 0 1 0 0; 0 0 2 1; 0 0 1 2; 0 0 1 1]; +%! nTrainSets = 8; +%! returnmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); +%!assert(returnmatrix(1,1)==1); +%!assert(returnmatrix(2,1)==4); +%!assert(returnmatrix(3,1)==1); +%!assert(returnmatrix(4,1)==10); +%!assert(returnmatrix(5,1)==3); +%! matrix = [0 1 0 0 0 0 1 0 1 1; \ +%! 4 4 4 4 4 4 4 4 4 4; \ +%! -1.1 -1.1 2 3 4 3.2 1 8 9 10; \ +%! 0 1.1 3 4 5 2 10 10 2 3; \ +%! -1 1 1 1 1 2 3 4 1 5; \ +%! 0 1 2 1 2 1 2 3 4 5;]; # the last row is euqal to the nnet targets +%! analyzeMatrix = [1 0 0 0; 0 1 0 0; 0 0 2 1; 0 0 1 2; 0 0 1 1]; +%! nTrainSets = 8; +%! returnmatrix = __rerangecolumns(matrix,analyzeMatrix,nTrainSets); +%!assert(returnmatrix(1,1)==1); +%!assert(returnmatrix(2,1)==4); +%!assert(returnmatrix(3,1)==1); +%!assert(returnmatrix(4,1)==10); +%!assert(returnmatrix(5,1)==3); +%!assert(returnmatrix(6,1)==2); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__setx.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,61 @@ +## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{net} = __setx (@var{net},@var{X2}) +## @code{__setx} sets the new weights to the neural network structure +## @end deftypefn + +## @seealso{getx} + +## Author: Michel D. Schmid + +function net = __setx(net,xx) + + ## check number of inputs + error(nargchk(2,2,nargin)); + + ## check input args + ## check "net", must be a net structure + if !__checknetstruct(net) + error("Structure doesn't seem to be a neural network") + endif + + ## inputs + [nRows, nColumns] = size(net.IW{1,1}); + nElementsIW = nRows*nColumns; + net.IW{1,1}(:) = xx(1:nElementsIW); + + [nRows, nColumns] = size(net.b{1,1}); + nElementsB1 = nRows*nColumns; + net.b{1,1}(:) = xx(1+nElementsIW:nElementsIW+nElementsB1); + start = nElementsIW + nElementsB1; + + ## layers + nLayers = net.numLayers; + for i = 2:nLayers + [nRows, nColumns] = size(net.LW{i,i-1}); + nElementsLW = nRows*nColumns; + net.LW{i,i-1}(:) = xx(1+start:start+nElementsLW); + + [nRows, nColumns] = size(net.b{i,1}); + nElementsBx = nRows*nColumns; + net.b{i,1}(:) = xx(1+start+nElementsLW:start+nElementsLW+nElementsBx); + start = start + nElementsLW + nElementsBx; + endfor + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/nnet/inst/private/__trainlm.m Thu Nov 08 01:51:04 2012 +0000 @@ -0,0 +1,361 @@ +## Copyright (C) 2006 Michel D. Schmid <michaelschmid@users.sourceforge.net> +## +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {}[@var{netOut}] = __trainlm (@var{net},@var{mInputN},@var{mOutput},@var{[]},@var{[]},@var{VV}) +## A neural feed-forward network will be trained with @code{__trainlm} +## +## @example +## [netOut,tr,out,E] = __trainlm(net,mInputN,mOutput,[],[],VV); +## @end example +## @noindent +## +## left side arguments: +## @example +## netOut: the trained network of the net structure @code{MLPnet} +## tr : +## out: +## E : Error +## @end example +## @noindent +## +## right side arguments: +## @example +## net : the untrained network, created with @code{newff} +## mInputN: normalized input matrix +## mOutput: output matrix +## [] : unused parameter +## [] : unused parameter +## VV : validize structure +## out: +## E : Error +## @end example +## @noindent +## +## +## @noindent +## are equivalent. +## @end deftypefn + +## @seealso{newff,prestd,trastd} + +## Author: Michel D. Schmid + +## Comments: see in "A neural network toolbox for Octave User's Guide" [4] +## for variable naming... there have inputs or targets only one letter, +## e.g. for inputs is P written. To write a program, this is stupid, you can't +## search for 1 letter variable... that's why it is written here like Pp, or Tt +## instead only P or T. + +function [net] = __trainlm(net,Im,Pp,Tt,VV) + + ## check range of input arguments + error(nargchk(5,5,nargin)) + + ## Initialize + ##------------ + + ## get parameters for training + epochs = net.trainParam.epochs; + goal = net.trainParam.goal; + maxFail = net.trainParam.max_fail; + minGrad = net.trainParam.min_grad; + mu = net.trainParam.mu; + muInc = net.trainParam.mu_inc; + muDec = net.trainParam.mu_dec; + muMax = net.trainParam.mu_max; + show = net.trainParam.show; + time = net.trainParam.time; + + ## parameter checking + checkParameter(epochs,goal,maxFail,minGrad,mu,\ + muInc,muDec,muMax,show,time); + + ## Constants + shortStr = "TRAINLM"; # TODO: shortStr is longer as TRAINLM !!!!!!!!!!! + doValidation = !isempty(VV); + stop = ""; + + + #startTime = clock(); # TODO: maybe this row can be placed + # some rows later + + ## the weights are used in column vector format + xx = __getx(net); # x is the variable with respect to, but no + # variables with only one letter!! + ## define identity matrix + muI = eye(length(xx)); + + startTime = clock(); # if the next some tests are OK, I can delete + # startTime = clock(); 9 rows above.. + + ## calc performance of the actual net + [perf,vE,Aa,Nn] = __calcperf(net,xx,Im,Tt); + if (doValidation) + ## calc performance if validation is used + VV.net = net; # save the actual net in the validate + # structure... if no train loop will show better validate + # performance, this will be the returned net + vperf = __calcperf(net,xx,VV.Im,VV.Tt); + VV.perf = vperf; + VV.numFail = 0; # one of the stop criterias + endif + + nLayers = net.numLayers; + for iEpochs = 0:epochs # longest loop & one of the stop criterias + ve = vE{nLayers,1}; + ## calc jacobian + ## Jj is jacobian matrix + [Jj] = __calcjacobian(net,Im,Nn,Aa,vE); + + ## rerange error vector for jacobi matrix + ve = ve(:); + + Jjve = (Jj' * ve); # will be used to calculate the gradient + + normGradX = sqrt(Jjve'*Jjve); + + ## record training progress for later plotting + ## if requested + trainRec.perf(iEpochs+1) = perf; + trainRec.mu(iEpochs+1) = mu; + if (doValidation) + trainRec.vperf(iEpochs+1) = VV.perf; + endif + + ## stoping criteria + [stop,currentTime] = stopifnecessary(stop,startTime,perf,goal,\ + iEpochs,epochs,time,normGradX,minGrad,mu,muMax,\ + doValidation,VV,maxFail); + + ## show train progress + showtrainprogress(show,stop,iEpochs,epochs,time,currentTime, \ + goal,perf,minGrad,normGradX,shortStr,net); + + ## show performance plot, if needed + if !isnan(show) # if no performance plot is needed + ## now make it possible to define after how much loops the + ## performance plot should be updated + if (mod(iEpochs,show)==0) + plot(1:length(trainRec.perf),trainRec.perf); + if (doValidation) + hold on; + plot(1:length(trainRec.vperf),trainRec.vperf,"--g"); + endif + endif + endif # if !(strcmp(show,"NaN")) +# legend("Training","Validation"); + + ## stop if one of the criterias is reached. + if length(stop) + if (doValidation) + net = VV.net; + endif + break + endif + + ## calculate DeltaX + while (mu <= muMax) + ## calculate change in x + ## see [4], page 12-21 + dx = -((Jj' * Jj) + (muI*mu)) \ Jjve; + + ## add changes in x to actual x values (xx) + x1 = xx + dx; + ## now add x1 to a new network to see if performance will be better + net1 = __setx(net,x1); + ## calc now new performance with the new net + [perf1,vE1,Aa1,N1] = __calcperf(net1,x1,Im,Tt); + + if (perf1 < perf) + ## this means, net performance with new weight values is better... + ## so save the new values + xx = x1; + net = net1; + Nn = N1; + Aa = Aa1; + vE = vE1; + perf = perf1; + + mu = mu * muDec; + if (mu < 1e-20) # 1e-20 is properly the hard coded parameter in MATLAB(TM) + mu = 1e-20; + endif + break + endif + mu = mu * muInc; + endwhile + + ## validate with DeltaX + if (doValidation) + vperf = __calcperf(net,xx,VV.Im,VV.Tt); + if (vperf < VV.perf) + VV.perf = vperf; + VV.net = net; + ## if actual validation performance is better, + ## set numFail to zero again + VV.numFail = 0; + elseif (vperf > VV.perf) + VV.numFail = VV.numFail + 1; + endif + endif + + endfor #for iEpochs = 0:epochs + +#======================================================= +# +# additional functions +# +#======================================================= + function checkParameter(epochs,goal,maxFail,minGrad,mu,\ + muInc, muDec, muMax, show, time) + ## Parameter Checking + + ## epochs must be a positive integer + if ( !isposint(epochs) ) + error("Epochs is not a positive integer.") + endif + + ## goal can be zero or a positive double + if ( (goal<0) || !(isa(goal,"double")) ) + error("Goal is not zero or a positive real value.") + endif + + ## maxFail must be also a positive integer + if ( !isposint(maxFail) ) # this will be used, to see if validation can + # break the training + error("maxFail is not a positive integer.") + endif + + if (!isa(minGrad,"double")) || (!isreal(minGrad)) || (!isscalar(minGrad)) || \ + (minGrad < 0) + error("minGrad is not zero or a positive real value.") + end + + ## mu must be a positive real value. this parameter is responsible + ## for moving from stepest descent to quasi newton + if ((!isa(mu,"double")) || (!isreal(mu)) || (any(size(mu)) != 1) || (mu <= 0)) + error("mu is not a positive real value.") + endif + + ## muDec defines the decrement factor + if ((!isa(muDec,"double")) || (!isreal(muDec)) || (any(size(muDec)) != 1) || \ + (muDec < 0) || (muDec > 1)) + error("muDec is not a real value between 0 and 1.") + endif + + ## muInc defines the increment factor + if (~isa(muInc,"double")) || (!isreal(muInc)) || (any(size(muInc)) != 1) || \ + (muInc < 1) + error("muInc is not a real value greater than 1.") + endif + + ## muMax is the upper boundary for the mu value + if (!isa(muMax,"double")) || (!isreal(muMax)) || (any(size(muMax)) != 1) || \ + (muMax <= 0) + error("muMax is not a positive real value.") + endif + + ## check for actual mu value + if (mu > muMax) + error("mu is greater than muMax.") + end + + ## check if show is activated + if (!isnan(show)) + if (!isposint(show)) + error(["Show is not " "NaN" " or a positive integer."]) + endif + endif + + ## check at last the time argument, must be zero or a positive real value + if (!isa(time,"double")) || (!isreal(time)) || (any(size(time)) != 1) || \ + (time < 0) + error("Time is not zero or a positive real value.") + end + + endfunction # parameter checking + +# +# ----------------------------------------------------------------------------- +# + + function showtrainprogress(show,stop,iEpochs,epochs,time,currentTime, \ + goal,perf,minGrad,normGradX,shortStr,net) + + ## check number of inputs + error(nargchk(12,12,nargin)); + + ## show progress + if isfinite(show) && (!rem(iEpochs,show) || length(stop)) + fprintf(shortStr); # outputs the training algorithm + if isfinite(epochs) + fprintf(", Epoch %g/%g",iEpochs, epochs); + endif + if isfinite(time) + fprintf(", Time %4.1f%%",currentTime/time*100); # \todo: Time wird nicht ausgegeben + endif + if isfinite(goal) + fprintf(", %s %g/%g",upper(net.performFcn),perf,goal); # outputs the performance function + endif + if isfinite(minGrad) + fprintf(", Gradient %g/%g",normGradX,minGrad); + endif + fprintf("\n") + if length(stop) + fprintf("%s, %s\n\n",shortStr,stop); + endif + fflush(stdout); # writes output to stdout as soon as output messages are available + endif + endfunction + +# +# ----------------------------------------------------------------------------- +# + + function [stop,currentTime] = stopifnecessary(stop,startTime,perf,goal,\ + iEpochs,epochs,time,normGradX,minGrad,mu,muMax,\ + doValidation,VV,maxFail) + + ## check number of inputs + error(nargchk(14,14,nargin)); + + currentTime = etime(clock(),startTime); + if (perf <= goal) + stop = "Performance goal met."; + elseif (iEpochs == epochs) + stop = "Maximum epoch reached, performance goal was not met."; + elseif (currentTime > time) + stop = "Maximum time elapsed, performance goal was not met."; + elseif (normGradX < minGrad) + stop = "Minimum gradient reached, performance goal was not met."; + elseif (mu > muMax) + stop = "Maximum MU reached, performance goal was not met."; + elseif (doValidation) + if (VV.numFail > maxFail) + stop = "Validation stop."; + endif + endif + endfunction + +# ===================================================================== +# +# END additional functions +# +# ===================================================================== + +endfunction \ No newline at end of file