protected double calcScoreOfCounts(int[] nCounts,int nCardinality,int numValues,Instances instances){
  double fLogScore=0.0;
  for (int iParent=0; iParent < nCardinality; iParent++) {
switch (m_nScoreType) {
case (Scoreable.BAYES):
{
        double nSumOfCounts=0;
        for (int iSymbol=0; iSymbol < numValues; iSymbol++) {
          if (m_fAlpha + nCounts[iParent * numValues + iSymbol] != 0) {
            fLogScore+=Statistics.lnGamma(m_fAlpha + nCounts[iParent * numValues + iSymbol]);
            nSumOfCounts+=m_fAlpha + nCounts[iParent * numValues + iSymbol];
          }
        }
        if (nSumOfCounts != 0) {
          fLogScore-=Statistics.lnGamma(nSumOfCounts);
        }
        if (m_fAlpha != 0) {
          fLogScore-=numValues * Statistics.lnGamma(m_fAlpha);
          fLogScore+=Statistics.lnGamma(numValues * m_fAlpha);
        }
      }
    break;
case (Scoreable.BDeu):
{
    double nSumOfCounts=0;
    for (int iSymbol=0; iSymbol < numValues; iSymbol++) {
      if (m_fAlpha + nCounts[iParent * numValues + iSymbol] != 0) {
        fLogScore+=Statistics.lnGamma(1.0 / (numValues * nCardinality) + nCounts[iParent * numValues + iSymbol]);
        nSumOfCounts+=1.0 / (numValues * nCardinality) + nCounts[iParent * numValues + iSymbol];
      }
    }
    fLogScore-=Statistics.lnGamma(nSumOfCounts);
    fLogScore-=numValues * Statistics.lnGamma(1.0 / (numValues * nCardinality));
    fLogScore+=Statistics.lnGamma(1.0 / nCardinality);
  }
break;
case (Scoreable.MDL):
case (Scoreable.AIC):
case (Scoreable.ENTROPY):
{
double nSumOfCounts=0;
for (int iSymbol=0; iSymbol < numValues; iSymbol++) {
  nSumOfCounts+=nCounts[iParent * numValues + iSymbol];
}
for (int iSymbol=0; iSymbol < numValues; iSymbol++) {
  if (nCounts[iParent * numValues + iSymbol] > 0) {
    fLogScore+=nCounts[iParent * numValues + iSymbol] * Math.log(nCounts[iParent * numValues + iSymbol] / nSumOfCounts);
  }
}
}
break;
default :
{
}
}
}
switch (m_nScoreType) {
case (Scoreable.MDL):
{
fLogScore-=0.5 * nCardinality * (numValues - 1)* Math.log(m_BayesNet.getNumInstances());
}
break;
case (Scoreable.AIC):
{
fLogScore-=nCardinality * (numValues - 1);
}
break;
}
return fLogScore;
}

protected double calcScoreOfCounts ( int [ ] nCounts , int nCardinality , int numValues , Instances instances ) { double fLogScore = 0.0 ; for ( int iParent = 0 ; iParent < nCardinality ; iParent ++ ) { switch ( m_nScoreType ) { case ( Scoreable . BAYES ) : { double nSumOfCounts = 0 ; for ( int iSymbol = 0 ; iSymbol < numValues ; iSymbol ++ ) { if ( m_fAlpha + nCounts [ iParent * numValues + iSymbol ] != 0 ) { fLogScore += Statistics . lnGamma ( m_fAlpha + nCounts [ iParent * numValues + iSymbol ] ) ; nSumOfCounts += m_fAlpha + nCounts [ iParent * numValues + iSymbol ] ; } } if ( nSumOfCounts != 0 ) { fLogScore -= Statistics . lnGamma ( nSumOfCounts ) ; } if ( m_fAlpha != 0 ) { fLogScore -= numValues * Statistics . lnGamma ( m_fAlpha ) ; fLogScore += Statistics . lnGamma ( numValues * m_fAlpha ) ; } } break ; case ( Scoreable . BDeu ) : { double nSumOfCounts = 0 ; for ( int iSymbol = 0 ; iSymbol < numValues ; iSymbol ++ ) { if ( m_fAlpha + nCounts [ iParent * numValues + iSymbol ] != 0 ) { fLogScore += Statistics . lnGamma ( 1.0 / ( numValues * nCardinality ) + nCounts [ iParent * numValues + iSymbol ] ) ; nSumOfCounts += 1.0 / ( numValues * nCardinality ) + nCounts [ iParent * numValues + iSymbol ] ; } } fLogScore -= Statistics . lnGamma ( nSumOfCounts ) ; fLogScore -= numValues * Statistics . lnGamma ( 1.0 / ( numValues * nCardinality ) ) ; fLogScore += Statistics . lnGamma ( 1.0 / nCardinality ) ; } break ; case ( Scoreable . MDL ) : case ( Scoreable . AIC ) : case ( Scoreable . ENTROPY ) : { double nSumOfCounts = 0 ; for ( int iSymbol = 0 ; iSymbol < numValues ; iSymbol ++ ) { nSumOfCounts += nCounts [ iParent * numValues + iSymbol ] ; } for ( int iSymbol = 0 ; iSymbol < numValues ; iSymbol ++ ) { if ( nCounts [ iParent * numValues + iSymbol ] > 0 ) { fLogScore += nCounts [ iParent * numValues + iSymbol ] * Math . log ( nCounts [ iParent * numValues + iSymbol ] / nSumOfCounts ) ; } } } break ; default : { } } } switch ( m_nScoreType ) { case ( Scoreable . MDL ) : { fLogScore -= 0.5 * nCardinality * ( numValues - 1 ) * Math . log ( m_BayesNet . getNumInstances ( ) ) ; } break ; case ( Scoreable . AIC ) : { fLogScore -= nCardinality * ( numValues - 1 ) ; } break ; } return fLogScore ; }
utility function used by calcscore and calcnodescore to determine the score based on observed frequencies .
