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 101", function () {
// import analytics module
var analytics = require('qminer').analytics;
// construct model
var pca = new analytics.PCA();
// create matrix
var matrix = new la.Matrix([[0, 1], [-1, 0]]);
// fit the matrix
pca.fit(matrix);
});
});
it("should throw an exception because k is bigger than matrix dimensions", function () {
var pca = new analytics.PCA({ k: 5 });
var matrix = new la.Matrix([[1, -1], [0, 0]]);
/*if (require('qminer').flags.blas) { // XXX WTF!? why is this here, the same logic is tested for different behaviour
assert.doesNotThrow(function () {
pca.fit(matrix);
});
} else {*/
assert.throws(function () {
pca.fit(matrix);
});
// }
});
it("should return the model parameters after using fit", function () {
it("should make test number 97", function () {
// import analytics module
var analytics = require('qminer').analytics;
// construct model
var pca = new analytics.PCA();
// create matrix
var matrix = new la.Matrix([[0, 1], [-1, 0]]);
// fit matrix
pca.fit(matrix);
var model = pca.getModel();
// save model
pca.save(require('qminer').fs.openWrite('pca_test.bin')).close();
});
});
it("should make test number 99", function () {
// import analytics module
var analytics = require('qminer').analytics;
// construct model
var pca = new analytics.PCA();
// check the constructor parameters
var paramvalue = pca.getParams();
});
});
it("should make test number 100", function () {
// import analytics module
var analytics = require('qminer').analytics;
// construct model
var pca = new analytics.PCA();
// set parameters
pca.setParams({iter: 10, k: 5});
// check the changed parameters
var paramvalue = pca.getParams();
});
});
it("should make test number 98", function () {
// import analytics module
var analytics = require('qminer').analytics;
// construct model
var pca = new analytics.PCA();
// set 5 eigenvectors and 10 iterations using setParams
pca.setParams({iter: 10, k: 5});
});
});
it("should return changed values of parameters", function () {
var pca = new analytics.PCA();
pca.setParams({ iter: 10, k: 5 });
var params = pca.getParams();
assert.equal(params.iter, 10);
assert.equal(params.k, 5);
});
it("should return changed values of parameters, ignoring added key values", function () {
it("should return values of parameters and added keys", function () {
var pca = new analytics.PCA({ iter: 30, alpha: 3 });
var params = pca.getParams();
assert.equal(params.iter, 30);
assert.equal(params.alpha, undefined);
});
it("should return empty model parameters", function () {
it("should throw and exception because matrix dimensions don't match", function () {
var pca = new analytics.PCA();
var matrix = new la.Matrix([[0, 1], [-1, 0], [2, -1]]);
pca.fit(matrix);
var newMatrix = new la.Matrix([[0, 1, 4], [-1, 0, 0]]);
var model = pca.getModel();
assert.throws(function () {
pca.transform(newMatrix);
});
});
});
it("should serialize and deserialize the model", function () {
var pca = new analytics.PCA({ k: 1 });
var matrix = new la.Matrix([[0, 1], [-1, 0]]);
pca.fit(matrix);
var model = pca.getModel();
var tran = pca.transform(matrix);
pca.save(require('qminer').fs.openWrite('pca_test.bin')).close();
var pca2 = new analytics.PCA(require('qminer').fs.openRead('pca_test.bin'));
var model2 = pca2.getModel();
assert.deepEqual(pca.getParams(), pca2.getParams());
assert.eqtol(model.mu.minus(model2.mu).norm(), 0);
assert.eqtol(model.lambda.minus(model2.lambda).norm(), 0);
assert.eqtol(model.P.minus(model2.P).frob(), 0);
});
});