Example #1
0
  /**
   * This is a test for compute depth of genome and compute if has a path from two nodes (is a test
   * for new version of method is_recur()) --> has_a_path(..) is not necessary for network
   * simulation
   */
  public static void Experiment5(String xFileName, int potin, int potout) {
    StringTokenizer st;
    String curword;
    String xline;
    String fnamebuf;
    IOseq xFile;
    int id;
    Genome g1 = null;
    Network net = null;

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

    if (ret) {

      try {
        System.out.println("------ Start experiment 5 -------");
        // read genome A

        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);

        System.out.print("\n Max depth virtuale=" + lx);
        System.out.print(", max depth reale=" + dx);

        // search the inode
        NNode inode = null;
        NNode onode = null;
        NNode curnode = null;
        boolean rc = false;
        int cnt = 0;

        for (int ix = 0; (ix < net.allnodes.size()) && (cnt < 2); ix++) {
          curnode = (NNode) net.allnodes.elementAt(ix);
          if (curnode.node_id == potin) {
            inode = curnode;
            cnt++;
          }

          if (curnode.node_id == potout) {
            onode = curnode;
            cnt++;
          }
        }

        // if exist , point to exitsting version
        if (cnt < 2) {

          System.out.print("\n ERROR :nodes in e/o out wrong's : retype!");
        } else {

          net.status = 0;
          rc = net.has_a_path(inode, onode, 0, 30);
          System.out.print("\n Result for  example " + xFileName + " for ipotetic path ");
          System.out.print(
              "\n   inode[" + potin + "] ---> onode[" + potout + "]  is  return code=" + rc);
          System.out.print(", status = " + net.status);
        }

        // after reset all value of net
        net.flush();

        // ok : the propagation is completed
      } 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");
  }
Example #2
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");
  }