Пример #1
0
  private void assignNeuronDepth(Gene[] nodeGenes, int depth, Chromosome mutated) {
    int i;
    NEATNodeGene node;
    // ArrayList nodeGenes = this.findOutputNodes(this.candidateNodes(genes));

    for (i = 0; i < nodeGenes.length; i++) {
      node = (NEATNodeGene) nodeGenes[i];
      if (node.getType() == NEATNodeGene.OUTPUT) {
        if (depth == 1) {
          node.setDepth(depth);
          this.assignNeuronDepth(
              this.findSourceNodes(node.id(), mutated.genes()), depth + 1, mutated);
        }
      } else if (node.getType() == NEATNodeGene.HIDDEN) {
        if (node.getDepth() == 0) {
          // we have an unassigned depth
          node.setDepth(depth);
          this.assignNeuronDepth(
              this.findSourceNodes(node.id(), mutated.genes()), depth + 1, mutated);
        }
      } else if (node.getType() == NEATNodeGene.INPUT) {
        node.setDepth(Integer.MAX_VALUE);
      }
    }
  }
Пример #2
0
  private Gene mutateNode(NEATNodeGene mutatee) {
    double perturbRandVal = perturbRand.nextDouble();
    double mutateBias = perturbRand.nextDouble();
    NEATNodeGene mutated = mutatee;
    double newSF = mutatee.sigmoidFactor();
    double newBias = mutatee.bias();

    if (perturbRandVal < this.pPerturb) {
      newSF = mutatee.sigmoidFactor() + MathUtils.nextClampedDouble(-perturb, perturb);
      mutated =
          new NEATNodeGene(
              mutated.getInnovationNumber(),
              mutated.id(),
              newSF,
              mutated.getType(),
              mutated.bias());
    }

    if (mutateBias < this.pMutateBias) {
      newBias += MathUtils.nextClampedDouble(-biasPerturb, biasPerturb);
      mutated =
          new NEATNodeGene(
              mutated.getInnovationNumber(),
              mutated.id(),
              mutated.sigmoidFactor(),
              mutated.getType(),
              newBias);
    }

    return (mutated);
  }
Пример #3
0
  private Gene[] findOutputNodes(ArrayList nodes) {
    ArrayList outputNodes = new ArrayList();
    Gene[] nodeGenes;
    NEATNodeGene node;
    int i;

    for (i = 0; i < nodes.size(); i++) {
      node = (NEATNodeGene) nodes.get(i);
      if (node.getType() == NEATNodeGene.OUTPUT) {
        outputNodes.add(node);
      }
    }

    nodeGenes = new NEATNodeGene[outputNodes.size()];
    for (i = 0; i < nodeGenes.length; i++) {
      nodeGenes[i] = (NEATNodeGene) outputNodes.get(i);
    }

    return (nodeGenes);
  }
Пример #4
0
  private boolean linkIllegal(NEATNodeGene from, NEATNodeGene to, ArrayList links) {
    boolean illegal = false;
    int idx = 0;
    NEATLinkGene linkGene;

    if ((to.getType() == NEATNodeGene.INPUT)) {
      illegal = true;
    } else {
      while (!illegal && (idx < links.size())) {
        linkGene = (NEATLinkGene) links.get(idx);
        //				if ((linkGene.getFromId() == from.id() && linkGene.getToId() == to.id()) ||
        // ((to.getDepth() <= from.getDepth()) && !this.recurrencyAllowed)) {
        if ((linkGene.getFromId() == from.id() && linkGene.getToId() == to.id())) {
          illegal = true;
        }
        idx++;
      }
    }

    return (illegal);
  }