-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathut_weights.m
81 lines (74 loc) · 1.55 KB
/
ut_weights.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
73
74
75
76
77
78
79
80
81
%UT_WEIGHTS - Generate unscented transformation weights
%
% Syntax:
% [WM,WC,c] = ut_weights(n,alpha,beta,kappa)
%
% In:
% n - Dimensionality of random variable
% alpha - Transformation parameter (optional, default 0.5)
% beta - Transformation parameter (optional, default 2)
% kappa - Transformation parameter (optional, default 3-n)
%
% Out:
% WM - Weights for mean calculation
% WC - Weights for covariance calculation
% c - Scaling constant
%
% Description:
% Computes unscented transformation weights.
%
% See also UT_MWEIGHTS UT_TRANSFORM UT_SIGMAS
%
% Copyright (C) 2006 Simo S�rkk�
%
% $Id: ut_weights.m 467 2010-10-12 09:30:14Z jmjharti $
%
% 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.
function [WM,WC,c] = ut_weights(n,alpha,beta,kappa)
%
% Check which arguments are there
%
if nargin < 1
error('At least dimensionality n required.');
end
if nargin < 2
alpha = [];
end
if nargin < 3
beta = [];
end
if nargin < 4
kappa = [];
end
%
% Apply default values
%
if isempty(alpha)
alpha = 1;
end
if isempty(beta)
beta = 0;
end
if isempty(kappa)
kappa = 3 - n;
end
%
% Compute the normal weights
%
lambda = alpha^2 * (n + kappa) - n;
WM = zeros(2*n+1,1);
WC = zeros(2*n+1,1);
for j=1:2*n+1
if j==1
wm = lambda / (n + lambda);
wc = lambda / (n + lambda) + (1 - alpha^2 + beta);
else
wm = 1 / (2 * (n + lambda));
wc = wm;
end
WM(j) = wm;
WC(j) = wc;
end
c = n + lambda;