Esempio n. 1
0
    static void ReduceVectors(CudaDataSet <int> teaching, CudaDataSet <int> test)
    {
        using (CudaContext context = new CudaContext())
        {
            int popSize = 100;
            DeviceDataSet <int> deviceTeaching = new DeviceDataSet <int>(teaching);
            DeviceDataSet <int> deviceTest     = new DeviceDataSet <int>(test);

            FlattArray <byte> initialPopulation;

            VectorReductionAccuracy acc = new VectorReductionAccuracy(context, deviceTeaching, deviceTest, popSize)
            {
                K           = 5,
                CountToPass = 3
            };

            VectorReductionFitness fitnessFunc =
                new VectorReductionFitness(context, acc, popSize, deviceTeaching.length)
            {
                Alpha = 0.7f
            };

            //Drop3 drop = new Drop3();
            //drop.CasheSize = 5;
            //drop.K = 3;

            //Profiler.Start("Drop3");
            //var indexesToStay = drop.Apply(teaching, context);
            //Profiler.Stop("Drop3");


            //byte[] parrent = new byte[teaching.Vectors.GetLength(0)];
            //foreach (var item in indexesToStay)
            //{
            //    parrent[item] = 1;
            //}



            initialPopulation = CreateRandomPopulation(popSize, deviceTeaching.length);
            //CreatePopulationBasedOnParent(parrent, popSize, 0.2f, 0.05f);

            var d = new Evolutionary2(context, fitnessFunc, initialPopulation)
            {
                Elitism      = 0.001f,
                MutationRate = 0.001f
            };
            for (int i = 0; i < 30; i++)
            {
                Profiler.Start("iteration");
                d.CreateNewPopulation();
                Profiler.Stop("iteration");
            }
            var best = d.FindFitest();
            Console.WriteLine(acc.GenAccuracy(best.index) / (float)deviceTest.length);
            Console.WriteLine(fitnessFunc.GenLength(best.index));

            Profiler.Print();
        }
    }
Esempio n. 2
0
    static void ReduceVectorsRegresion(CudaDataSet <float> teaching, CudaDataSet <float> test)
    {
        using (CudaContext context = new CudaContext())
        {
            int popSize        = 100;
            var deviceTeaching = new DeviceDataSet <float>(teaching);
            var deviceTest     = new DeviceDataSet <float>(test);

            FlattArray <byte> initialPopulation;

            var acc = new VectorReductionAccuracyRegresion(context, deviceTeaching, deviceTest, popSize)
            {
                K           = 3,
                CountToPass = 2
            };

            VectorReductionFitness fitnessFunc =
                new VectorReductionFitness(context, acc, popSize, deviceTeaching.length)
            {
                Alpha = 0.7f
            };

            initialPopulation = CreateRandomPopulation(popSize, deviceTeaching.length);

            var d = new Evolutionary2(context, fitnessFunc, initialPopulation)
            {
                Elitism      = 0.1f,
                MutationRate = 0.05f
            };
            for (int i = 0; i < 10; i++)
            {
                Profiler.Start("iteration");
                d.CreateNewPopulation();
                Profiler.Stop("iteration");
            }
            Console.WriteLine(acc.BaseAccuracy());
            var best = d.FindFitest();
            Console.WriteLine(acc.GenAccuracy(best.index));
            Console.WriteLine(fitnessFunc.GenLength(best.index) / (float)deviceTeaching.length);

            Profiler.Print();
        }
    }