annotate toolboxes/FullBNT-1.0.7/netlab3.3/rbffwd.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [a, z, n2] = rbffwd(net, x)
wolffd@0 2 %RBFFWD Forward propagation through RBF network with linear outputs.
wolffd@0 3 %
wolffd@0 4 % Description
wolffd@0 5 % A = RBFFWD(NET, X) takes a network data structure NET and a matrix X
wolffd@0 6 % of input vectors and forward propagates the inputs through the
wolffd@0 7 % network to generate a matrix A of output vectors. Each row of X
wolffd@0 8 % corresponds to one input vector and each row of A contains the
wolffd@0 9 % corresponding output vector. The activation function that is used is
wolffd@0 10 % determined by NET.ACTFN.
wolffd@0 11 %
wolffd@0 12 % [A, Z, N2] = RBFFWD(NET, X) also generates a matrix Z of the hidden
wolffd@0 13 % unit activations where each row corresponds to one pattern. These
wolffd@0 14 % hidden unit activations represent the design matrix for the RBF. The
wolffd@0 15 % matrix N2 is the squared distances between each basis function centre
wolffd@0 16 % and each pattern in which each row corresponds to a data point.
wolffd@0 17 %
wolffd@0 18 % See also
wolffd@0 19 % RBF, RBFERR, RBFGRAD, RBFPAK, RBFTRAIN, RBFUNPAK
wolffd@0 20 %
wolffd@0 21
wolffd@0 22 % Copyright (c) Ian T Nabney (1996-2001)
wolffd@0 23
wolffd@0 24 % Check arguments for consistency
wolffd@0 25 errstring = consist(net, 'rbf', x);
wolffd@0 26 if ~isempty(errstring);
wolffd@0 27 error(errstring);
wolffd@0 28 end
wolffd@0 29
wolffd@0 30 [ndata, data_dim] = size(x);
wolffd@0 31
wolffd@0 32 % Calculate squared norm matrix, of dimension (ndata, ncentres)
wolffd@0 33 n2 = dist2(x, net.c);
wolffd@0 34
wolffd@0 35 % Switch on activation function type
wolffd@0 36 switch net.actfn
wolffd@0 37
wolffd@0 38 case 'gaussian' % Gaussian
wolffd@0 39 % Calculate width factors: net.wi contains squared widths
wolffd@0 40 wi2 = ones(ndata, 1) * (2 .* net.wi);
wolffd@0 41
wolffd@0 42 % Now compute the activations
wolffd@0 43 z = exp(-(n2./wi2));
wolffd@0 44
wolffd@0 45 case 'tps' % Thin plate spline
wolffd@0 46 z = n2.*log(n2+(n2==0));
wolffd@0 47
wolffd@0 48 case 'r4logr' % r^4 log r
wolffd@0 49 z = n2.*n2.*log(n2+(n2==0));
wolffd@0 50
wolffd@0 51 otherwise
wolffd@0 52 error('Unknown activation function in rbffwd')
wolffd@0 53 end
wolffd@0 54
wolffd@0 55 a = z*net.w2 + ones(ndata, 1)*net.b2;