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

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