Skip to content

Commit

Permalink
fix demo
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed May 25, 2023
1 parent 141d8f6 commit 5377359
Show file tree
Hide file tree
Showing 7 changed files with 1,566 additions and 744 deletions.
28 changes: 1 addition & 27 deletions demo/bike/kf-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const observationCovariance = require('./observation-covariance.json');

const posVar = 100;
const timeStep = 0.2;
const sizeVar = 1;
Expand All @@ -13,36 +11,12 @@ module.exports = {
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
],
// Covariance generated thanks to getCovariance
covariance: observationCovariance,
// Covariance: [posVar, posVar, posVar, posVar],

covariance: [posVar, posVar, sizeVar, sizeVar],
},

dynamic: {
name: 'constant-acceleration',
timeStep: 0.2,
// Init: {
// mean: [[943], [385], [75], [65], [-200], [-200], [0], [0], [-20], [-20], [0], [0]],
//
// covariance: [
// [huge, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// [0, huge, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// [0, 0, huge, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// [0, 0, 0, huge, 0, 0, 0, 0, 0, 0, 0, 0],
// [0, 0, 0, 0, huge, 0, 0, 0, 0, 0, 0, 0],
// [0, 0, 0, 0, 0, huge, 0, 0, 0, 0, 0, 0],
// [0, 0, 0, 0, 0, 0, huge, 0, 0, 0, 0, 0],
// [0, 0, 0, 0, 0, 0, 0, huge, 0, 0, 0, 0],
// [0, 0, 0, 0, 0, 0, 0, 0, huge, 0, 0, 0],
// [0, 0, 0, 0, 0, 0, 0, 0, 0, huge, 0, 0],
// [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, huge, 0],
// [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, huge],
// ]
// },

dimension: 12,

covariance: [
posVar,
posVar,
Expand Down
22 changes: 17 additions & 5 deletions demo/bike/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {KalmanFilter} = kalmanFilter;// eslint-disable-line no-undef
const createElement = require('../shared/views/create-element');
const createGroupBoxes = require('../shared/views/create-group-boxes');
const kfOptions = require('./kf-options.js');
const noisyObservations = require('./observations.json').observations;

const kf = new KalmanFilter(kfOptions);
Expand All @@ -13,26 +12,37 @@ const img = document.querySelector('#bikes');// eslint-disable-line no-undef
const delay = 200;

let promise = Promise.resolve();
let previousCorrected = null;

const delayPromise = delay => new Promise(resolve => {
setTimeout(resolve, delay);
});

const els = [];

module.exports = {
run() {
let previousCorrected = null;
let i = els.length;
while (i-- >= 0) {
const el = els[i];
el.remove();
els.splice(i, 1);
}

for (const [index, box] of noisyObservations.entries()) {
promise = promise
.then(() => {
console.log(previousCorrected.mean);
predicted = kf.predict({previousCorrected});
const {mean, covariance} = predicted;

createGroupBoxes({mean, covariance, parent: img, className: 'predicted', color: 'blue'});
const element = createGroupBoxes({mean, covariance, parent: img, className: 'predicted', color: 'blue'});
els.append(element);

return delayPromise(delay);
})
.then((b => {
createElement({
const element = createElement({
className: 'observation',
bbox: [
b[0] + (b[2] / 2),
Expand All @@ -44,14 +54,16 @@ module.exports = {
color: 'white',
lineStyle: 'solid',
});
els.append(element);

return delayPromise(delay);
}).bind(null, box, index))
.then((b => {
previousCorrected = kf.correct({predicted, observation: b});
const {mean, covariance} = previousCorrected;

createGroupBoxes({mean, covariance, parent: img, className: 'corrected', color: 'red'});
const element = createGroupBoxes({mean, covariance, parent: img, className: 'corrected', color: 'red'});
els.append(element);

return delayPromise(delay);
}).bind(null, box, index));
Expand Down
Loading

0 comments on commit 5377359

Please sign in to comment.