Example #1
0
  private void initializeBN(SelectedSet selectedSet) {
    int NS = selectedSet.getN();
    int SIZE = selectedSet.getIndividual(0).getIndividual().length;
    this.bestScoreGain = Double.NEGATIVE_INFINITY;
    Individual[] individuals = selectedSet.getIndividuals();
    for (int i = 0; i < Problem.n; i++) { // Refresh the Bayesian Network structure.
      parentList[i] =
          new HashSet<Integer>(
              Problem.n); // Initial Capacity = stringSize; 	Default Load Factor = 0.75
      adjacencyList[i] =
          new HashSet<Integer>(
              Problem.n); // Initial Capacity = stringSize; 	Default Load Factor = 0.75
      splitList[i] =
          new HashSet<Integer>(
              2 * Problem.n); // Initial Capacity = 2*stringSize; Default Load Factor = 0.75
      for (int n = 0; n < Problem.n; n++) {
        if (n != i) {
          splitList[i].add(n);
        }
      }

      int mOne =
          selectedSet.getUniFrequencies(i); // Construct the initial single leaf decision graphs.
      int mZero = NS - mOne;
      Leaf newLeaf =
          new Leaf(
              0, -1, mZero, mOne,
              SIZE); // There is only a single leaf per variable, at depth 0, with side -1.
      if (mZero > 0
          && mOne
              > 0) { // If mZero = 0 or mOne = 0 there is no need to try any split with this leaf.
        for (int j = 0; j < NS; j++) {
          char alleleJI = individuals[j].getAllele(i); // Value of Xi in individual j.
          for (int s : splitList[i]) {
            char alleleS = individuals[j].getAllele(s); // Value of Xs in individual j.
            if (alleleJI == '0') {
              if (alleleS == '0') {
                newLeaf.addPossibleSplitFrequency(0, s); // m00[s]++;
              } else {
                newLeaf.addPossibleSplitFrequency(1, s); // m01[s]++;
              }
            } else if (alleleS == '0') {
              newLeaf.addPossibleSplitFrequency(2, s); // m10[s]++;
            } else {
              newLeaf.addPossibleSplitFrequency(3, s); // m11[s]++;
            }
          }
        }
        for (int s : splitList[i]) {
          int m00 = newLeaf.getPossibleSplitFrequency(0, s);
          int m01 = newLeaf.getPossibleSplitFrequency(1, s);
          int m10 = newLeaf.getPossibleSplitFrequency(2, s);
          int m11 = newLeaf.getPossibleSplitFrequency(3, s);
          double scoreGain = bayesianMetric.computeScoreGain(mZero, mOne, m00, m01, m10, m11);
          newLeaf.setScoreGain(s, scoreGain);
          newLeaf.updateBestSplit(
              s,
              scoreGain); // Responsible for updating the value of the best split score gain in this
          // leaf.
        }
      } // END: if(mZero > 0 ...)
      decisionGraphs[i] =
          new DecisionGraph(
              newLeaf); // Initially each graph as a single leaf and there are n-1 possible splits.
      decisionGraphs[i].updateBestLeaf();
      double scoreGain = decisionGraphs[i].getBestLeafScoreGain();
      if (scoreGain
          > this
              .bestScoreGain) { // Update the value of the global best score gain and position (DG).
        this.bestDecisionGraphPos = i;
        this.bestScoreGain = scoreGain;
      }
    } // END: for(int i = 0 ...)
  } // END: initializeBN(...)