wolffd@0
|
1 function net = rbf(nin, nhidden, nout, rbfunc, outfunc, prior, beta)
|
wolffd@0
|
2 %RBF Creates an RBF network with specified architecture
|
wolffd@0
|
3 %
|
wolffd@0
|
4 % Description
|
wolffd@0
|
5 % NET = RBF(NIN, NHIDDEN, NOUT, RBFUNC) constructs and initialises a
|
wolffd@0
|
6 % radial basis function network returning a data structure NET. The
|
wolffd@0
|
7 % weights are all initialised with a zero mean, unit variance normal
|
wolffd@0
|
8 % distribution, with the exception of the variances, which are set to
|
wolffd@0
|
9 % one. This makes use of the Matlab function RANDN and so the seed for
|
wolffd@0
|
10 % the random weight initialization can be set using RANDN('STATE', S)
|
wolffd@0
|
11 % where S is the seed value. The activation functions are defined in
|
wolffd@0
|
12 % terms of the distance between the data point and the corresponding
|
wolffd@0
|
13 % centre. Note that the functions are computed to a convenient
|
wolffd@0
|
14 % constant multiple: for example, the Gaussian is not normalised.
|
wolffd@0
|
15 % (Normalisation is not needed as the function outputs are linearly
|
wolffd@0
|
16 % combined in the next layer.)
|
wolffd@0
|
17 %
|
wolffd@0
|
18 % The fields in NET are
|
wolffd@0
|
19 % type = 'rbf'
|
wolffd@0
|
20 % nin = number of inputs
|
wolffd@0
|
21 % nhidden = number of hidden units
|
wolffd@0
|
22 % nout = number of outputs
|
wolffd@0
|
23 % nwts = total number of weights and biases
|
wolffd@0
|
24 % actfn = string defining hidden unit activation function:
|
wolffd@0
|
25 % 'gaussian' for a radially symmetric Gaussian function.
|
wolffd@0
|
26 % 'tps' for r^2 log r, the thin plate spline function.
|
wolffd@0
|
27 % 'r4logr' for r^4 log r.
|
wolffd@0
|
28 % outfn = string defining output error function:
|
wolffd@0
|
29 % 'linear' for linear outputs (default) and SoS error.
|
wolffd@0
|
30 % 'neuroscale' for Sammon stress measure.
|
wolffd@0
|
31 % c = centres
|
wolffd@0
|
32 % wi = squared widths (null for rlogr and tps)
|
wolffd@0
|
33 % w2 = second layer weight matrix
|
wolffd@0
|
34 % b2 = second layer bias vector
|
wolffd@0
|
35 %
|
wolffd@0
|
36 % NET = RBF(NIN, NHIDDEN, NOUT, RBFUND, OUTFUNC) allows the user to
|
wolffd@0
|
37 % specify the type of error function to be used. The field OUTFN is
|
wolffd@0
|
38 % set to the value of this string. Linear outputs (for regression
|
wolffd@0
|
39 % problems) and Neuroscale outputs (for topographic mappings) are
|
wolffd@0
|
40 % supported.
|
wolffd@0
|
41 %
|
wolffd@0
|
42 % NET = RBF(NIN, NHIDDEN, NOUT, RBFUNC, OUTFUNC, PRIOR, BETA), in which
|
wolffd@0
|
43 % PRIOR is a scalar, allows the field NET.ALPHA in the data structure
|
wolffd@0
|
44 % NET to be set, corresponding to a zero-mean isotropic Gaussian prior
|
wolffd@0
|
45 % with inverse variance with value PRIOR. Alternatively, PRIOR can
|
wolffd@0
|
46 % consist of a data structure with fields ALPHA and INDEX, allowing
|
wolffd@0
|
47 % individual Gaussian priors to be set over groups of weights in the
|
wolffd@0
|
48 % network. Here ALPHA is a column vector in which each element
|
wolffd@0
|
49 % corresponds to a separate group of weights, which need not be
|
wolffd@0
|
50 % mutually exclusive. The membership of the groups is defined by the
|
wolffd@0
|
51 % matrix INDX in which the columns correspond to the elements of ALPHA.
|
wolffd@0
|
52 % Each column has one element for each weight in the matrix, in the
|
wolffd@0
|
53 % order defined by the function RBFPAK, and each element is 1 or 0
|
wolffd@0
|
54 % according to whether the weight is a member of the corresponding
|
wolffd@0
|
55 % group or not. A utility function RBFPRIOR is provided to help in
|
wolffd@0
|
56 % setting up the PRIOR data structure.
|
wolffd@0
|
57 %
|
wolffd@0
|
58 % NET = RBF(NIN, NHIDDEN, NOUT, FUNC, PRIOR, BETA) also sets the
|
wolffd@0
|
59 % additional field NET.BETA in the data structure NET, where beta
|
wolffd@0
|
60 % corresponds to the inverse noise variance.
|
wolffd@0
|
61 %
|
wolffd@0
|
62 % See also
|
wolffd@0
|
63 % RBFERR, RBFFWD, RBFGRAD, RBFPAK, RBFTRAIN, RBFUNPAK
|
wolffd@0
|
64 %
|
wolffd@0
|
65
|
wolffd@0
|
66 % Copyright (c) Ian T Nabney (1996-2001)
|
wolffd@0
|
67
|
wolffd@0
|
68 net.type = 'rbf';
|
wolffd@0
|
69 net.nin = nin;
|
wolffd@0
|
70 net.nhidden = nhidden;
|
wolffd@0
|
71 net.nout = nout;
|
wolffd@0
|
72
|
wolffd@0
|
73 % Check that function is an allowed type
|
wolffd@0
|
74 actfns = {'gaussian', 'tps', 'r4logr'};
|
wolffd@0
|
75 outfns = {'linear', 'neuroscale'};
|
wolffd@0
|
76 if (strcmp(rbfunc, actfns)) == 0
|
wolffd@0
|
77 error('Undefined activation function.')
|
wolffd@0
|
78 else
|
wolffd@0
|
79 net.actfn = rbfunc;
|
wolffd@0
|
80 end
|
wolffd@0
|
81 if nargin <= 4
|
wolffd@0
|
82 net.outfn = outfns{1};
|
wolffd@0
|
83 elseif (strcmp(outfunc, outfns) == 0)
|
wolffd@0
|
84 error('Undefined output function.')
|
wolffd@0
|
85 else
|
wolffd@0
|
86 net.outfn = outfunc;
|
wolffd@0
|
87 end
|
wolffd@0
|
88
|
wolffd@0
|
89 % Assume each function has a centre and a single width parameter, and that
|
wolffd@0
|
90 % hidden layer to output weights include a bias. Only the Gaussian function
|
wolffd@0
|
91 % requires a width
|
wolffd@0
|
92 net.nwts = nin*nhidden + (nhidden + 1)*nout;
|
wolffd@0
|
93 if strcmp(rbfunc, 'gaussian')
|
wolffd@0
|
94 % Extra weights for width parameters
|
wolffd@0
|
95 net.nwts = net.nwts + nhidden;
|
wolffd@0
|
96 end
|
wolffd@0
|
97
|
wolffd@0
|
98 if nargin > 5
|
wolffd@0
|
99 if isstruct(prior)
|
wolffd@0
|
100 net.alpha = prior.alpha;
|
wolffd@0
|
101 net.index = prior.index;
|
wolffd@0
|
102 elseif size(prior) == [1 1]
|
wolffd@0
|
103 net.alpha = prior;
|
wolffd@0
|
104 else
|
wolffd@0
|
105 error('prior must be a scalar or a structure');
|
wolffd@0
|
106 end
|
wolffd@0
|
107 if nargin > 6
|
wolffd@0
|
108 net.beta = beta;
|
wolffd@0
|
109 end
|
wolffd@0
|
110 end
|
wolffd@0
|
111
|
wolffd@0
|
112 w = randn(1, net.nwts);
|
wolffd@0
|
113 net = rbfunpak(net, w);
|
wolffd@0
|
114
|
wolffd@0
|
115 % Make widths equal to one
|
wolffd@0
|
116 if strcmp(rbfunc, 'gaussian')
|
wolffd@0
|
117 net.wi = ones(1, nhidden);
|
wolffd@0
|
118 end
|
wolffd@0
|
119
|
wolffd@0
|
120 if strcmp(net.outfn, 'neuroscale')
|
wolffd@0
|
121 net.mask = rbfprior(rbfunc, nin, nhidden, nout);
|
wolffd@0
|
122 end
|
wolffd@0
|
123
|