-
Notifications
You must be signed in to change notification settings - Fork 0
/
poor_cosine_measures.m
155 lines (106 loc) · 4.53 KB
/
poor_cosine_measures.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% Author: Osama M. Raisuddin
% This script creates 3D figures of the searches done with regular convex
% polyhedra and their cosine measures and duality property
close all
clear
clc
% Use the high quality renderer to ensure SVG plots are created
set(0, 'defaultFigureRenderer', 'painters')
set(groot, 'defaultFigureRenderer', 'painters')
% Choose the
% color,
% and viewing angle
% for the figures
color = [149, 121, 232]/255;
view_angle = [120,30];
%% Nelder Mead
% Generate the search directions for Nelder Mead search and the vertex sets
% for the corresponding polyhedron, the tetrahedron
search_dir = [1, 1, 1;1, -1, -1;-1, 1, -1 ;-1, -1, 1]/sqrt(3);
search_dir_vertex_sets = [[1,2,3];[1,2,4];[1,3,4];[2,3,4]];
% Generate the cosine measure directions for Nelder Mead search and the
% vertex sets for the corresponding polyhedron, the tetrahedron
cm_dir = [-1, -1, -1; -1, 1, 1; 1, -1, 1; 1, 1, -1]/sqrt(3);
cm_dir_vertex_sets = [[1,2,3];[1,2,4];[1,3,4];[2,3,4]];
% Plot the polyhera and vectors
figure
hold on
axis off
axis equal
quiver3(zeros(length(search_dir),1),zeros(length(search_dir),1),zeros(length(search_dir),1),search_dir(:,1),search_dir(:,2),search_dir(:,3),'black','LineWidth',2)
quiver3(zeros(length(cm_dir),1),zeros(length(cm_dir),1),zeros(length(cm_dir),1),cm_dir(:,1),cm_dir(:,2),cm_dir(:,3),'color',color,'LineWidth',2)
for i = 1:length(search_dir_vertex_sets)
plot3( search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],1) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],2) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],3), ':','Color','black')
end
for i = 1:length(cm_dir_vertex_sets)
plot3( cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],1) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],2) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],3), ':','Color',color)
end
view(view_angle)
%% Pattern Search
search_dir = [1,0,0;-1,0,0; 0,1,0;0,-1,0; 0,0,1;0,0,-1];
search_dir_vertex_sets = [1,3,5; 1,3,6; 1,4,5; 1,4,6; 2,3,5; 2,3,6; 2,4,5; 2,4,6;];
cm_dir = [
1, 1, 1;
1, 1,-1;
1,-1, 1;
1,-1,-1;
-1, 1, 1;
-1, 1,-1;
-1,-1, 1;
-1,-1,-1;
]/sqrt(3);
cm_dir_vertex_sets = [
1,2,4,3;
1,5,7,3;
1,2,6,5;
8,7,5,6;
8,4,3,7;
8,4,2,6
];
figure
hold on
axis off
axis equal
quiver3(zeros(length(search_dir),1),zeros(length(search_dir),1),zeros(length(search_dir),1),search_dir(:,1),search_dir(:,2),search_dir(:,3),'black','LineWidth',2)
quiver3(zeros(length(cm_dir),1),zeros(length(cm_dir),1),zeros(length(cm_dir),1),cm_dir(:,1),cm_dir(:,2),cm_dir(:,3),'color',color,'LineWidth',2)
for i = 1:length(search_dir_vertex_sets)
plot3( search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],1) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],2) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],3), ':','Color','black')
end
for i = 1:length(cm_dir_vertex_sets)
plot3( cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],1) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],2) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],3), ':','Color',color)
end
view(view_angle)
%% Hypercube Search
search_dir = [
1, 1, 1;
1, 1,-1;
1,-1, 1;
1,-1,-1;
-1, 1, 1;
-1, 1,-1;
-1,-1, 1;
-1,-1,-1;
]/sqrt(3);
search_dir_vertex_sets = [
1,2,4,3;
1,5,7,3;
1,2,6,5;
8,7,5,6;
8,4,3,7;
8,4,2,6
];
cm_dir = [1,0,0;-1,0,0; 0,1,0;0,-1,0; 0,0,1;0,0,-1];
cm_dir_vertex_sets = [1,3,5; 1,3,6; 1,4,5; 1,4,6; 2,3,5; 2,3,6; 2,4,5; 2,4,6;];
figure
hold on
axis off
axis equal
quiver3(zeros(length(search_dir),1),zeros(length(search_dir),1),zeros(length(search_dir),1),search_dir(:,1),search_dir(:,2),search_dir(:,3),'black','LineWidth',2)
quiver3(zeros(length(cm_dir),1),zeros(length(cm_dir),1),zeros(length(cm_dir),1),cm_dir(:,1),cm_dir(:,2),cm_dir(:,3),'color',color,'LineWidth',2)
for i = 1:length(search_dir_vertex_sets)
plot3( search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],1) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],2) , search_dir([search_dir_vertex_sets(i,:) search_dir_vertex_sets(i,1)],3), ':','Color','black')
end
for i = 1:length(cm_dir_vertex_sets)
plot3( cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],1) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],2) , cm_dir([cm_dir_vertex_sets(i,:) cm_dir_vertex_sets(i,1)],3), ':','Color',color)
end
view(view_angle)