Exemplo n.º 1
0
 public NeuralNetwork(NeuralNetworkParameters parameters, IContinuousDistribution rng)
 {
     NetworkParameters = parameters;
     HiddenWeights     = CreateMatrix.Random <float>(NetworkParameters.HiddenLayerNeuronCount, NetworkParameters.InputCount, rng);
     HiddenBiases      = CreateVector.Random <float>(NetworkParameters.HiddenLayerNeuronCount, rng);
     OutputWeights     = CreateMatrix.Random <float>(NetworkParameters.OutputCount, NetworkParameters.HiddenLayerNeuronCount, rng);
     OutputBiases      = CreateVector.Random <float>(NetworkParameters.OutputCount, rng);
 }
Exemplo n.º 2
0
        public void Initialize()
        {
            var inputCountDistribution        = new DiscreteUniform(1 + AlgorithmParameters.MinSensorCount, 1 + AlgorithmParameters.MaxSensorCount);
            var hiddenNeuronCountDistribution = new DiscreteUniform(AlgorithmParameters.MinHiddenLayerNeuronCount, AlgorithmParameters.MaxHiddenLayerNeuronCount);

            for (int i = 0; i < AlgorithmParameters.PopulationCount; i++)
            {
                var networkParameters = new NeuralNetworkParameters()
                {
                    InputCount                    = AlgorithmParameters.EvolveNetworkTopology ? inputCountDistribution.Sample() : AlgorithmParameters.MinSensorCount + 1,
                    HiddenLayerNeuronCount        = AlgorithmParameters.EvolveNetworkTopology ? hiddenNeuronCountDistribution.Sample() : AlgorithmParameters.MinHiddenLayerNeuronCount,
                    OutputCount                   = 2,
                    HiddenLayerActivationFunction = AlgorithmParameters.NeuralNetworkHiddenLayerActivationFunction,
                    OutputLayerActivationFunction = AlgorithmParameters.NeuralNetworkOutputLayerActivationFunction
                };

                Population.Add(new NeuralNetwork(networkParameters, AlgorithmParameters.NeuralNetworkWeightInitializationDistribution));
            }
        }