itamarwe / kalman

Kalman Filter in Javascript
113 stars 30 forks source link

Converting to bower component #4

Open FreakTheMighty opened 9 years ago

FreakTheMighty commented 9 years ago

I've made your library into a bower component so that its easier for other people to install and would like to make a merge request. At the moment, though, your test isn't passing.

https://github.com/htmlfusion/kalman

Despite adding the same version of sylvester (0.1.3) as is used in your test, there appears to be a slight different between them. The difference lies in the determinant function.

The version installed in your test directory looks like so:

  // Returns the determinant for square matrices
  determinant: function() {
    if (this.elements.length === 0) { return 1; }
    if (!this.isSquare()) { return null; }
    var M = this.toRightTriangular();
    var det = M.elements[0][0], n = M.elements.length;
    for (var i = 1; i < n; i++) {
      det = det * M.elements[i][i];
    }
    return det;
  },

While the version installed by bower looks like:

  // Returns the determinant for square matrices
  determinant: function() {
    if (!this.isSquare()) { return null; }
    var M = this.toRightTriangular();
    var det = M.elements[0][0], n = M.elements.length - 1, k = n, i;
    do { i = k - n + 1;
      det = det * M.elements[i][i];
    } while (--n);
    return det;
  },

This is the only difference between the two files and results in the following error.

 Uncaught TypeError: Cannot read property '1' of undefined
sylvester.src.js:586
Matrix.determinantsylvester.src.js:595 
Matrix.isSingularsylvester.src.js:643
Matrix.inversekalman.js:49
KalmanModel.updatetest.html:23 (anonymous function)
itamarwe commented 9 years ago

Yes. The problem in the new sylvester code is that it seems to crash for a 1x1 matrix. So basically it seems like there is a bug in their new code...

FreakTheMighty commented 9 years ago

I see, perhaps the fix was made in a later version. If not I'll just leave the one you've packaged.