-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHaltonSampling.m
42 lines (36 loc) · 1.32 KB
/
HaltonSampling.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
function sampled_nodes = HaltonSampling( num_dim, num_samples, ...
sample_space, skip_size, leap_size, scram)
%HaltonSampling generates the Halton set for given state space for a given
%number of samples
%
% Ross Allen, ASL, Stanford Univeristy
% Started: Nove 8, 2013
%
% Inputs:
% num_dim: number of dimensions
% num_samples: number of samples
% sample_space: num_dim x 2 matrix holding sample space bounds
% skip_size: number of initial points to omit
% leap_size: number of elements to leap in halton
% scram boolean indicating if scrambled or not
%
% Outputs:
% sampled_nodes: sampled nodes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if num_dim ~= size(sample_space,1)
disp('dimension of sample_space must equal num_dim')
sampled_nodes = NaN;
return
end
% Generate Halton set
halset = haltonset(num_dim, 'Skip', skip_size, 'Leap', leap_size);
% Scramble
if scram
halset = scramble(halset, 'RR2');
end
% Extract samples
halset = net(halset, num_samples);
% Map to sample space
sampled_nodes = halset*diag([-1 1]*sample_space') + ...
ones(num_samples, num_dim)*diag(sample_space(:,1));
end