sparse-belief
v0.1.1
Published
Sparse belief manager using Bayes law to update belief after an observation
Downloads
13
Maintainers
Readme
sparse-belief
const { SparseBelief } = require('sparse-belief');
// suppose category k can generate numbers 1,2,...,k uniformly
// then the likehood function for observing x when the category is k
// is 1/k on k's domain and 0 elsewhere
function likelihood(x,k){
if ((x>=1) && (x<=k))
return 1/k;
return 0;
}
// create a flat prior on categories k=1,2,3,4
const prior = [[1,0.25],[2,0.25],[3,0.25],[4,0.25]];
let sparse = new SparseBelief({prior,likelihood});
// observe an x data value
sparse.observe(1);
// Bayes Law posterior probabilities of categories
sparse.prob(1) // 0.48
sparse.prob(2) // 0.24
sparse.prob(3) // 0.16
sparse.prob(4) // 0.12
see tests for more examples