Skip to content

Commit

Permalink
fix: add 1D and 2D tests for piercus#34
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed Jun 13, 2022
1 parent fdc5b14 commit a226029
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/issues/34.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const {KalmanFilter} = require('../../index.js');

const test = require('ava');

test('#34 1-D', t => {

let dataset = [0,0,0,0,16.1,0,0,30.9,0,0,0,0,26.1,null,null].map(a => [a])
let baseVariance = 1;
let huge = 1e30;
let kf = new KalmanFilter({
observation : {
dimension: 1,
covariance: function (o) {
if (o.observation[0][0] === null){
return [[huge]]
} else {
return [[baseVariance]]
}
}
}
})

const res = kf.filterAll(dataset);
t.is(res.length, dataset.length)
})



test('#34 2D', t => {
const {diag} = require('../..').linalgebra;

let dataset = [
[22, null],
[25, null],
[4, 4],
[4, 4],
[22, 5],
[null, null],
[34, 45]
];

let baseVariance = 1;
let huge = 1e15;
let kf = new KalmanFilter({
observation : {
dimension: 2,
stateProjection: [[1], [1]],
covariance: function (o) {
let variances = o.observation.map(a => {
if(a[0] === null){
return huge
} else {
return baseVariance
}
})
return diag(variances)
}
}
});

const res = kf.filterAll(dataset);
t.is(res.length, dataset.length)
})


0 comments on commit a226029

Please sign in to comment.