Daniel@0: %DEMNS1 Demonstrate Neuroscale for visualisation. Daniel@0: % Daniel@0: % Description Daniel@0: % This script demonstrates the use of the Neuroscale algorithm for Daniel@0: % topographic projection and visualisation. A data sample is generated Daniel@0: % from a mixture of two Gaussians in 4d space, and an RBF is trained Daniel@0: % with the stress error function to project the data into 2d. The Daniel@0: % training data and a test sample are both plotted in this projection. Daniel@0: % Daniel@0: % See also Daniel@0: % RBF, RBFTRAIN, RBFPRIOR Daniel@0: % Daniel@0: Daniel@0: % Copyright (c) Ian T Nabney (1996-2001) Daniel@0: Daniel@0: % Generate the data Daniel@0: % Fix seeds for reproducible results Daniel@0: rand('state', 420); Daniel@0: randn('state', 420); Daniel@0: Daniel@0: input_dim = 4; Daniel@0: output_dim = 2; Daniel@0: mix = gmm(input_dim, 2, 'spherical'); Daniel@0: mix.centres = [1 1 1 1; 0 0 0 0]; Daniel@0: mix.priors = [0.5 0.5]; Daniel@0: mix.covars = [0.1 0.1]; Daniel@0: Daniel@0: ndata = 60; Daniel@0: [data, labels] = gmmsamp(mix, ndata); Daniel@0: Daniel@0: clc Daniel@0: disp('This demonstration illustrates the use of the Neuroscale model') Daniel@0: disp('to perform a topographic projection of data. We begin by generating') Daniel@0: disp('60 data points from a mixture of two Gaussians in 4 dimensional space.') Daniel@0: disp(' ') Daniel@0: disp('Press any key to continue') Daniel@0: pause Daniel@0: Daniel@0: ncentres = 10; Daniel@0: net = rbf(input_dim, ncentres, output_dim, 'tps', 'neuroscale'); Daniel@0: dstring = ['the Sammon mapping. The model has ', num2str(ncentres), ... Daniel@0: ' centres, two outputs, and uses']; Daniel@0: clc Daniel@0: disp('The Neuroscale model is an RBF with a Stress error measure as used in') Daniel@0: disp(dstring) Daniel@0: disp('thin plate spline basis functions.') Daniel@0: disp(' ') Daniel@0: disp('It is trained using the shadow targets algorithm for at most 60 iterations.') Daniel@0: disp(' ') Daniel@0: disp('Press any key to continue') Daniel@0: pause Daniel@0: Daniel@0: % First row controls shadow targets, second row controls rbfsetbf Daniel@0: options(1, :) = foptions; Daniel@0: options(2, :) = foptions; Daniel@0: options(1, 1) = 1; Daniel@0: options(1, 2) = 1e-2; Daniel@0: options(1, 3) = 1e-2; Daniel@0: options(1, 6) = 1; % Switch on PCA initialisation Daniel@0: options(1, 14) = 60; Daniel@0: options(2, 1) = -1; % Switch off all warnings Daniel@0: options(2, 5) = 1; Daniel@0: options(2, 14) = 10; Daniel@0: net2 = rbftrain(net, options, data); Daniel@0: Daniel@0: disp(' ') Daniel@0: disp('After training the model, we project the training data by a normal') Daniel@0: disp('forward propagation through the RBF network. Because there are two') Daniel@0: disp('outputs, the results can be plotted and visualised.') Daniel@0: disp(' ') Daniel@0: disp('Press any key to continue') Daniel@0: pause Daniel@0: Daniel@0: % Plot the result Daniel@0: y = rbffwd(net2, data); Daniel@0: ClassSymbol1 = 'r.'; Daniel@0: ClassSymbol2 = 'b.'; Daniel@0: PointSize = 12; Daniel@0: fh1 = figure; Daniel@0: hold on; Daniel@0: plot(y((labels==1),1),y(labels==1,2),ClassSymbol1, 'MarkerSize', PointSize) Daniel@0: plot(y((labels>1),1),y(labels>1,2),ClassSymbol2, 'MarkerSize', PointSize) Daniel@0: Daniel@0: disp(' ') Daniel@0: disp('In this plot, the red dots denote the first class and the blue') Daniel@0: disp('dots the second class.') Daniel@0: disp(' ') Daniel@0: disp('Press any key to continue.') Daniel@0: disp(' ') Daniel@0: pause Daniel@0: Daniel@0: disp('We now generate a further 100 data points from the original distribution') Daniel@0: disp('and plot their projection using star symbols. Note that a Sammon') Daniel@0: disp('mapping cannot be used to generalise to new data in this fashion.') Daniel@0: Daniel@0: [test_data, test_labels] = gmmsamp(mix, 100); Daniel@0: ytest = rbffwd(net2, test_data); Daniel@0: ClassSymbol1 = 'ro'; Daniel@0: ClassSymbol2 = 'bo'; Daniel@0: % Circles are rather large symbols Daniel@0: PointSize = 6; Daniel@0: hold on Daniel@0: plot(ytest((test_labels==1),1),ytest(test_labels==1,2), ... Daniel@0: ClassSymbol1, 'MarkerSize', PointSize) Daniel@0: plot(ytest((test_labels>1),1),ytest(test_labels>1,2),... Daniel@0: ClassSymbol2, 'MarkerSize', PointSize) Daniel@0: hold on Daniel@0: legend('Class 1', 'Class 2', 'Test Class 1', 'Test Class 2') Daniel@0: disp('Press any key to exit.') Daniel@0: pause Daniel@0: Daniel@0: close(fh1); Daniel@0: clear all; Daniel@0: