Exemplo n.º 1
0
        /*
         * Calcula distância euclidiana do padrão de entrada
         */
        public double GetEuclideanDistance(DataSetObject pattern)
        {
            double dist = 0;

            if (pattern.GetInputLenght() != weights.Length)
            {
                throw new Exception("Incorrect data format!");
            }
            else
            {
                double[] inputWeights = pattern.GetInput();

                if (weights.Length != inputWeights.Length)
                {
                    throw new Exception("Incorrect data format!");
                }
                else
                {
                    for (int x = 0; x < weights.Length; x++)
                    {
                        dist += ((inputWeights[x] - weights[x]) * (inputWeights[x] - weights[x]));
                    }
                }
            }
            return(dist);
        }
Exemplo n.º 2
0
        /*
         * Dado um padrão de entrada e uma variável de aprendizado, atualiza os pesos do neurônio
         */
        public void UpdateWeights(DataSetObject pattern, double learningRate)
        {
            if (pattern.GetInputLenght() != weights.Length)
            {
                throw new Exception("Incorrect data format!");
            }
            else
            {
                double[] inputWeights = pattern.GetInput();

                for (int i = 0; i < inputWeights.Length; i++)
                {
                    weights[i] += learningRate * (inputWeights[i] - weights[i]);
                }
            }
        }