private void replaceEnvironment(ITerminator terminator, TestEnvironment environment) { Type typeInQuestion = typeof(Terminator); FieldInfo field = typeInQuestion.GetField("_environment", BindingFlags.NonPublic | BindingFlags.Instance); field.SetValue(terminator, environment); }
public void UpdateTerminator(ITerminator terminator) { if (terminator != null) { _terminator = terminator; } }
public void Launch() { if (generations != null) { generations.Reset(); } if (setup == null) { setup = GetComponent <SetupScript>(); } ui = GetComponent <UIManager>(); cars = setup.Setup(); carStates = new Dictionary <GameObject, CarState>(); carExecutors = new Dictionary <GameObject, GeneExecutor>(); generations = GetComponent <GenerationDB>(); fitness = (IFitnessFunction)System.Activator.CreateInstance(setup.FitnessFunctions.Where(type => type.Name.Equals(selectedFitnessFunction)).First()); terminator = (ITerminator)System.Activator.CreateInstance(setup.Terminators.Where(type => type.Name.Equals(selectedTerminator)).First()); mutator = (IMutator)System.Activator.CreateInstance(setup.Mutators.Where(type => type.Name.Equals(selectedMutator)).First()); foreach (string genetype in selectedGenes) { mutator.AssignGene(((IGene)System.Activator.CreateInstance(setup.GeneTypes.Where(type => type.Name.Equals(genetype)).First())).ID); } selector = (ISelector)System.Activator.CreateInstance(setup.Selectors.Where(type => type.Name.Equals(selectedSelector)).First()); recombiner = (IRecombiner)System.Activator.CreateInstance(setup.Recombiners.Where(type => type.Name.Equals(selectedRecombiner)).First()); init = (IInitializer)System.Activator.CreateInstance(setup.Initializers.Where(type => type.Name.Equals(selectedInitializer)).First()); foreach (string genetype in selectedGenes) { init.AssignGene(((IGene)System.Activator.CreateInstance(setup.GeneTypes.Where(type => type.Name.Equals(genetype)).First())).ID); } SetupCars(); simulation = StartCoroutine(FullSimulation()); }
/// <summary> /// Initialise a new instance of the GeneticEngine class with the supplied plug-ins and populate the initial generation. /// </summary> /// <param name="populator">The populator plug-in. Generates the initial population.</param> /// <param name="evaluator">The evaluator plug-in. Provides the fitness function.</param> /// <param name="geneticOperator">The genetic operator plug-in. Processes one generation to produce the individuals for the next.</param> /// <param name="terminator">The terminator plug-in. Provides the termination condition.</param> /// <param name="outputter">The outputter plug-in or null for no output. Outputs each generation.</param> /// <param name="generationFactory">The generation factory plug-in or null to use the default. Creates the generation container.</param> public GeneticEngine(IPopulator populator, IEvaluator evaluator, IGeneticOperator geneticOperator, ITerminator terminator, IOutputter outputter = null, IGenerationFactory generationFactory = null) { if (populator == null) { throw new GeneticEngineException("populator must not be null"); } if (evaluator == null) { throw new GeneticEngineException("pvaluator must not be null"); } if (geneticOperator == null) { throw new GeneticEngineException("geneticOperator must not be null"); } if (terminator == null) { throw new GeneticEngineException("terminator must not be null"); } this.populator = populator; this.evaluator = evaluator; this.geneticOperator = geneticOperator; this.terminator = terminator; this.outputter = outputter; this.generationFactory = generationFactory == null ? new AATreeGenerationFactory() : generationFactory; Setup(); }
public bool Ignore(ITerminator term) { if (_indexDict.ContainsKey(term.Name)) { return(false); } term.Weight = -1; _ignores.Add(term.Name, term); _indexDict.Add(term.Name, -1); return(true); }
/// <summary> /// The InferPipelines methods are just public portals to the internal function that handle different /// types of data being passed in: training IDataView, path to training file, or train and test files. /// </summary> public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimizerBase autoMlEngine, IDataView trainData, IDataView testData, int numTransformLevels, int batchSize, SupportedMetric metric, out PipelinePattern bestPipeline, ITerminator terminator, MacroUtils.TrainerKinds trainerKind) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(trainData, nameof(trainData)); env.CheckValue(testData, nameof(testData)); int numOfRows = (int)(trainData.GetRowCount(false) ?? 1000); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, trainData, testData); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfRows); return(amls); }
public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimizerBase autoMlEngine, IDataView data, int numTransformLevels, int batchSize, SupportedMetric metric, out PipelinePattern bestPipeline, int numOfSampleRows, ITerminator terminator, MacroUtils.TrainerKinds trainerKind) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(data, nameof(data)); var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return(amls); }
public bool Regist(ITerminator term) { if (_indexDict.ContainsKey(term.Name)) { return(false); } if (term.Weight < 0) { return(false); } if (!_terminators.ContainsKey(term.Weight)) { _terminators.Add(term.Weight, new Dictionary <string, ITerminator>()); } _terminators[term.Weight].Add(term.Name, term); _indexDict.Add(term.Name, term.Weight); return(true); }
public AutoMlMlState(IHostEnvironment env, SupportedMetric metric, IPipelineOptimizer autoMlEngine, ITerminator terminator, MacroUtils.TrainerKinds trainerKind, IDataView trainData = null, IDataView testData = null, string[] requestedLearners = null) { Contracts.CheckValue(env, nameof(env)); _sortedSampledElements = metric.IsMaximizing ? new SortedList <double, PipelinePattern>(new ReversedComparer <double>()) : new SortedList <double, PipelinePattern>(); _history = new List <PipelinePattern>(); _env = env; _host = _env.Register("AutoMlState"); _trainData = trainData; _testData = testData; _terminator = terminator; _requestedLearners = requestedLearners; AutoMlEngine = autoMlEngine; BatchCandidates = new PipelinePattern[] { }; Metric = metric; TrainerKind = trainerKind; }
public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimizerBase autoMlEngine, string trainDataPath, string schemaDefinitionFile, out string schemaDefinition, int numTransformLevels, int batchSize, SupportedMetric metric, out PipelinePattern bestPipeline, int numOfSampleRows, ITerminator terminator, MacroUtils.TrainerKinds trainerKind) { Contracts.CheckValue(env, nameof(env)); // REVIEW: Should be able to infer schema by itself, without having to // infer recipes. Look into this. // Set loader settings through inference RecipeInference.InferRecipesFromData(env, trainDataPath, schemaDefinitionFile, out var _, out schemaDefinition, out var _, true); #pragma warning disable 0618 var data = ImportTextData.ImportText(env, new ImportTextData.Input { InputFile = new SimpleFileHandle(env, trainDataPath, false, false), CustomSchema = schemaDefinition }).Data; #pragma warning restore 0618 var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return(amls); }
/// <summary> ///Check if the plugins have been selected by the user, if not the revelant exceptions are thrown ///asking the user to make a choice. ///So, if the populator,evaluators, geneticOperator and terminator choices are not chosen, then ///error messages are displayed to alert the user, that the choices for these four plugins cannot be null. ///If the plugins are chosen, the engine object is created according to the user choices and it is initialised. ///Once the engine is initialised, the rest of the buttons on the interface are activated and the fitness values ///are displayed. /// </summary> private void initEngineButton_Click(object sender, EventArgs e) { if (!engineRunning) { SetEngineRunning(true); populator = null; evaluator = null; geneticOperator = null; terminator = null; outputter = null; generationFactory = null; string errorMsg = ""; if (cbPopulator.SelectedItem == null) errorMsg += "Populator must not be null\n"; else { string choice = getChoice(populators, cbPopulator); try { populator = (IPopulator)loader.GetInstance(choice, (object)tbMapFile.Text); } catch (GeneticEngineException exception) { MessageBox.Show(exception.Message); } } if (cbEvaluator.SelectedItem == null) errorMsg += "Evaluator must not be null\n"; else { string choice = getChoice(evaluators, cbEvaluator); try { evaluator = (IEvaluator)loader.GetInstance(choice, null); } catch (GeneticEngineException exception) { MessageBox.Show(exception.Message); } } if (cbGeneticOperator.SelectedItem == null) errorMsg += "Genetic Operator must not be null\n"; else { string choice = getChoice(geneticOperators, cbGeneticOperator); try { geneticOperator = (IGeneticOperator)loader.GetInstance(choice, null); } catch (GeneticEngineException exception) { MessageBox.Show(exception.Message); } } if (cbTerminator.SelectedItem == null) errorMsg += "Terminator must not be null\n"; else { string choice = getChoice(terminators, cbTerminator); if ((int)targetFitness.Value == 0) errorMsg += "Provide a target fitness value greater than 1 for the terminator plug-in\n"; else { try { terminator = (ITerminator)loader.GetInstance(choice, (object)(uint)targetFitness.Value); } catch (GeneticEngineException exception) { MessageBox.Show(exception.Message); } } } if (cbOutputter.SelectedItem != null) { string choice = getChoice(outputters, cbOutputter); if (choice != noOutputterString) { if (tbOutputFile.Text == "") { MessageBox.Show("Select an output file for the outputter\n"); } else { outputter = (IOutputter)loader.GetInstance(choice, (object)tbOutputFile.Text); } } } if (cbGenerationFactory.SelectedItem != null) { string choice = getChoice(generationFactories, cbGenerationFactory); if (choice != defaultGenerationFactoryString) { generationFactory = (IGenerationFactory)loader.GetInstance(choice, null); } } if (errorMsg != "") MessageBox.Show(errorMsg + "Please make sure you have selected a populator, evaluator, genetic operator and terminator and then try pressing the button again\n"); else { try { displayOutputter = new DisplayOutputter(this, outputter); engine = new GeneticEngine(populator, evaluator, geneticOperator, terminator, displayOutputter, generationFactory); hasInitialised = true; } catch (GeneticEngineException ex) { MessageBox.Show(ex.Message); } } SetEngineRunning(false); } }
public bool IsRegist(ITerminator term) { return(IsRegist(term.Name)); }
public bool IsIgnore(ITerminator term) { return(IsIgnore(term.Name)); }
public MyDIApplication(ITerminator terminatorDependency) { this.terminator = terminatorDependency; }