コード例 #1
0
 /// <summary>
 /// This method implements weights update procedure for the single neuron 
 /// </summary>
 /// <param name="neuron">neuron to update weights for</param>
 protected override void UpdateNeuronWeights(Neuron neuron)
 {
     double output = neuron.Output;
     foreach (Connection connection in neuron.InputConnections)
     {
         double input = connection.Input;
         double weight = connection.ConnectionWeight.Value;
         double deltaWeight = this.LearningRate * output * (input - weight);
         connection.ConnectionWeight.Inc(deltaWeight);
     }
 }
コード例 #2
0
ファイル: LMS.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// This method implements weights update procedure for the single neuron 
 /// </summary>
 /// <param name="neuron">neuron to update weights</param>
 protected virtual void UpdateNeuronWeights(Neuron neuron)
 {
     // get the error for specified neuron
     double neuronError = neuron.Error;
     // iterate through all neuron's input connections
     foreach (Connection connection in neuron.InputConnections)
     {
         // get the input from current connection
         double input = connection.Input;
         // calculate the weight change
         double deltaWeight = this.LearningRate * neuronError * input;
         // apply the weight change
         connection.ConnectionWeight.Inc(deltaWeight);
     }
 }
コード例 #3
0
        /// <summary>
        /// This method implements weights update procedure for the single neuron
        /// In addition to weights change in LMS it applies change to neuron's threshold 
        /// </summary>
        /// <param name="neuron">neuron to update weights</param>
        protected override void UpdateNeuronWeights(Neuron neuron)
        {
            // adjust the input connection weights with method from superclass
            base.UpdateNeuronWeights(neuron);

            // and adjust the neurons threshold
            ThresholdNeuron thresholdNeuron = (ThresholdNeuron)neuron;
            // get neurons error
            double neuronError = thresholdNeuron.Error;
            // get the neurons threshold
            double thresh = thresholdNeuron.Thresh;
            // calculate new threshold value
            thresh = thresh - this.LearningRate * neuronError;
            // apply the new threshold
            thresholdNeuron.Thresh = thresh;
        }
