jsbayes.js
function normalizeProbs(arr) {
    var probs = [];
    var sum = 0.0;
    for (var i=0; i < arr.length; i++) {
      probs[i] = arr[i] + 0.001
      sum += probs[i]
    }
    for (var i=0; i < arr.length; i++) {
      probs[i] = probs[i] / sum;
    }
    return probs;
  }
function normalizeProbs(arr) {
    var probs = [];
    var sum = 0.0;
    for (var i=0; i < arr.length; i++) {
      probs[i] = arr[i] + 0.001
      sum += probs[i]
    }
    for (var i=0; i < arr.length; i++) {
      probs[i] = probs[i] / sum;
    }
    return probs;
  }
function normalizeProbs ( arr ) { var probs = [ ] ; var sum = 0.0 ; for ( var i = 0 ; i < arr . length ; i ++ ) { probs [ i ] = arr [ i ] + 0.001 sum += probs [ i ] } for ( var i = 0 ; i < arr . length ; i ++ ) { probs [ i ] = probs [ i ] / sum ; } return probs ; }
Normalizes an array of values such that the elements sum to 1.0. Note that
0.001 is added to every value to avoid 0.0 probabilities. This adjustment
helps with visualization downstream.
@param {Array} arr Array of probabilities.
@returns {Array} Normalized probailities.
Normalizes an array of values such that the elements sum to 1 . 0 . Note that 0 . 001 is added to every value to avoid 0 . 0 probabilities . This adjustment helps with visualization downstream .