Skip to content

Commit

Permalink
fix: update xo
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed Apr 20, 2023
1 parent bcb5c8d commit 373e8bb
Show file tree
Hide file tree
Showing 45 changed files with 4,285 additions and 5,990 deletions.
10 changes: 5 additions & 5 deletions demo/bike/kf-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module.exports = {
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 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: observationCovariance,
// Covariance: [posVar, posVar, posVar, posVar],

},
Expand Down Expand Up @@ -55,7 +55,7 @@ module.exports = {
posVar * (timeStep ** 4),
posVar * (timeStep ** 4),
sizeVar * (timeStep ** 4),
sizeVar * (timeStep ** 4)
]
}
sizeVar * (timeStep ** 4),
],
},
};
15 changes: 7 additions & 8 deletions demo/bike/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const {KalmanFilter} = kalmanFilter;// eslint-disable-line no-undef

const noisyObservations = require('./observations.json').observations;
const kfOptions = require('./kf-options.js');
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);
let predicted = kf.predict();
Expand All @@ -22,7 +21,7 @@ const delayPromise = delay => new Promise(resolve => {

module.exports = {
run() {
noisyObservations.forEach((box, index) => {
for (const [index, box] of noisyObservations.entries()) {
promise = promise
.then(() => {
predicted = kf.predict({previousCorrected});
Expand All @@ -39,11 +38,11 @@ module.exports = {
b[0] + (b[2] / 2),
b[1] + (b[3] / 2),
b[2],
b[3]
b[3],
],
parent: img,
color: 'white',
lineStyle: 'solid'
lineStyle: 'solid',
});

return delayPromise(delay);
Expand All @@ -56,6 +55,6 @@ module.exports = {

return delayPromise(delay);
}).bind(null, box, index));
});
}
}
},
};
16 changes: 8 additions & 8 deletions demo/bouncing-ball/kf-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module.exports = {
dimension: 2,
stateProjection: [
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0]
[0, 1, 0, 0, 0],
],
// Covariance generated thanks to getCovariance
covariance: [posVar / 5, posVar / 5]
covariance: [posVar / 5, posVar / 5],
// Covariance: [posVar, posVar, posVar, posVar],

},
Expand All @@ -26,8 +26,8 @@ module.exports = {
[0, huge, 0, 0, 0],
[0, 0, huge, 0, 0],
[0, 0, 0, huge, 0],
[0, 0, 0, 0, huge]
]
[0, 0, 0, 0, huge],
],
},

constant({previousCorrected}) {
Expand Down Expand Up @@ -55,7 +55,7 @@ module.exports = {
[0, 1, 0, timeStep, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, vY, timeStep],
[0, 0, 0, 0, 1]
[0, 0, 0, 0, 1],
];
},

Expand All @@ -66,7 +66,7 @@ module.exports = {
posVar,
posVar * timeStep * timeStep,
posVar * timeStep * timeStep,
posVar * (timeStep ** 4)
]
}
posVar * (timeStep ** 4),
],
},
};
15 changes: 7 additions & 8 deletions demo/bouncing-ball/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const {KalmanFilter} = kalmanFilter;// eslint-disable-line no-undef

const noisyObservations = require('./observations.json').observations;
const kfOptions = require('./kf-options.js');
const createElement = require('../shared/views/create-element');
const createGroupPoint = require('../shared/views/create-group-point');
const kfOptions = require('./kf-options.js');
const noisyObservations = require('./observations.json').observations;

