LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
laplaceapprox.m
1%{
2%{
3 % @file laplaceapprox.m
4 % @brief Laplace approximation for multidimensional integrals.
5%}
6%}
7
8%{
9%{
10 % @brief Laplace approximation for multidimensional integrals.
11 % @fn laplaceapprox(h, x0)
12 % @param h Function handle to approximate integral of.
13 % @param x0 Point for Laplace approximation.
14 % @return I Approximate integral value.
15 % @return H Hessian matrix at x0.
16 % @return logI Logarithm of integral value.
17%}
18%}
19function [I,H,logI] = laplaceapprox(h,x0)
20% I = laplaceapprox(f,x0)
21% approximates I=int f(x)dx by Laplace approximation at x0
22% example: I = laplaceapprox(@(x) prod(x),[0.5,0.5])
23d = length(x0); % number of dimensions
24tol = 1e-5;
25H = num_hess(@(x) log(h(x)), x0, tol);
26detnH=det(-H);
27if detnH<0
28 tol = 1e-4;
29 H = num_hess(@(x) log(h(x)), x0, tol);
30 detnH=det(-H);
31end
32if detnH<0
33 tol = 1e-3;
34 H = num_hess(@(x) log(h(x)), x0, tol);
35 detnH=det(-H);
36end
37if detnH<0
38 warning('laplaceapprox.m: det(-H)<0')
39end
40I = h(x0) * sqrt((2*pi)^d/detnH);
41logI = log(h(x0)) + (d/2)*log(2*pi) - log(detnH);
42end