org.neuroph.core.NeuralNetwork Java Examples

The following examples show how to use org.neuroph.core.NeuralNetwork. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example #2
Source File: Ionosphere.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        Evaluation evaluation = new Evaluation();
        evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

        evaluation.addEvaluator(new ClassifierEvaluator.Binary(0.5));
        evaluation.evaluate(neuralNet, dataSet);

        ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.Binary.class);
        ConfusionMatrix confusionMatrix = evaluator.getResult();
        System.out.println("Confusion matrrix:\r\n");
        System.out.println(confusionMatrix.toString() + "\r\n\r\n");
        System.out.println("Classification metrics\r\n");
        ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
        ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
        for (ClassificationMetrics cm : metrics) {
            System.out.println(cm.toString() + "\r\n");
        }
        System.out.println(average.toString());
    }
 
Example #3
Source File: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {

            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example #4
Source File: NetworkUtils.java    From developerWorks with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a NxNxNxN style string showing the layer structure
 * of the specified network.
 * 
 * @param network
 * @return
 */
public static String getNetworkStructure(NeuralNetwork<BackPropagation> network) {
  StringBuilder sb = new StringBuilder();
  //
  // First the inputs
  if (network != null) {
    sb.append(network.getInputsCount());
    //
    // Now for the hidden layers
    for (Layer layer : network.getLayers()) {
      sb.append("x");
      sb.append(layer.getNeuronsCount());
    }
    //
    // Finally, the outputs
    sb.append("x");
    sb.append(network.getOutputsCount());
  }
  return sb.toString();
}
 
Example #5
Source File: BackPropagationTest.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateNetworkWeights() {
    NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>();
    nn.setInputNeurons(new ArrayList<Neuron>() {
        {
            add(new Neuron());
            add(new Neuron());
        }
    });
    nn.setOutputNeurons(new ArrayList<Neuron>() {
        {
            add(new Neuron());
        }
    });
    nn.setLearningRule(instance);
    BackPropagation bp1 = Mockito.spy(new BackPropagation());
    nn.setLearningRule(bp1);
    double[] weigths = {1, 2};
    bp1.calculateWeightChanges(weigths);
    Mockito.verify(bp1).calculateErrorAndUpdateOutputNeurons(weigths);
    Mockito.verify(bp1).calculateErrorAndUpdateHiddenNeurons();
}
 
Example #6
Source File: DigitsRecognition.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {

    System.out.println("--------------------------------------------------------------------");
    System.out.println("***********************TESTING NEURAL NETWORK***********************");
    for (DataSetRow testSetRow : testSet.getRows()) {
        neuralNet.setInput(testSetRow.getInput());
        neuralNet.calculate();

        int outputIdx = maxOutput(neuralNet.getOutput());

        String[] inputDigit = DigitData.convertDataIntoImage(testSetRow.getInput());

        for (int i = 0; i < inputDigit.length; i++) {
            if (i != inputDigit.length - 1) {
                System.out.println(inputDigit[i]);
            } else {
                System.out.println(inputDigit[i] + "----> " + outputIdx);
            }
        }
        System.out.println("");
    }
}
 
Example #7
Source File: DiabetesSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**********************RESULT**********************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            // get network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = interpretOutput(networkOutput);

            // get target/desired output
            double[] desiredOutput = testSetRow.getDesiredOutput();
            int target = (int)desiredOutput[0];

            // count predictions
            countPredictions(predicted, target);
        }

        System.out.println("Total cases: " + total + ". ");
        System.out.println("Correctly predicted cases: " + correct);
        System.out.println("Incorrectly predicted cases: " + incorrect);
        double percentTotal = (correct / (double)total) * 100;
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");
    }
 
Example #8
Source File: BackPropagationTest.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
@Test
public void testCalculateErrorAndUpdateOutputNeurons() {
    NeuralNetwork<BackPropagation> nn = new NeuralNetwork<>();
    nn.setInputNeurons(new ArrayList<Neuron>() {
        {
            add(new Neuron());
            add(new Neuron());
        }
    });
    nn.setOutputNeurons(new ArrayList<Neuron>() {
        {
            add(new Neuron());
        }
    });
    nn.setLearningRule(instance);
    nn.getOutputNeurons().get(0).setDelta(1);
    instance.calculateErrorAndUpdateOutputNeurons(new double[]{0});
    assertTrue(nn.getOutputNeurons().get(0).getDelta() == 0);
    instance.calculateErrorAndUpdateOutputNeurons(new double[]{0.5});
    assertTrue(nn.getOutputNeurons().get(0).getDelta() == 0.5);
}
 
