Daniel@0: function net = rbf(nin, nhidden, nout, rbfunc, outfunc, prior, beta) Daniel@0: %RBF Creates an RBF network with specified architecture Daniel@0: % Daniel@0: % Description Daniel@0: % NET = RBF(NIN, NHIDDEN, NOUT, RBFUNC) constructs and initialises a Daniel@0: % radial basis function network returning a data structure NET. The Daniel@0: % weights are all initialised with a zero mean, unit variance normal Daniel@0: % distribution, with the exception of the variances, which are set to Daniel@0: % one. This makes use of the Matlab function RANDN and so the seed for Daniel@0: % the random weight initialization can be set using RANDN('STATE', S) Daniel@0: % where S is the seed value. The activation functions are defined in Daniel@0: % terms of the distance between the data point and the corresponding Daniel@0: % centre. Note that the functions are computed to a convenient Daniel@0: % constant multiple: for example, the Gaussian is not normalised. Daniel@0: % (Normalisation is not needed as the function outputs are linearly Daniel@0: % combined in the next layer.) Daniel@0: % Daniel@0: % The fields in NET are Daniel@0: % type = 'rbf' Daniel@0: % nin = number of inputs Daniel@0: % nhidden = number of hidden units Daniel@0: % nout = number of outputs Daniel@0: % nwts = total number of weights and biases Daniel@0: % actfn = string defining hidden unit activation function: Daniel@0: % 'gaussian' for a radially symmetric Gaussian function. Daniel@0: % 'tps' for r^2 log r, the thin plate spline function. Daniel@0: % 'r4logr' for r^4 log r. Daniel@0: % outfn = string defining output error function: Daniel@0: % 'linear' for linear outputs (default) and SoS error. Daniel@0: % 'neuroscale' for Sammon stress measure. Daniel@0: % c = centres Daniel@0: % wi = squared widths (null for rlogr and tps) Daniel@0: % w2 = second layer weight matrix Daniel@0: % b2 = second layer bias vector Daniel@0: % Daniel@0: % NET = RBF(NIN, NHIDDEN, NOUT, RBFUND, OUTFUNC) allows the user to Daniel@0: % specify the type of error function to be used. The field OUTFN is Daniel@0: % set to the value of this string. Linear outputs (for regression Daniel@0: % problems) and Neuroscale outputs (for topographic mappings) are Daniel@0: % supported. Daniel@0: % Daniel@0: % NET = RBF(NIN, NHIDDEN, NOUT, RBFUNC, OUTFUNC, PRIOR, BETA), in which Daniel@0: % PRIOR is a scalar, allows the field NET.ALPHA in the data structure Daniel@0: % NET to be set, corresponding to a zero-mean isotropic Gaussian prior Daniel@0: % with inverse variance with value PRIOR. Alternatively, PRIOR can Daniel@0: % consist of a data structure with fields ALPHA and INDEX, allowing Daniel@0: % individual Gaussian priors to be set over groups of weights in the Daniel@0: % network. Here ALPHA is a column vector in which each element Daniel@0: % corresponds to a separate group of weights, which need not be Daniel@0: % mutually exclusive. The membership of the groups is defined by the Daniel@0: % matrix INDX in which the columns correspond to the elements of ALPHA. Daniel@0: % Each column has one element for each weight in the matrix, in the Daniel@0: % order defined by the function RBFPAK, and each element is 1 or 0 Daniel@0: % according to whether the weight is a member of the corresponding Daniel@0: % group or not. A utility function RBFPRIOR is provided to help in Daniel@0: % setting up the PRIOR data structure. Daniel@0: % Daniel@0: % NET = RBF(NIN, NHIDDEN, NOUT, FUNC, PRIOR, BETA) also sets the Daniel@0: % additional field NET.BETA in the data structure NET, where beta Daniel@0: % corresponds to the inverse noise variance. Daniel@0: % Daniel@0: % See also Daniel@0: % RBFERR, RBFFWD, RBFGRAD, RBFPAK, RBFTRAIN, RBFUNPAK Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: net.type = 'rbf'; Daniel@0: net.nin = nin; Daniel@0: net.nhidden = nhidden; Daniel@0: net.nout = nout; Daniel@0: Daniel@0: % Check that function is an allowed type Daniel@0: actfns = {'gaussian', 'tps', 'r4logr'}; Daniel@0: outfns = {'linear', 'neuroscale'}; Daniel@0: if (strcmp(rbfunc, actfns)) == 0 Daniel@0: error('Undefined activation function.') Daniel@0: else Daniel@0: net.actfn = rbfunc; Daniel@0: end Daniel@0: if nargin <= 4 Daniel@0: net.outfn = outfns{1}; Daniel@0: elseif (strcmp(outfunc, outfns) == 0) Daniel@0: error('Undefined output function.') Daniel@0: else Daniel@0: net.outfn = outfunc; Daniel@0: end Daniel@0: Daniel@0: % Assume each function has a centre and a single width parameter, and that Daniel@0: % hidden layer to output weights include a bias. Only the Gaussian function Daniel@0: % requires a width Daniel@0: net.nwts = nin*nhidden + (nhidden + 1)*nout; Daniel@0: if strcmp(rbfunc, 'gaussian') Daniel@0: % Extra weights for width parameters Daniel@0: net.nwts = net.nwts + nhidden; Daniel@0: end Daniel@0: Daniel@0: if nargin > 5 Daniel@0: if isstruct(prior) Daniel@0: net.alpha = prior.alpha; Daniel@0: net.index = prior.index; Daniel@0: elseif size(prior) == [1 1] Daniel@0: net.alpha = prior; Daniel@0: else Daniel@0: error('prior must be a scalar or a structure'); Daniel@0: end Daniel@0: if nargin > 6 Daniel@0: net.beta = beta; Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: w = randn(1, net.nwts); Daniel@0: net = rbfunpak(net, w); Daniel@0: Daniel@0: % Make widths equal to one Daniel@0: if strcmp(rbfunc, 'gaussian') Daniel@0: net.wi = ones(1, nhidden); Daniel@0: end Daniel@0: Daniel@0: if strcmp(net.outfn, 'neuroscale') Daniel@0: net.mask = rbfprior(rbfunc, nin, nhidden, nout); Daniel@0: end Daniel@0: