public Population InitializePopulation(string filePath) { //Todo List <double> inputList = FileHandler.getResult(filePath); Helper.inputArray = inputList.ToArray <double>(); //FileHandler.WriteToFile(Helper.inputArray); inputList.Clear(); this.chromosomes = new Chromosome[Helper.inputArray.Length / 2]; double[] prevGenes = inititialChromosome.GetGenes(); for (int i = 0; i < Helper.inputArray.Length / 2; i++) { try { double x1 = MackeyGlassEquation.GetValue(ref prevGenes, ref Helper.inputArray, i + 100); double error = Error.CalculateError(Helper.inputArray[i], x1); Error.UpdateValueByError(ref prevGenes, error); double[] newGenes = new double[6]; prevGenes.CopyTo(newGenes, 0); chromosomes[i] = new Chromosome(newGenes); } catch (Exception) { } } CalculateFitnesses(); SortChromosomesByFistness(); return(this); }
public double[] GetOutputArray() { double[] outputArray = new double[Helper.inputArray.Length]; for (int i = 0; i < Helper.inputArray.Length; i++) { if (i <= genes[3] + 1) { outputArray[i] = Helper.inputArray[i]; } else { outputArray[i] = MackeyGlassEquation.GetValue(ref genes, ref Helper.inputArray, i - 1); } } return(outputArray); }
public int RecalculateFitness() { //Todo double[] outputArray = new double[Helper.inputArray.Length / 2]; for (int i = 0; i < Helper.inputArray.Length / 2; i++) { if (i <= genes[3] + 1) { outputArray[i] = Helper.inputArray[i]; } else { outputArray[i] = MackeyGlassEquation.GetValue(ref genes, ref Helper.inputArray, i - 1); } } double error = NMSE.calculate(ref Helper.inputArray, ref outputArray) * 100; fitness = (int)(100 - error); return(fitness); }