package com.core.perceptron; import java.util.Arrays; import org.neuroph.core.*; import org.neuroph.core.data.*; import org.neuroph.nnet.MultiLayerPerceptron; import org.neuroph.util.TransferFunctionType; public class XORDemo { public static void main(String[] args){ DataSet trainingSet = new DataSet(2, 1); trainingSet.addRow(new DataSetRow(new double[]{0, 0}, new double[] {0})); trainingSet.addRow(new DataSetRow(new double[]{0, 1}, new double[] {1})); trainingSet.addRow(new DataSetRow(new double[]{1, 0}, new double[] {1})); trainingSet.addRow(new DataSetRow(new double[]{1, 1}, new double[] {0})); MultiLayerPerceptron myMLP = new MultiLayerPerceptron(TransferFunctionType.TANH, 2 ,3 ,1); System.out.println("Training network..."); myMLP.learn(trainingSet); System.out.println("Testing network"); testNeuralNetwork(myMLP, trainingSet); } public static void testNeuralNetwork(NeuralNetwork nnet, DataSet tset) { for (DataSetRow dataRow : tset.getRows()) { nnet.setInput(dataRow.getInput()); nnet.calculate(); double[ ] networkOutput = nnet.getOutput(); System.out.print("Input: " + Arrays.toString(dataRow.getInput()) ); System.out.println(" Output: " + Arrays.toString(networkOutput) ); } } }
导入neuroph-core-2.93.jar neuroph-imgrec-2.93.jar neuroph-ocr-2.93.jar及slf4j
原文:http://www.cnblogs.com/cnlixl/p/7096603.html