Пример #1
0
  /**
   * This is a test for compute depth of genome and trace all debug information for viewing all
   * signal flowing is not necessary for network simulation
   */
  public static void Experiment2(String xFileName) {
    StringTokenizer st;
    String curword;
    String xline;
    String fnamebuf;
    IOseq xFile;
    int id;
    Genome g1 = null;
    Network net = null;

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

    xFile = new IOseq(xFileName);

    boolean ret = xFile.IOseqOpenR();

    if (ret) {

      try {

        System.out.println(" Start experiment 2");
        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);
        g1 = new Genome(id, xFile);

        // generate	a link mutation
        g1.mutate_link_weight(Neat.p_weight_mut_power, 1.0, NeatConstant.GAUSSIAN);
        // generate from genome the phenotype
        g1.genesis(id);
        // view genotype
        g1.op_view();

        // assign reference to genotype
        net = g1.phenotype;

        // compute first the 'teorical' depth
        int lx = net.max_depth();

        // compute . after, the 'pratical' depth passing
        // the virtual depth;
        int dx = net.is_stabilized(lx);
        // after reset all value of net
        net.flush();

        System.out.print("\n For genome : " + xFileName + " : max depth virtuale=" + lx);
        System.out.print(", max depth reale=" + dx);

        if (dx != lx) System.out.print("\n  *ALERT*  This net is   NOT   S T A B L E ");

        net.flush();

        double errorsum = 0.0;
        double[] out = new double[4]; // The four outputs

        int numnodes = 0;
        int net_depth = 0; // The max depth of the network to be activated
        int count = 0;
        boolean success = false;

        double in[] = {1.0, 1.0, 1.0};

        count = 0;
        // first activation from sensor to first next level of neurons
        net.load_sensors(in);

        // first activation....
        success = net.activate();

        // next activation while last level is reached !
        // use depth to ensure relaxation

        for (int relax = 1; relax <= dx; relax++) {
          success = net.activate();
          //		  	System.out.print("\n -----TIME <"+relax+"> -----");
        }

        // ok : the propagation is completed
      } catch (Throwable e) {
        System.err.println(e + " : error during open " + xFileName);
      }

      xFile.IOseqCloseR();

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

    System.out.println("\n\n End of experiment");
  }
Пример #2
0
  /** Insert the method's description here. Creation date: (16/01/2002 9.53.37) */
  public static boolean xor_evaluate(Organism organism) {

    Network _net = null;
    boolean success = false;
    double errorsum = 0.0;
    double[] out = new double[4]; // The four outputs

    //   int numnodes = 0;
    int net_depth = 0; // The max depth of the network to be activated
    int count = 0;

    // The four possible input combinations to xor
    // The first number is for biasing

    double in[][] = {{1.0, 0.0, 0.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 0.0}, {1.0, 1.0, 1.0}};

    _net = organism.net;
    //   numnodes = organism.genome.nodes.size();

    net_depth = _net.max_depth();

    // for each example , 'count', propagate signal .... and compute results
    for (count = 0; count <= 3; count++) {

      // first activation from sensor to first next levelof neurons
      _net.load_sensors(in[count]);
      success = _net.activate();

      // next activation while last level is reached !
      // use depth to ensure relaxation

      for (int relax = 0; relax <= net_depth; relax++) success = _net.activate();

      // ok : the propagation is completed : repeat until all examples are presented
      out[count] = ((NNode) _net.getOutputs().firstElement()).getActivation();
      _net.flush();
    }

    // control the result
    if (success) {
      errorsum =
          (double)
              (Math.abs(out[0])
                  + Math.abs(1.0 - out[1])
                  + Math.abs(1.0 - out[2])
                  + Math.abs(out[3]));
      organism.setFitness(Math.pow((4.0 - errorsum), 2));
      organism.setError(errorsum);
    } else {
      errorsum = 999.0;
      organism.setFitness(0.001);
      organism.setError(errorsum);
    }
    String mask03 = "0.000";
    DecimalFormat fmt03 = new DecimalFormat(mask03);

    if ((out[0] < 0.5) && (out[1] >= 0.5) && (out[2] >= 0.5) && (out[3] < 0.5)) {
      organism.setWinner(true);
      return true;
    } else {
      organism.setWinner(false);
      return false;
    }
  }