示例#1
0
        public Network(int InputLayerSize, int[] HiddenLayerSizes, int OutputLayerSize, Function[] activationFuncs)
        {
            Random r = new Random();

            //will create a network with InputLayerSize inputneurons, HiddenLayerSizes.count Hiddenlayers (Each with the size of the array at that position), and OutputLayerSize outputneurons

            /*****************************
             * InputNeurons
             ****************************/
            InputLayer = new InputLayer(InputLayerSize, this);

            /*****************************
             * HiddenNeurons
             ****************************/

            hiddenLayer = new HiddenLayer[HiddenLayerSizes.Length];

            for (int i = 0; i < hiddenLayer.Length; i++) //for each layer
            {
                hiddenLayer[i] = new HiddenLayer(HiddenLayerSizes[i], this);
                if (i == 0)
                {
                    hiddenLayer[i].connectToInputLayer(InputLayer);//connect the hiddenlayer to the inputlayer
                }
                else
                {
                    hiddenLayer[i].connectToInputLayer(hiddenLayer[i - 1]);//connect the hiddenlayer to the hiddenlayer before
                }
                hiddenLayer[i].ActivationFunction = activationFuncs[i];
            }

            /*****************************
             * OutputNeurons
             ****************************/
            outputLayer = new OutputLayer(OutputLayerSize, this);
            outputLayer.connectToInputLayer(hiddenLayer[HiddenLayerSizes.Length - 1]);
            outputLayer.ActivationFunction = activationFuncs[activationFuncs.Length - 1];
            this.RandomizeAllWeights();
            this.DatabaseID = db.getNetworkID();
        }
示例#2
0
 public void Mutate()
 {
     if (RandomGenerator.NextDouble() < Constants.Con.mutate_weights_chanse)
     {
         //Debug.Log("mutate");
         OutputLayer.Mutate();
         foreach (var neuron in HiddenLayers)
         {
             neuron.Value.Mutate();
         }
     }
     if (RandomGenerator.NextDouble() < Constants.Con.mutate_new_neuron_chanse)
     {
         //Debug.Log("mutate");
         if (AllSynapses.Count == 0)
         {
             return;
         }
         AddNeuron();
     }
     if (RandomGenerator.NextDouble() < Constants.Con.mutate_del_neuron_chanse)
     {
         //Debug.Log("mutate");
         if (AllSynapses.Count == 0)
         {
             return;
         }
         DelNeuron();
     }
     if (RandomGenerator.NextDouble() < Constants.Con.mutate_new_synapse_chanse)
     {
         //Debug.Log("mutate");
         AddSynapse();
     }
     if (RandomGenerator.NextDouble() < Constants.Con.mutate_del_synapse_chanse)
     {
         //Debug.Log("mutate");
         DelSynapse();
     }
 }
示例#3
0
 public void FeedForward()
 {
     HiddenLayer.CalculateNeuronValues();
     OutputLayer.CalculateNeuronValues();
 }
        public OutputLayer CreateOutputLayer()
        {
            OutputLayer = new OutputLayer();

            return(OutputLayer);
        }
 public NeuralNetwork()
 {
     InputLayer   = null;
     HiddenLayers = new List <HiddenLayer>();
     OutputLayer  = null;
 }