コード例 #1
0
ファイル: nemo_c.cpp プロジェクト: MogeiWang/nemosim
nemo_status_t
nemo_add_neuron(nemo_network_t net,
		unsigned type, unsigned idx,
		unsigned nargs, float args[])
{
	CATCH_(net, addNeuron(type, idx, nargs, args));
}
コード例 #2
0
ファイル: clayer.cpp プロジェクト: TheftO/NNE
CLayer::CLayer(int neuron_count, StdString sum, int sumSize, StdString activation, int actSize)
{
    id_layer = CLayer::last_layer_id++;
    setSummFunc(sum, sumSize);
    setActivFunc(activation, actSize);
    nextLayer = NULL;
    addNeuron(neuron_count);
}
コード例 #3
0
ファイル: nemo_c.cpp プロジェクト: MogeiWang/nemosim
nemo_status_t
nemo_add_neuron_iz(nemo_network_t net,
		unsigned idx,
		float a, float b, float c, float d,
		float u, float v, float sigma)
{
	CATCH_(net, addNeuron(idx, a, b, c, d, u, v, sigma));
}
コード例 #4
0
ファイル: ico.cpp プロジェクト: sinusoidplus/gorobots_edu
// default constructor
ICO::ICO(){
  // change default transfer function to linear
  ANN::setDefaultTransferFunction(ANN::identityFunction());

  rate_ico=0.1;
  oldReflexiveInput=0;

  // create two input neurons, reflexive and predictive
  for(int i=0; i<2; i++){
    inputNeurons.push_back(addNeuron());
  }

  // create output neuron
  outputNeuron=addNeuron();

  // create synapses between the neurons
  w(outputNeuron, inputNeurons[0], 1.0);
  w(outputNeuron, inputNeurons[1], 0.0);
}
コード例 #5
0
ファイル: net.cpp プロジェクト: episkipoe/Agents
Neuron * Net::addNeuron(int type, string name)  {
	Point where;
	Neuron * newNeuron = addNeuron(type);
	newNeuron->name = name;
	return newNeuron;
}
コード例 #6
0
ファイル: qtAnn.cpp プロジェクト: tnachstedt/neuronizer
neuron* qtAnn::addNeuron() {
  return addNeuron(QPointF(100,100));
}
コード例 #7
0
ファイル: population.c プロジェクト: alinehuf/neattest
/*  This function performs one epoch of the genetic algorithm and returns
 *  a vector of pointers to the new phenotypes
 */