const kf = new KalmanFilter(kfOptions);
let predicted = kf.predict();
Expand All @@ -22,7 +21,7 @@ const delayPromise = delay => new Promise(resolve => {

module.exports = {
run() {
noisyObservations.forEach((box, index) => {
for (const [index, box] of noisyObservations.entries()) {
promise = promise
.then(() => {
predicted = kf.predict({previousCorrected});
Expand All @@ -42,11 +41,11 @@ module.exports = {
b[0],
b[1],
w,
h
h,
],
parent: img,
color: 'white',
lineStyle: 'solid'
lineStyle: 'solid',
});

return delayPromise(delay);
Expand All @@ -59,6 +58,6 @@ module.exports = {

return delayPromise(delay);
}).bind(null, box, index));
});
}
}
},
};
26 changes: 13 additions & 13 deletions demo/shared/views/create-custom-dashed-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function ({
parent,
color,
percentage,
position = 'vertical'
position = 'vertical',
}) {
// Bbox contains 3 elements: left, top and bottom of the dashed line or top, left and right
const element = document.createElement(tag);// eslint-disable-line no-undef
Expand All @@ -28,18 +28,18 @@ module.exports = function ({
}

// El.style.opacity = 1-percentage
const urlString = 'data:image/svg+xml,%3csvg ' +
'width=\'100%25\' ' +
'height=\'100%25\' ' +
'xmlns=\'http://www.w3.org/2000/svg\'%3e%3crect ' +
'width=\'100%25\' ' +
'height=\'100%25\' ' +
'fill=\'none\' ' +
`stroke='${color}' ` +
'stroke-width=\'4\' ' +
`stroke-dasharray='10%2c${Math.floor(percentage * 100)}' ` +
'stroke-dashoffset=\'0\' ' +
'stroke-linecap=\'round\'/%3e%3c/svg%3e';
const urlString = 'data:image/svg+xml,%3csvg '
+ 'width=\'100%25\' '
+ 'height=\'100%25\' '
+ 'xmlns=\'http://www.w3.org/2000/svg\'%3e%3crect '
+ 'width=\'100%25\' '
+ 'height=\'100%25\' '
+ 'fill=\'none\' '
+ `stroke='${color}' `
+ 'stroke-width=\'4\' '
+ `stroke-dasharray='10%2c${Math.floor(percentage * 100)}' `
+ 'stroke-dashoffset=\'0\' '
+ 'stroke-linecap=\'round\'/%3e%3c/svg%3e';

const backgroundImage1 = `url("${urlString}")`;

Expand Down
24 changes: 12 additions & 12 deletions demo/shared/views/create-group-boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ module.exports = function ({mean, covariance, color, parent, className, tag = 'd
bbox: [center[0], center[1], mean[2][0], mean[3][0]],
parent: container,
color,
lineStyle: 'solid'
lineStyle: 'solid',
});
createElement({
className: 'box stdDev',
bbox: [
center[0],
center[1],
mean[2][0] + (2 * 3 * Math.sqrt(covariance[2][2])),
mean[3][0] + (2 * 3 * Math.sqrt(covariance[3][3]))
mean[3][0] + (2 * 3 * Math.sqrt(covariance[3][3])),
],
parent: container,
color
color,
});
createPoint({
bbox: [center[0], center[1], 2, 2],
parent: container,
color
color,
});
const correlationXY = covariance[0][1] / (Math.sqrt(covariance[0][0]) * Math.sqrt(covariance[1][1]));
createElement({
Expand All @@ -38,49 +38,49 @@ module.exports = function ({mean, covariance, color, parent, className, tag = 'd
center[0],
center[1],
2 * 3 * Math.sqrt(covariance[0][0]),
2 * 3 * Math.sqrt(covariance[1][1])
2 * 3 * Math.sqrt(covariance[1][1]),
],
parent: container,
rotationCoefficient: correlationXY,
color
color,
});
const correlationXW = covariance[0][2] / (Math.sqrt(covariance[0][0]) * Math.sqrt(covariance[2][2]));
createCustomDashedLine({
className: 'dashedLine',
bbox: [
center[0],
center[1] + (3 * Math.sqrt(covariance[1][1])),
center[1] + (mean[3][0] / 2) + (3 * Math.sqrt(covariance[3][3]))
center[1] + (mean[3][0] / 2) + (3 * Math.sqrt(covariance[3][3])),
],
parent: container,
percentage: Math.abs(correlationXW),
color
color,
});
const correlationYH = covariance[1][3] / (Math.sqrt(covariance[1][1]) * Math.sqrt(covariance[3][3]));
createCustomDashedLine({
className: 'dashedLine',
bbox: [
center[1],
center[0] + (3 * Math.sqrt(covariance[0][0])),
center[0] + (mean[2][0] / 2) + (3 * Math.sqrt(covariance[2][2]))
center[0] + (mean[2][0] / 2) + (3 * Math.sqrt(covariance[2][2])),
],
parent: container,
percentage: Math.abs(correlationYH),
position: 'horizontal',
color
color,
});
const arrowRotation = (-1 * Math.atan(mean[4][0] / mean[5][0]) * 180 / Math.PI) - 45;
const arrowScale = Math.sqrt((mean[4][0] ** 2) + (mean[5][0] ** 2));
createArrow({
className: 'arrow',
bbox: [
center[0] + 6,
center[1] - 9
center[1] - 9,
],
parent: container,
rotationCoefficient: arrowRotation,
scale: arrowScale,
color
color,
});
parent.append(container);
};
10 changes: 5 additions & 5 deletions demo/shared/views/create-group-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function ({mean, covariance, color, parent, className, tag = 'd
createPoint({
bbox: [center[0], center[1], 2, 2],
parent: container,
color
color,
});

const correlationXY = covariance[0][1] / (Math.sqrt(covariance[0][0]) * Math.sqrt(covariance[1][1]));
Expand All @@ -21,24 +21,24 @@ module.exports = function ({mean, covariance, color, parent, className, tag = 'd
center[0],
center[1],
2 * 3 * Math.sqrt(covariance[0][0]),
2 * 3 * Math.sqrt(covariance[1][1])
2 * 3 * Math.sqrt(covariance[1][1]),
],
parent: container,
rotationCoefficient: correlationXY,
color
color,
});
const arrowRotation = (-1 * Math.atan(mean[2][0] / mean[3][0]) * 180 / Math.PI) - 45;
const arrowScale = Math.sqrt((mean[2][0] ** 2) + (mean[3][0] ** 2));
createArrow({
className: 'arrow',
bbox: [
center[0] + 6,
center[1] - 9
center[1] - 9,
],
parent: container,
rotationCoefficient: arrowRotation,
scale: arrowScale,
color
color,
});
parent.append(container);
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = {
State: require('./lib/state'),
checkCovariance: require('./lib/utils/check-covariance'),
correlationToCovariance: require('./lib/utils/correlation-to-covariance'),
covarianceToCorrelation: require('./lib/utils/covariance-to-correlation')
covarianceToCorrelation: require('./lib/utils/covariance-to-correlation'),
};
Loading

0 comments on commit 373e8bb

Please sign in to comment.