Java Code Examples for org.neuroph.core.NeuralNetwork#getOutput()

The following examples show how to use org.neuroph.core.NeuralNetwork#getOutput() . 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: 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 2
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 3
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 4
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 5
Source File: BalanceScaleSample.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 6
Source File: ConcreteStrenghtTestSample.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 7
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 8
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 9
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 10
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));
        }
    }
 
Example 11
Source File: ShuttleLandingControlSample.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 12
Source File: Banknote.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: " + Arrays.toString(networkOutput));
            System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput()));
        }
    }
 
Example 13
Source File: XorMultiLayerPerceptronSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Prints network output for the each element from the specified training set.
 * @param neuralNet neural network
 * @param testSet test 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.println(" Output: " + Arrays.toString( networkOutput) );
    }
}
 
Example 14
Source File: WheatSeeds.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: " + Arrays.toString(networkOutput));
            System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput()));
        }
    }
 
Example 15
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 16
Source File: Evaluate.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();

            //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[7] + ". ");
        System.out.println("Correct cases: " + this.correct[7] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[7] - this.correct[7] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");

        double percentTotal = (double) this.correct[7] * 100 / (double) this.count[7];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        for (int i = 0; i < correct.length - 1; i++) {
            double p = (double) this.correct[i] * 100.0 / (double) this.count[i];
            System.out.println("Tree type: " + (i + 1) + " - Correct/total: "
                    + this.correct[i] + "/" + count[i] + "(" + formatDecimalNumber(p) + "%). ");
        }
    }
 
Example 17
Source File: GlassIdentificationSample.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 18
Source File: PredictingPokerHandsSample.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 19
Source File: SunSpots.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
/**
 * Predict sunspots.
 * @param network Neural network to use.
 */
public void predict(NeuralNetwork network) {
	NumberFormat f = NumberFormat.getNumberInstance();
	f.setMaximumFractionDigits(4);
	f.setMinimumFractionDigits(4);

	System.out.println("Year\tActual\tPredict\tClosed Loop Predict");

	for (int year = EVALUATE_START; year < EVALUATE_END; year++) {
		// calculate based on actual data
		double[] input = new double[WINDOW_SIZE];
		for (int i = 0; i < input.length; i++) {
			input[i] = this.normalizedSunspots[(year - WINDOW_SIZE) + i];
		}

		network.setInput(input);
		network.calculate();

		double[] output = network.getOutput();
		double prediction = output[0];
		this.closedLoopSunspots[year] = prediction;

		// calculate "closed loop", based on predicted data
		for (int i = 0; i < input.length; i++) {
			input[i] = this.closedLoopSunspots[(year - WINDOW_SIZE) + i];
		}

		network.setInput(input);
		network.calculate();
		output = network.getOutput();

		double closedLoopPrediction = output[0];

		// display
		System.out.println((STARTING_YEAR + year) + "\t"
				+ f.format(this.normalizedSunspots[year]) + "\t"
				+ f.format(prediction) + "\t"
				+ f.format(closedLoopPrediction));

	}
}
 
Example 20
Source File: McNemarTest.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
/**
     * @param network1 first trained neurl netowrk
     * @param network2 second trained neural network
     * @param dataSet  data set used for performance evaluation
     * @return if there exists significant difference between two classification models
     */
    public boolean evaluateNetworks(NeuralNetwork network1, NeuralNetwork network2, DataSet dataSet) {
        for (DataSetRow dataRow : dataSet.getRows()) {
            forwardPass(network1, dataRow);
            forwardPass(network2, dataRow);
           
            double[] networkOutput1 = network1.getOutput();
            double[] networkOutput2 = network2.getOutput();
            
            int maxNeuronIdx1 = Utils.maxIdx(networkOutput1);
            int maxNeuronIdx2 = Utils.maxIdx(networkOutput2);         
            
            ClassificationResult output1 = new ClassificationResult(maxNeuronIdx1, networkOutput1[maxNeuronIdx1]);
            ClassificationResult output2 = new ClassificationResult(maxNeuronIdx2, networkOutput2[maxNeuronIdx2]);     

//            ClassificationResult output1 = ClassificationResult.fromMaxOutput(network1.getOutput());
//            ClassificationResult output2 = ClassificationResult.fromMaxOutput(network2.getOutput());

            //are their results different
            if (output1.getClassIdx() != output2.getClassIdx()) {
                //if first one is correct and second incorrect
                if (output1.getClassIdx() == getDesiredClass(dataRow.getDesiredOutput())) {
                    contigencyMatrix[1][0]++;
                    //if first is incorrect and second is correct
                } else {
                    contigencyMatrix[0][1]++;
                }
            } else {
                //if both are correct
                if (output1.getClassIdx() == getDesiredClass(dataRow.getDesiredOutput())) {
                    contigencyMatrix[1][1]++;
                    //if both are incorrect
                } else {
                    contigencyMatrix[0][0]++;
                }
            }
        }

        printContingencyMatrix();

        double a = Math.abs(contigencyMatrix[0][1] - contigencyMatrix[1][0]) - 1;
        double hiSquare = (a * a) / (contigencyMatrix[0][1] + contigencyMatrix[1][0]);


        System.out.println(hiSquare);
        return hiSquare > 3.841;
    }