/**
  * Neural network learns from Java-ML data set
  *
  * @param dataSetJML Dataset Java-ML data set
  */
 @Override
 public void buildClassifier(Dataset dataSetJML) {
   DataSet dataSet =
       JMLDataSetConverter.convertJMLToNeurophDataset(
           dataSetJML, neuralNet.getInputsCount(), neuralNet.getOutputsCount());
   neuralNet.learn(dataSet);
 }
  /**
   * Prints network output for the each element from the specified training set.
   *
   * @param neuralNet neural network
   * @param testSet test data set
   */
  public static void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

    for (DataSetRow testSetRow : testSet.getRows()) {
      neuralNet.setInput(testSetRow.getInput());
      neuralNet.calculate();
      double[] networkOutput = neuralNet.getOutput();

      System.out.print("Input: " + Arrays.toString(testSetRow.getInput()));
      System.out.print(" Output: " + Arrays.toString(networkOutput));
    }
  }
 public void orderForm(NeuralNetwork nnet) {
   drawButton.setEnabled(false);
   openInLauncherButton.setEnabled(false);
   this.nnet = nnet;
   graphTypeCombo.removeAllItems();
   layerCombo.removeAllItems();
   datasetTextField.setEditable(false);
   nnetField.setEditable(false);
   nnetField.setText(nnet.getLabel());
   Layer[] layers = nnet.getLayers();
   for (int i = layers.length; i > 0; i--) {
     layerCombo.addItem(i);
   }
 }
 private void fillAttributes() {
   int layerIdx = nnet.getLayersCount() - 1; // output layerIdx by default
   Attribute attr1;
   Attribute attr2 = null;
   if (layerCombo.isEnabled()) {
     layerIdx = (Integer) layerCombo.getSelectedItem() - 1;
   }
   attr1 = new Attribute(layerIdx, false, "Layer");
   if (attributeTxtField.isEnabled()) {
     attribute = Integer.parseInt(attributeTxtField.getText());
     attr2 = new Attribute(attribute, false, "Input");
   }
   graphBuilder.setAttribute1(attr1);
   graphBuilder.setAttribute2(attr2);
   outputNeuronCount = nnet.getLayerAt(layerIdx).getNeuronsCount();
 }
Ejemplo n.º 5
0
  @Override
  public vafusion.recog.Character match(Object arg) {

    BufferedImage charimg = (BufferedImage) arg;
    OcrPlugin plugin = (OcrPlugin) nnet.getPlugin(OcrPlugin.OCR_PLUGIN_NAME);
    return Character.mapCharacter(plugin.recognizeCharacter(charimg));
  }
Ejemplo n.º 6
0
  /** Sets default input and output neurons for network (first layer as input, last as output) */
  public static void setDefaultIO(NeuralNetwork nnet) {
    ArrayList<Neuron> inputNeuronsList = new ArrayList<Neuron>();
    Layer firstLayer = nnet.getLayerAt(0);
    for (Neuron neuron : firstLayer.getNeurons()) {
      if (!(neuron instanceof BiasNeuron)) { // dont set input to bias
        // neurons
        inputNeuronsList.add(neuron);
      }
    }

    Neuron[] inputNeurons = new Neuron[inputNeuronsList.size()];
    inputNeurons = inputNeuronsList.toArray(inputNeurons);
    Neuron[] outputNeurons = ((Layer) nnet.getLayerAt(nnet.getLayersCount() - 1)).getNeurons();

    nnet.setInputNeurons(inputNeurons);
    nnet.setOutputNeurons(outputNeurons);
  }
  /**
   * Calculates predict values for every possible class that instance can be classified as that
   *
   * @param instnc Instance
   * @return Map<Object, Double>
   */
  @Override
  public Map<Object, Double> classDistribution(Instance instnc) {

    // Convert instance to double array
    double[] item = convertInstanceToDoubleArray(instnc);

    // set neural network input
    neuralNet.setInput(item);
    // calculate neural network output
    neuralNet.calculate();

    // find neuron with highest output
    Map<Object, Double> possibilities = new HashMap<Object, Double>();

    for (Neuron neuron : neuralNet.getOutputNeurons()) {
      possibilities.put(neuron.getLabel(), neuron.getOutput());
    }

    return possibilities;
  }
  /**
   * Classifies instance as one of possible classes
   *
   * @param instnc Instance to classify
   * @return Object class as Object
   */
  @Override
  public Object classify(Instance instnc) {

    double[] item = convertInstanceToDoubleArray(instnc);

    // set neural network input
    neuralNet.setInput(item);
    // calculate neural network output
    neuralNet.calculate();

    // find neuron with highest output
    Neuron maxNeuron = null;
    double maxOut = Double.NEGATIVE_INFINITY;
    for (Neuron neuron : neuralNet.getOutputNeurons()) {
      if (neuron.getOutput() > maxOut) {
        maxNeuron = neuron;
        maxOut = neuron.getOutput();
      }
    }

    // and return its label
    return maxNeuron.getLabel();
  }
 private boolean validateAttribute(JTextField attributeField) {
   if (attributeField.isEnabled()) {
     try {
       int a = Integer.parseInt(attributeField.getText().trim());
       if (a > nnet.getInputsCount() || a <= 0) {
         JOptionPane.showMessageDialog(
             this,
             "There is no data set attribute (input) with index: " + a,
             "Error",
             JOptionPane.ERROR_MESSAGE);
         return false;
       }
       return true;
     } catch (Exception e) {
       JOptionPane.showMessageDialog(
           this,
           "Please enter an integer value in attribute field.",
           "Error",
           JOptionPane.ERROR_MESSAGE);
       return false;
     }
   }
   return true;
 }
 @Override
 public void setNeuralNetwork(NeuralNetwork neuralNetwork) {
   super.setNeuralNetwork(neuralNetwork);
   int neuronsNum = neuralNetwork.getLayerAt(1).getNeuronsCount();
   mapSize = (int) Math.sqrt(neuronsNum);
 }
 public ErrorSurface3D(NeuralNetwork nnet, DataSet dataset) {
   dataProvider3D = new ErrorDataProvider3D(dataset, nnet);
   dataSetRowCount = dataset.getRows().size();
   outputNeuronCount = nnet.getOutputsCount();
 }