예제 #1
0
 public Neuron(string filePath)
 {
     Letter  = Path.GetFileNameWithoutExtension(filePath);
     Weights = LetterExtensions.ReadLetterFromFile(filePath);
     VectorExtensions.NormalizeVector(Weights);
     Console.WriteLine("Wczytano szablon litery " + filePath);
 }
예제 #2
0
        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");
            }
        }