Skip to content

Commit

Permalink
feat: pass correct, predict, getGain input in getValue call
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed Oct 6, 2020
1 parent 6e53280 commit 356f545
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions lib/core-kalman-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ class CoreKalmanFilter {
* @returns{Array.<Array.<Number>>}
*/

getPredictedCovariance({previousCorrected, index} = {}) {
getPredictedCovariance(options = {}) {
let {previousCorrected, index} = options;
previousCorrected = previousCorrected || this.getInitState();

const getValueOptions = {previousCorrected, index};
const getValueOptions = Object.assign({}, {previousCorrected, index}, options);
const d = this.getValue(this.dynamic.transition, getValueOptions);
const dTransposed = transpose(d);
const covarianceInter = matMul(d, previousCorrected.covariance);
Expand All @@ -103,7 +104,8 @@ class CoreKalmanFilter {
* @returns{State} predicted State
*/

predict({previousCorrected, index} = {}) {
predict(options = {}) {
let {previousCorrected, index} = options;
previousCorrected = previousCorrected || this.getInitState();

if (typeof (index) !== 'number' && typeof (previousCorrected.index) === 'number') {
Expand All @@ -112,10 +114,10 @@ class CoreKalmanFilter {

State.check(previousCorrected, {dimension: this.dynamic.dimension});

const getValueOptions = {
const getValueOptions = Object.assign({}, {
previousCorrected,
index
};
}, options);
const d = this.getValue(this.dynamic.transition, getValueOptions);

checkMatrix(d, [this.dynamic.dimension, this.dynamic.dimension], 'dynamic.transition');
Expand All @@ -135,8 +137,9 @@ class CoreKalmanFilter {
* @returns{Array<Array>} kalmanGain
*/

getGain({predicted, stateProjection}) {
const getValueOptions = {predicted, index: predicted.index};
getGain(options) {
let {predicted, stateProjection} = options;
const getValueOptions = Object.assign({}, {index: predicted.index}, options);
stateProjection = stateProjection || this.getValue(this.observation.stateProjection, getValueOptions);
const obsCovariance = this.getValue(this.observation.covariance, getValueOptions);
checkMatrix(obsCovariance, [this.observation.dimension, this.observation.dimension], 'observation.covariance');
Expand All @@ -163,8 +166,9 @@ class CoreKalmanFilter {
* @returns{Array.<Array.<Number>>}
*/

getCorrectedCovariance({predicted}) {
const getValueOptions = {predicted, index: predicted.index};
getCorrectedCovariance(options) {
const {predicted} = options;
const getValueOptions = Object.assign({}, {index: predicted.index}, options);
const identity = getIdentity(predicted.covariance.length);
const stateProj = this.getValue(this.observation.stateProjection, getValueOptions);
const optimalKalmanGain = this.getGain({predicted, stateProjection: stateProj});
Expand All @@ -182,13 +186,14 @@ class CoreKalmanFilter {
* @returns{State} corrected State of the Kalman Filter
*/

correct({predicted, observation}) {
correct(options) {
const {predicted, observation} = options;
State.check(predicted, {dimension: this.dynamic.dimension});
if (!observation) {
throw (new Error('no measure available'));
}

const getValueOptions = {observation, predicted, index: predicted.index};
const getValueOptions = Object.assign({}, {observation, predicted, index: predicted.index}, options);
const stateProj = this.getValue(this.observation.stateProjection, getValueOptions);

const optimalKalmanGain = this.getGain({predicted, stateProjection: stateProj});
Expand Down
2 changes: 1 addition & 1 deletion lib/model-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
},
buildDynamic: (dynamic, observation) => {
if (!registeredDynamicModels[dynamic.name]) {
throw (new Error('The provided dynamic model name is not registered'));
throw (new Error(`The provided dynamic model (${dynamic.name}) name is not registered`));
}

return registeredDynamicModels[dynamic.name](dynamic, observation);
Expand Down

0 comments on commit 356f545

Please sign in to comment.