public void Initialize() { //parameters.eselectionMethod= ESelectionMethod. if (parameters == null) { parameters = new GPParameters(); } parameters.einitializationMethod = mGPModelParameter.PopulatonInitialization; parameters.eselectionMethod = mGPModelParameter.SelectionMethod; parameters.efitnessFunction = mGPModelParameter.Fitness; parameters.InitiFitness(); parameters.SelParam1 = mGPModelParameter.SelectionParam1; parameters.SelParam2 = mGPModelParameter.SelectionParam2; parameters.maxInitLevel = mGPModelParameter.MaxInitLevel; parameters.maxCossoverLevel = mGPModelParameter.MaxCossoverLevel; parameters.maxMutationLevel = mGPModelParameter.MaxMutationLevel; parameters.elitism = mGPModelParameter.Elitism; parameters.probCrossover = mGPModelParameter.ProbCrossover; parameters.probMutation = mGPModelParameter.ProbMutation; parameters.probPermutation = mGPModelParameter.ProbPermutation; parameters.probReproduction = mGPModelParameter.ProbReproduction; }
/// <summary> /// Set GUI based on the GPParameters /// </summary> /// <param name="parameters"></param> /// <returns></returns> public bool SetParameters(GPParameters parameters) { txtPopSize.Text = parameters.popSize.ToString(); cmbSelectionMethods.SelectedIndex = (int)parameters.eselectionMethod; cmbFitnessFuncs.SelectedIndex = getFitnessSelectedIndex(parameters.GPFitness); txtElitism.Text = parameters.elitism.ToString(); cmbInitMethods.SelectedIndex = (int)parameters.einitializationMethod; txtSelParam1.Text = parameters.SelParam1.ToString(); txtSelParam2.Text = parameters.SelParam1.ToString(); txtInitTreeDepth.Text = parameters.maxInitLevel.ToString(); txtOperationTreeDepth.Text = parameters.maxOperationLevel.ToString(); txtProbCrossover.Text = parameters.probCrossover.ToString(); txtProbMutation.Text = parameters.probMutation.ToString(); txtProbReproduction.Text = parameters.probReproduction.ToString(); //txtProbPermutation.Text = parameters.probPermutation.ToString(); //txtProbEncaptulation.Text = "ewe"; txtRandomConsTo.Text = parameters.rConstTo.ToString(); txtRandomConsFrom.Text = parameters.rConstFrom.ToString(); txtRandomConstNum.Text = parameters.rConstNum.ToString(); radioIsParallel.Checked = parameters.bParalelGP; /// txtBroodSize.Text = parameters.broodSize.ToString(); isProtectedOperation.Checked = parameters.isProtectedOperationEnabled; return(true); }
/// <summary> /// Before we start GP prepare all neccessery information /// </summary> /// <param name="termSet"></param> /// <param name="funSet"></param> /// <param name="gpParams"></param> public void PrepareAlgorithm(GPTerminalSet termSet, GPFunctionSet funSet, GPParameters gpParams = null) { m_IterationCounter = 0; if (Population == null) { Population = new CHPopulation(); } Population.InitPopulation(termSet, funSet, gpParams); Population.CalculatePopulation(); IsAlgorthmPrepared = true; StopIteration = false; //calculate model and prediction GPChromosome ch = Population.bestChromosome as GPChromosome; double[][] model = CalculateModel(ch); double[][] prediction = CalculateModel(ch, false); //Report the evolution has been started if (ReportEvolution != null) { ReportEvolution(this, new ProgressIndicatorEventArgs() { ReportType = ProgramState.Started, AverageFitness = Population.fitnessAvg, BestChromosome = Population.bestChromosome, CurrentIteration = 0, LearnOutput = model, PredicOutput = prediction }); } }
/// <summary> /// Initialisation of chromosomes in Genetic programming /// </summary> /// <param name="size">Size of the chromosomes, default value is 1000</param> /// <param name="initMethod">Initializastion method, default HalfandHalf</param> public void InitPopulation( GPTerminalSet termSet, GPFunctionSet funSet, GPParameters gpParams = null ) { if (gpParams == null) { gpParameters = new GPParameters(); } else { gpParameters = gpParams; } fitnessFunction = gpParameters.GPFitness; if (funSet == null) { throw new Exception("FunctionSet is not defined, and cannot be null!"); } { functionSet = funSet; Globals.functions = functionSet; } if (funSet == null) { throw new Exception("TerminalSet is not defined, and cannot be null!"); } Globals.terminals = termSet; GeneratePopulation(gpParameters.popSize); }
public void SetGPParameter(GPParameters gpp) { Population.SetParameters(gpp); }
/// <summary> /// Return current value of GP params /// </summary> /// <returns></returns> public GPParameters GetParameters() { GPParameters parameters = new GPParameters(); parameters.einitializationMethod = (GPInitializationMethod)cmbInitMethods.SelectedIndex; parameters.eselectionMethod = (GPSelectionMethod)cmbSelectionMethods.SelectedIndex; // parameters.GPFitness = SelectFitnessFun(cmbFitnessFuncs.SelectedIndex); // parameters.InitiFitness(); if (!int.TryParse(txtPopSize.Text, out parameters.popSize)) { MessageBox.Show("Invalid value for Population size!"); return(null); } if (!int.TryParse(txtElitism.Text, out parameters.elitism)) { MessageBox.Show("Invalid value for Elitism!"); return(null); } if (!float.TryParse(txtSelParam1.Text, out parameters.SelParam1)) { MessageBox.Show("Invalid value for Parameter 1!"); return(null); } if (!float.TryParse(txtSelParam2.Text, out parameters.SelParam2)) { MessageBox.Show("Invalid value for Parameter 2!"); return(null); } if (!int.TryParse(txtInitTreeDepth.Text, out parameters.maxInitLevel)) { MessageBox.Show("Invalid value for Initial tree depth!"); return(null); } if (!int.TryParse(txtOperationTreeDepth.Text, out parameters.maxOperationLevel)) { MessageBox.Show("Invalid value for Operation tree depth!"); return(null); } parameters.bParalelGP = radioIsParallel.Checked; if (!float.TryParse(txtRandomConsFrom.Text, out parameters.rConstFrom)) { MessageBox.Show("Invalid value for interval to!"); return(null); } if (!float.TryParse(txtRandomConsTo.Text, out parameters.rConstTo)) { MessageBox.Show("Invalid value for interval from!"); return(null); } if (!int.TryParse(txtRandomConstNum.Text, out parameters.rConstNum)) { MessageBox.Show("Invalid value for Number of Constants!"); return(null); } if (parameters.rConstNum < 0) { MessageBox.Show("Invalid value for Number of Constants!"); return(null); } if (!float.TryParse(txtProbCrossover.Text, out parameters.probCrossover)) { MessageBox.Show("Invalid value for Crossover probability!"); return(null); } if (!float.TryParse(txtProbMutation.Text, out parameters.probMutation)) { MessageBox.Show("Invalid value for Mutation probability!"); return(null); } if (!float.TryParse(txtProbReproduction.Text, out parameters.probReproduction)) { MessageBox.Show("Invalid value for Reproduction probability!"); return(null); } if (!int.TryParse(txtBroodSize.Text, out parameters.broodSize)) { MessageBox.Show("Invalid Brood Size value!"); return(null); } parameters.isProtectedOperationEnabled = isProtectedOperation.Checked; return(parameters); }
/// <summary> /// /// </summary> /// <param name="gpp"></param> internal void SetParameters(GPParameters gpp) { Globals.gpparameters = gpp; }
/// <summary> /// Initialisation of chromosomes in Genetic programming /// </summary> /// <param name="size">Size of the chromosomes, default value is 1000</param> /// <param name="initMethod">Initializastion method, default HalfandHalf</param> public void InitPopulation( GPTerminalSet termSet, IFunctionSet funSet, GPParameters gpParams = null ) { if (gpParams == null) { Globals.gpparameters = new GPParameters(); } else { Globals.gpparameters = gpParams; } if (Globals.gpparameters.algorithmType == Algorithm.GA) { if (Globals.gpparameters.chromosomeKind == GAChromosome.Continue) { GANumChromosome.functionSet = funSet; } else if (Globals.gpparameters.chromosomeKind == GAChromosome.TSP) { GAVChromosome.functionSet = funSet; } else if (Globals.gpparameters.chromosomeKind == GAChromosome.ALOC) { GAVChromosome.functionSet = funSet; } else if (Globals.gpparameters.chromosomeKind == GAChromosome.TP) { GAMChromosome.terminalSet = termSet; GAMChromosome.functionSet = funSet; } else { GABinChromosome.functionSet = funSet; } } else { GPChromosome.MaxOperationLevel = Globals.gpparameters.maxOperationLevel; } //init default fitness type if (Globals.gpparameters.GPFitness == null) { Globals.gpparameters.GPFitness = new RMSEFitness(); } fitnessFunction = Globals.gpparameters.GPFitness; if (funSet == null) { throw new Exception("FunctionSet is not defined, and cannot be null!"); } else { functionSet = funSet; Globals.functions = functionSet; } if (termSet == null) { throw new Exception("TerminalSet is not defined, and cannot be null!"); } else { Globals.gpterminals = termSet; } var siz = Globals.gpparameters.popSize - chromosomes.Count; if (siz > 0) { GeneratePopulation(siz); } }