comparison toolboxes/FullBNT-1.0.7/nethelp3.3/hmc.htm @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 <html>
2 <head>
3 <title>
4 Netlab Reference Manual hmc
5 </title>
6 </head>
7 <body>
8 <H1> hmc
9 </H1>
10 <h2>
11 Purpose
12 </h2>
13 Hybrid Monte Carlo sampling.
14
15 <p><h2>
16 Synopsis
17 </h2>
18 <PRE>
19
20 samples = hmc(f, x, options, gradf)
21 samples = hmc(f, x, options, gradf, P1, P2, ...)
22 [samples, energies, diagn] = hmc(f, x, options, gradf)
23 s = hmc('state')
24 hmc('state', s)
25 </PRE>
26
27
28 <p><h2>
29 Description
30 </h2>
31 <CODE>samples = hmc(f, x, options, gradf)</CODE> uses a
32 hybrid Monte Carlo algorithm to sample from the distribution <CODE>p ~ exp(-f)</CODE>,
33 where <CODE>f</CODE> is the first argument to <CODE>hmc</CODE>.
34 The Markov chain starts at the point <CODE>x</CODE>, and the function <CODE>gradf</CODE>
35 is the gradient of the `energy' function <CODE>f</CODE>.
36
37 <p><CODE>hmc(f, x, options, gradf, p1, p2, ...)</CODE> allows
38 additional arguments to be passed to <CODE>f()</CODE> and <CODE>gradf()</CODE>.
39
40 <p><CODE>[samples, energies, diagn] = hmc(f, x, options, gradf)</CODE> also returns
41 a log of the energy values (i.e. negative log probabilities) for the
42 samples in <CODE>energies</CODE> and <CODE>diagn</CODE>, a structure containing
43 diagnostic information (position, momentum and
44 acceptance threshold) for each step of the chain in <CODE>diagn.pos</CODE>,
45 <CODE>diagn.mom</CODE> and
46 <CODE>diagn.acc</CODE> respectively. All candidate states (including rejected ones)
47 are stored in <CODE>diagn.pos</CODE>.
48
49 <p><CODE>[samples, energies, diagn] = hmc(f, x, options, gradf)</CODE> also returns the
50 <CODE>energies</CODE> (i.e. negative log probabilities) corresponding to the samples.
51 The <CODE>diagn</CODE> structure contains three fields:
52
53 <p><CODE>pos</CODE> the position vectors of the dynamic process.
54
55 <p><CODE>mom</CODE> the momentum vectors of the dynamic process.
56
57 <p><CODE>acc</CODE> the acceptance thresholds.
58
59 <p><CODE>s = hmc('state')</CODE> returns a state structure that contains the state of the
60 two random number generators <CODE>rand</CODE> and <CODE>randn</CODE> and the momentum of
61 the dynamic process. These are contained in fields
62 <CODE>randstate</CODE>, <CODE>randnstate</CODE>
63 and <CODE>mom</CODE> respectively. The momentum state is
64 only used for a persistent momentum update.
65
66 <p><CODE>hmc('state', s)</CODE> resets the state to <CODE>s</CODE>. If <CODE>s</CODE> is an integer,
67 then it is passed to <CODE>rand</CODE> and <CODE>randn</CODE> and the momentum variable
68 is randomised. If <CODE>s</CODE> is a structure returned by <CODE>hmc('state')</CODE> then
69 it resets the generator to exactly the same state.
70
71 <p>The optional parameters in the <CODE>options</CODE> vector have the following
72 interpretations.
73
74 <p><CODE>options(1)</CODE> is set to 1 to display the energy values and rejection
75 threshold at each step of the Markov chain. If the value is 2, then the
76 position vectors at each step are also displayed.
77
78 <p><CODE>options(5)</CODE> is set to 1 if momentum persistence is used; default 0, for
79 complete replacement of momentum variables.
80
81 <p><CODE>options(7)</CODE> defines the trajectory length (i.e. the number of leap-frog
82 steps at each iteration). Minimum value 1.
83
84 <p><CODE>options(9)</CODE> is set to 1 to check the user defined gradient function.
85
86 <p><CODE>options(14)</CODE> is the number of samples retained from the Markov chain;
87 default 100.
88
89 <p><CODE>options(15)</CODE> is the number of samples omitted from the start of the
90 chain; default 0.
91
92 <p><CODE>options(17)</CODE> defines the momentum used when a persistent update of
93 (leap-frog) momentum is used. This is bounded to the interval [0, 1).
94
95 <p><CODE>options(18)</CODE> is the step size used in leap-frogs; default 1/trajectory
96 length.
97
98 <p><h2>
99 Examples
100 </h2>
101 The following code fragment samples from the posterior distribution of
102 weights for a neural network.
103 <PRE>
104
105 w = mlppak(net);
106 [samples, energies] = hmc('neterr', w, options, 'netgrad', net, x, t);
107 </PRE>
108
109
110 <p><h2>
111 Algorithm
112 </h2>
113
114 The algroithm follows the procedure outlined in Radford Neal's technical
115 report CRG-TR-93-1 from the University of Toronto. The stochastic update of
116 momenta samples from a zero mean unit covariance gaussian.
117
118 <p><h2>
119 See Also
120 </h2>
121 <CODE><a href="metrop.htm">metrop</a></CODE><hr>
122 <b>Pages:</b>
123 <a href="index.htm">Index</a>
124 <hr>
125 <p>Copyright (c) Ian T Nabney (1996-9)
126
127
128 </body>
129 </html>