Example #9
Source File: SunSpots.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void run() {

		// uncomment the following line to use regular Neuroph (non-flat) processing
		//Neuroph.getInstance().setFlattenNetworks(false);
		// create neural network
		NeuralNetwork network = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, WINDOW_SIZE, 10, 1);

                // normalize training data
		normalizeSunspots(0.1, 0.9);

		network.getLearningRule().addListener(this);

                // create training set
		DataSet trainingSet = generateTrainingData();
		network.learn(trainingSet);
		predict(network);

		Neuroph.getInstance().shutdown();
	}
 
Example #10
Source File: BreastCancerSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {
    System.out.println("********************** TEST RESULT **********************");
    for (DataSetRow testSetRow : testSet.getRows()) {
        neuralNet.setInput(testSetRow.getInput());
        neuralNet.calculate();

        // get network output
        double[] networkOutput = neuralNet.getOutput();
        int predicted = interpretOutput(networkOutput);

        // get target/desired output
        double[] desiredOutput = testSetRow.getDesiredOutput();
        int target = (int)desiredOutput[0];

        // count predictions
        countPredictions(predicted, target);
    }

    System.out.println("Total cases: " + total + ". ");
    System.out.println("Correctly predicted cases: " + correct);
    System.out.println("Incorrectly predicted cases: " + incorrect);
    double percentTotal = (correct / (double)total) * 100;
    System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");
}
 
Example #11
Source File: WheatSeeds.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        Evaluation evaluation = new Evaluation();
        evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

        String[] classLabels = new String[]{"1", "2", "3"};
        evaluation.addEvaluator(new ClassifierEvaluator.MultiClass(classLabels));
        evaluation.evaluate(neuralNet, dataSet);

        ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.MultiClass.class);
        ConfusionMatrix confusionMatrix = evaluator.getResult();
        System.out.println("Confusion matrrix:\r\n");
        System.out.println(confusionMatrix.toString() + "\r\n\r\n");
        System.out.println("Classification metrics\r\n");
        ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
        ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
        for (ClassificationMetrics cm : metrics) {
            System.out.println(cm.toString() + "\r\n");
        }
        System.out.println(average.toString());
    }
 
Example #12
Source File: Banknote.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        Evaluation evaluation = new Evaluation();
        evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

        evaluation.addEvaluator(new ClassifierEvaluator.Binary(0.5));
        evaluation.evaluate(neuralNet, dataSet);

        ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.Binary.class);
        ConfusionMatrix confusionMatrix = evaluator.getResult();
        System.out.println("Confusion matrrix:\r\n");
        System.out.println(confusionMatrix.toString() + "\r\n\r\n");
        System.out.println("Classification metrics\r\n");
        ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
        ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
        for (ClassificationMetrics cm : metrics) {
            System.out.println(cm.toString() + "\r\n");
        }
        System.out.println(average.toString());
    }
 
Example #13
Source File: Abalone.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");
        Evaluation evaluation = new Evaluation();
        evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

        String classLabels[] = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"};
        evaluation.addEvaluator(new ClassifierEvaluator.MultiClass(classLabels));
        evaluation.evaluate(neuralNet, dataSet);

        ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.MultiClass.class);
        ConfusionMatrix confusionMatrix = evaluator.getResult();
        System.out.println("Confusion matrrix:\r\n");
        System.out.println(confusionMatrix.toString() + "\r\n\r\n");
        System.out.println("Classification metrics\r\n");
        ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
        ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
        for (ClassificationMetrics cm : metrics) {
            System.out.println(cm.toString() + "\r\n");
        }
        System.out.println(average.toString());
    }
 
