-
Notifications
You must be signed in to change notification settings - Fork 195
/
CreatePoints.m
52 lines (51 loc) · 1.64 KB
/
CreatePoints.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
function [points, N] = CreatePoints(N,s,gridtype)
% Computes a set of N points in [0,1]^s
% Note: could add variable interval later
% Inputs:
% N: number of interpolation points
% s: space dimension
% gridtype: 'c'=Chebyshev, 'f'=fence(rank-1 lattice),
% 'h'=Halton, 'l'=latin hypercube, 'r'=random uniform,
% 's'=Sobol, 'u'=uniform grid
% Outputs:
% points: an Nxs matrix (each row contains one s-D point)
% N: might be slightly less than original N for
% Chebyshev and gridded uniform points
% Calls on: chebsamp, lattice, lhsamp, gridsamp
% Also needs: fdnodes, gaussj
% Requires Statistics Toolbox for haltonset and sobolset.
switch gridtype
case 'c'
ppd = zeros(1,s);
for j=1:s
ppd(j) = floor(nthroot(N,s+1-j));
N = N/ppd(j);
end
gam = 0.5*ones(1,s); % density for point distribution, 0.5=Chebyshev
points = chebsamp([zeros(1,s); ones(1,s)], ppd, gam);
N = prod(ppd);
case 'f'
points = lattice(N,s); % N should be(?) power of 2
case 'h'
temp = haltonset(s);
points = net(temp,N);
case 'l'
points = lhsamp(N,s);
case 'r'
rand('state',47);
points = rand(N,s);
case 's'
temp = sobolset(s);
points = net(temp,N);
points = N*points/(N-1);
case 'u'
ppd = zeros(1,s);
for j=1:s
ppd(j) = floor(nthroot(N,s+1-j));
N = N/ppd(j);
end
points = gridsamp([zeros(1,s); ones(1,s)], ppd);
N = prod(ppd);
otherwise
error('Please use c, f, h, r, s or u data types')
end