コード例 #1
0
 public void MutateActivation(DenseRandomParams drp, int mutateRate)
 {
     if (random.Next(100) < mutateRate)
     {
         if (random.Next(100) < 10)
         {
             sameActivations = !sameActivations;
             if (sameActivations)
             {
                 int absorberIndex = random.Next(denseLayers.Count);
                 foreach (var t in denseLayers)
                 {
                     t.activationIndex = denseLayers[absorberIndex].activationIndex;
                 }
             }
         }
         else
         {
             foreach (var t in denseLayers)
             {
                 t.MutateActivation(drp, mutateRate);
             }
         }
     }
 }
コード例 #2
0
        } // конструктор для инициализации объекта DenseStructure по полям объекта ConvolutionalNetwork

        public void MutateLayersNumb(DenseRandomParams drp, int mutateRate)
        {
            if (random.Next(100) < mutateRate)
            {
                denseLayersNumb = random.Next(1, drp.denseLayersNumbRange);
            }
            if (denseLayersNumb >= denseLayers.Count)
            {
                denseLayers.Capacity = denseLayersNumb;
                int powIndex = Support.GetPow2(denseLayers[denseLayers.Count - 1].neurons);
                while (denseLayers.Count != denseLayers.Capacity)
                {
                    powIndex += random.Next(0, 2);
                    int neurons = (int)Math.Pow(2, powIndex);
                    denseLayers.Insert(0, new DenseLayer(drp, random, neurons));
                    if (sameActivations)
                    {
                        denseLayers[0].activationIndex = denseLayers[1].activationIndex;
                    }
                }
            }
            else
            {
                denseLayers.RemoveRange(0, denseLayers.Capacity - denseLayersNumb); // перепроверить!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                denseLayers.Capacity = denseLayersNumb;
            }
        }
コード例 #3
0
 public void MutateDropouts(DenseRandomParams drp, int mutateRate)
 {
     if (random.Next(100) < mutateRate)
     {
         if (random.Next(100) < 10)
         {
             if (denseLayers[0].dropoutExist)
             {
                 foreach (var t in denseLayers)
                 {
                     t.dropoutExist = false;
                     t.dropoutRate  = 0;
                 }
             }
             else
             {
                 foreach (var t in denseLayers)
                 {
                     t.dropoutExist = true;
                     t.dropoutRate  = random.Next(10, drp.denseDropRange);
                 }
             }
         }
         else
         {
             foreach (var t in denseLayers)
             {
                 t.MutateDropout(drp, mutateRate);
             }
         }
     }
 }
コード例 #4
0
 public ConvolutionalChromosome(ConvolutionalNetwork cNet, ConvRandomParams crp, DenseRandomParams drp)
 {
     this.crp = crp;
     this.drp = drp;
     //добавить рандомные параметры
     convPart  = new ConvStructure(cNet.slidingWindows, cNet.convActivationIndexes, cNet.filters, cNet.convDropoutIndexes, cNet.convDropoutRates);
     densePart = new DenseStructure(cNet.denseActivationIndexes, cNet.neurons, cNet.denseDropoutIndexes, cNet.denseDropoutRates);
 } // конструктор для создания хромосомы из полей описательного класса ConvolutionalNetwork для последующего использования в генетических алгоритмах (например, для поиска лучшего варианта чем текущий)
コード例 #5
0
        } // псевдокопирующий конструктор

        public void MutateActivation(DenseRandomParams drp, int mutateRate)
        {
            if (random.Next(100) < mutateRate)
            {
                activationIndex = random.Next(drp.denseActIndexesRange);
            }
            // поменять переменную sameActivations в другом классе(классе выше)
        }
コード例 #6
0
 public DenseLayer(DenseRandomParams drp, Random random, int neurons)
 {
     this.random  = random;
     dropoutExist = random.Next(100) < 10 ? true : false;
     if (dropoutExist)
     {
         dropoutRate = random.Next(10, drp.denseDropRange);
     }
     else
     {
         dropoutRate = 0;
     }
     activationIndex = random.Next(drp.denseActIndexesRange);
     this.neurons    = neurons;
 }
