annotate toolboxes/FullBNT-1.0.7/nethelp3.3/hmc.htm @ 0:cc4b1211e677 tip

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