forked from lawrennd/gpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpnddisimSampleHMC.m
72 lines (58 loc) · 1.63 KB
/
gpnddisimSampleHMC.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
function [samples, E_hist, g_mean] = gpnddisimSampleHMC(model, display, iters, options);
% GPNDDISIMSAMPLEHMC Do HMC sampling for the GPNDDISIM model.
% FORMAT
% DESC performs HMC sampling for the Gaussian process single input
% motif model for a given number of iterations.
% ARG model : the model to be optimised.
% ARG display : whether or not to display while optimisation
% proceeds, set to 2 for the most verbose and 0 for the least
% verbose.
% ARG iters : number of samples to return.
% RETURN samples : the samples.
%
% SEEALSO : hmc, gpsimCreate, gpsimGradient, gpsimObjective
%
% COPYRIGHT : Neil D. Lawrence, 2006
%
% COPYRIGHT : Antti Honkela, 2007-2013
%
% COPYRIGHT : Jaakko Peltonen, 2011
% GPNDDISIM
if nargin < 3
iters = 2000;
if nargin < 2
display = 1;
end
end
[params,paramnames] = modelExtractParam(model);
if nargin < 4,
options = hmcDefaultOptions;
end
if isfield(model, 'uniformPriors') && model.uniformPriors,
options.iters = iters;
bounds = gpnddisimExtractParamTransformSettings(model);
bounds = cat(1, bounds{:})';
[samples, E_hist, g_mean] = ...
myhmc_bounded('modelObjective', params, options, ...
'modelGradient', bounds, model);
else
hmcopt = optOptions;
if display
hmcopt(1) = display;
if length(params) <= 100
hmcopt(9) = 1;
end
end
% Momentum persistence
hmcopt(5) = 1;
% Leapfrog steps
hmcopt(7) = options.tau;
% hmcopt(18) = epsilon, step length
hmcopt(18) = options.epsilon;
% Number of samples to return
hmcopt(14) = iters;
samples = hmc('modelObjective', params, hmcopt, ...
'modelGradient', model);
E_hist = [];
g_mean = [];
end