Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
});
});
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
});
});
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);
});
});
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
});
});
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]
});
});
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);
});
});
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
});
});
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
});
});
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
});
});
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);
});
})