Read a CSV file and do beckpropogation with encog
Code: "neural_net_encog1.java". Programming language: Java DMelt Version 1. Last modified: 10/25/2015. License: Pro
https://datamelt.org/code/cache/neural_net_encog1_7368.java
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



/*
 * Encog(tm) Examples v3.1 - Java Version
 * http://www.heatonresearch.com/encog/
 * http://code.google.com/p/encog-java/
 
 * Copyright 2008-2012 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
 */

import org.encog.Encog;
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 neural_net_encog1 {

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

		if (args.length == 0) {
			System.out.println("Usage:\n\nXORCSV [xor.csv]");
		} else {
			final MLDataSet trainingSet = TrainingSetUtil.loadCSVTOMemory(
					CSVFormat.ENGLISH, args[0], 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);
		}
		Encog.getInstance().shutdown();
	}
}

Ads help maintain this website.