コード例 #7
0
 public GeneticProgramm(NetworkRandomParams nrp, ConvRandomParams crp, DenseRandomParams drp,
                        int genEpochs, int[] selection, int populationSize, int mutateRate,
                        float accPriority, float paramPriority, int assessmentIndex, int percent)
 {
     _nrp             = nrp;
     _crp             = crp;
     _drp             = drp;
     _genEpochs       = genEpochs;
     _selection       = selection;
     _populationSize  = populationSize;
     _mutateRate      = mutateRate;
     _accPriority     = accPriority;
     _paramPriority   = paramPriority;
     _assessmentIndex = assessmentIndex;
     _percent         = percent;
 }
コード例 #8
0
 public void MutateDense(DenseRandomParams drp, int mutateRate)
 {
     if (random.Next(100) < mutateRate)
     {
         if (random.Next(100) < 5)
         {
             densePart = new DenseStructure(nrp, drp, random);
         }
         else
         {
             densePart.MutateLayersNumb(drp, mutateRate);
             densePart.MutateActivation(drp, mutateRate);
             densePart.MutateNeurons(drp, mutateRate);
             densePart.MutateDropouts(drp, mutateRate);
         }
     }
 }
コード例 #9
0
 public ConvolutionalChromosome(GeneticProgramm gp, Random random)
 {
     _gp         = gp;
     this.random = random;
     nrp         = gp._nrp;
     crp         = gp._crp;
     drp         = gp._drp;
     convPart    = new ConvStructure(crp, random);
     densePart   = new DenseStructure(nrp, drp, random);
     if (nrp.notRandomSpeed)
     {
         trainConstSpeed = nrp.trainConstSpeedRange[0];
     }
     else
     {
         trainConstSpeed = Convert.ToSingle(random.Next((int)(nrp.trainConstSpeedRange[0] * 1000), (int)(nrp.trainConstSpeedRange[1] * 1000))) / 1000;
     }
     optimizer     = nrp.optimizers[random.Next(nrp.optimizers.Count)];
     loss_function = nrp.loss_functions[random.Next(nrp.loss_functions.Count)];
 }
コード例 #10
0
        public DenseStructure(NetworkRandomParams nrp, DenseRandomParams drp, Random random)
        {
            this.nrp    = nrp;
            this.drp    = drp;
            this.random = random;

            sameActivations = random.Next(100) < 10 ? true : false;
            int absorber = 0;

            if (sameActivations)
            {
                absorber = random.Next(drp.denseActIndexesRange);
            }

            denseLayersNumb = random.Next(1, drp.denseLayersNumbRange);
            denseLayers     = new List <DenseLayer>(denseLayersNumb);

            int powIndex = 0;

            for (int i = 0; i < denseLayers.Capacity; i++)
            {
                int neurons = 0;

                if (i == 0)
                {
                    powIndex = random.Next(Support.GetPow2(nrp.networkOutputNumb), drp.firstDenseNeuronsRange);
                }
                else
                {
                    powIndex += random.Next(0, 2);
                }
                neurons = (int)Math.Pow(2, powIndex);
                denseLayers.Insert(0, new DenseLayer(drp, random, neurons));

                if (sameActivations)
                {
                    denseLayers[0].activationIndex = absorber;
                }
            }
        }
コード例 #11
0
 public void MutateNeurons(DenseRandomParams drp, int mutateRate) // проверить
 {
     if (random.Next(100) < mutateRate)
     {
         int mutateIndex = random.Next(0, denseLayers.Count);
         int powIndex    = 0;
         while (mutateIndex != -1)
         {
             if (mutateIndex != (denseLayers.Count - 1))
             {
                 powIndex = Support.GetPow2(denseLayers[mutateIndex + 1].neurons);
             }
             else
             {
                 powIndex = drp.firstDenseNeuronsRange;
             }
             powIndex += random.Next(0, 2);
             denseLayers[mutateIndex].neurons = (int)Math.Pow(2, powIndex);
             mutateIndex--;
         }
     }
 }
コード例 #12
0
 public void MutateDropout(DenseRandomParams drp, int mutateRate)
 {
     if (random.Next(100) < mutateRate)
     {
         int mutationWay = random.Next(100);
         if (mutationWay < 10)
         {
             dropoutExist = !dropoutExist;
             if (dropoutExist)
             {
                 dropoutRate = random.Next(10, drp.denseDropRange);
             }
             else
             {
                 dropoutRate = 0;
             }
         }
         else
         {
             dropoutRate = random.Next(10, drp.denseDropRange);
         }
     }
 }
