jsbayes.js
function initCptWithParents(values, parents, paIndex) {
    if(parents && parents.length > 0) {
      if(parents.length === 1 || paIndex === parents.length - 1) {
        var idx = parents.length === 1 ? 0 : paIndex;
        var numPaVals = parents[idx].values.length;
        var cpts = [];
        for(var i=0; i < numPaVals; i++) {
          var cpt = initCpt(values.length);
          cpts.push(cpt);
        }
        return cpts;
      } else {
        var cpts = [];
        var numPaVals = parents[paIndex].values.length;
        for(var i=0; i < numPaVals; i++) {
          var cpt = initCptWithParents(values, parents, paIndex+1);
          cpts.push(cpt);
        }
        return cpts;
      }
    } else {
      return initCpt(values.length);
    }
  }
function initCptWithParents(values, parents, paIndex) {
    if(parents && parents.length > 0) {
      if(parents.length === 1 || paIndex === parents.length - 1) {
        var idx = parents.length === 1 ? 0 : paIndex;
        var numPaVals = parents[idx].values.length;
        var cpts = [];
        for(var i=0; i < numPaVals; i++) {
          var cpt = initCpt(values.length);
          cpts.push(cpt);
        }
        return cpts;
      } else {
        var cpts = [];
        var numPaVals = parents[paIndex].values.length;
        for(var i=0; i < numPaVals; i++) {
          var cpt = initCptWithParents(values, parents, paIndex+1);
          cpts.push(cpt);
        }
        return cpts;
      }
    } else {
      return initCpt(values.length);
    }
  }
function initCptWithParents ( values , parents , paIndex ) { if ( parents && parents . length > 0 ) { if ( parents . length === 1 || paIndex === parents . length - 1 ) { var idx = parents . length === 1 ? 0 : paIndex ; var numPaVals = parents [ idx ] . values . length ; var cpts = [ ] ; for ( var i = 0 ; i < numPaVals ; i ++ ) { var cpt = initCpt ( values . length ) ; cpts . push ( cpt ) ; } return cpts ; } else { var cpts = [ ] ; var numPaVals = parents [ paIndex ] . values . length ; for ( var i = 0 ; i < numPaVals ; i ++ ) { var cpt = initCptWithParents ( values , parents , paIndex + 1 ) ; cpts . push ( cpt ) ; } return cpts ; } } else { return initCpt ( values . length ) ; } }
Initializes a CPT with fake and normalized values using recursion.
@param {Array} values Values of variables (array of values).
@param {Array} parents Array of JSON nodes that are parents of the variable.
@param {Number} paIndex The current parent index.
@returns {Array} An array of nested arrays representing the CPT.
Initializes a CPT with fake and normalized values using recursion .