Ejemplo n.º 1
0
 public RotatePanel(Image image) {
   this.image = image;
   MediaTracker mt = new MediaTracker(this);
   mt.addImage(image, 0);
   try {
     mt.waitForID(0);
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
  /**
   * Creates a new NetworkPanel
   *
   * @param _g The genome of the network
   * @param _w The weights of the network
   */
  public NetworkPanel(Genome _g, Link[] _w) {
    setBackground(Color.white);

    genome = _g;
    weights = _w;

    // Tracker for the images
    tracker.addImage(inputNeuron, 0);
    tracker.addImage(hiddenNeuron, 1);
    tracker.addImage(outputNeuron, 2);
    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
    }

    // Create the lines for the links between the layers
    // The array of lines is actually complete (as for a fully connected network)
    // The loop in paintComponent decideds whether to draw the line or not.
    linkLines = new Line2D.Double[weights.length];
    int counter = 0;
    double fromX = leftMargin + inW;
    double fromY = topMargin + titleSpace + iconHeight / 2.0;
    double toX = leftMargin + space;
    double toY = fromY;

    // Create the lines for the links between the first hidden layer and the input layer
    for (int i = 0;
        i < genome.getNeuronsInHiddenLayer();
        i++) // Loop through the neurons in 1st hidden layer
    {
      fromY = topMargin + titleSpace + iconHeight / 2.0;
      for (int j = 0; j < genome.getInputs(); j++) // Loop through the neurons in the input layer
      {
        linkLines[counter] = new Line2D.Double(fromX, fromY, toX, toY);
        fromY += space;
        counter++;
      }
      toY += space;
    }

    // Create the lines for the links between the hidden layers
    fromX += space;
    fromY = topMargin + titleSpace + iconHeight / 2.0;
    toX = fromX + space - hW;
    toY = fromY;
    for (int i = 0; i < genome.getHiddenLayers() - 1; i++) // Loop across the hidden layers
    {
      fromY = topMargin + titleSpace + iconHeight / 2.0;
      toY = fromY;
      for (int j = 0; j < genome.getNeuronsInHiddenLayer(); j++) // Loop down the 'to' hidden layer
      {
        fromY = topMargin + titleSpace + iconHeight / 2.0;
        for (int k = 0;
            k < genome.getNeuronsInHiddenLayer();
            k++) // Loop down the 'from' hidden layer
        {
          linkLines[counter] = new Line2D.Double(fromX, fromY, toX, toY);
          fromY += space;
          counter++;
        }
        toY += space;
      }
      fromX += space;
      toX = fromX + space - hW;
    }

    // Create the lines for the links between the output layer and the final hidden layer
    fromX = leftMargin + space * genome.getHiddenLayers() + hW;
    fromY = topMargin + titleSpace + iconHeight / 2.0;
    toX = leftMargin + space * (genome.getHiddenLayers() + 1);
    toY = fromY;
    for (int i = 0; i < genome.getOutputs(); i++) // Loop through the outputs
    {
      fromY = topMargin + titleSpace + 14.0;
      for (int j = 0;
          j < genome.getNeuronsInHiddenLayer();
          j++) // Loop through the neurons in the final hidden layer
      {
        linkLines[counter] = new Line2D.Double(fromX, fromY, toX, toY);
        fromY += space;
        counter++;
      }
      toY += space;
    }
  }