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