From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: BNW using Octave instead of Matlab. This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02 --- sourcecodes/bnt-master/Kalman/eval_AR_perf.m | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sourcecodes/bnt-master/Kalman/eval_AR_perf.m (limited to 'sourcecodes/bnt-master/Kalman/eval_AR_perf.m') diff --git a/sourcecodes/bnt-master/Kalman/eval_AR_perf.m b/sourcecodes/bnt-master/Kalman/eval_AR_perf.m new file mode 100644 index 00000000..9e6f05d8 --- /dev/null +++ b/sourcecodes/bnt-master/Kalman/eval_AR_perf.m @@ -0,0 +1,40 @@ +function [ypred, ll, mse] = eval_AR_perf(coef, C, y, model) +% Evaluate the performance of an AR model. +% +% Inputs +% coef(:,:,k,m) - coef. matrix to use for k steps back, model m +% C(:,:,m) - cov. matrix for model m +% y(:,t) - observation at time t +% model(t) - which model to use at time t (defaults to 1 if not specified) +% +% Outputs +% ypred(:,t) - the predicted value of y at t based on the evidence thru t-1. +% ll - log likelihood +% mse - mean squared error = sum_t d_t . d_t, where d_t = pred(y_t) - y(t) + +[s T] = size(y); +k = size(coef, 3); +M = size(coef, 4); + +if nargin<4, model = ones(1, T); end + +ypred = zeros(s, T); +ypred(:, 1:k) = y(:, 1:k); +mse = 0; +ll = 0; +for j=1:M + c(j) = log(normal_coef(C(:,:,j))); + invC(:,:,j) = inv(C(:,:,j)); +end +coef = reshape(coef, [s s*k M]); + +for t=k+1:T + m = model(t-k); + past = y(:,t-1:-1:t-k); + ypred(:,t) = coef(:, :, m) * past(:); + d = ypred(:,t) - y(:,t); + mse = mse + d' * d; + ll = ll + c(m) - 0.5*(d' * invC(:,:,m) * d); +end +mse = mse / (T-k+1); + -- cgit 1.4.1