/*Updating weight equation*/ public double UpdateWeights(double[] pattern, Neuron winner, int it) { double sum = 0; for (int i = 0; i < Weights.Length; i++) { double delta = LearningRate(it) * Gauss(winner, it) * (pattern[i] - Weights[i]); Weights[i] += delta; sum += delta; } return sum / Weights.Length; }
/*gaussian function*/ private double Gauss(Neuron win, int it) { //euclidean distance double distance = Math.Sqrt(Math.Pow(win.X - X, 2) + Math.Pow(win.Y - Y, 2)); return Math.Exp(-Math.Pow(distance, 2) / (Math.Pow(Strength(it), 2))); }
private void Initialise() { Console.WriteLine("Neuron Initialized.... "); outputs = new Neuron[length, length]; for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { outputs[i, j] = new Neuron(i, j, length); Console.WriteLine("Output Neuron {0}: [{1},{2}] weight:", i, outputs[i, j].X, outputs[i, j].Y); outputs[i, j].Weights = new double[dimensions]; for (int k = 0; k < dimensions; k++) { outputs[i, j].Weights[k] = rnd.NextDouble(); Console.Write("{0:N2} ", outputs[i, j].Weights[k]); } } } }