Package weka.classifiers.bayes.net

Examples of weka.classifiers.bayes.net.ParentSet


   */
  Operation findBestArcToDelete(BayesNet bayesNet, Instances instances, Operation oBestOperation) throws Exception {
    int nNrOfAtts = instances.numAttributes();
    // find best arc to delete
    for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
      ParentSet parentSet = bayesNet.getParentSet(iNode);
      for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
        Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_DEL);
        double fScore = calcScoreWithMissingParent(oOperation.m_nHead, oOperation.m_nTail);
        if (fScore > oBestOperation.m_fScore) {
          if (isNotTabu(oOperation)) {
            oBestOperation = oOperation;
            oBestOperation.m_fScore = fScore;
View Full Code Here


   */
  Operation findBestArcToReverse(BayesNet bayesNet, Instances instances, Operation oBestOperation) throws Exception {
    int nNrOfAtts = instances.numAttributes();
    // find best arc to reverse
    for (int iNode = 0; iNode < nNrOfAtts; iNode++) {
      ParentSet parentSet = bayesNet.getParentSet(iNode);
      for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
        int iTail = parentSet.getParent(iParent);
        // is reversal allowed?
        if (reverseArcMakesSense(bayesNet, instances, iNode, iTail) &&
            bayesNet.getParentSet(iTail).getNrOfParents() < m_nMaxNrOfParents) {
          // go check if reversal results in the best step forward
          Operation oOperation = new Operation(parentSet.getParent(iParent), iNode, Operation.OPERATION_REVERSE);
          double fScore = calcScoreWithReversedParent(oOperation.m_nHead, oOperation.m_nTail);
          if (fScore > oBestOperation.m_fScore) {
            if (isNotTabu(oOperation)) {
              oBestOperation = oOperation;
              oBestOperation.m_fScore = fScore;
View Full Code Here

   * @param nNode node for which the score is calculate
   * @param nCandidateParent candidate parent to add to the existing parent set
   * @return log score
   */
  public double calcScoreWithExtraParent(int nNode, int nCandidateParent) {
    ParentSet oParentSet = m_BayesNet.getParentSet(nNode);

    // sanity check: nCandidateParent should not be in parent set already
    if (oParentSet.contains(nCandidateParent)) {
        return -1e100;
    }

    // set up candidate parent
    oParentSet.addParent(nCandidateParent, m_BayesNet.m_Instances);

    // calculate the score
    double logScore = calcNodeScore(nNode);

    // delete temporarily added parent
    oParentSet.deleteLastParent(m_BayesNet.m_Instances);

    return logScore;
  } // CalcScoreWithExtraParent
View Full Code Here

   * @param nNode node for which the score is calculate
   * @param nCandidateParent candidate parent to delete from the existing parent set
   * @return log score
   */
  public double calcScoreWithMissingParent(int nNode, int nCandidateParent) {
    ParentSet oParentSet = m_BayesNet.getParentSet(nNode);

    // sanity check: nCandidateParent should be in parent set already
    if (!oParentSet.contains( nCandidateParent)) {
        return -1e100;
    }

    // set up candidate parent
    int iParent = oParentSet.deleteParent(nCandidateParent, m_BayesNet.m_Instances);

    // calculate the score
    double logScore = calcNodeScore(nNode);

    // restore temporarily deleted parent
    oParentSet.addParent(nCandidateParent, iParent, m_BayesNet.m_Instances);

    return logScore;
  } // CalcScoreWithMissingParent
View Full Code Here

            // find a node for which all parents are 'done'
            boolean bFound = false;

            for (int iNode2 = 0; !bFound && iNode2 < nNodes; iNode2++) {
                if (!bDone[iNode2]) {
                  ParentSet parentSet = bayesNet.getParentSet(iNode2);
                    boolean bHasNoParents = true;
                    for (int iParent = 0; iParent < parentSet.getNrOfParents(); iParent++) {
                        if (!bDone[parentSet.getParent(iParent)]) {
                         
                            // this one has a parent which is not 'done' UNLESS it is the arc to be reversed
                            if (!(iNode2 == iAttributeHead && parentSet.getParent(iParent) == iAttributeTail)) {
                                bHasNoParents = false;
                            }
                        }
                    }
View Full Code Here

     * @param instances
     */
    protected void doMarkovBlanketCorrection(BayesNet bayesNet, Instances instances) {
        // Add class node as parent if it is not in the Markov Boundary
        int iClass = instances.classIndex();
        ParentSet ancestors = new ParentSet();
        int nOldSize = 0;
        ancestors.addParent(iClass, instances);
        while (nOldSize != ancestors.getNrOfParents()) {
            nOldSize = ancestors.getNrOfParents();
            for (int iNode = 0; iNode < nOldSize; iNode++) {
                int iCurrent = ancestors.getParent(iNode);
                ParentSet p = bayesNet.getParentSet(iCurrent);
                for (int iParent = 0; iParent < p.getNrOfParents(); iParent++) {
                    if (!ancestors.contains(p.getParent(iParent))) {
                        ancestors.addParent(p.getParent(iParent), instances);
                    }
                }
            }
        }
        for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
View Full Code Here

    BIFReader bifReader = new BIFReader();
    bifReader.processFile(m_sBIFFile);
    // copy parent sets
        for (int iAttribute = 0; iAttribute < instances.numAttributes(); iAttribute++) {
            int iBIFAttribute = bifReader.getNode(bayesNet.getNodeName(iAttribute));
            ParentSet bifParentSet = bifReader.getParentSet(iBIFAttribute);
          for (int iBIFParent = 0; iBIFParent < bifParentSet.getNrOfParents(); iBIFParent++) {
              String sParent = bifReader.getNodeName(bifParentSet.getParent(iBIFParent));
              int iParent = 0;
              while (iParent < instances.numAttributes() && !bayesNet.getNodeName(iParent).equals(sParent)) {
                  iParent++;
              }
              if (iParent >= instances.numAttributes()) {
View Full Code Here

        calcArcDirections(edges, arrows);

    // transfrom into BayesNet datastructure
    for (int iNode = 0; iNode < maxn(); iNode++) {
      // clear parent set of AttributeX
      ParentSet oParentSet = m_BayesNet.getParentSet(iNode);
      while (oParentSet.getNrOfParents() > 0) {
        oParentSet.deleteLastParent(m_instances);
      }
      for (int iParent = 0; iParent < maxn(); iParent++) {
        if (arrows[iParent][iNode]) {
          oParentSet.addParent(iParent, m_instances);
        }
      }
    }
  } // search
View Full Code Here

     * As a side effect, the parent sets are set
     */
    void calcScore() {
      // clear current network
      for (int iNode = 0; iNode < m_nNodes; iNode++) {
        ParentSet parentSet = m_BayesNet.getParentSet(iNode);
        while (parentSet.getNrOfParents() > 0) {
          parentSet.deleteLastParent(m_BayesNet.m_Instances);
        }
      }
      // insert arrows
      for (int iNode = 0; iNode < m_nNodes; iNode++) {
        ParentSet parentSet = m_BayesNet.getParentSet(iNode);
        for (int iNode2 = 0; iNode2 < m_nNodes; iNode2++) {
          if (m_bits[iNode2 + iNode * m_nNodes]) {
            parentSet.addParent(iNode2, m_BayesNet.m_Instances);
          }
        }
      }
      // calc score
      m_fScore = 0.0;
View Full Code Here

  protected boolean isConditionalIndependent(
    int iAttributeX,
    int iAttributeY,
    int [] iAttributesZ,
    int nAttributesZ) {
    ParentSet oParentSetX = m_BayesNet.getParentSet(iAttributeX);
    // clear parent set of AttributeX
    while (oParentSetX.getNrOfParents() > 0) {
      oParentSetX.deleteLastParent(m_instances);
    }
   
    // insert parents in iAttributeZ
    for (int iAttributeZ = 0; iAttributeZ < nAttributesZ; iAttributeZ++) {
      oParentSetX.addParent( iAttributesZ[iAttributeZ], m_instances);
    }
   
    double fScoreZ = calcNodeScore(iAttributeX);
    double fScoreZY = calcScoreWithExtraParent(iAttributeX, iAttributeY);
    if (fScoreZY <= fScoreZ) {
View Full Code Here

TOP

Related Classes of weka.classifiers.bayes.net.ParentSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.