Пример #1
0
        /// <summary>
        /// ONLY for testing to set up a network with known weights in future use to
        /// deserialize networks after adding variables for pen weightupdate,
        /// lastnput etc
        /// </summary>
        /// <param name="hiddenLayersWeights"></param>
        /// <param name="hiddenLayersBias"></param>
        /// <param name="outputLayerWeights"></param>
        /// <param name="outputLayerBias"></param>
        public FeedForwardDeepNeuralNetwork(Matrix[] hiddenLayersWeights,
                                            Vector[] hiddenLayersBias,
                                            Matrix outputLayerWeights,
                                            Vector outputLayerBias)
        {
            if (hiddenLayersWeights.Length != config.GetParameterAsInteger(NUMBER_OF_HIDDEN_LAYERS) ||
                hiddenLayersBias.Length != config.GetParameterAsInteger(NUMBER_OF_HIDDEN_LAYERS))
            {
                throw new ArgumentOutOfRangeException("hiddenLayerWeights,hiddenLayerBias != NUMBER_OF_HIDDEN_LAYERS");
            }

            hiddenLayers = new Layer[config.GetParameterAsInteger(NUMBER_OF_HIDDEN_LAYERS)];
            for (int i = 0; i < hiddenLayers.Length; ++i)
            {
                hiddenLayers[i] = new Layer(hiddenLayersWeights[i], hiddenLayersBias[i], new LogSigActivationFunction());
            }

            outputLayer = new Layer(outputLayerWeights, outputLayerBias, new PureLinearActivationFunction());
        }
        /// <summary>
        /// Constructor to be used for non testing code.
        /// </summary>
        /// <param name="config"></param>
        public FeedForwardNeuralNetwork(NeuralNetworkConfig config)
        {
            int numberOfInputNeurons = config
                                       .GetParameterAsInteger(NUMBER_OF_INPUTS);
            int numberOfHiddenNeurons = config
                                        .GetParameterAsInteger(NUMBER_OF_HIDDEN_NEURONS);
            int numberOfOutputNeurons = config
                                        .GetParameterAsInteger(NUMBER_OF_OUTPUTS);

            double lowerLimitForWeights = config
                                          .GetParameterAsDouble(LOWER_LIMIT_WEIGHTS);
            double upperLimitForWeights = config
                                          .GetParameterAsDouble(UPPER_LIMIT_WEIGHTS);

            hiddenLayer = new Layer(numberOfHiddenNeurons, numberOfInputNeurons,
                                    lowerLimitForWeights, upperLimitForWeights,
                                    new LogSigActivationFunction());

            outputLayer = new Layer(numberOfOutputNeurons, numberOfHiddenNeurons,
                                    lowerLimitForWeights, upperLimitForWeights,
                                    new PureLinearActivationFunction());
        }
Пример #3
0
        /// <summary>
        /// Constructor to be used for non testing code.
        /// </summary>
        /// <param name="config"></param>
        public FeedForwardDeepNeuralNetwork(NeuralNetworkConfig config, IActivationFunction activationFunction)
        {
            if (config.GetParameterAsInteger(NUMBER_OF_HIDDEN_LAYERS) < 1)
            {
                throw new ArgumentOutOfRangeException("NUMBER_OF_HIDDEN_LAYERS must be >= 1");
            }

            if (null == activationFunction)
            {
                activationFunction = new LogSigActivationFunction();
            }
            this.config = config;

            int numberOfInputNeurons  = config.GetParameterAsInteger(NUMBER_OF_INPUTS);
            int numberOfOutputNeurons = config.GetParameterAsInteger(NUMBER_OF_OUTPUTS);

            double lowerLimitForWeights = config.GetParameterAsDouble(LOWER_LIMIT_WEIGHTS);
            double upperLimitForWeights = config.GetParameterAsDouble(UPPER_LIMIT_WEIGHTS);

            hiddenLayers = new Layer[config.GetParameterAsInteger(NUMBER_OF_HIDDEN_LAYERS)];

            //TODO: Create Hidden layers here
        }