comparison toolboxes/FullBNT-1.0.7/netlab3.3/demns1.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 %DEMNS1 Demonstrate Neuroscale for visualisation.
2 %
3 % Description
4 % This script demonstrates the use of the Neuroscale algorithm for
5 % topographic projection and visualisation. A data sample is generated
6 % from a mixture of two Gaussians in 4d space, and an RBF is trained
7 % with the stress error function to project the data into 2d. The
8 % training data and a test sample are both plotted in this projection.
9 %
10 % See also
11 % RBF, RBFTRAIN, RBFPRIOR
12 %
13
14 % Copyright (c) Ian T Nabney (1996-2001)
15
16 % Generate the data
17 % Fix seeds for reproducible results
18 rand('state', 420);
19 randn('state', 420);
20
21 input_dim = 4;
22 output_dim = 2;
23 mix = gmm(input_dim, 2, 'spherical');
24 mix.centres = [1 1 1 1; 0 0 0 0];
25 mix.priors = [0.5 0.5];
26 mix.covars = [0.1 0.1];
27
28 ndata = 60;
29 [data, labels] = gmmsamp(mix, ndata);
30
31 clc
32 disp('This demonstration illustrates the use of the Neuroscale model')
33 disp('to perform a topographic projection of data. We begin by generating')
34 disp('60 data points from a mixture of two Gaussians in 4 dimensional space.')
35 disp(' ')
36 disp('Press any key to continue')
37 pause
38
39 ncentres = 10;
40 net = rbf(input_dim, ncentres, output_dim, 'tps', 'neuroscale');
41 dstring = ['the Sammon mapping. The model has ', num2str(ncentres), ...
42 ' centres, two outputs, and uses'];
43 clc
44 disp('The Neuroscale model is an RBF with a Stress error measure as used in')
45 disp(dstring)
46 disp('thin plate spline basis functions.')
47 disp(' ')
48 disp('It is trained using the shadow targets algorithm for at most 60 iterations.')
49 disp(' ')
50 disp('Press any key to continue')
51 pause
52
53 % First row controls shadow targets, second row controls rbfsetbf
54 options(1, :) = foptions;
55 options(2, :) = foptions;
56 options(1, 1) = 1;
57 options(1, 2) = 1e-2;
58 options(1, 3) = 1e-2;
59 options(1, 6) = 1; % Switch on PCA initialisation
60 options(1, 14) = 60;
61 options(2, 1) = -1; % Switch off all warnings
62 options(2, 5) = 1;
63 options(2, 14) = 10;
64 net2 = rbftrain(net, options, data);
65
66 disp(' ')
67 disp('After training the model, we project the training data by a normal')
68 disp('forward propagation through the RBF network. Because there are two')
69 disp('outputs, the results can be plotted and visualised.')
70 disp(' ')
71 disp('Press any key to continue')
72 pause
73
74 % Plot the result
75 y = rbffwd(net2, data);
76 ClassSymbol1 = 'r.';
77 ClassSymbol2 = 'b.';
78 PointSize = 12;
79 fh1 = figure;
80 hold on;
81 plot(y((labels==1),1),y(labels==1,2),ClassSymbol1, 'MarkerSize', PointSize)
82 plot(y((labels>1),1),y(labels>1,2),ClassSymbol2, 'MarkerSize', PointSize)
83
84 disp(' ')
85 disp('In this plot, the red dots denote the first class and the blue')
86 disp('dots the second class.')
87 disp(' ')
88 disp('Press any key to continue.')
89 disp(' ')
90 pause
91
92 disp('We now generate a further 100 data points from the original distribution')
93 disp('and plot their projection using star symbols. Note that a Sammon')
94 disp('mapping cannot be used to generalise to new data in this fashion.')
95
96 [test_data, test_labels] = gmmsamp(mix, 100);
97 ytest = rbffwd(net2, test_data);
98 ClassSymbol1 = 'ro';
99 ClassSymbol2 = 'bo';
100 % Circles are rather large symbols
101 PointSize = 6;
102 hold on
103 plot(ytest((test_labels==1),1),ytest(test_labels==1,2), ...
104 ClassSymbol1, 'MarkerSize', PointSize)
105 plot(ytest((test_labels>1),1),ytest(test_labels>1,2),...
106 ClassSymbol2, 'MarkerSize', PointSize)
107 hold on
108 legend('Class 1', 'Class 2', 'Test Class 1', 'Test Class 2')
109 disp('Press any key to exit.')
110 pause
111
112 close(fh1);
113 clear all;
114