public void PrepareForSave(ActiveDataBase activeData) { //transfer activadata in to Model Factory.FunctionSet = copyFunctionSet(activeData.FunctionSet); var dic = activeData.Parameters.ToDictionary(); Factory.Parameters = Parameters.FromDictionary(dic); //termination criteria Factory.TC.IsIteration = activeData.TC.IsIteration; Factory.TC.Value = activeData.TC.Value; //mark the file as saved IsDiry = false; }
/// <summary> /// Returns the curent settings of the model /// </summary> /// <returns></returns> public ActiveDataBase GetModelSettings(Action <ProgressReport, Parameters> reportRun) { var adb = new ActiveDataBase(); // //first 4 algebraical operations +,-,*,/ adb.FunctionSet = copyFunctionSet(Factory.FunctionSet); //terminal set // adb.t= new int[] { 1000, 1001, 1002, 1003 }; //prepare params adb.Parameters = Parameters.FromDictionary(Factory.Parameters.ToDictionary());; //termination criteria adb.TC = new TerminationCriteria() { IsIteration = Factory.TC.IsIteration, Value = Factory.TC.Value }; adb.reportRun = reportRun; return(adb); }
/// <summary> /// Run GP Program /// </summary> public async Task RunGPAsync(ActiveDataBase currentData, CancellationToken cancellationToken, bool resetPrevSolution) { try { if (resetPrevSolution) { ResetModel(); } //Get parameters from Settings panel var param = Parameters.FromDictionary(currentData.Parameters.ToDictionary()); //set random constants setRandomConstants(param, resetPrevSolution); //use this only when developing this module in order to make debug simple //param.ParallelProcessing = false; //create fitness function //Inputs = ExpData.GetInputData(param.Constants); var rv = ExpData.GetInputData(); var dataSet = new ExperimentData(rv.train, rv.test, param.Constants); dataSet.SetExperiment(ExpData); Inputs = dataSet; // param.FitnessFunction = selectFitnessFunction(param.FitnessName, Inputs); if (param.FitnessFunction == null) { throw new Exception("Fitness type is not defined!"); } //define Learning type setLearningType(param); //creating function and terminal set Function[] functionSet = copyFunctionSet(currentData.FunctionSet); var term = terminalSet(param); //create termination criteria var terrCriteria = new TerminationCriteria() { IsIteration = currentData.TC.IsIteration, Value = currentData.TC.Value }; //create GPFactory if (Factory != null && !resetPrevSolution) { Factory.Population.Token = cancellationToken; Factory.Continue(param, functionSet, term.ToArray()); } else { Factory = new Core.Factory(param, functionSet, term.ToArray(), cancellationToken); } IsDiry = true; //start GP await Factory.RunAsync(currentData.reportRun, terrCriteria, cancellationToken); } catch (Exception) { throw; } }