public void AddDataAfterEducate(NeuralNetworkObj neuralNetworkObj, Dictionary <double[], double[]> prepareData) { data.Add("#########################################"); data.Add("#########################################"); int id = 1; foreach (var entity in prepareData) { double[] inputVector = entity.Key; double[] expectedResultVector = entity.Value; neuralNetworkObj.Clear(); neuralNetworkObj.SetInputVector(inputVector); neuralNetworkObj.Process(); double[] resultVector = GetResultVector(neuralNetworkObj); data.Add($"ID: {id}"); data.Add($"Epoch: {neuralNetworkObj.GetCountEpochPassed()} (After educate)"); data.Add($"Error: {this.errorMethod.GetError(expectedResultVector, resultVector).ToString()}"); data.Add("Expected Result:"); foreach (var item in expectedResultVector) { data.Add(item.ToString()); } data.Add("Result:"); foreach (var item in resultVector) { data.Add(item.ToString()); } data.Add("#########################################"); id++; } }
private double[] GetResultVector(NeuralNetworkObj neuralNetworkObj, double[] inputVector) { double[] result = new double[neuralNetworkObj.GetLastLayer().GetCountNeurons()]; neuralNetworkObj.Clear(); neuralNetworkObj.SetInputVector(inputVector); neuralNetworkObj.Process(); List <NeuralNetwork.NeuronObj> neurons = neuralNetworkObj.GetLastLayer().GetListNeurons(); for (int i = 0; i < neurons.Count; i++) { result[i] = neurons[i].GetOutputData(); } return(result); }
public int GetAnswer(double[] inputVector) { if (inputVector.Length != INPUT_VECTOR_LENGTH) { throw new Exception("Invalid input vector length."); } NeuralNetworkObj neuralNetwork = this.GetNeuralNetwork(); neuralNetwork.SetInputVector(inputVector); neuralNetwork.Process(); if (neuralNetwork.GetLastLayer().GetNeuronById(1).GetOutputData() >= MIN_CORRECT_ANSWER) { return(1); } return(0); }
public int GetNumberFromImgVector(double[] inputVector) { if (inputVector.Length != this.countNeuronsInFirstLayer) { throw new Exception("Invalid input vector length."); } NeuralNetworkObj neuralNetworkObj = this.GetNeuralNetwork(); neuralNetworkObj.Clear(); neuralNetworkObj.SetInputVector(inputVector); neuralNetworkObj.Process(); foreach (NeuronObj neuron in neuralNetworkObj.GetLastLayer().GetListNeurons()) { if (neuron.GetOutputData() > MINIMUM_OUTPUT_DATA_FOR_SUCCESS_RESULT) { return(neuron.Id); } } return(-1); }