-
Notifications
You must be signed in to change notification settings - Fork 20
/
sphericalradial.m
70 lines (58 loc) · 1.53 KB
/
sphericalradial.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
function [I,x,W,F] = sphericalradial(f,m,P,param)
% SPHERICALRADIAL - ND scaled spherical-radial cubature rule
%
% Syntax:
% [I,x,W,F] = sphericalradial(f,m,P[,param])
%
% In:
% f - Function f(x,param) as inline, name or reference
% m - Mean of the d-dimensional Gaussian distribution
% P - Covariance of the Gaussian distribution
% param - Parameters for the function (optional)
%
% Out:
% I - The integral
% x - Evaluation points
% W - Weights
% F - Function values
%
% Description:
% Apply the spherical-radial cubature rule to integrals of form:
% int f(x) N(x | m,P) dx
% History:
% Aug 5, 2010 - Renamed from 'cubature' to 'sphericalradial' (asolin)
% Copyright (c) 2010 Arno Solin
%
% This software is distributed under the GNU General Public
% Licence (version 2 or later); please refer to the file
% Licence.txt, included with the software, for details.
%% Spherical-radial cubature rule
% The dimension of m is
n = size(m,1);
% Evaluation points (nx2n)
x = [eye(n) -eye(n)];
% Scaling
x = sqrt(n)*x;
x = chol(P)'*x + repmat(m,1,2*n);
% Evaluate the function at the points
if ischar(f) || strcmp(class(f),'function_handle')
if nargin < 4
F = feval(f,x);
else
F = feval(f,x,param);
end
elseif isnumeric(f)
F = f*x;
else
if nargin < 4
F = f(x);
else
F = f(x,param);
end
end
% The weights are
W = 1/(2*n);
% Return integral value
I = W*sum(F,2);
% Return weights
W = W*ones(1,2*n);