Example #14
Source File: Sonar.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        Evaluation evaluation = new Evaluation();
        evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

        evaluation.addEvaluator(new ClassifierEvaluator.Binary(0.5));
        evaluation.evaluate(neuralNet, dataSet);

        ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.Binary.class);
        ConfusionMatrix confusionMatrix = evaluator.getResult();
        System.out.println("Confusion matrrix:\r\n");
        System.out.println(confusionMatrix.toString() + "\r\n\r\n");
        System.out.println("Classification metrics\r\n");
        ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
        ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
        for (ClassificationMetrics cm : metrics) {
            System.out.println(cm.toString() + "\r\n");
        }
        System.out.println(average.toString());
    }
 
Example #15
Source File: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example #16
Source File: NeurophXOR.java    From tutorials with MIT License 6 votes vote down vote up
public static NeuralNetwork trainNeuralNetwork(NeuralNetwork ann) {
    int inputSize = 2;
    int outputSize = 1;
    DataSet ds = new DataSet(inputSize, outputSize);

    DataSetRow rOne = new DataSetRow(new double[] { 0, 1 }, new double[] { 1 });
    ds.addRow(rOne);
    DataSetRow rTwo = new DataSetRow(new double[] { 1, 1 }, new double[] { 0 });
    ds.addRow(rTwo);
    DataSetRow rThree = new DataSetRow(new double[] { 0, 0 }, new double[] { 0 });
    ds.addRow(rThree);
    DataSetRow rFour = new DataSetRow(new double[] { 1, 0 }, new double[] { 1 });
    ds.addRow(rFour);

    BackPropagation backPropagation = new BackPropagation();
    backPropagation.setMaxIterations(1000);

    ann.learn(ds, backPropagation);
    return ann;
}
 
Example #17
Source File: ImageRecognitionSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
      // load trained neural network saved with NeurophStudio (specify existing neural network file here)
      NeuralNetwork nnet = NeuralNetwork.createFromFile("MyImageRecognition.nnet");
      // get the image recognition plugin from neural network
      ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class);

      try {
            // image recognition is done here
            HashMap<String, Double> output = imageRecognition.recognizeImage(new File("someImage.jpg")); // specify some existing image file here
            System.out.println(output.toString());
      } catch(IOException ioe) {
          System.out.println("Error: could not read file!");
      } catch (VectorSizeMismatchException vsme) {
          System.out.println("Error: Image dimensions dont !");
      }
}
 
Example #18
Source File: NeuralNetworkCODEC.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Decode a network from an array.
 * @param array The array used to decode.
 * @param network The network to decode into.
 */
public static void array2network(double[] array, NeuralNetwork network) {
	int index = 0;
               
               List<Layer> layers = network.getLayers();
               for (Layer layer : layers) {
		for (Neuron neuron : layer.getNeurons()) {
			for (Connection connection : neuron.getOutConnections()) {
				connection.getWeight().setValue(array[index++]);
				//connection.getWeight().setPreviousValue(array[index++]);
			}
		}
	}
}
 
Example #19
Source File: GraphmlExport.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Create XML graph from neuroph neural network. 
 * @param ann
 * @return
 */
private Graph createGraph( final NeuralNetwork ann ) {
	String id = ann.getLabel();
	if( id == null || id.length() == 0 ) { 
		id = "defaultId"; 
	}
	Graph graph = new Graph( id );
	graph.addNetwork( ann ); 
	
	return graph; 
}
 
Example #20
Source File: BrestCancerSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'M (malignant)' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'B (benign)' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
    }
 
Example #21
Source File: PredictingPerformanceOfCPUSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public 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.println(" Output: " + Arrays.toString(networkOutput));
        }
    }
 
Example #22
Source File: NetworkUtils.java    From developerWorks with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the specified network using the Neuroph API.
 * 
 * @param network
 * @param input
 * @return
 */
public static <T extends NeuralNetwork<BackPropagation>> double[] runNetwork(T network, double[] input) {
  double[] ret;
  network.setInput(input);
  network.calculate();
  // Return value is the network's output
  ret = network.getOutput();
  if (log.isTraceEnabled()) {
    log.trace("Input : " + Arrays.toString(input));
    log.trace("Output: " + Arrays.toString(ret));
  }
  return ret;
}
 
