Exemplo n.º 1
0
        /// <summary>
        /// Runs through the network and makes a prediction.
        /// </summary>
        /// <param name="input">The input image to run the prediction on.</param>
        /// <returns>The values from the final layer. The largest value is the networks prediction.</returns>
        public double[] FeedForward(double[] input)
        {
            Matrix <double> _currentImages = CreateMatrix.DenseOfRowVectors(CreateVector.DenseOfArray <double>(input));

            foreach (ILayerInformation _layerInformation in this.LayerInformation)
            {
                switch (_layerInformation.LayerType)
                {
                case (LayerType.Convolutional):
                    ConvolutionalLayerInformation _convInfo = _layerInformation as ConvolutionalLayerInformation;
                    _currentImages = this.Convolve(_convInfo, _currentImages);
                    break;

                case (LayerType.Pooling):
                    PoolingLayerInformation _poolInfo = _layerInformation as PoolingLayerInformation;
                    _currentImages = this.Pool(_poolInfo, _currentImages);
                    break;

                case (LayerType.NonLinear):
                    NonLinearLayerInformation _nonLinearInfo = _layerInformation as NonLinearLayerInformation;
                    _currentImages = this.NonLinear(_nonLinearInfo, _currentImages);
                    break;
                }
            }

            double[] _fullyConnectedInput = CreateVector.DenseOfEnumerable <double>(_currentImages.EnumerateRows().SelectMany(a => a)).ToArray();

            return(this.FullyConnectedNetwork.FeedForward(_currentImages.Enumerate().ToArray()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs through a non-linear layer of the network.
        /// </summary>
        /// <param name="layerInfo">The layer info used for this layer.</param>
        /// <param name="inputImages">
        /// A matrix of all the images that will be ran through the non-linear function. Each row is
        /// an image.
        /// </param>
        /// <returns>A matrix of all the resulting images. Each row is an image.</returns>
        internal Matrix <double> NonLinear(NonLinearLayerInformation layerInfo, Matrix <double> inputImages)
        {
            switch (layerInfo.NonLinearFunction)
            {
            case NonLinearFunction.Sigmoid:
                return(NonLinearTransformations.Sigmoid(inputImages));

            case NonLinearFunction.Tanh:
                return(NonLinearTransformations.Tanh(inputImages));

            case NonLinearFunction.ReLU:
                return(NonLinearTransformations.ReLU(inputImages));

            case NonLinearFunction.LReLU:
                return(NonLinearTransformations.LReLU(inputImages));

            default:
                return(null);
            }
        }