private XorTrResult trainByTwoNeuronsBySigmoid() { Debug.WriteLine("Działa"); float[,] inputs = { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } }; float[] results = { 0, 1, 1, 0 }; Neuron hiddenNeuron1 = new Neuron(); Neuron hiddenNeuron2 = new Neuron(); Neuron outputNeuron = new Neuron(); List <String> raport = new List <String>(); hiddenNeuron1.randomizeWeights(); raport.Add("Inicjalizacja: "); raport.Add("hiddenNeuron1.weights[0]: " + hiddenNeuron1.weights[0]); raport.Add("hiddenNeuron1.weights[1]: " + hiddenNeuron1.weights[1]); hiddenNeuron2.randomizeWeights(); raport.Add("hiddenNeuron2.weights[0]: " + hiddenNeuron2.weights[0]); raport.Add("hiddenNeuron2.weights[1]: " + hiddenNeuron2.weights[1]); outputNeuron.randomizeWeights(); raport.Add("outputNeuron.weights[0]: " + outputNeuron.weights[0]); raport.Add("outputNeuron.weights[1]: " + outputNeuron.weights[1]); bool isChanged = true; int epochs = 0; while (isChanged) { isChanged = false; for (int i = 0; i < 4; i++) { // 1) forward propagation (calculates output) hiddenNeuron1.inputs = new float[] { inputs[i, 0], inputs[i, 1] }; hiddenNeuron2.inputs = new float[] { inputs[i, 0], inputs[i, 1] }; outputNeuron.inputs = new float[] { hiddenNeuron1.output(), hiddenNeuron2.output() }; float result = outputNeuron.output(); Debug.WriteLine("{0} xor {1} = {2}", inputs[i, 0], inputs[i, 1], result); // 2) back propagation (adjusts weights) // adjusts the weight of the output neuron, based on its error result = activationFunctions.correctionForSigmoid(result); Debug.WriteLine("output po korekcji: " + result); if (result != results[i]) { isChanged = true; outputNeuron.error = Sigmoid.derivative(outputNeuron.output()) * (results[i] - outputNeuron.output()); outputNeuron.adjustWeights(trainingSetings.learningRate); // then adjusts the hidden neurons' weights, based on their errors hiddenNeuron1.error = Sigmoid.derivative(hiddenNeuron1.output()) * outputNeuron.error * outputNeuron.weights[0]; hiddenNeuron2.error = Sigmoid.derivative(hiddenNeuron2.output()) * outputNeuron.error * outputNeuron.weights[1]; hiddenNeuron1.adjustWeights(trainingSetings.learningRate); hiddenNeuron2.adjustWeights(trainingSetings.learningRate); raport.Add("Zmiana wag: "); raport.Add("hiddenNeuron1.weights[0]: " + hiddenNeuron1.weights[0]); raport.Add("hiddenNeuron1.weights[1]: " + hiddenNeuron1.weights[1]); raport.Add("hiddenNeuron2.weights[0]: " + hiddenNeuron2.weights[0]); raport.Add("hiddenNeuron2.weights[1]: " + hiddenNeuron2.weights[1]); raport.Add("outputNeuron.weights[0]: " + outputNeuron.weights[0]); raport.Add("outputNeuron.weights[1]: " + outputNeuron.weights[1]); } } epochs++; } raport.Add("Ilość epochs: " + epochs); return(new XorTrResult(hiddenNeuron1, hiddenNeuron2, outputNeuron, raport)); }