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.

linspaceInt(s1, s2, n)
function [a, b] = linspaceInt(s1, s2, n)    
    len = (s2 - s1 + 1);
    assert(len >= n, 'n is too large');
    assert(s2 >= s1, 's2 is smaller then s1');
    steps_lower = floor(len/n);
    steps_upper = ceil(len/n);
    number_upper = len - steps_lower * n;
    number_lower = n - number_upper;
    if (number_upper ~= 0)
        a1 = linspaceIntDetail(s1, steps_lower, number_lower); 
        a2 = linspaceIntDetail(steps_lower*number_lower+s1, steps_upper, number_upper); 
        a = [a1, a2];
    else
        a = linspaceIntDetail(s1, steps_lower, number_lower); 
    end
    a = a(:);
    b = a;
    for i = 1:numel(b)
        b{i} = b{i}*0 + i;
    end
    b = cell2mat(b);
    assert(sum(cell2mat(a)' ~= s1:s2) == 0, 'mismatches are found');
end

function a = linspaceIntDetail(s1, steps, n)
    a = mat2cell(reshape(s1:(n*steps+s1-1), steps, []), steps, ones(1, n));
end

Contact us