コード例 #4
0
        /// <summary>
        /// This method implements weights update procedure for the single neuron 
        /// </summary>
        /// <param name="neuron">neuron to update weights</param>
        protected override void UpdateNeuronWeights(Neuron neuron)
        {
            double output = neuron.Output;
            foreach (Connection connection in neuron.InputConnections)
            {
                double input = connection.Input;

                if (((input > 0) && (output > 0)) || ((input <= 0) && (output <= 0)))
                {
                    connection.ConnectionWeight.Inc(this.LearningRate);
                }
                else
                {
                    connection.ConnectionWeight.Dec(this.LearningRate);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// This method implements weights update procedure for the single neuron
        /// for the backpropagation with momentum factor 
        /// </summary>
        /// <param name="neuron">neuron to update weights</param>
        protected override void UpdateNeuronWeights(Neuron neuron)
        {
            foreach (Connection connection in neuron.InputConnections)
            {
                double input = connection.Input;
                if (input == 0)
                {
                    continue;
                }
                double neuronError = neuron.Error;

                Weight weight = connection.ConnectionWeight;

                double currentWeighValue = weight.Value;
                double previousWeightValue = weight.PreviousValue;
                double deltaWeight = this.LearningRate * neuronError * input +
                    Momentum * (currentWeighValue - previousWeightValue);

                weight.PreviousValue = currentWeighValue;
                weight.Inc(deltaWeight);
            }
        }
コード例 #6
0
ファイル: Connection.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Creates a new connection to specified neuron with specified weight object
 /// </summary>
 /// <param name="connectTo">neuron to connect to</param>
 /// <param name="weight">weight for this connection</param>
 public Connection(Neuron fromNeuron, Neuron toNeuron, double weightValue)
 {
     this.fromNeuron = fromNeuron;
     this.toNeuron = toNeuron;
     this.weight = new Weight(weightValue);
 }
コード例 #7
0
ファイル: Layer.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Adds specified neuron to this layer 
 /// </summary>
 /// <param name="neuron">neuron to add</param>
 public void AddNeuron(Neuron neuron)
 {
     neuron.ParentLayer = this;
     this.neurons.Add(neuron);
 }
コード例 #8
0
ファイル: Connection.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Creates a new connection to specified neuron with specified weight object
 /// </summary>
 /// <param name="connectTo">neuron to connect to</param>
 /// <param name="weight">weight for this connection</param>
 public Connection(Neuron fromNeuron, Neuron toNeuron, Weight weight)
 {
     this.fromNeuron = fromNeuron;
     this.toNeuron = toNeuron;
     this.weight = weight;
 }
コード例 #9
0
ファイル: Connection.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Creates a new connection between specified neurons with random weight value
 /// </summary>
 /// <param name="fromNeuron">neuron to connect</param>
 /// <param name="toNeuron">neuron to connect to</param>
 public Connection(Neuron fromNeuron, Neuron toNeuron)
 {
     this.fromNeuron = fromNeuron;
     this.toNeuron = toNeuron;
     this.weight = new Weight();
 }
コード例 #10
0
ファイル: BiasNeuron.cs プロジェクト: mikowiec/sharpneuroph
 public override void AddInputConnection(Neuron fromNeuron, double weightVal)
 {
 }
コード例 #11
0
ファイル: Neuron.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Removes input connection which is connected to specified neuron 
 /// </summary>
 /// <param name="fromNeuron">neuron which is connected as input</param>
 public virtual void RemoveInputConnectionFrom(Neuron fromNeuron)
 {
     foreach (Connection connection in this.inputConnections)
     {
         if (connection.FromNeuron == fromNeuron)
         {
             this.inputConnections.Remove(connection);
             return;
         }
     }
 }
コード例 #12
0
ファイル: Layer.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Returns the index position in layer for the specified neuron 
 /// </summary>
 /// <param name="neuron">neuron object</param>
 /// <returns>index position of specified neuron</returns>
 public int IndexOf(Neuron neuron)
 {
     return this.neurons.IndexOf(neuron);
 }
コード例 #13
0
ファイル: Layer.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Sets (replace) the neuron at specified position in layer 
 /// </summary>
 /// <param name="idx">index position to set/replace</param>
 /// <param name="neuron">new Neuron object to set</param>
 public void SetNeuron(int idx, Neuron neuron)
 {
     neuron.ParentLayer = this;
     this.neurons[idx] = neuron;
 }
コード例 #14
0
 private void AdjustCellWeights(Neuron cell, int r)
 {
     IEnumerator<Connection> i = cell.GetInputsEnumerator();
     while (i.MoveNext())
     {
         Connection conn = i.Current;
         double dWeight = (LearningRate / (r + 1))
                 * (conn.Input - conn.ConnectionWeight.Value);
         conn.ConnectionWeight.Inc(dWeight);
     }// while
 }
コード例 #15
0
        /// <summary>
        /// This method implements weights update procedure for the single neuron 
        /// </summary>
        /// <param name="neuron">neuron to update weights</param>
        protected virtual void UpdateNeuronWeights(Neuron neuron)
        {
            double output = neuron.Output;

            foreach (Connection connection in neuron.InputConnections)
            {
                double input = connection.Input;
                double deltaWeight = input * output * this.LearningRate;
                connection.ConnectionWeight.Inc(deltaWeight);
            }
        }
コード例 #16
0
ファイル: BiasNeuron.cs プロジェクト: mikowiec/sharpneuroph
 public override void AddInputConnection(Neuron fromNeuron)
 {
 }
コード例 #17
0
 /// <summary>
 /// Creates an instance of delayed connection to cpecified neuron and
 /// with specified weight 
 /// </summary>
 /// <param name="connectTo">neuron to connect ti</param>
 /// <param name="weightVal">weight value for the connection</param>
 /// <param name="delay">delay for the connection</param>
 public DelayedConnection(Neuron fromNeuron, Neuron toNeuron, double weightVal, int delay)
     : base(fromNeuron, toNeuron, weightVal)
 {
     this.delay = delay;
 }
コード例 #18
0
 /// <summary>
 /// Creates connection between two specified neurons
 /// </summary>
 /// <param name="from">output neuron</param>
 /// <param name="to">input neuron</param>
 /// <param name="weight">connection weight</param>
 public static void CreateConnection(Neuron from, Neuron to, Weight weight)
 {
     Connection connection = new Connection(from, to, weight);
     to.AddInputConnection(connection);
 }
コード例 #19
0
 public static void CreateConnection(Neuron from, Neuron to, double weightVal, int delay)
 {
     DelayedConnection connection = new DelayedConnection(from, to, weightVal, delay);
     to.AddInputConnection(connection);
 }
コード例 #20
0
 /// <summary>
 /// Creates connection with specified weight value between specified neurons
 /// </summary>
 /// <param name="fromNeuron">neuron to connect</param>
 /// <param name="toNeuron">neuron to connect to</param>
 /// <param name="weightVal">connection weight value</param>
 public void CreateConnection(Neuron fromNeuron, Neuron toNeuron, double weightVal)
 {
     Connection connection = new Connection(fromNeuron, toNeuron, weightVal);
     toNeuron.AddInputConnection(connection);
 }
コード例 #21
0
 // get unit with closetst weight vector
 private Neuron GetClosest()
 {
     IEnumerator<Neuron> i = this.NeuralNetwork.GetLayerAt(1)
             .GetNeuronsEnumerator();
     Neuron winner = new Neuron();
     double minOutput = 100;
     while (i.MoveNext())
     {
         Neuron n = i.Current;
         double o = n.Output;
         if (o < minOutput)
         {
             minOutput = o;
             winner = n;
         } // if
     } // while
     return winner;
 }
コード例 #22
0
 /// <summary>
 /// This method implements weights update procedure for the single neuron
 /// </summary>
 /// <param name="neuron">neuron to update weights</param>
 /// <param name="desiredOutput"></param>
 protected void UpdateNeuronWeights(Neuron neuron, double desiredOutput)
 {
     foreach (Connection connection in neuron.InputConnections)
     {
         double input = connection.Input;
         double deltaWeight = input * desiredOutput * this.LearningRate;
         connection.ConnectionWeight.Inc(deltaWeight);
     }
 }
コード例 #23
0
ファイル: Layer.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Adds specified neuron to this layer,at specified index position
 /// </summary>
 /// <param name="idx">neuron to add</param>
 /// <param name="neuron">index position at which neuron should be added</param>
 public void AddNeuron(int idx, Neuron neuron)
 {
     neuron.ParentLayer = this;
     this.neurons.Insert(idx, neuron);
 }
コード例 #24
0
ファイル: Neuron.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Adds input connection from specified neuron 
 /// </summary>
 /// <param name="fromNeuron">neuron to connect from</param>
 public virtual void AddInputConnection(Neuron fromNeuron)
 {
     Connection connection = new Connection(fromNeuron, this);
     this.AddInputConnection(connection);
 }
コード例 #25
0
ファイル: Layer.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Removes neuron from layer
 /// </summary>
 /// <param name="neuron">neuron to remove</param>
 public void RemoveNeuron(Neuron neuron)
 {
     this.neurons.Remove(neuron);
 }
コード例 #26
0
ファイル: Neuron.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Adds input connection with the given weight, from given neuron 
 /// </summary>
 /// <param name="fromNeuron">neuron to connect from</param>
 /// <param name="weightVal">connection weight value</param>
 public virtual void AddInputConnection(Neuron fromNeuron, double weightVal)
 {
     Connection connection = new Connection(fromNeuron, this, weightVal);
     this.AddInputConnection(connection);
 }
コード例 #27
0
ファイル: Neuron.cs プロジェクト: mikowiec/sharpneuroph
 /// <summary>
 /// Gets input connection from the specified neuron * @param fromNeuron
 /// neuron connected to this neuron as input 
 /// </summary>
 /// <param name="fromNeuron"></param>
 /// <returns></returns>
 public virtual Connection GetConnectionFrom(Neuron fromNeuron)
 {
     foreach (Connection connection in this.inputConnections)
     {
         if (connection.FromNeuron == fromNeuron)
             return connection;
     }
     return null;
 }
コード例 #28
0
        /// <summary>
        /// Calculates and returns delta parameter (neuron error) for the specified
        /// neuron 
        /// </summary>
        /// <param name="neuron">neuron to calculate error for</param>
        /// <returns>(neuron error) for the specified neuron</returns>
        private double CalculateDelta(Neuron neuron)
        {
            IList<Connection> connectedTo = ((Neuron)neuron).OutConnections;

            double delta_sum = 0d;
            foreach (Connection connection in connectedTo)
            {
                double d = connection.ToNeuron.Error
                        * connection.ConnectionWeight.Value;
                delta_sum += d; // weighted sum from the next layer
            } // for

            TransferFunction transferFunction = neuron.TransferFunction;
            double netInput = neuron.NetInput;
            double f1 = transferFunction.CalculateDerivative(netInput);
            double delta = f1 * delta_sum;
            return delta;
        }