# Licensed under the Apache License, Version 2.0 (the "License");
# based on http://www.heatonresearch.com/encog/
"""
/**
* 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:
*
**/
"""
from org.encog import Encog
from org.encog.util.csv import CSVFormat
from org.encog.util.simple import EncogUtility,TrainingSetUtil
# create data file
data="""
0,0,0
1,0,1
0,1,1
1,1,0
"""
name="test.csv"
fi=open(name, "w")
fi.write(data)
fi.close()
trainingSet=TrainingSetUtil.loadCSVTOMemory(CSVFormat.ENGLISH,name,False,2,1)
network=EncogUtility.simpleFeedForward(2,4,0,1,True)
EncogUtility.trainToError(network, trainingSet, 0.01)
EncogUtility.evaluate(network, trainingSet)
Encog.getInstance().shutdown()
Ads help maintain this website.