# source:projects/ckbs/trunk/test/sumsq_obj_ok.m@95

Last change on this file since 95 was 35, checked in by bradbell, 11 years ago

File size: 2.1 KB
Line
1% -------------------------------------------------------------------
2% ckbs: Constrained Kalman-Bucy Smoother Program: Copyright (C) 2006
4%          Gianluigi Pillonetto: giapi at dei dot unipd dot it
6% -------------------------------------------------------------------
7% \$begin sumsq_obj_ok.m\$\$ \$newlinech %\$\$
8% \$spell
9%       ckbs
10%       dg
11%       dh
12%       obj obj
13%       qinv
14%       rinv
15%       sumsq
16%       tmp
17%       xk
18%       xkm
19%       xres
20%       zres
21% \$\$
22%
23% \$section ckbs_sumsq_obj Example and Test\$\$
24%
25% \$index ckbs_sumsq_obj, example and test\$\$
26% \$index sumsq_obj, example and test\$\$
27% \$index example, sumsq_obj\$\$
28% \$index test, sumsq_obj\$\$
29%
31% \$newlinech \$\$ \$codep
32function [ok] = sumsq_obj_ok()
33ok = true;
34% --------------------------------------------------------
35% You can change these parameters
36m    = 1;   % number of measurements per time point
37n    = 2;   % number of state vector components per time point
38N    = 3;   % number of time points
39% ---------------------------------------------------------
40%  Define the problem
41rand('seed', 123);
42x    = rand(n, N);
43z    = rand(m, N);
44h    = rand(m, N);
45g    = rand(n, N);
46dh   = zeros(m, n, N);
47dg   = zeros(n, n, N);
48qinv = zeros(n, n, N);
49rinv = zeros(m, m, N);
50for k = 1 : N
51        dh(:, :, k)   = rand(m, n);
52        dg(:, :, k)   = rand(n, n);
53        tmp           = rand(m, m);
54        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
55        tmp           = rand(n, n);
56        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
57end
58% ---------------------------------------------------------
59% Compute the Objective using ckbs_sumsq_obj
60obj  = ckbs_sumsq_obj(x, z, g, h, dg, dh, qinv, rinv);
61% ---------------------------------------------------------
62sumsq = 0;
63xk    = zeros(n, 1);
64for k = 1 : N
65        xkm   = xk;
66        xk    = x(:, k);
67        xres  = xk      - g(:, k) - dg(:,:, k) * xkm;
68        zres  = z(:, k) - h(:, k) - dh(:,:, k) * xk;
69        sumsq = sumsq + xres' * qinv(:,:, k) * xres;
70        sumsq = sumsq + zres' * rinv(:,:, k) * zres;
71end
72ok = ok & ( abs(obj - sumsq/2) < 1e-10 );
73return
74end
75% \$\$ \$newlinech %\$\$
76% \$end
Note: See TracBrowser for help on using the repository browser.