Skip to content

Commit 88ee3df

Browse files
jajoemaasencioh
authored andcommitted
feat: add linearDependencies method
1 parent 9b52976 commit 88ee3df

File tree

6 files changed

+231
-47
lines changed

6 files changed

+231
-47
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const matrix = Matrix.ones(5, 5);
3535

3636
### Standard operations
3737

38-
``` javascript
38+
``` js
3939
const {Matrix} = require('ml-matrix');
4040

4141
var A = new Matrix([[1, 1], [2, 2]]);
@@ -101,8 +101,16 @@ var z = Matrix.eye(3, 4); // Matrix [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], r
101101
```
102102

103103
### Maths :
104-
```javascript
105-
const {Matrix, inverse, solve, QrDecomposition, LuDecomposition, CholeskyDecomposition} = require('ml-matrix');
104+
```js
105+
const {
106+
Matrix,
107+
inverse,
108+
solve,
109+
linearDependencies,
110+
QrDecomposition,
111+
LuDecomposition,
112+
CholeskyDecomposition
113+
} = require('ml-matrix');
106114

107115
//===========================
108116
// inverse and pseudo-inverse
@@ -168,6 +176,13 @@ var A = new Matrix([[2, 3, 5], [4, 1, 6], [1, 3, 0]]);
168176
var cholesky = CholeskyDecomposition(A);
169177
var L = cholesky.lowerTriangularMatrix;
170178

179+
//=======
180+
// Others
181+
//=======
182+
183+
// Linear dependencies
184+
var A = new Matrix([[2, 0, 0, 1], [0, 1, 6, 0], [0, 3, 0, 1], [0, 0, 1, 0], [0, 1, 2, 0]]);
185+
var dependencies = linearDependencies(A); // dependencies is a matrix with the dependencies of the rows. When we look row by row, we see that the first row is [0, 0, 0, 0, 0], so it means that the first row is independent, and the second row is [ 0, 0, 0, 4, 1 ], i.e the second row = 4 times the 4th row + the 5th row.
171186

172187
```
173188

package-lock.json

Lines changed: 125 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
"devDependencies": {
5151
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
5252
"benchmark": "^2.1.0",
53-
"codecov": "^2.2.0",
53+
"codecov": "^2.3.0",
5454
"csv-parse": "^1.0.0",
55-
"eslint": "^4.2.0",
55+
"eslint": "^4.4.1",
5656
"eslint-config-cheminfo": "^1.5.2",
5757
"eslint-plugin-no-only-tests": "^2.0.0",
5858
"jest-cli": "^20.0.4",
59-
"jest-matcher-deep-close-to": "^1.0.0",
60-
"mathjs": "^3.14.2",
59+
"jest-matcher-deep-close-to": "^1.0.2",
60+
"mathjs": "^3.16.0",
6161
"npm-run-all": "^4.0.1",
6262
"numeric": "^1.2.6",
6363
"pretty-hrtime": "^1.0.0",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Matrix, linearDependencies} from '../..';
2+
import {toBeDeepCloseTo} from 'jest-matcher-deep-close-to';
3+
expect.extend({toBeDeepCloseTo});
4+
5+
describe('Linear Dependencies', () => {
6+
it('should compute the rows dependencies', () => {
7+
const A = new Matrix([
8+
[2, 0, 0, 1],
9+
[0, 1, 6, 0],
10+
[0, 3, 0, 1],
11+
[0, 0, 1, 0],
12+
[0, 1, 2, 0]
13+
]);
14+
const dependencies = linearDependencies(A);
15+
expect(dependencies.to2DArray()).toBeDeepCloseTo([
16+
[0, 0, 0, 0, 0],
17+
[0, 0, 0, 4, 1],
18+
[0, 0, 0, 0, 0],
19+
[0, 0.25, 0, 0, -0.25],
20+
[0, 1, 0, -4, 0]
21+
], 3);
22+
});
23+
});

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export {default as WrapperMatrix2D} from './wrap/WrapperMatrix2D';
66
export {default as WrapperMatrix1D} from './wrap/WrapperMatrix1D';
77

88
export {solve, inverse} from './decompositions';
9+
export {linearDependencies} from './linearDependencies';
910
export {default as SingularValueDecomposition, default as SVD} from './dc/svd.js';
1011
export {default as EigenvalueDecomposition, default as EVD} from './dc/evd.js';
1112
export {default as CholeskyDecomposition, default as CHO} from './dc/cholesky.js';

0 commit comments

Comments
 (0)