Package org.encog.examples.neural.csv

Source Code of org.encog.examples.neural.csv.XORCSV

/*
* Encog(tm) Examples v3.0 - Java Version
* http://www.heatonresearch.com/encog/
* http://code.google.com/p/encog-java/
* Copyright 2008-2011 Heaton Research, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*  
* For more information on Heaton Research copyrights, licenses
* and trademarks visit:
* http://www.heatonresearch.com/copyright
*/
package org.encog.examples.neural.csv;

import org.encog.ml.data.MLDataSet;
import org.encog.neural.networks.BasicNetwork;
import org.encog.util.csv.CSVFormat;
import org.encog.util.simple.EncogUtility;
import org.encog.util.simple.TrainingSetUtil;

/**
* XOR: This example is essentially the "Hello World" of neural network
* programming. This example shows how to construct an Encog neural network to
* predict the output from the XOR operator. This example uses resilient
* propagation (RPROP) to train the neural network. RPROP is the best general
* purpose supervised training method provided by Encog.
*
* For the XOR example with RPROP I use 4 hidden neurons. XOR can get by on just
* 2, but often the random numbers generated for the weights are not enough for
* RPROP to actually find a solution. RPROP can have issues on really small
* neural networks, but 4 neurons seems to work just fine.
*
* This example reads the XOR data from a CSV file. This file should be
* something like:
*
* 0,0,0
* 1,0,1
* 0,1,1
* 1,1,0
*/
public class XORCSV {

  public static void main(final String args[]) {

    final MLDataSet trainingSet = TrainingSetUtil.loadCSVTOMemory(
        CSVFormat.ENGLISH, "c:\\temp\\xor.csv", false, 2, 1);
    final BasicNetwork network = EncogUtility.simpleFeedForward(2, 4, 0, 1,
        true);

    System.out.println();
    System.out.println("Training Network");
    EncogUtility.trainToError(network, trainingSet, 0.01);

    System.out.println();
    System.out.println("Evaluating Network");
    EncogUtility.evaluate(network, trainingSet);
  }
}
TOP

Related Classes of org.encog.examples.neural.csv.XORCSV

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.