% BPM demonstrates the Bayes Point Machine algorithm
%
% 2001 written by Ralf Herbrich
% Microsoft Research Cambridge
%
% (c) 2001 Microsoft Corporation. Reproduced with permission. All rights reserved.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 0: INITIALISE THE DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set of training point of unit length
%% the data points are given by their latitude and azimuth
data = [[0, pi/4]; [0, -pi/4]; [pi/4, pi/4]];
col = [[0 0 1]; [0 1 0]; [1 0 0]];
grid = -1.3:0.05:1.3;
%% one particular weight vector (polar coordinates) - SVM solution
phi = pi/8;
theta = -pi/2;
%% a sequence of artificially setup hitpoints
P = [phi phi+pi/6 phi+pi/4 phi-pi/6 phi-pi/4];
T = [theta theta+pi/6 theta-pi/9 theta+pi/6 theta-95*pi/400];
N = length (P);
%% number of samples
M = 10;
m = size (data, 1);
[sx, sy, sz] = sphere (50);
%% compute Cartesian coordinates of the data points
X = zeros (m, 3);
for i = 1:m
[X(i,1), X(i,2), X(i,3)] = pol2car(data (i,1), data (i,2));
end
X = 2.0*X;
%% compute Cartesian coordinates of the data points
W = zeros (3,1);
[W(1), W(2), W(3)] = pol2car (phi, theta);
figure;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 1.A: PLOT THE VERSION SPACE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% plot sphere
sp_hd = surfl (sx, sy, sz);
colormap gray;
shading interp;
l = camlight;
set (l, 'Position', [2 0 0.5], 'Style', 'local');
lighting gouraud;
axis off;
axis equal;
set (sp_hd, 'EdgeColor', [0.3, 0.3, 0.3]);
set (sp_hd, 'EdgeAlpha', 0.2);
view (60, 5)
hold on;
for i=1:m
[px, py, pz] = plane (grid, data (i,1), data (i,2));
hold on;
surfl (px, py, pz);
shading interp;
[gc_x, gc_y, gc_z] = grandcircle (100, data (i,1), data (i,2), 1);
hold on;
plot3(gc_x, gc_y, gc_z, 'k-','LineWidth', 3);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 2.A: SIMULATE BILLIARD HITPOINT BY HITPOINT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a = zeros (1, (N-1));
b = zeros (1, (N-1));
for i=1:(N-1)
W = zeros (3);
[W(1), W(2), W(3)] = pol2car (P (i), T (i));
[xp, yp, zp] = ellipsoid (W(1), W(2), W(3), 0.04, 0.04, 0.04);
hold on;
hp_hd = surfl (xp, yp, zp);
hold on;
set (hp_hd, 'FaceColor', 'interp');
set (hp_hd, 'EdgeColor', 'none');
[x, y, z] = arc (100, P(i), T(i), P(i+1), T(i+1));
a(i) = plot3 (x, y, z, 'w-');
%% draw the straight line
W2 = zeros (3);
[W2(1), W2(2), W2(3)] = pol2car (P (i+1), T (i+1));
b(i) = plot3 ([W(1) W2(1)], [W(2) W2(2)], [W(3) W2(3)], 'w-');
end
[W(1), W(2), W(3)] = pol2car (P (N), T (N));
[xp, yp, zp] = ellipsoid (W(1), W(2), W(3), 0.04, 0.04, 0.04);
hold on;
hp_hd = surfl (xp, yp, zp);
set (hp_hd, 'FaceColor', 'interp');
set (hp_hd, 'EdgeColor', 'none');
hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 3.A: SHOW THE REAL LINES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set (sp_hd, 'EdgeColor', [0.3, 0.3, 0.3]);
set (sp_hd, 'EdgeAlpha', 0.4);
set (sp_hd, 'FaceAlpha', 1/2);
for i=1:(N-1)
set (a(i), 'LineWidth', 2, 'Color', [0.5 0.5 0.5]);
set (b(i), 'LineWidth', 2, 'Color', [0.5 0.5 0.5]);
end
print -deps ../../ps/bpm_ball.ps