首页 > 其他 > 详细

neuroph实现感知机 计算xor问题

时间:2017-06-29 23:16:57      阅读:636      评论:0      收藏:0      [点我收藏+]
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

neuroph实现感知机 计算xor问题

原文:http://www.cnblogs.com/cnlixl/p/7096603.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!