TRAINPARAM Computes the Kalman gain given an annotated train dataset.

Usage: [u,d,x0,K]=trainparam(trainset,trainlabels,labelset,isRatios)

Parameters: 'labelset' - class labels uniquely identifying each class in the dataset; returned by: [labelset,features]=readdotnames(namesfile) 'trainlabels' - class membership labels for each train sample 'trainset' - train samples; numerical data They are returned by: [trainset,trainlabels]=readdotdata(datafile,features) 'isRatios' - boolean parameter; true if 'trainset' containes log-ratio data, false otherwise

Returns: u,d - orthogonal and diagonal matrix respectively, resulting from an "economy size" SVD on the 'trainset' [u,d,v]=svd(trainset',0) x0 - state estimate from the 'trainset' K - steady-state Kalman gain

This function internally estimates the covariance matrices Q and R according to 'isRatio', then computes the steady-state Kalman gain using the Matlab function DARE.

See also READDOTNAMES, READDOTDATA, FILTERDATASET, SVD, DARE.

function [u,d,x0,K] = trainparam(trainset,trainlabels,labelset,isRatios)

[u,d,v]=svd(trainset',0);
Q=[];
R=[];
for i=1:length(labelset),
    idx=strmatch(labelset(i),trainlabels,'exact');
    Q=[Q;mean(v(idx,:))];
    R=[R;v(idx,:)-repmat(mean(v(idx,:)),length(idx),1)];
end
x0=mean(Q)';
Q=cov(Q-repmat(mean(Q),length(labelset),1));
R=cov(R);
I=eye(size(v));
if ~isRatios,
    [p,l,K]=dare(I,I,Q+Q(1,1)*I,R+R(1,1)*I);
else
    [p,l,K]=dare(I,I,Q+sum(diag(Q))*I,R+sum(diag(R))*I);
end