https://github.com/probmods/webppl
Tip revision: 43df929f674e06d97919c2ba5a589afc93c0a59b authored by Andreas Stuhlmüller on 25 March 2015, 22:24:25 UTC
Update README.md
Update README.md
Tip revision: 43df929
test-util.js
'use strict';
var util = require('../src/util.js');
function testAlmostEqual(test, x, y, epsilon) {
if (x === y) {
test.equal(x, y);
} else {
test.ok(Math.abs(x - y) < epsilon);
}
}
module.exports = {
testLogSumExp: {
test1: function(test) {
var epsilon = 0.0000000001;
var xs = [-Infinity, -100, -30, -1, 0, 1, 10];
xs.forEach(
function(x) {
testAlmostEqual(test, x, util.logsumexp([x]), epsilon);
xs.forEach(
function(y) {
var targetVal = Math.log(Math.exp(x) + Math.exp(y));
var actualVal = util.logsumexp([x, y]);
testAlmostEqual(test, targetVal, actualVal, epsilon);
});
});
test.done();
}
}
};