-
Notifications
You must be signed in to change notification settings - Fork 1
/
hmc_wrapper.m
47 lines (40 loc) · 1.15 KB
/
hmc_wrapper.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
function [samples, energies, diagn] = hmc_wrapper(f, x, options, gradf, varargin)
ioptions = foptions;
ioptions(14) = 10000;
num_samples = options(14);
num_skip = options(15);
num_test = 25;
x = scg(f, x, ioptions, gradf, varargin{:});
ix = x;
while (1)
options(14) = 1;
options(15) = 0;
x = ix;
[samples, energies, diagn] = hmc(f, x, options, gradf, varargin{:});
if diagn.acc(1) < 1e-4
ratio = 0.1;
else
options(14) = num_test;
options(15) = num_skip;
x = ix;
[samples, energies, diagn] = hmc(f, x, options, gradf, varargin{:});
diagn.acc(find(diagn.acc > 1)) = 1;
ratio = sum(diagn.acc)/size(diagn.acc, 1)
options(18)
end
if (ratio < 0.6)
options(18) = 0.7*options(18);
end
if (ratio > 0.9)
options(18) = 1.5*options(18);
end
if (ratio > 0.6 && ratio < 0.95)
options(15) = 0;
options(14) = num_samples-num_test;
if (options(14) > 0)
[samples2] = hmc(f, samples(end,:), options, gradf, varargin{:});
samples = [samples; samples2];
end
break;
end
end