forked from sbyrnes/likely.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regression_test.js
47 lines (37 loc) · 1.02 KB
/
regression_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Regression test for the Likely.js recommendation library.
*/
var sylvester = require('sylvester');
var Recommender = require('./likely.js');
// TODO: lower the maximum error threshold
// Note that this is the squared error
var MAXIMUM_ERROR = 1;
var input = $M([
[1, 0, 3, 1, 0],
[2, 3, 0, 0, 5],
[3, 1, 3, 4, 1],
[0, 1, 1, 1, 1]
]);
console.log('Input Matrix: ');
prettyPrint(input);
console.log('\nEstimated Matrix: ');
var model = Recommender.buildModel(input);
var estimate = model.estimated;
prettyPrint(estimate);
console.log('\nError Matrix: ');
var errorMatrix = Recommender.calculateError(estimate, input);
prettyPrint(errorMatrix);
console.log('\nTotal Error: ');
var error = Recommender.calculateTotalError(errorMatrix);
console.log(error);
console.log('\n');
if(error > MAXIMUM_ERROR)
console.log('FAIL - Error too large');
else
console.log('SUCCESS');
console.log('\n\n');
/** Utility to pretty print matrix contents */
function prettyPrint(matrix)
{
console.log(matrix.inspect());
}