public Neuron(string filePath) { Letter = Path.GetFileNameWithoutExtension(filePath); Weights = LetterExtensions.ReadLetterFromFile(filePath); VectorExtensions.NormalizeVector(Weights); Console.WriteLine("Wczytano szablon litery " + filePath); }
public void Process(double[] inputVector) { if (letterSize != inputVector.Length) { throw new ArgumentException("Wprowadzony znak ma niepoprawny rozmiar matrycy"); } VectorExtensions.NormalizeVector(inputVector); var outputValues = new double[Neurons.Count]; for (int i = 0; i < Neurons.Count; i++) { var neuron = Neurons[i]; for (int j = 0; j < Neurons[i].Weights.Length; j++) { outputValues[i] += neuron.Weights[j] * inputVector[j]; } } for (int i = 0; i < outputValues.Length; i++) { Console.WriteLine("{0}, zgodność w {1:P}", Neurons[i].Letter, outputValues[i]); } var maxValue = outputValues.Max(); if (maxValue > 0) { var indexOfMaxValue = Array.IndexOf(outputValues, maxValue); Console.WriteLine("Rozpoznana litera: " + Neurons[indexOfMaxValue].Letter); } else { Console.WriteLine("Nie rozpoznano litery"); } }