Example #23
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("Showing inputs, desired output and neural network output for every row in test set.");

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

            System.out.println("Input: " + Arrays.toString(testSetRow.getInput()));
            System.out.println("Output: " + networkOutput[0]);
            System.out.println("Desired output" + Arrays.toString(networkOutput));

        }
    }
 
Example #24
Source File: BatchImageTrainer.java    From FakeImageDetection with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doRun() {
    try {
        System.out.println("Starting training thread....." + sampleDimension.toString() + " and " + imageLabels.toString());

        HashMap<String, BufferedImage> imagesMap = new HashMap<String, BufferedImage>();
        for (File file : srcDirectory.listFiles()) {
            imageLabels.add(FilenameUtils.removeExtension(file.getName()));
            if (sampleDimension.getWidth() > 0 && sampleDimension.getHeight() > 0) {
                Double w = sampleDimension.getWidth();
                Double h = sampleDimension.getHeight();
                imagesMap.put(file.getName(), ImageUtilities.resizeImage(ImageUtilities.loadImage(file), w.intValue(), h.intValue()));
            }
        }
        Map<String, FractionRgbData> imageRgbData = ImageUtilities.getFractionRgbDataForImages(imagesMap);
        DataSet learningData = ImageRecognitionHelper.createRGBTrainingSet(imageLabels, imageRgbData);

        nnet = NeuralNetwork.load(new FileInputStream(nnFile)); //Load NNetwork
        MomentumBackpropagation mBackpropagation = (MomentumBackpropagation) nnet.getLearningRule();
        mBackpropagation.setLearningRate(learningRate);
        mBackpropagation.setMaxError(maxError);
        mBackpropagation.setMomentum(momentum);

        System.out.println("Network Information\nLabel = " + nnet.getLabel()
                + "\n Input Neurons = " + nnet.getInputsCount()
                + "\n Number of layers = " + nnet.getLayersCount()
        );

        mBackpropagation.addListener(this);
        System.out.println("Starting training......");
        nnet.learn(learningData, mBackpropagation);
        //Training Completed
        listener.batchImageTrainingCompleted();
    } catch (FileNotFoundException ex) {
        System.out.println(ex.getMessage() + "\n" + ex.getLocalizedMessage());
    }

}
 
Example #25
Source File: Evaluate.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void evaluate() {
    System.out.println("Evaluating neural network...");
    //Loading neural network from file
    MultiLayerPerceptron neuralNet = (MultiLayerPerceptron) NeuralNetwork.createFromFile(config.getTrainedNetworkFileName());

    //Load normalized balanced data set from file
    DataSet dataSet = DataSet.load(config.getTestFileName());

    //Testing neural network
    testNeuralNetwork(neuralNet, dataSet);

}
 
Example #26
Source File: ConceptLearningAndClassificationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public 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.println(" Output: " + Arrays.toString(networkOutput));
        }
    }
 
Example #27
Source File: GraphmlExport.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Labels neurons which are yet unlabelled. 
 *  
 * @param ann
 */
private void labelUnmarkedNeurons( final NeuralNetwork ann ) {

	for( int layer = 0; layer < ann.getLayersCount(); layer++ ) {
		
		int neuronCount = 0; 
		for( Neuron neuron : ann.getLayerAt( layer ).getNeurons()  ) {
		
			labelNeuron(layer, neuronCount, neuron);
			neuronCount++;  
		}
	}
}
 
Example #28
Source File: IOHelper.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Feeds specified neural network with data from InputAdapter and writes
 * output using OutputAdapter
 * @param neuralNet neural network
 * @param in input data source
 * @param out output data target  
 */
public static void process(NeuralNetwork neuralNet, InputAdapter in, OutputAdapter out) {
   
    double[] input;
    while( (input = in.readInput()) != null) {
        neuralNet.setInput(input);
        neuralNet.calculate();  
        double[] output = neuralNet.getOutput();
        out.writeOutput(output);
    }
    
    in.close();
    out.close();         
}
 
Example #29
Source File: GermanCreditDataSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'Good credit risk' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'Bad credit risk' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
    }
 
Example #30
Source File: ForestFiresSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public 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.println(" Output: " + Arrays.toString(networkOutput));
        }
    }