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(); } }
static void ReduceDimension(CudaDataSet <int> teaching, CudaDataSet <int> test) { using (CudaContext context = new CudaContext()) { int popSize = 20; int genLength = teaching.Vectors.GetLength(1); DeviceDataSet <int> deviceTeaching = new DeviceDataSet <int>(teaching); DeviceDataSet <int> deviceTest = new DeviceDataSet <int>(test); FlattArray <byte> initialPopulation; DimensionReductionAccuracy accuracy = new DimensionReductionAccuracy(context, deviceTeaching, deviceTest, popSize) { K = 3, CountToPass = 2 }; DimensionReductionFitness fitnessFunc = new DimensionReductionFitness(context, accuracy, popSize, genLength) { Alpha = 1f }; Console.WriteLine(accuracy.BaseAccuracy()); Console.WriteLine(); initialPopulation = CreateRandomPopulation(popSize, deviceTeaching.attributeCount); var d = new Evolutionary2(context, fitnessFunc, initialPopulation) { CrossOverRate = 0.5f, MutationRate = 0.02f, Elitism = 0.2f }; for (int i = 0; i < 200; i++) { Profiler.Start("iteration"); d.CreateNewPopulation(); Profiler.Stop("iteration"); } var best = d.FindFitest(); // Console.WriteLine(best.fitness); var acc = accuracy.GenAccuracy(best.index); var len = fitnessFunc.GenLength(best.index); var gen = d.genGen(best.index); foreach (var item in gen) { Console.Write(item + " "); } Console.WriteLine($"accuracy: {acc / (float)deviceTest.length} length: {len / (float)genLength}"); Console.WriteLine(); // Profiler.Print(); } }
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(); } }