Пример #1
0
        /// <summary>
        /// Propagates a weight update event upstream through the network.
        /// </summary>
        /// <param name="properties">Network training properties.</param>
        /// <param name="networkTrainer">Network training method.</param>
        public override void Update(NetworkTrainingProperties properties, INetworkTrainer networkTrainer)
        {
            double lm = (properties.Lambda / (int)properties[nameof(GatedRecurrentGenerator.SequenceLength)]);

            if (!this.Constrained)
            {
                this.Rx = networkTrainer.Update(this.NodeId, this.NodeId, nameof(this.Rx), this.Rx, this.DRx, properties);
                this.Rh = networkTrainer.Update(this.NodeId, this.NodeId, nameof(this.Rh), this.Rh, this.DRh, properties);

                this.Zx = networkTrainer.Update(this.NodeId, this.NodeId, nameof(this.Zx), this.Zx, this.DZx, properties);
                this.Zh = networkTrainer.Update(this.NodeId, this.NodeId, nameof(this.Zh), this.Zh, this.DZh, properties);

                this.Hh = networkTrainer.Update(this.NodeId, this.NodeId, nameof(this.Hh), this.Hh, this.DHh, properties);
            }

            for (int edge = 0; edge < this.In.Count; edge++)
            {
                Delta = (1.0 / properties.Examples) * Delta;

                if (!this.In[edge].Source.IsBias)
                {
                    Delta = Delta + (lm * this.In[edge].Weight);
                }

                if (!this.Constrained)
                {
                    this.In[edge].Weight = networkTrainer.Update(this.In[edge].ParentId, this.In[edge].ChildId,
                                                                 nameof(Edge.Weight), this.In[edge].Weight, Delta, properties);
                }

                this.In[edge].Source.Update(properties, networkTrainer);
            }
        }
Пример #2
0
        /// <summary>
        /// Propagates a weight update event upstream through the network.
        /// </summary>
        /// <param name="properties">Network training properties.</param>
        /// <param name="networkTrainer">Network training method.</param>
        public virtual void Update(NetworkTrainingProperties properties, INetworkTrainer networkTrainer)
        {
            for (int edge = 0; edge < this.In.Count; edge++)
            {
                Delta = (1.0 / properties.Examples) * Delta;

                if (edge > 0)
                {
                    Delta = Delta + ((properties.Lambda / properties.Examples) * this.In[edge].Weight);
                }

                if (!this.Constrained)
                {
                    this.In[edge].Weight = networkTrainer.Update(this.In[edge].ParentId, this.In[edge].ChildId,
                                                                 nameof(Edge.Weight), this.In[edge].Weight, Delta, properties);
                }
                this.In[edge].Source.Update(properties, networkTrainer);
            }
        }
Пример #3
0
        /// <summary>Backpropagates the errors through the network given the supplied sequence label.</summary>
        /// <param name="y">Output vector to process.</param>
        /// <param name="properties">Network training properties for use in learning.</param>
        /// <param name="networkTrainer">Network training method.</param>
        /// <param name="update">Indicates whether to update the weights after computing the errors.</param>
        public void Back(Vector y, NetworkTrainingProperties properties, INetworkTrainer networkTrainer, bool update = true)
        {
            this.Cost = this.LossFunction.Compute(this.Output(), y);

            // CK
            // propagate error gradients
            for (int i = 0; i < Out.Length; i++)
            {
                Out[i].Error(y[i], properties);
            }

            if (update)
            {
                // reset weights
                for (int i = 0; i < Out.Length; i++)
                {
                    Out[i].Update(properties, networkTrainer);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Train the network using a Network Trainer agent.
        /// </summary>
        /// <param name="progress">Delegate to update the progress (between 0 and 100).</param>
        /// <returns>Whether the training was successful or not.</returns>
        public bool AutoTrainNetwork(Progress progress)
        {
            int attempts = _config.AutoTrainingAttempts.Value;

            if (_trainer == null)
            {
                _trainer = new FeedbackTrainer(); //SimpleTrainer(); //ConditionalTrainer();
            }
            bool wasQuiet = _config.Basic.QuietModeEnable.Value;

            _config.Basic.QuietModeEnable.Value = true;
            bool succeeded = _trainer.Train(this, progress);

            while (!succeeded && --attempts > 0)
            {
                RebuildNetwork();
                succeeded = _trainer.Train(this, progress);
            }
            _config.Basic.QuietModeEnable.Value = wasQuiet;
            return(succeeded);
        }
Пример #5
0
 /// <summary>Backpropagates the errors through the network given the supplied label.</summary>
 /// <param name="y">Label to process.</param>
 /// <param name="properties">Network training properties for use in learning.</param>
 /// <param name="networkTrainer">Network training method.</param>
 public void Back(double y, NetworkTrainingProperties properties, INetworkTrainer networkTrainer)
 {
     this.Back(Vector.Create(this.Out.Length, () => y), properties, networkTrainer);
 }
Пример #6
0
 /// <summary>
 /// Train the network using a Network Trainer agent.
 /// </summary>
 /// <param name="progress">Delegate to update the progress (between 0 and 100).</param>
 /// <returns>Whether the training was successful or not.</returns>
 public bool AutoTrainNetwork(Progress progress)
 {
     int attempts = _config.AutoTrainingAttempts.Value;
     if(_trainer == null)
         _trainer = new FeedbackTrainer(); //SimpleTrainer(); //ConditionalTrainer();
     bool wasQuiet = _config.Basic.QuietModeEnable.Value;
     _config.Basic.QuietModeEnable.Value = true;
     bool succeeded = _trainer.Train(this, progress);
     while(!succeeded && --attempts > 0)
     {
         RebuildNetwork();
         succeeded = _trainer.Train(this, progress);
     }
     _config.Basic.QuietModeEnable.Value = wasQuiet;
     return succeeded;
 }