Exemple #1
0
  /**
   * This is a sample of creating a new Population with 'size_population' organisms , and simulation
   * of XOR example This sample can be started in two modality : -cold : each time the population is
   * re-created from 0; -warm : each time the population re-read last population created and restart
   * from last epoch. (the population backup file is : 'c:\\jneat\\dati\\population.primitive'
   */
  public static void Experiment3(int size_population, int mode, int gens) {
    Population pop = null;
    String fname_prefix = "c:\\jneat\\dati\\population.primitive";
    String fnamebuf;
    int gen;
    int id;
    int expcount = 0;
    String mask6 = "000000";
    DecimalFormat fmt6 = new DecimalFormat(mask6);

    System.out.println("------ Start experiment 3 -------");

    for (expcount = 0; expcount < Neat.p_num_runs; expcount++) {
      System.out.println(" Spawned population off genome");

      double prb_link = 0.50;
      boolean recurrent = true;

      // default cold is : 3 sensor (1 for bias) , 1 out , 5 nodes max, no recurrent
      if (mode == NeatConstant.COLD)
        pop = new Population(size_population, 3, 1, 5, recurrent, prb_link); // cold start-up
      //		   pop = new Population(size_population, 3, 1, 5, recurrent, prb_link);		// cold start-up
      else pop = new Population(fname_prefix + ".last"); // warm start-up

      pop.verify();
      System.out.print("\n---------------- Generation starting with----------");
      System.out.print("\n  Population : innov num   = " + pop.getCur_innov_num());
      System.out.print("\n             : cur_node_id = " + pop.getCur_node_id());
      System.out.print("\n---------------------------------------------------");

      System.out.print("\n");
      for (gen = 1; gen <= gens; gen++) {
        System.out.print("\n---------------- Generation ----------------------" + gen);
        fnamebuf = "g_" + fmt6.format(gen);
        boolean esito = xor_epoch(pop, gen, fnamebuf);
        System.out.print("\n  Population : innov num   = " + pop.getCur_innov_num());
        System.out.print("\n             : cur_node_id = " + pop.getCur_node_id());
        System.out.print("\n   result    : " + esito);
      }
    }

    // backup of population for warm startup
    pop.print_to_filename(fname_prefix + ".last");

    System.out.println("\n\n End of experiment");
  }
Exemple #2
0
  /**
   * this is a standard experiment for XOR emulation; is passed a name of a started genome and a
   * number of times can be execute this experiment;
   */
  public static void Experiment1(String xFileName, int gens) {

    String fname_prefix = "c:\\jneat\\dati\\population.natural";
    Population pop = null;
    StringTokenizer st;
    String curword;
    String xline;
    String fnamebuf;
    int gen;
    IOseq xFile;
    int id;
    int expcount = 0;
    String mask6 = "000000";
    DecimalFormat fmt6 = new DecimalFormat(mask6);

    System.out.println("------ Start experiment 1 -------");

    xFile = new IOseq(xFileName);
    boolean ret = xFile.IOseqOpenR();
    if (ret) {

      try {

        System.out.println(" Start XOR experiment");
        System.out.println("  .read start genome..");

        xline = xFile.IOseqRead();

        st = new StringTokenizer(xline);
        // skip
        curword = st.nextToken();
        // id of genome can be readed
        curword = st.nextToken();
        id = Integer.parseInt(curword);

        System.out.println("  .create genome id " + id);

        Genome start_genome = new Genome(id, xFile);
        // backup this 'initial' genome (is only for test
        // if the read & write are correct
        start_genome.print_to_filename("c:\\jneat\\dati\\genome.readed");

        for (expcount = 0; expcount < Neat.p_num_runs; expcount++) {
          System.out.println(" Spawned population off genome");
          pop = new Population(start_genome, Neat.p_pop_size);
          System.out.print("\n\n Verifying Spawned Pop");
          pop.verify();

          System.out.print("\n");

          for (gen = 1; gen <= gens; gen++) {
            System.out.print("\n---------------- E P O C H  < " + gen + " >--------------");

            fnamebuf = "g_" + fmt6.format(gen);
            boolean esito = xor_epoch(pop, gen, fnamebuf);
          }

          System.out.print("\n  Population : innov num   = " + pop.getCur_innov_num());
          System.out.print("\n             : cur_node_id = " + pop.getCur_node_id());

          pop.print_to_filename(fname_prefix);
        }
      } catch (Throwable e) {
        System.err.println(e + " : error during read " + xFileName);
      }

      xFile.IOseqCloseR();

    } else System.err.print("\n : error during open " + xFileName);

    System.out.println("\n\n End of experiment");
  }