Ejemplo n.º 1
0
        public void InitPersistedModel()
        {
            //gp panel
            if (Factory != null && Factory.Parameters != null)
            {
                var p = Factory.Parameters;

                //Input data
                //Inputs = ExpData.GetInputData(p.Constants);
                var rv      = ExpData.GetInputData();
                var dataSet = new ExperimentData(rv.train, rv.test, p.Constants);
                dataSet.SetExperiment(ExpData);
                Inputs = dataSet;

                //Calculate nonPersisted parameter properties
                Factory.Parameters.FeatureCount     = ExpData.GetEncodedColumnInputCount();
                Factory.Parameters.IsMultipleOutput = ExpData.GetEncodedColumnOutputCount() > 1;
            }
        }
Ejemplo n.º 2
0
        /// <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;
            }
        }