How to use the qminer.la.SparseMatrix function in qminer

To help you get started, we’ve selected a few qminer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 50", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse matrix
	 var mat = new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]);
	 // check the number of rows in sparse matrix
	 mat.rows;
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 44", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create two sparse matrices
	 var mat = new la.SparseMatrix([[[0, 1], [3, 2]], [[1, -3]]]);
	 var mat2 = new la.SparseMatrix([[[0, 3]],[[2, 1]]]);
	 // get the sum of the two matrices
	 // returns the sum ( insparse form)
	 // 4    0
	 // 0   -3
	 // 0    1
	 // 2    0
	 var sum = mat.plus(mat2);
	
});
});
github qminer / qminer / test / nodejs / exampleladoc.js View on Github external
it("should make test number 49", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse matrix
	 var mat = new la.SparseMatrix([[[0, 1], [1, 3]], [[0, 2], [1, 4]]]);
	 // get the frobenious norm of sparse matrix
	 var norm = mat.frob(); // returns sqrt(30)
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 52", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse matrix
	 var spMat = new la.SparseMatrix([[[0, 1]], [[0, 3], [1, 8]]]);
	 // print sparse matrix on screen
	 // each row represents a nonzero element, where first value is row index, second
	 // value is column index and third value is element value. For this matrix:
	 // 0  0  1.000000
	 // 0  1  3.000000
	 // 1  1  8.000000
	 spMat.print();
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 45", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create two sparse matrices
	 var mat = new la.SparseMatrix([[[0, 1], [3, 2]], [[1, -3]]]);
	 var mat2 = new la.SparseMatrix([[[0, 3]],[[2, 1]]]);
	 // get the sum of the two matrices
	 // returns the sum ( insparse form)
	 // -2    0
	 //  0   -3
	 //  0   -1
	 //  2    0
	 var diff = mat.minus(mat2);
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 54", function () {

	 // import the modules
	 var fs = require('qminer').fs;
	 var la = require('qminer').la;
	 // create an empty matrix
	 var mat = new la.SparseMatrix();
	 // open a read stream ('mat.dat' was previously created)
	 var fin = fs.openRead('mat.dat');
	 // load the matrix
	 mat.load(fin);
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 55", function () {

	 // import the modules
	 var la = require('qminer').la;
	 // create an empty matrix
	 var mat = new la.SparseMatrix();
	 mat.setRowDim(2);
	 mat.rows // prints 2
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 38", function () {

 // import la module
 var la = require('qminer').la;
 // create a new sparse matrix with array
 var mat = new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]]);
 // create a new sparse matrix with specified max rows
 var mat2 = new la.SparseMatrix([[[0, 2]], [[0, 1], [2, 3]]], 3);

});
});
github qminer / qminer / test / nodejs / onevsall.js View on Github external
it('should not throw an exception, sparse matrix', function () {
            this.timeout(10000);
            var json = { c: 10, maxTime: 12000 };
            var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: json, cats: 2 });
            var matrix = new la.Matrix([[1, 2, 1, 1], [2, 1, -3, -4]]);
            var vector = new la.Vector([0, 0, 1, 1]);
            onevsall.fit(matrix, vector);

            var test = new la.SparseMatrix([[[0, 1], [1, 2]], [[0, 1], [1, -3]]]);
            assert.doesNotThrow(function () {
                var prediction = onevsall.predict(test);
            });
        })
        it('should return an integer vector containing the cluster indeces, sparse matrix', function () {
github qminer / qminer / test / nodejs / onevsall.js View on Github external
it('should set the models, sparse matrix', function () {
            this.timeout(10000);
            var json = { c: 10, maxTime: 12000 };
            var onevsall = new analytics.OneVsAll({ model: analytics.SVC, modelParam: json, cats: 2 });

            var matrix = new la.SparseMatrix([[[0, 1], [1, 2]], [[0, 2], [1, 1]], [[0, 1], [1, -3]], [[0, 1], [1, -4]]]);
            var vector = new la.Vector([0, 0, 1, 1]);

            onevsall.fit(matrix, vector);

            var param = onevsall.getParams();
            assert.equal(param.models.length, 2);
        })
        it('should throw an exception if there are no parameters given', function () {