void epoch(sPopulation * pop) {
  int spec, gen;
  // reset appropriate values and kill off the existing phenotypes and
  // any poorly performing species
  resetAndKill(pop);

  // sort genomes
  sortGenomes(pop);

  // separate the population into species of similar topology, adjust
  // fitnesses and calculate spawn levels
  speciateAndCalculateSpawnLevels(pop);
  if (Verbose) dumpSpecies(stdout, pop);
  if (GlobalLog) dumpSpecies(GlobalLogFile, pop);
  
  // this will hold the new population of genomes
  sGenome ** newGenomes = calloc( pop->sParams->iNumIndividuals,
                                  sizeof(*newGenomes) );
  // request the offspring from each species. The number of children to
  // spawn is a double which we need to convert to an int.
  int numSpawnedSoFar = 0;
  sGenome * baby;
  // now to iterate through each species selecting offspring to be mated and
  // mutated
  for (spec = 0; spec < pop->iNumSpecies; spec++) {
    // because of the number to spawn from each species is a double
    // rounded up or down to an integer it is possible to get an overflow
    // of genomes spawned. This statement just makes sure that doesn't happen
    if (numSpawnedSoFar < pop->sParams->iNumIndividuals) {
      //this is the amount of offspring this species is required to
      // spawn. Round simply rounds the double up or down.
      int numToSpawn = round(pop->vSpecies[spec]->dSpawnsRqd);

      bool bChosenBestYet = E_FALSE;

      while (numToSpawn--) {
        // first grab the best performing genome from this species and transfer
        // to the new population without mutation. This provides per species
        // elitism
        // => Stanley recommends to do this only if the species has more than
        //    five networks, in Neat1.1 he used the futur number of individual
        //    instead of the current one... 
        if (!bChosenBestYet) { //  && numToSpawn > 5
          baby = copyGenome(pop->vSpecies[spec]->sLeader);
          bChosenBestYet = E_TRUE;
        } else {
          // if the number of individuals in this species is only one
          // then we can only perform mutation
          if (pop->vSpecies[spec]->iNumMembers == 1) {
            // spawn a child
            baby = copyGenome(randomAmongBest( pop->vSpecies[spec],
                                               pop->sParams->dSurvivalRate ));
          }
          //if greater than one we can use the crossover operator
          else {
            // spawn1
            sGenome * g1 = randomAmongBest( pop->vSpecies[spec],
                                            pop->sParams->dSurvivalRate );
            if (randFloat() < pop->sParams->dCrossoverRate) {
              // spawn2, make sure it's not the same as g1
              sGenome * g2 = randomAmongBest( pop->vSpecies[spec],
                                              pop->sParams->dSurvivalRate );
              // number of attempts at finding a different genome
              int numAttempts = pop->sParams->iNumTrysToFindMate;
              while (g1->iId == g2->iId && numAttempts--)
                g2 = randomAmongBest( pop->vSpecies[spec],
                                      pop->sParams->dSurvivalRate);
              if (g1->iId != g2->iId)
                baby = crossover(g1, g2);
              else
                baby = copyGenome(g1); // crossover fail
            } else {
              baby = copyGenome(g1);   // no crossover
            }
          }

          // adjust new genome id
          baby->iId = pop->iNextGenomeId++;

          // now we have a spawned child lets mutate it! First there is the
          // chance a neuron may be added
          if (randFloat() < pop->sParams->dChanceAddNode)
            addNeuron(baby, pop);
          // now there's the chance a link may be added
          else if (randFloat() < pop->sParams->dChanceAddLink)
            addLink(baby, pop);
          else {
            // mutate the weights
            mutateWeigth(baby, pop->sParams);
            // mutate the activation response
            mutateActivationResponse(baby, pop->sParams);
            // enable or disable a random gene
            if (randFloat() < 0.1)  // mutate_toggle_enable_prob = 0.1
              mutateToggleEnable(baby);
            // find first disabled gene and enable it
            if (randFloat() < 0.05)  // mutate_gene_reenable_prob = 0.05
              mutateReenableFirst(baby);
          }
       } // end choice of a baby

        //sort the babies genes by their innovation numbers
        qsort(baby->vLinks, baby->iNumLinks, sizeof(sLinkGene *),
              (int (*) (const void *, const void *)) cmpLinksByInnovIds);

        //add to new pop
        newGenomes[numSpawnedSoFar++] = baby;
        
        if (numSpawnedSoFar == pop->sParams->iNumIndividuals)
          goto newGenerationReady;

      } // end while not enougth babies
    } // end if to much babies
  } // next species

  // if there is an underflow due to the rounding error and the amount
  // of offspring falls short of the population size additional children
  // need to be created and added to the new population. This is achieved
  // simply, by using tournament selection over the entire population.
  if (numSpawnedSoFar < pop->sParams->iNumIndividuals) {
    //calculate amount of additional children required
    int rqd = pop->sParams->iNumIndividuals - numSpawnedSoFar;
    //grab them
    while (rqd--) {
      sGenome * chosenOne = tournamentSelection(pop, pop->iNumGenomes / 5);
      newGenomes[numSpawnedSoFar++] = copyGenome(chosenOne);
    }
  }

newGenerationReady:

  // free the old vector of genomes
  for (gen = 0; gen < pop->iNumGenomes; gen++)
    freeGenome(pop->vGenomes[gen]); // free the genome itself
  free(pop->vGenomes);              // free the vector containing the genomes
  
  //replace the current population with the new one
  pop->vGenomes = newGenomes;

  //create the new phenotypes
  for (gen = 0; gen < pop->iNumGenomes; gen++) {
    if (UltraVerbose) dumpGenome(stdout, pop->vGenomes[gen]);
    //calculate max network depth
    //int depth = calculateNetDepth(pop->vGenomes[gen]);
    createPhenotype(pop->vGenomes[gen],
                    pop->iNumDepth + pop->vGenomes[gen]->iNumRecur);
    if (UltraVerbose)
      dumpPhenotype(pop->vGenomes[gen]->pPhenotype, pop->vGenomes[gen]->iId);
  }

  //increase generation counter
  pop->iGeneration++;
}