コード例 #1
0
  /**
   * This method allows you to learn from several examples
   *
   * @param examples A population of examples.
   * @param learnRate The learning rate.
   */
  public void learnFrom(Population examples, double learnRate) {
    InterfaceGAIndividual tmpIndy;
    BitSet tmpBitSet;

    for (int i = 0; i < examples.size(); i++) {
      tmpIndy = (InterfaceGAIndividual) (examples.getEAIndividual(i)).clone();
      tmpBitSet = tmpIndy.getBGenotype();
      for (int j = 0; j < this.m_ProbabilityVector.length; j++) {
        this.m_ProbabilityVector[j] = this.m_ProbabilityVector[j] * (1.0 - learnRate);
        if (tmpBitSet.get(j)) this.m_ProbabilityVector[j] += learnRate;
      }
    }
  }
コード例 #2
0
  /** This method creates a new population based on the bit probability vector */
  public void initPBIL() {
    InterfaceGAIndividual tmpIndy,
        template = (InterfaceGAIndividual) ((AbstractEAIndividual) this.get(0)).clone();
    BitSet tmpBitSet;

    this.clear();
    for (int i = 0; i < this.getTargetSize(); i++) {
      tmpIndy = (InterfaceGAIndividual) ((AbstractEAIndividual) template).clone();
      tmpBitSet = tmpIndy.getBGenotype();
      for (int j = 0; j < this.m_ProbabilityVector.length; j++) {
        if (RNG.flipCoin(this.m_ProbabilityVector[j])) tmpBitSet.set(j);
        else tmpBitSet.clear(j);
      }
      tmpIndy.SetBGenotype(tmpBitSet);
      super.add(tmpIndy);
    }
  }