Esempio n. 1
0
        /// <summary>
        /// Randomizes the weights of all connections between all neurons in range of -5.0 to 5.0
        /// </summary>
        public void RandomizeWeights()
        {
            MyRandom r = new MyRandom(-0.5, 0.5);

            //set random weights for output
            foreach (Neuron itOut in outputLayer)
            {
                List <Connection> con = ((WorkingNeuron)(itOut)).connections;

                foreach (Connection c in con)
                {
                    c.SetWeight(r.NextDouble());
                }
            }

            //set random weights for hidden
            foreach (Neuron itHid in hiddenLayer)
            {
                WorkingNeuron wn = itHid as WorkingNeuron;
                if (wn != null)
                {
                    List <Connection> con = wn.connections;

                    foreach (Connection c in con)
                    {
                        c.SetWeight(r.NextDouble());
                    }
                }
            }
        }
Esempio n. 2
0
        public void MutateWeightsRandom(int mutations)
        {
            MyRandom myrand = new MyRandom(-0.3, 0.3);

            for (int i = 0; i < mutations; ++i)
            {
                int layer = myrand.NextInt(0, 10);


                if (layer <= 6)
                {
                    //select neuron
                    Neuron neuron = null;
                    while (neuron == null)
                    {
                        neuron = hiddenLayer.ElementAt(myrand.NextInt(0, hiddenLayer.Count - 1)) as WorkingNeuron;
                    }

                    //select connection index
                    int    index  = myrand.NextInt(0, ((WorkingNeuron)neuron).connections.Count - 1);
                    double w      = ((WorkingNeuron)neuron).connections.ElementAt(index).GetWeight();
                    double change = myrand.NextDouble(-0.3, 0.3);
                    change *= w;

                    ((WorkingNeuron)neuron).connections[index].SetWeight(w + change);
                }
                else if (layer >= 7)
                {
                    //select neuron
                    Neuron neuron = null;
                    while (neuron == null)
                    {
                        neuron = outputLayer.ElementAt(myrand.NextInt(0, outputLayer.Count - 1)) as WorkingNeuron;
                    }

                    //select connection index
                    int    index  = myrand.NextInt(0, ((WorkingNeuron)neuron).connections.Count - 1);
                    double w      = ((WorkingNeuron)neuron).connections.ElementAt(index).GetWeight();
                    double change = myrand.NextDouble(-0.3, 0.3);
                    change *= w;

                    ((WorkingNeuron)neuron).connections[index].SetWeight(w + change);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Randomizes the weights of all connections between all neurons in range of -5.0 to 5.0
        /// </summary>
        public void RandomizeWeights()
        {
            MyRandom r = new MyRandom(-0.5, 0.5);

            for (int l = layers.Count - 1; l > 0; --l)
            {
                foreach (Neuron n in layers.ElementAt(l))
                {
                    WorkingNeuron wn = n as WorkingNeuron;

                    if (wn != null)
                    {
                        List <Connection> con = wn.connections;

                        foreach (Connection c in con)
                        {
                            c.SetWeight(r.NextDouble());
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public void MutateWeightsRandom(int mutations)
        {
            MyRandom myrand = new MyRandom(-0.3, 0.3);

            for (int i = 0; i < mutations; ++i)
            {
                int layer = myrand.NextInt(1, this.layers.Count - 1);

                //select neuron
                Neuron neuron = null;
                while (neuron == null)
                {
                    neuron = layers.ElementAt(layer).ElementAt(myrand.NextInt(0, layers.ElementAt(layer).Count - 1)) as WorkingNeuron;
                }

                //select connection index
                int    index  = myrand.NextInt(0, ((WorkingNeuron)neuron).connections.Count - 1);
                double w      = ((WorkingNeuron)neuron).connections.ElementAt(index).GetWeight();
                double change = myrand.NextDouble(-0.3, 0.3);
                change *= w;

                ((WorkingNeuron)neuron).connections[index].SetWeight(w + change);
            }
        }