public override void Build() { if (save) { writerEnv = UIO.CreateStreamWriter(GeneratePath(task, true), "GeneSessionResults.csv", false); UIO.WriteLine(writerEnv, "Generation;Angle Random Rotation;Wind"); } Debug.Log("Build DroneSession"); signal = new ControlSignal(); tsignal = new ThrustSignal(); tmpBuildCustomWeights = new List <Matrix <float> >(); externalEvaluations = Vector <float> .Build.Dense(populationSize); //Debug.Log(fromTask); taskObject = (DroneTask)Activator.CreateInstance(Type.GetType("Lexmou.MachineLearning.Drone" + task), rndGenerator, fromTask); //Debug.Log(taskObject.fromTask); dronePopulation = new GameObject[populationSize]; droneRigid = new Rigidbody[populationSize]; targetPosition = new Vector3[populationSize]; mlpPopulation = new MultiLayerMathsNet[populationSize]; gene = new Genetic(seed, rndGenerator, populationSize, taskObject.individualSize, initialValueWeights, mutationRate, randomIndividualsRate, bestIndividualsRate, emptyRate, GeneratePath(task, false), save); if (loadGeneration != 0) { float[,] floatArr = new float[taskObject.individualSize - taskObject.rowIndex, populationSize]; Debug.Log(taskObject.fromTask); //Debug.Log(taskObject.individualSize); gene.LoadGeneration(GeneratePath(taskObject.fromTask, true), loadGeneration, floatArr, taskObject.rowIndex); gene.generation = loadGeneration; } }
public void SaveTest() { Vector <float> externalEvaluations = Vector <float> .Build.DenseOfArray(new float[2] { 0.0f, 1.0f }); geneRndGenerator.Evaluation(externalEvaluations, "max"); geneRndGenerator.SaveGeneration(); float[,] floatArr = new float[geneRndGenerator.individualSize, geneRndGenerator.populationSize]; float[] floatArrBest = new float[geneRndGenerator.individualSize]; geneRndGenerator.LoadGeneration(1, floatArr); geneRndGenerator.LoadBest(1, floatArrBest); Matrix <float> result = Matrix <float> .Build.DenseOfArray(floatArr); Vector <float> resultBest = Vector <float> .Build.DenseOfArray(floatArrBest); Assert.AreEqual(geneRndGenerator.GetPopulation(), result); Assert.AreEqual(geneRndGenerator.GetBestIndividual(), resultBest); Debug.Log(geneRndGenerator.GetPopulation()); Debug.Log(result); }