Skip to content

Commit

Permalink
feat: remove linalgebra and use simple-linalg instead
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the linalgebra is not exposed anymore
  • Loading branch information
piercus committed Apr 20, 2023
1 parent ffeed39 commit bcb5c8d
Show file tree
Hide file tree
Showing 43 changed files with 141 additions and 322 deletions.
73 changes: 10 additions & 63 deletions docs/dist/bouncing-ball.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/dist/kalman-filter.js

Large diffs are not rendered by default.

96 changes: 83 additions & 13 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,84 @@
<title>Kalman Filter Demo on Bike Image</title>
<link rel="stylesheet" type="text/css" href="./style.css">

<!-- Add a header section with the demo title and description -->
<header>
<h1>Kalman Filter Demo</h1>
<p>This demo shows how a Kalman filter can be used to estimate the position of a moving object over time, even in the presence of noise and uncertainty.</p>
</header>

<!-- Use CSS Grid to create a flexible layout -->
<style>
body {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
grid-gap: 1rem;
}
.img, .controls {
width: 100%;
margin: auto;
}
h1, p {
text-align: center;
}
img {
max-width: 100%;
height: auto;
display: block;
margin: 0 auto;
}
.top-right {
position: absolute;
top: 0;
right: 0;
margin: 1rem;
z-index: 1;
font-size: 0.8rem;
}
.top-right h4 {
margin: 0;
font-weight: normal;
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 1rem;
background-color: #f2f2f2;
}
.controls input[type="button"] {
background-color: #4CAF50;
color: white;
border: none;
padding: 0.5rem 1rem;
margin: 0.5rem;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s ease;
}
.controls input[type="button"]:hover {
background-color: #3e8e41;
}
.controls label {
font-size: 0.8rem;
margin-left: 0.5rem;
}
#status {
text-align:center;
font-size: 0.8rem;
margin-top: 1rem;
}
</style>

</head>
<body>
<div class="img" id='bikes'>
<img src="./bike.gif">
<div class="top-right" id='legend'>
<h4 style="color: blue;"> Prediction
</h4>
<h4 style="color: white;"> Observation
</h4>
<h4 style="color: red;"> Correction
</h4>
<h4 style="color: blue;">Prediction</h4>
<h4 style="color: white;">Observation</h4>
<h4 style="color: red;">Correction</h4>
</div>
</div>
<div class="controls" id='controls'>
Expand All @@ -27,21 +93,20 @@ <h4 style="color: red;"> Correction
<input id="clickMe" type="button" value="Show/Hide Corrections" onclick="showHide('corrected');" />

<input type="checkbox" id="speedVectors" onclick="showHide('speedVectors');">
<label for="checkbox1"> Speed Vectors </label>
<label for="checkbox1">Speed Vectors</label>
<input type="checkbox" id="Variances" onclick="showHide('variances');" checked="checked">
<label for="checkbox1"> Variances </label>
<label for="checkbox2">Variances</label>
<input type="checkbox" id="Covariances" onclick="showHide('covariances');">
<label for="checkbox1"> Covariances </label>
<label for="checkbox3">Covariances</label>
</div>


<!-- Add a div to display status messages -->
<div id="status"></div>
</body>
<script src="dist/kalman-filter.js"></script>
<script src="dist/bike.js"></script>

<script>
//
// const btn = document.querySelector('button');
const status = {
'predicted': false,
'observation': true,
Expand Down Expand Up @@ -72,7 +137,12 @@ <h4 style="color: red;"> Correction
const run = function(){
require('bike').run()
}

// Add event listener to display status messages when the user clicks the "Run Kalman Filter" button
document.querySelector('#clickMe').addEventListener('click', function() {
document.querySelector('#status').innerHTML = 'Running Kalman Filter...';
});
</script>


</html>
</html>
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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'),
linalgebra: require('./lib/linalgebra')
covarianceToCorrelation: require('./lib/utils/covariance-to-correlation')
};
8 changes: 2 additions & 6 deletions lib/core-kalman-filter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const matMul = require('../lib/linalgebra/mat-mul.js');
const transpose = require('../lib/linalgebra/transpose.js');
const add = require('../lib/linalgebra/add.js');
const invert = require('../lib/linalgebra/invert.js');
const sub = require('../lib/linalgebra/sub.js');
const getIdentity = require('../lib/linalgebra/identity.js');
const {matMul, transpose, add, invert, subtract: sub, identity: getIdentity} = require('simple-linalg');

const State = require('./state.js');
const checkMatrix = require('./utils/check-matrix.js');
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic/constant-acceleration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const identity = require('../linalgebra/identity.js');
const {identity} = require('simple-linalg');

/**
*Creates a dynamic model, following constant acceleration model with respect with the dimensions provided in the observation parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic/constant-position.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const identity = require('../linalgebra/identity.js');
const {identity} = require('simple-linalg');
/**
*Creates a dynamic model, following constant position model with respect with the dimensions provided in the observation parameters
* @param {DynamicConfig} dynamic
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic/constant-speed.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const identity = require('../linalgebra/identity.js');
const {identity} = require('simple-linalg');

/**
*Creates a dynamic model, following constant position model with respect with the dimensions provided in the observation parameters
Expand Down
2 changes: 1 addition & 1 deletion lib/kalman-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const extendDynamicInit = require('../lib/setup/extend-dynamic-init.js');
const toFunction = require('../lib/utils/to-function.js');
const deepAssign = require('../lib/utils/deep-assign.js');
const polymorphMatrix = require('../lib/utils/polymorph-matrix.js');
const distanceMat = require('../lib/linalgebra/distance-mat.js');
const {frobenius: distanceMat} = require('simple-linalg');
const State = require('./state.js');
const modelCollection = require('./model-collection.js');
const CoreKalmanFilter = require('./core-kalman-filter.js');
Expand Down
17 changes: 0 additions & 17 deletions lib/linalgebra/add.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/linalgebra/diag.js

This file was deleted.

20 changes: 0 additions & 20 deletions lib/linalgebra/distance-mat.js

This file was deleted.

27 changes: 0 additions & 27 deletions lib/linalgebra/elem-wise.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/linalgebra/identity.js

This file was deleted.

16 changes: 0 additions & 16 deletions lib/linalgebra/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions lib/linalgebra/invert.js

This file was deleted.

28 changes: 0 additions & 28 deletions lib/linalgebra/mat-mul.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/linalgebra/pad-with-zeros.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/linalgebra/sub-square-matrix.js

This file was deleted.

5 changes: 0 additions & 5 deletions lib/linalgebra/sub.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/linalgebra/sum.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/linalgebra/trace.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/linalgebra/transpose.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/linalgebra/zeros.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/observation/sensor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const identity = require('../linalgebra/identity.js');
const {identity} = require('simple-linalg');
const polymorphMatrix = require('../utils/polymorph-matrix.js');
const checkMatrix = require('../utils/check-matrix.js');

Expand Down
Loading

0 comments on commit bcb5c8d

Please sign in to comment.