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 46", function () {
// import analytics module
var analytics = require('qminer').analytics;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// set the parameters of the model
linreg.setParams({ dim: 3, recFact: 1e2, forgetFact: 0.5 });
});
});
it("should make test number 47", function () {
// import analytics module
var analytics = require('qminer').analytics;
// create a new Recursive Linear Regression model
var linreg = new analytics.RecLinReg({ dim: 10 });
// get the parameters of the model
var params = linreg.getParams(); // returns { dim: 10, recFact: 1.0, forgetFact: 1.0 }
});
});
it('should return the model', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
linreg.fit(X, y);
var model = linreg.getModel();
assert.eqtol(model.weights.length, 2);
assert.eqtol(model.weights[0], 2);
assert.eqtol(model.weights[1], 1);
})
});
it('should not throw an exception', function () {
var linreg = new analytics.RecLinReg({ dim: 10, regFact: 2.0, forgetFact: 15.0 });
assert.doesNotThrow(function () {
linreg.setParams({ dim: 1.0 });
});
})
it('should change some of the parameters', function () {
it('should serialize and deserialize', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
linreg.fit(X, y);
linreg.save(require('qminer').fs.openWrite('reclinreg_test.bin')).close();
var linreg2 = new analytics.RecLinReg(require('qminer').fs.openRead('reclinreg_test.bin'));
assert.deepEqual(linreg.getParams(), linreg2.getParams());
assert.eqtol(linreg.weights.minus(linreg2.weights).norm(), 0, 1e-8);
})
});
it('should make a new model by fitting the matrix', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
linreg.fit(X, y);
var weights = linreg.weights;
assert.eqtol(weights[0], 2);
assert.eqtol(weights[1], 1);
})
it('should throw an exception if the number of rows exceed the dimension', function () {
it('should serialize and deserialize', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
linreg.fit(X, y);
linreg.save(require('qminer').fs.openWrite('reclinreg_test.bin')).close();
var linreg2 = new analytics.RecLinReg(require('qminer').fs.openRead('reclinreg_test.bin'));
assert.deepEqual(linreg.getParams(), linreg2.getParams());
assert.eqtol(linreg.weights.minus(linreg2.weights).norm(), 0, 1e-8);
})
});
it('should throw an exception if there are no parameters given', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1]]);
var y = new la.Vector([3, 3]);
linreg.fit(X, y);
assert.throws(function () {
linreg.predict();
});
})
});
it('should throw an exception if the number of rows exceed the dimension', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
var X = new la.Matrix([[1, 2], [1, -1], [1, 1]]);
var y = new la.Vector([3, 3]);
assert.throws(function () {
linreg.fit(X, y);
});
})
it('should throw an exception if the number of rows is less than the dimension', function () {
it('should not throw an exception', function () {
var linreg = new analytics.RecLinReg({ dim: 2, regFact: 1e-10, forgetFact: 1.0 });
assert.doesNotThrow(function () {
var model = linreg.getModel();
});
})
it('should return the default values of the model', function () {