Package org.encog.workbench.dialogs.createnetwork

Examples of org.encog.workbench.dialogs.createnetwork.CreateFeedforward


    } else
      return null;
  }

  private static MLMethod createFeedForward() {
    CreateFeedforward dialog = new CreateFeedforward(EncogWorkBench
        .getInstance().getMainWindow());
    dialog.setActivationFunctionHidden(new ActivationTANH());
    dialog.setActivationFunctionOutput(new ActivationTANH());
   
    if (dialog.process()) {
      FeedForwardPattern feedforward = new FeedForwardPattern();
      feedforward.setActivationFunction(dialog.getActivationFunctionHidden());
      feedforward.setActivationOutput(dialog.getActivationFunctionOutput());
      feedforward.setInputNeurons(dialog.getInputCount().getValue());
      for (int i = 0; i < dialog.getHidden().getModel().size(); i++) {
        String str = (String) dialog.getHidden().getModel()
            .getElementAt(i);
        int i1 = str.indexOf(':');
        int i2 = str.indexOf("neur");
        if (i1 != -1 && i2 != -1) {
          str = str.substring(i1 + 1, i2).trim();
          int neuronCount = Integer.parseInt(str);
          feedforward.addHiddenLayer(neuronCount);
        }
      }
      feedforward.setInputNeurons(dialog.getInputCount().getValue());
      feedforward.setOutputNeurons(dialog.getOutputCount().getValue());
      return feedforward.generate();
    }
    return null;

  }
View Full Code Here


      produceReport();
    }
  }

  private void restructureFeedforward() {
    CreateFeedforward dialog = new CreateFeedforward(EncogWorkBench
        .getInstance().getMainWindow());
    BasicNetwork network = (BasicNetwork)method;

    ActivationFunction oldActivationOutput = network.getActivation(network
        .getLayerCount() - 1);
    dialog.setActivationFunctionOutput(oldActivationOutput);
    dialog.getInputCount().setValue(network.getInputCount());
    dialog.getOutputCount().setValue(network.getOutputCount());
    int hiddenLayerCount = network.getLayerCount() - 2;

    ActivationFunction oldActivationHidden = new ActivationTANH();
    for (int i = 0; i < hiddenLayerCount; i++) {
      int num = network.getLayerNeuronCount(i + 1);
      String str = "Hidden Layer " + (i + 1) + ": " + num + " neurons";
      dialog.getHidden().getModel().addElement(str);
    }
    dialog.setActivationFunctionHidden(oldActivationHidden);

    if (dialog.process()) {
      // decide if entire network is to be recreated
      if ((dialog.getActivationFunctionHidden() != oldActivationHidden)
          || (dialog.getActivationFunctionOutput() != oldActivationOutput)
          || dialog.getHidden().getModel().size() != (network
              .getLayerCount() - 2)) {
        FeedForwardPattern feedforward = new FeedForwardPattern();
        feedforward.setActivationFunction(dialog
            .getActivationFunctionHidden());
        feedforward.setInputNeurons(dialog.getInputCount().getValue());
        for (int i = 0; i < dialog.getHidden().getModel().size(); i++) {
          String str = (String) dialog.getHidden().getModel()
              .getElementAt(i);
          int i1 = str.indexOf(':');
          int i2 = str.indexOf("neur");
          if (i1 != -1 && i2 != -1) {
            str = str.substring(i1 + 1, i2).trim();
            int neuronCount = Integer.parseInt(str);
            feedforward.addHiddenLayer(neuronCount);
          }
        }
        feedforward.setInputNeurons(dialog.getInputCount().getValue());
        feedforward.setOutputNeurons(dialog.getOutputCount().getValue());
        BasicNetwork obj = (BasicNetwork) feedforward.generate();
      } else {
        // try to prune it
        PruneSelective prune = new PruneSelective(network);
        int newInputCount = dialog.getInputCount().getValue();
        int newOutputCount = dialog.getOutputCount().getValue();

        // did input neurons change?
        if (newInputCount != network.getInputCount()) {
          prune.changeNeuronCount(0, newInputCount);
        }

        // did output neurons change?
        if (newOutputCount != network.getOutputCount()) {
          prune.changeNeuronCount(0, newOutputCount);
        }

        // did the hidden layers change?
        for (int i = 0; i < network.getLayerCount() - 2; i++) {
          int newHiddenCount = 1;
          String str = (String) dialog.getHidden().getModel()
              .getElementAt(i);
          int i1 = str.indexOf(':');
          int i2 = str.indexOf("neur");
          if (i1 != -1 && i2 != -1) {
            str = str.substring(i1 + 1, i2).trim();
View Full Code Here

TOP

Related Classes of org.encog.workbench.dialogs.createnetwork.CreateFeedforward

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.