Skip to content

Commit

Permalink
fix: new dynamics
Browse files Browse the repository at this point in the history
  • Loading branch information
piercus committed Apr 20, 2023
1 parent a2ea997 commit b4dfb9f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
6 changes: 2 additions & 4 deletions lib/dynamic/composition.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {registerDynamic, buildDynamic} = require('../model-collection');
const {buildDynamic} = require('../model-collection');

/**
* @typedef {Object.<DynamicName, DynamicConfig>} PerNameConfigs
Expand All @@ -17,7 +17,7 @@ const {registerDynamic, buildDynamic} = require('../model-collection');
* @param {Array.<Array.<Number>>} opts.observedProjection
* @returns {DynamicConfig}
*/
const composition = function ({perName}, observation) {
module.exports = function ({perName}, observation) {
const {observedProjection} = observation;
const observedDynamDimension = observedProjection[0].length;

Expand Down Expand Up @@ -134,5 +134,3 @@ const composition = function ({perName}, observation) {
},
};
};

registerDynamic('composition', composition);
1 change: 1 addition & 0 deletions lib/dynamic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = {
'constant-position-with-null': require('./constant-position-with-null.js'),
'constant-speed-with-null': require('./constant-speed-with-null.js'),
'constant-speed-dynamic': require('./constant-speed-dynamic.js'),
'shortterm-constant-speed': require('./shortterm-constant-speed.js'),
};
4 changes: 1 addition & 3 deletions lib/dynamic/shortterm-constant-speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const safeDiv = function (a, b) {
* @param {Number} [options.typicalTime=10]
* @returns {DynamicConfig}
*/
const shorttermConstantSpeed = function (options, observation) {
module.exports = function (options, observation) {
const {typicalTimes} = options;

if (!Array.isArray(typicalTimes)) {
Expand Down Expand Up @@ -82,5 +82,3 @@ const shorttermConstantSpeed = function (options, observation) {
},
};
};

module.exports = shorttermConstantSpeed;
8 changes: 4 additions & 4 deletions lib/model-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
* @returns {ObservationConfig} the configuration with respect to the model
*/
buildObservation(observation) {
if (!registeredObservationModels[observation.name]) {
throw (new Error(`The provided observation model name (${observation.name}) is not registered`));
if (typeof (registeredObservationModels[observation.name]) !== 'function') {
throw (new TypeError(`The provided observation model name (${observation.name}) is not registered`));
}

return registeredObservationModels[observation.name](observation);
Expand All @@ -41,8 +41,8 @@ module.exports = {
*/

buildDynamic(dynamic, observation) {
if (!registeredDynamicModels[dynamic.name]) {
throw (new Error(`The provided dynamic model (${dynamic.name}) name is not registered`));
if (typeof (registeredDynamicModels[dynamic.name]) !== 'function') {
throw (new TypeError(`The provided dynamic model (${dynamic.name}) name is not registered`));
}

return registeredDynamicModels[dynamic.name](dynamic, observation);
Expand Down
18 changes: 10 additions & 8 deletions lib/observation/sensor-projected.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {identity} = require('simple-linalg');
const {identity, matPermutation} = require('simple-linalg');
const correlationToCovariance = require('../utils/correlation-to-covariance');
const covarianceToCorrelation = require('../utils/covariance-to-correlation');
const buildObservedProjection = require('../utils/build-observed-projection.js');

/**
*Creates an observation model with a observedProjection corresponding to
Expand Down Expand Up @@ -32,12 +31,15 @@ const sensorProjected = function ({selectedCovariance, totalDimension, obsIndexe

const dynaDimension = selectedStateProjection[0].length;

const observedProjection = buildObservedProjection({
inDimension: dynaDimension,
inIndexes: selectedStateProjection[0].map((_, i) => i),
outIndexes: obsIndexes,
selectedStateProjection,
outDimension: totalDimension,
if (selectedStateProjection.length !== obsIndexes.length) {
throw (new Error(`shape mismatch (${selectedStateProjection.length} vs ${obsIndexes.length})`));
}

const observedProjection = matPermutation({
outputSize: [totalDimension, dynaDimension],
colIndexes: selectedStateProjection[0].map((_, i) => i),
rowIndexes: obsIndexes,
matrix: selectedStateProjection,
});

return {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"dependencies": {
"@rayyamhk/matrix": "^1.0.5",
"matrix-inverse": "^2.0.0",
"simple-linalg": "^1.0.1"
"simple-linalg": "^1.2.0"
},
"xo": {
"ignores": [
Expand Down

0 comments on commit b4dfb9f

Please sign in to comment.