Пример #1
0
        /// <summary>
        /// Return a clone of the structure of this neural network.
        /// </summary>
        /// <returns>A cloned copy of the structure of the neural network.</returns>

        public FeedforwardNetwork CloneStructure()
        {
            FeedforwardNetwork result = new FeedforwardNetwork();

            foreach (FeedforwardLayer layer in this.layers)
            {
                FeedforwardLayer clonedLayer = new FeedforwardLayer(layer.NeuronCount);
                result.AddLayer(clonedLayer);
            }

            return(result);
        }
        /// <summary>
        /// Prune one of the neurons from this layer. Remove all entries in this
        /// weight matrix and other layers.
        /// </summary>
        /// <param name="neuron">The neuron to prune. Zero specifies the first neuron.</param>
        public void Prune(int neuron)
        {
            // delete a row on this matrix
            if (this.matrix != null)
            {
                this.LayerMatrix = (MatrixMath.DeleteRow(this.matrix, neuron));
            }

            // delete a column on the previous
            FeedforwardLayer previous = this.Previous;

            if (previous != null)
            {
                if (previous.LayerMatrix != null)
                {
                    previous.LayerMatrix = (MatrixMath.DeleteCol(previous.LayerMatrix,
                                                                 neuron));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Add a layer to the neural network. The first layer added is the input
        /// layer, the last layer added is the output layer.
        /// </summary>
        /// <param name="layer">The layer to be added.</param>
        public void AddLayer(FeedforwardLayer layer)
        {
            // setup the forward and back pointer
            if (this.outputLayer != null)
            {
                layer.Previous        = this.outputLayer;
                this.outputLayer.Next = layer;
            }

            // update the inputLayer and outputLayer variables
            if (this.layers.Count == 0)
            {
                this.inputLayer = this.outputLayer = layer;
            }
            else
            {
                this.outputLayer = layer;
            }

            // add the new layer to the list
            this.layers.Add(layer);
        }
Пример #4
0
        /// <summary>
        /// Compare the two neural networks. For them to be equal they must be of the
        /// same structure, and have the same matrix values.
        /// </summary>
        /// <param name="other">The other neural network.</param>
        /// <returns>True if the two networks are equal.</returns>
        public bool Equals(FeedforwardNetwork other)
        {
            int i = 0;

            foreach (FeedforwardLayer layer in this.Layers)
            {
                FeedforwardLayer otherLayer = other.Layers[i++];

                if (layer.NeuronCount != otherLayer.NeuronCount)
                {
                    return(false);
                }

                // make sure they either both have or do not have
                // a weight matrix.
                if ((layer.LayerMatrix == null) && (otherLayer.LayerMatrix != null))
                {
                    return(false);
                }

                if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix == null))
                {
                    return(false);
                }

                // if they both have a matrix, then compare the matrices
                if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix != null))
                {
                    if (!layer.LayerMatrix.Equals(otherLayer.LayerMatrix))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Return a clone of the structure of this neural network. 
        /// </summary>
        /// <returns>A cloned copy of the structure of the neural network.</returns>

        public FeedforwardNetwork CloneStructure()
        {
            FeedforwardNetwork result = new FeedforwardNetwork();

            foreach (FeedforwardLayer layer in this.layers)
            {
                FeedforwardLayer clonedLayer = new FeedforwardLayer(layer.NeuronCount);
                result.AddLayer(clonedLayer);
            }

            return result;
        }
Пример #6
0
        /// <summary>
        /// Add a layer to the neural network. The first layer added is the input
        /// layer, the last layer added is the output layer.
        /// </summary>
        /// <param name="layer">The layer to be added.</param>
        public void AddLayer(FeedforwardLayer layer)
        {
            // setup the forward and back pointer
            if (this.outputLayer != null)
            {
                layer.Previous = this.outputLayer;
                this.outputLayer.Next = layer;
            }

            // update the inputLayer and outputLayer variables
            if (this.layers.Count == 0)
            {
                this.inputLayer = this.outputLayer = layer;
            }
            else
            {
                this.outputLayer = layer;
            }

            // add the new layer to the list
            this.layers.Add(layer);
        }