Ma sortie est très mauvaise. Réel n'est pas égal idéal. Quels codes ont tort?Comment utiliser la méthode d'apprentissage Java Encog with GA pour résoudre XOR?
Ma sortie:
Epoch #129 Error:8.755514431853456E-6
Neural Network Results:
0.0,0.0, actual=0.57600,ideal=0.0
1.0,0.0, actual=0.58016,ideal=1.0
0.0,1.0, actual=0.58886,ideal=1.0
1.0,1.0, actual=0.59317,ideal=0.0
Voici mon code:
public class XOR {
public static double XOR_INPUT[][] = { { 0.0, 0.0 }, { 1.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 } };
/**
* The ideal data necessary for XOR.
*/
public static double XOR_IDEAL[][] = { { 0.0 }, { 1.0 }, { 1.0 }, { 0.0 } };
//public static BasicNetwork network = new BasicNetwork();
public static BasicNetwork createNetwork()
{
// create a neural network, without using a factory
BasicNetwork network = new BasicNetwork();
network.addLayer(new BasicLayer(null,true,2));
network.addLayer(new BasicLayer(new ActivationSigmoid(),true,3));
network.addLayer(new BasicLayer(new ActivationSigmoid(),false,1));
network.getStructure().finalizeStructure();
network.reset();
return network;
}
/**
* The main method.
* @param args No arguments are used.
*/
public static void main(final String args[]) {
BasicNetwork network = createNetwork();
MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
// train the neural network
CalculateScore score = new TrainingSetScore(trainingSet);
MLTrain train = new MLMethodGeneticAlgorithm(new MethodFactory(){
@Override
public MLMethod factor() {
final BasicNetwork result = createNetwork();
((MLResettable)result).reset();
return result;
}}, score, 500);
int epoch = 1;
do {
train.iteration();;
System.out
.println("Epoch #" + epoch + " Error:" + train.getError());
epoch++;
} while(train.getError() > 0.01);
// test the neural network
System.out.println("Neural Network Results:");
for(MLDataPair pair: trainingSet) {
final MLData output = network.compute(pair.getInput());
System.out.println(pair.getInput().getData(0) + "," + pair.getInput().getData(1)
+ ", actual=" + output.getData(0) + ",ideal=" + pair.getIdeal().getData(0));
}
}
}
Je travaille très bien. Merci beaucoup. – icashwave