zoukankan      html  css  js  c++  java
  • neuroph实现感知机 计算xor问题

    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

  • 相关阅读:
    20200630(A--E)题解 by 王文硕
    20200629(A--E)题解 by 章思航
    GC垃圾回收
    Codeforces Round #629 (Div. 3) A、B、C
    AtomicInteger的Increment方法的自己实现。
    两个线程,一个输出字母一个输出数字,输出A1B2C3....Z26
    NIO记录
    mysql优化相关
    一些Nginx的Linux命令和conf配置文件
    docker记录
  • 原文地址:https://www.cnblogs.com/cnlixl/p/7096603.html
Copyright © 2011-2022 走看看