image thumbnail

Hierarchical Kalman Filter for clinical time series prediction

by

 

It is an implementation of hierarchical (a.k.a. multi-scale) Kalman filter using belief propagation.

EMConvergence(msg, varNode, ts_data, numLevels)
function ts_data = EMConvergence(msg, varNode, ts_data, numLevels)
    ts_data.oldLoglik = ts_data.newLoglik;
    ts_data.newLoglik = genLoglikLevel1(msg, varNode, ts_data);
    if(numLevels >= 2)
        ts_data.newLoglik = ts_data.newLoglik + genLoglikLevel2(msg, varNode, ts_data);
    end
end

    % x{1}(1) ~ N(mu_0{1}, V_0{1})
    % x{1}(t1) = A{1}*x{1}(t1-1) + q{1}; N(0, V_Q{1})
    % y{1}(t1) = B{1}*x{1}(t1) + w{1}; N(0, V_W{1})
    % x{2}(t2) = A{2}*x{1}(parent) + q{2}; N(0, V_Q{2})
    % y{2}(t2) = B{2}*x{1}(t2) + w{2}; N(0, V_W{2})
    
function newLoglik = genLoglikLevel1(msg, varNode, ts_data)
    useLog = true;
    Lv1 = ts_data.Lv1;  
    for t = 1:ts_data.T(Lv1)
        mu = msg{varNode.x{Lv1}{t}.backwardNeighborMsgID}.toVarNode.mu;
        V = msg{varNode.x{Lv1}{t}.backwardNeighborMsgID}.toVarNode.V;
        newLoglik(t) = gaussian_prob(ts_data.y{Lv1}(:,t),ts_data.B{Lv1}*mu, ts_data.B{Lv1}*V*ts_data.B{Lv1}' + ts_data.V_W{Lv1}, useLog);
    end
    newLoglik = sum(newLoglik);
end

function newLoglik = genLoglikLevel2(msg, varNode, ts_data)
    useLog = true;
    Lv2 = ts_data.Lv2;
    newLoglik = 0;
    for t = 1:ts_data.T(Lv2) 
        mu = msg{varNode.x{Lv2}{t}.upperNeighborMsgID}.toVarNode.mu;
        V = msg{varNode.x{Lv2}{t}.upperNeighborMsgID}.toVarNode.V;
        newLoglik = newLoglik + gaussian_prob(ts_data.y{Lv2}(:,t),ts_data.B{Lv2}*mu, ts_data.B{Lv2}*V*ts_data.B{Lv2}' + ts_data.V_W{Lv2}, useLog);
    end
end

Contact us