JNEAT - iterator.next()对象包含0

时间:2015-10-30 19:07:38

标签: java

所以我使用了一个名为JNEAT的库。它已经很老了(从2002年开始)。

问题出在哪里:

我使用这个库来发展一组神经网络。我使用这些神经网络来控制模拟中的某些东西。在模拟结束时,我确定神经网络在健身状态下的表现如何。值。然后我将此适应性分配给一个名为“有机体”的对象。

问题是JNEAT认为健身总是零。但是我知道我传入的对象包含实际的适应性。

以下是一些代码段:

这是我用新的适应性设置生物的地方。在这里,输出完全符合我的预期。意味着正确印刷了适合度。

public void setOrganisms(Vector<Organism> organisms) {
     this.organisms = organisms;
     for(int i = 0; i < organisms.size(); i++)
     {
         System.out.printf("Organism %d fitness: %f\n", i, organisms.get(i).fitness);
     }
  }

**** ******无论其

这是物种和生物被初始化的地方:

/** A Population is a group of Organisms including their species */
    public class Population extends Neat {
   /** The organisms in the Population */
      public Vector<Organism> organisms;

   /** Species in the Population the species should comprise all the genomes */
      public Vector<Species> species;

   /** For holding the genetic innovations of the newest generation */
      Vector<Innovation> innovations = new Vector<Innovation>(1,0);

这是第一次在演化函数中使用拟合:

public void epoch(int generation) 
      {

         Iterator<Species> itr_specie;
         Iterator<Organism> itr_organism;
         double total = 0.0;
      //double total_expected=0.0;
         int orgcount = 0;
         int max_expected;
         int total_expected; //precision checking
         int final_expected;
         int half_pop = 0;
         double overall_average = 0.0;
         int total_organisms = 0;
         double tmpd = 0.0;
         double skim = 0.0;
         int tmpi = 0;
         int best_species_num = 0;
         int stolen_babies = 0;
         int one_fifth_stolen = 0;
         int one_tenth_stolen = 0;
         int size_of_curr_specie = 0;
         int NUM_STOLEN = Neat.p_babies_stolen; //Number of babies to steal
      // al momento NUM_STOLEN=1

         Species _specie = null;
         Species curspecies = null;
         Species best_specie = null;
         Vector<Species> sorted_species = null;


      // Use Species' ages to modify the objective fitness of organisms
      // in other words, make it more fair for younger species
      // so they have a chance to take hold
      // Also penalize stagnant species
      // Then adjust the fitness using the species size to "share" fitness
      // within a species.
      // Then, within each Species, mark for death 
      // those below survival_thresh * average


         itr_specie = species.iterator();
         while (itr_specie.hasNext()) 
         {
            _specie = ((Species) itr_specie.next());
            _specie.adjust_fitness();
         }

      //Go through the organisms and add up their fitnesses to compute the
      //overall average

         itr_organism = organisms.iterator();
         total = 0.0;
         while (itr_organism.hasNext()) 
         {
            Organism _organism = ((Organism) itr_organism.next());
            System.out.println(_organism.fitness);
            total += _organism.fitness;
         }


         total_organisms = organisms.size();
         overall_average = total / total_organisms;

         System.out.println(overall_average);

    }

这些println中的每一个都打印出0.0到控制台。我相信这与迭代器有关,因为有机体本身会返回0。

有什么想法吗?

0 个答案:

没有答案