forked from jrvmalik/gradient-descent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnnulus.m
41 lines (35 loc) · 807 Bytes
/
Annulus.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
function X = Annulus( n, p )
% Uniformly sample n points from the Annulus. Set in ambient space R^p.
% INPUT
% n : Number of points.
% p : Dimension of ambient Euclidean space (>= 2).
% OUTPUT
% X : Data matrix (n x p).
% Written by John Malik on 2018.13.10, [email protected]
switch nargin
case 1
p = 2;
case 0
error('Select a number of points to sample.')
end
rho = nan(n, 1);
i = 1;
inner = sqrt(8) / 3;
while i <= n
xvec = sqrt(rand(1));
if xvec < 1 / 3 || xvec >= inner
rho(i) = xvec;
i = i + 1;
else
continue
end
end
r = sort(rho);
t = 2 * pi * rand(n, 1);
x = r .* cos(t);
y = r .* sin(t);
X = [x, y];
if p > 2
X = X * transpose(orth(randn(p, 2)));
end
end