comparison toolboxes/FullBNT-1.0.7/Kalman/eval_AR_perf.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [ypred, ll, mse] = eval_AR_perf(coef, C, y, model)
2 % Evaluate the performance of an AR model.
3 %
4 % Inputs
5 % coef(:,:,k,m) - coef. matrix to use for k steps back, model m
6 % C(:,:,m) - cov. matrix for model m
7 % y(:,t) - observation at time t
8 % model(t) - which model to use at time t (defaults to 1 if not specified)
9 %
10 % Outputs
11 % ypred(:,t) - the predicted value of y at t based on the evidence thru t-1.
12 % ll - log likelihood
13 % mse - mean squared error = sum_t d_t . d_t, where d_t = pred(y_t) - y(t)
14
15 [s T] = size(y);
16 k = size(coef, 3);
17 M = size(coef, 4);
18
19 if nargin<4, model = ones(1, T); end
20
21 ypred = zeros(s, T);
22 ypred(:, 1:k) = y(:, 1:k);
23 mse = 0;
24 ll = 0;
25 for j=1:M
26 c(j) = log(normal_coef(C(:,:,j)));
27 invC(:,:,j) = inv(C(:,:,j));
28 end
29 coef = reshape(coef, [s s*k M]);
30
31 for t=k+1:T
32 m = model(t-k);
33 past = y(:,t-1:-1:t-k);
34 ypred(:,t) = coef(:, :, m) * past(:);
35 d = ypred(:,t) - y(:,t);
36 mse = mse + d' * d;
37 ll = ll + c(m) - 0.5*(d' * invC(:,:,m) * d);
38 end
39 mse = mse / (T-k+1);
40