1 ## Copyright (C) 2007 Michel D. Schmid <michaelschmid@users.sourceforge.net>
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ## General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING. If not, write to the Free
16 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 ## @deftypefn {Function File} {@var{net}} = newp (@var{Pr},@var{ss},@var{transFunc},@var{learnFunc})
21 ## @code{newp} create a perceptron
24 ## PLEASE DON'T USE THIS FUNCTIONS, IT'S STILL NOT FINISHED!
25 ## =========================================================
28 ## Pr - R x 2 matrix of min and max values for R input elements
29 ## ss - a scalar value with the number of neurons
30 ## transFunc - a string with the transfer function
31 ## default = "hardlim"
32 ## learnFunc - a string with the learning function
41 ## Author: Michel D. Schmid
43 function net = newp(Pr,ss,transFunc,learnFunc)
45 ## initial descriptipn
46 ## newp(Pr,ss,transFunc,learnFunc)
47 ## * Pr is a nx2 matrix with min and max values of standardized inputs
49 ## * ss is a scalar value which describes the number of neurons
51 ## * transFunc is the transfer function, standard is "hardlim"
52 ## * learnFunc is the learning function, standard is "learnp"
54 ## check range of input arguments
55 error(nargchk(1,4,nargin))
59 ss = 1; # means one neuron
62 transFunc = "hardlim";
69 checkInputArgs(Pr,ss);
71 # ## get number of layers (without input layer)
72 # nLayers = length(ss);
74 ## Standard architecture of neural network
75 net = __newnetwork(1,1,1,"newp");
77 ## first argument: number of inputs, nothing else allowed till now
78 ## it's not the same like the number of neurons in this input
79 ## second argument: number of layers, including output layer
80 ## third argument: number of outputs, nothing else allowed till now
81 ## it's not the same like the number of neurons in this output
82 ## fourth argument: network type
85 ## set inputs with limit of only ONE input
86 net.inputs{1}.range = Pr;
87 [nRows, nColumns] = size(Pr);
88 net.inputs{1}.size = nRows;
91 net.IW{1,1} = zeros(1,nRows);
92 ## set number of bias, one per layer
95 ## define everything with "layers"
96 net.numLayers = ss(end);
97 net.layers = cell(1,1);
98 net.layers{1}.size = ss(end);
99 net.layers{1}.transFcn = transFunc;
100 ## next row of code is only for MATLAB(TM) compatibility
101 ## I never used this the last 4 years ...
102 net.targets{i}.userdata = "Put your custom informations here!";
104 ## performance function
105 net.performFnc = "mae";
108 net.biases{1}.learnFcn = learnFunc;
109 net.inputWeights{1,1}.learnFcn = learnFunc;
112 net.adaptFcn = "trains";
115 net.trainFcn = "trainc";
120 # ======================================================
122 # additional check functions...
124 # ======================================================
125 function checkInputArgs(Pr,ss)
127 ## check if Pr has correct format
128 if !isreal(Pr) | (size(Pr,2)!=2)
129 error("Input ranges must be a two column matrix!")
131 if any(Pr(:,1) > Pr(:,2)) # check if numbers in the second column are larger as in the first one
132 error("Input ranges has values in the second column larger as in the same row of the first column.")
135 ## check if ss has correct format, must be a scalar value
136 if ( (size(ss,1)!=1) || (size(ss,2)!=1))
137 error("Layer sizes is not a scalar value.")
142 # ========================================================