コード例 #13
0
        public GeneticProgramm CollectConv_NN_Params()
        {
            List <String> convActivations = new List <string>();

            if (reluConvChb.Checked)
            {
                convActivations.Add("relu");
            }
            if (softmaxConvChb.Checked)
            {
                convActivations.Add("softmax");
            }
            if (lReluConvChb.Checked)
            {
                convActivations.Add("Leaky ReLU");
            }
            if (softsignConvChb.Checked)
            {
                convActivations.Add("softsign");
            }
            if (sigmoidConvChb.Checked)
            {
                convActivations.Add("sigmoid");
            }
            if (eluConvChb.Checked)
            {
                convActivations.Add("elu");
            }
            if (seluConvChb.Checked)
            {
                convActivations.Add("selu");
            }
            if (softplusConvChb.Checked)
            {
                convActivations.Add("softplus");
            }
            if (tanhConvChb.Checked)
            {
                convActivations.Add("tang");
            }
            if (PReLUConvChB.Checked)
            {
                convActivations.Add("PReLu");
            }
            if (TReLUConvChB.Checked)
            {
                convActivations.Add("TReLU");
            }

            List <String> denseActivations = new List <string>();

            if (reluDenseChb.Checked)
            {
                denseActivations.Add("relu");
            }
            if (softmaxDenseChb.Checked)
            {
                denseActivations.Add("softmax");
            }
            if (lReluDenseChb.Checked)
            {
                denseActivations.Add("Leaky ReLU");
            }
            if (softsignDenseChb.Checked)
            {
                denseActivations.Add("softsign");
            }
            if (sigmoidDenseChb.Checked)
            {
                denseActivations.Add("sigmoid");
            }
            if (eluDenseChb.Checked)
            {
                denseActivations.Add("elu");
            }
            if (seluDenseChb.Checked)
            {
                denseActivations.Add("selu");
            }
            if (softplusDenseChb.Checked)
            {
                denseActivations.Add("softplus");
            }
            if (tanhDenseChb.Checked)
            {
                denseActivations.Add("tang");
            }
            if (PReLUDenseChB.Checked)
            {
                denseActivations.Add("PReLU");
            }
            if (ThReLUDenseChB.Checked)
            {
                denseActivations.Add("TReLU");
            }

            List <String> optimazers = new List <string>();

            if (SGD_OptChB.Checked)
            {
                optimazers.Add("SGD");
            }

            List <String> lossFunctions = new List <string>();

            if (categorical_crossentropyChB.Checked)
            {
                lossFunctions.Add("categorical_crossentropy");
            }

            List <int> callbacks_indexes = new List <int>();

            if (modelCPChB.Checked)
            {
                callbacks_indexes.Add(0);
            }


            var nrp = new NetworkRandomParams(constSpeedChB.Checked,
                                              new[] { float.Parse(minConstSpeedTB.Text, System.Globalization.CultureInfo.InvariantCulture),
                                                      float.Parse(maxConstSpeedTB.Text, System.Globalization.CultureInfo.InvariantCulture) },
                                              datasetPathTB.Text, modelsPathTB.Text, labelsPathTB.Text, plotsPathTB.Text,
                                              networkNameTB.Text, optimazers, lossFunctions, (int)learningEpochsNUD.Value, (int)batchSizeNUD.Value);

            var crp = new ConvRandomParams((int)ConvLayersNumbNUD.Value,
                                           (int)ConvFiltersNUD.Value,
                                           convActivations.Count,
                                           convActivations,
                                           new[] { (int)slidingWindow1NUD.Value, (int)slidingWindow2NUD.Value },
                                           convDropoutChB.Checked,
                                           (int)convDropoutNUD.Value);
            var drp = new DenseRandomParams((int)DenseLayersNumbNUD.Value,
                                            (int)DenseNeuronsNUD.Value,
                                            nrp.networkOutputNumb, // Support.GetOutputNumb(datasetPath);
                                            denseActivations.Count,
                                            denseActivations,
                                            denseDropoutChB.Checked,
                                            (int)denseDropoutNUD.Value);
            var gp = new GeneticProgramm(nrp, crp, drp, (int)geneticEpochsNUD.Value, new[] { (int)copySelNUD.Value, (int)crossSelNUD.Value, (int)mutateRateNUD.Value },
                                         (int)popolationCountNUD.Value, (int)mutateRateNUD.Value, (float)accPriorityNUD.Value, (float)memPriorityNUD.Value,
                                         EstimatorCB.SelectedIndex, (int)instance.percentNUD.Value);

            return(gp);
        }