How to use the qminer.la.SparseVector 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.js View on Github external
it("should make test number 42", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse matrix
	 var mat = new la.SparseMatrix([[[0, 3], [1, 2]], [[1, -2], [3, 4]], [[10, 8]]]);
	 // create a new sparse vector to replace the third column
	 var vec = new la.SparseVector([[0, 3], [2, -5]]);
	 // set the third column of mat to vec
	 mat.setCol(2, vec); // returns mat with the third column changed
	
});
});
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 40", function () {

	 // import modules
	 var analytics = require('qminer').analytics;
	 var la = require('qminer').la;
	 // create a new NearestNeighborAD object
	 var neighbor = new analytics.NearestNeighborAD();
	 // create a new sparse matrix
	 var matrix = new la.SparseMatrix([[[0, 1], [1, 2]], [[0, -2], [1, 3]], [[0, 0], [1, 1]]]);
	 // fit the model with the matrix
	 neighbor.fit(matrix);
	 // create a new sparse vector
	 var vector = new la.SparseVector([[0, 4], [1, 0]]);
	 // check if the vector is an anomaly
	 var prediction = neighbor.predict(vector); // returns 1
	
});
});
github qminer / qminer / test / nodejs / exampleladoc.js View on Github external
it("should make test number 32", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse vector
	 var vec = new la.SparseVector([[0, 1], [3, 2], [4, -5]]);
	 // set the new values at position 2
	 vec.put(2, -4);
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 34", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create two vectors, one sparse and one dense
	 var sparse = new la.SparseVector([[0, 1], [3, 2], [4, -5]]);
	 var dense = new la.Vector([3, -4, 2, 0.5, -1]);
	 // get the inner product of the vectors
	 sparse.inner(dense); // returns the value 9
	
});
});
github qminer / qminer / test / nodejs / exampleladoc_structures.js View on Github external
it("should make test number 35", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse vector
	 var spVec = new la.SparseVector([[0, 1], [2, 3], [3, 6]]);
	 // multiply sparse vector with scalar 3.14
	 var spVec2 = spVec.multiply(3.14); // returns sparse vector [3.14, 0, 9.42, 18.84]
	
});
});
github qminer / qminer / test / nodejs / exampleladoc.js View on Github external
it("should make test number 43", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse vector
	 var mat = new la.SparseMatrix([[[0, 2], [3, 5]], [[1, -3]]]);
	 // create a new vector
	 var vec = new la.SparseVector([[0, 2], [2, -3]]);
	 // push the newly created vector to the matrix
	 // the new matrix is going to be (in sparse form)
	 // 2    0    2
	 // 0   -3    0
	 // 0    0   -3
	 // 5    0    0
	 mat.push(vec);
	
});
});
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 39", function () {

	  // import modules
	  var analytics = require('qminer').analytics;
	  var la = require('qminer').la;
	  // create a new NearestNeighborAD object
	  var neighbor = new analytics.NearestNeighborAD();
	  // create a new sparse matrix
	  var matrix = new la.SparseMatrix([[[0, 1], [1, 2]], [[0, -2], [1, 3]], [[0, 0], [1, 1]]]);
	  // fit the model with the matrix
	  neighbor.fit(matrix);
	  // create a new sparse vector
	  var vector = new la.SparseVector([[0, 4], [1, 0]]);
	  // get the distance of the vector from the model
	  var prediction = neighbor.decisionFunction(vector); // returns 1
	 
});
});
github qminer / qminer / test / nodejs / exampleladoc.js View on Github external
it("should make test number 33", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a new sparse vector
	 var vec = new la.SparseVector([[0, 1], [3, 2], [4, -5]]);
	 // get the sum of the values in the vector
	 vec.sum(); // returns -2
	
});
});
github qminer / qminer / test / nodejs / exampleladoc.js View on Github external
it("should make test number 31", function () {

	 // import la module
	 var la = require('qminer').la;
	 // create a sparse vector
	 var vec = new la.SparseVector([[0, 1], [3, 2], [4, -5]]);
	 // get the value at the position 3
	 vec.at(3); // returns the value 2
	
});
});
github qminer / qminer / test / nodejs / onevsall.js View on Github external
it('should not throw an exception, sparse vector', 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.SparseVector([[0, 1], [1, 2]]);
            assert.doesNotThrow(function () {
                var decision = onevsall.decisionFunction(test);
            });
        })