/// <summary> /// Configures the current target algorithm and gray box handler. /// </summary> /// <param name="targetAlgorithmFactory">The <see cref="ITargetAlgorithmFactory{TTargetAlgorithm,TInstance,TResult}"/>.</param> /// <param name="parameterTree">The <see cref="ParameterTree"/>.</param> /// <param name="indexOfDesiredPostTuningRun">The index of the desired post tuning run.</param> /// <param name="postTuningGenomeInstancePair">The post tuning genome instance pair.</param> private void ConfigureTargetAlgorithmAndGrayBoxHandler( ITargetAlgorithmFactory <TGrayBoxTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, ParameterTree parameterTree, int indexOfDesiredPostTuningRun, GenomeInstancePairStringRepresentation postTuningGenomeInstancePair) { var genomeDoubleRepresentation = GenomeDoubleRepresentation.GetGenomeDoubleRepresentationFromGenomeIdentifierStringRepresentation(postTuningGenomeInstancePair.Genome); var genomeTransformation = new GenomeTransformation <CategoricalBinaryEncoding>(parameterTree); var genome = genomeTransformation.ConvertBack(genomeDoubleRepresentation); var runnerDictionary = genome.GetFilteredGenes(parameterTree); this._configuredTargetAlgorithm = targetAlgorithmFactory.ConfigureTargetAlgorithm(runnerDictionary); // Set generation to -1, since this is a post tuning run. var tunerDataRecord = new TunerDataRecord <TResult>( NetworkUtils.GetFullyQualifiedDomainName(), -1, 0, postTuningGenomeInstancePair.Instance, double.NaN, genomeTransformation.GetConverterColumnHeader(), genomeDoubleRepresentation, null); this._grayBoxHandler = new GrayBoxHandler <TInstance, TResult>( this._tunerConfiguration, this._configuredTargetAlgorithm, indexOfDesiredPostTuningRun, tunerDataRecord, false, null, null); }
/// <summary> /// Validates the parameters: /// * Null checks for every one of them. /// * Checks that the number of training instances provided is sufficient considering the given configuration. /// * Checks that configuration about whether to use run time tuning /// and the usage of the run time tuning result interface fit together /// * Checks that the parameter tree contains parameters. /// * Checks that those parameters' identifiers are unique. /// </summary> /// <param name="targetAlgorithmFactory"> /// Produces configured instances of the target algorithm to tune. /// </param> /// <param name="runEvaluator"> /// Object for evaluating target algorithm runs. /// </param> /// <param name="trainingInstances"> /// The set of instances used for tuning. /// </param> /// <param name="parameterTree"> /// The parameter tree. /// </param> /// <param name="configuration"> /// Algorithm tuner configuration parameters. /// </param> /// <param name="genomeBuilder"> /// The genome builder. /// </param> private static void ValidateParameters( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, GenomeBuilder genomeBuilder) { // Check argument for nulls. if (targetAlgorithmFactory == null) { throw new ArgumentNullException(nameof(targetAlgorithmFactory), "You must specify a target algorithm factory."); } if (runEvaluator == null) { throw new ArgumentNullException(nameof(runEvaluator), "You must specify a run evaluator."); } if (trainingInstances == null) { throw new ArgumentNullException(nameof(trainingInstances), "You must specify a list of training instances."); } if (parameterTree == null) { throw new ArgumentNullException(nameof(parameterTree), "You must specify a parameter tree."); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration), "You must specify an algorithm tuner configuration."); } if (genomeBuilder == null) { throw new ArgumentNullException(nameof(genomeBuilder), "You must specify a genome builder."); } // Check enough training instances have been provided. var numInstances = trainingInstances.Count(); if (numInstances < configuration.EndNumInstances) { throw new ArgumentException( $"In the end, {configuration.EndNumInstances} training instances should be used, but only {numInstances} have been provided.", nameof(trainingInstances)); } // Check that the parameter tree is valid. if (!parameterTree.ContainsParameters()) { throw new ArgumentException("Specified parameter tree without parameters.", nameof(parameterTree)); } if (!parameterTree.IdentifiersAreUnique()) { throw new ArgumentException("Specified parameter tree contained duplicate identifiers.", nameof(parameterTree)); } }
/// <summary> /// Initializes a new instance of the <see cref="DataRecordCsvMapping{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="targetAlgorithmFactory">The target algorithm factory.</param> /// <param name="genomeHeader">The genome header.</param> /// <param name="adapterFeaturesHeader">The adapter features header.</param> /// <param name="numberOfResultColumns">The number of result columns.</param> public DataRecordCsvMapping( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, string[] genomeHeader, string[] adapterFeaturesHeader, int numberOfResultColumns) { var lastTunerDataRecordColumn = TunerDataRecord <TResult> .OtherHeader.Length + genomeHeader.Length + numberOfResultColumns - 1; var lastAdapterDataRecordColumn = lastTunerDataRecordColumn + AdapterDataRecord <TResult> .OtherHeader.Length + adapterFeaturesHeader.Length + numberOfResultColumns; this.MapProperty( new RangeDefinition(0, lastTunerDataRecordColumn), x => x.TunerDataRecord, new TunerDataRecordCsvMapping <TTargetAlgorithm, TInstance, TResult>( targetAlgorithmFactory, genomeHeader, numberOfResultColumns)); this.MapProperty( new RangeDefinition(lastTunerDataRecordColumn + 1, lastAdapterDataRecordColumn), x => x.AdapterDataRecord, new AdapterDataRecordCsvMapping <TTargetAlgorithm, TInstance, TResult>( targetAlgorithmFactory, adapterFeaturesHeader, numberOfResultColumns)); }
/// <summary> /// Initializes a new instance of the <see cref="MiniTournamentActor{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="targetAlgorithmFactory">Produces configured target algorithms to run with the genomes.</param> /// <param name="runEvaluator">Object for evaluating target algorithm runs.</param> /// <param name="configuration">Algorithm tuner configuration parameters.</param> /// <param name="resultStorageActor"> /// Actor which is responsible for storing all evaluation results that have /// been observed so far. /// </param> /// <param name="parameterTree">Specifies parameters and their relationships.</param> /// <param name="tournamentSelector">Actor which provides this actor with evaluation tasks.</param> public MiniTournamentActor( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, AlgorithmTunerConfiguration configuration, IActorRef resultStorageActor, ParameterTree parameterTree, IActorRef tournamentSelector) : base(runEvaluator) { if (tournamentSelector == null) { throw new ArgumentNullException(nameof(tournamentSelector)); } this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory)); this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._resultStorageActor = resultStorageActor ?? throw new ArgumentNullException(nameof(resultStorageActor)); this._parameterTree = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree)); // Start in waiting for instances state. this.WaitForInstances(); // Finally, find out if there is something to do already. tournamentSelector.Tell(new InstancesRequest()); }
/// <summary> /// Initializes a new instance of the <see cref="AdapterDataRecordCsvMapping{TTargetAlgorithm, TInstance, TResult}"/> class. /// </summary> /// <param name="targetAlgorithmFactory">The target algorithm factory.</param> /// <param name="adapterFeaturesHeader">The adapter features header.</param> /// <param name="numberOfResultColumns">The number of result columns.</param> public AdapterDataRecordCsvMapping( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, string[] adapterFeaturesHeader, int numberOfResultColumns) { this._targetAlgorithmFactory = targetAlgorithmFactory; this._adapterFeaturesHeader = adapterFeaturesHeader; this._numberOfResultColumns = numberOfResultColumns; }
/// <summary> /// Initializes a new instance of the <see cref="TunerDataRecordCsvMapping{TTargetAlgorithm, TInstance, TResult}"/> class. /// </summary> /// <param name="targetAlgorithmFactory">The target algorithm factory.</param> /// <param name="genomeHeader">The genome header.</param> /// <param name="numberOfResultColumns">The number of result columns.</param> public TunerDataRecordCsvMapping( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, string[] genomeHeader, int numberOfResultColumns) { this._targetAlgorithmFactory = targetAlgorithmFactory; this._genomeHeader = genomeHeader; this._numberOfResultColumns = numberOfResultColumns; }
/// <summary> /// Initializes a new instance of the <see cref="AlgorithmTuner{TTargetAlgorithm,TInstance,TResult}"/> class. /// </summary> /// <param name="targetAlgorithmFactory"> /// The target algorithm factory. /// </param> /// <param name="runEvaluator"> /// The run evaluator. /// </param> /// <param name="trainingInstances"> /// The training instances. /// </param> /// <param name="parameterTree"> /// The parameter tree. /// </param> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="genomeBuilder"> /// The genome builder. /// </param> public AlgorithmTuner( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, GenomeBuilder genomeBuilder) : base(targetAlgorithmFactory, runEvaluator, trainingInstances, parameterTree, configuration, genomeBuilder) { }
/// <summary> /// Initializes a new instance of the <see cref="TournamentSelector{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="targetAlgorithmFactory">Produces configured target algorithms to run with the genomes.</param> /// <param name="runEvaluator">Object for evaluating target algorithm runs.</param> /// <param name="configuration">Algorithm tuner configuration parameters.</param> /// <param name="resultStorageActor"> /// Actor which is responsible for storing all evaluation results that have /// been observed so far. /// </param> /// <param name="parameterTree">Specifies parameters and their relationships.</param> public TournamentSelector( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, AlgorithmTunerConfiguration configuration, IActorRef resultStorageActor, ParameterTree parameterTree) { // Verify parameters. if (targetAlgorithmFactory == null) { throw new ArgumentNullException("targetAlgorithmFactory"); } if (runEvaluator == null) { throw new ArgumentNullException("runEvaluator"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (resultStorageActor == null) { throw new ArgumentNullException("resultStorageActor"); } if (parameterTree == null) { throw new ArgumentNullException("parameterTree"); } // Use them to set fields. this._targetAlgorithmFactory = targetAlgorithmFactory; this._runEvaluator = runEvaluator; this._configuration = configuration; this._resultStorageActor = resultStorageActor; this._parameterTree = parameterTree; this._selectionProgress = new TournamentSelectionProgress <TInstance, TResult>(this._configuration); // If Akka.Cluster gets used, watch for disconnecting cluster members // to make tournament rollbacks possible. if (Context.System.HasExtension <Cluster>()) { Cluster.Get(Context.System).Subscribe(this.Self, typeof(ClusterEvent.UnreachableMember)); } // Start in waiting for workers state. this.WaitingForWorkers(); // And directly check if we have enough workers to switch to ready state. this.Self.Tell(new CheckWorkers()); }
/// <summary> /// Creates a <see cref="TournamentSelector{TTargetAlgorithm, TInstance, TResult}"/>. /// </summary> /// <typeparam name="TTargetAlgorithm">Algorithm to execute.</typeparam> /// <typeparam name="TInstance">Type of instances the algorithm takes.</typeparam> /// <typeparam name="TResult">Type of result the algorithm returns.</typeparam> /// <param name="system">The <see cref="ActorSystem"/> to add the actor to.</param> /// <param name="targetAlgorithmFactory">Specifies how to create an algorithm instance.</param> /// <param name="runEvaluator">Specifies how runs should be compared.</param> /// <returns>The created <see cref="TournamentSelector{TTargetAlgorithm, TInstance, TResult}"/>.</returns> private IActorRef CreateTournamentSelector <TTargetAlgorithm, TInstance, TResult>( ActorSystem system, ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator) where TTargetAlgorithm : ITargetAlgorithm <TInstance, TResult> where TInstance : InstanceBase where TResult : ResultBase <TResult>, new() { return(system.ActorOf( Props.Create( () => new TournamentSelector <TTargetAlgorithm, TInstance, TResult>( targetAlgorithmFactory, runEvaluator, this._configuration, this._resultStorageActor, this._parameterTree)), AkkaNames.TournamentSelector)); }
/// <summary> /// Initializes a new instance of the <see cref="AlgorithmTuner{TTargetAlgorithm,TInstance,TResult}"/> class. /// </summary> /// <param name="targetAlgorithmFactory"> /// The target algorithm factory. /// </param> /// <param name="runEvaluator"> /// The run evaluator. /// </param> /// <param name="trainingInstances"> /// The training instances. /// </param> /// <param name="parameterTree"> /// The parameter tree. /// </param> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>, if any. Default is null.</param> public AlgorithmTuner( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TInstance, TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, ICustomGrayBoxMethods <TResult> customGrayBoxMethods = null) : this( targetAlgorithmFactory, runEvaluator, trainingInstances, parameterTree, configuration, new GenomeBuilder(parameterTree, configuration), customGrayBoxMethods) { }
/// <summary> /// Initializes a new instance of the <see cref="EvaluationActor{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="targetAlgorithmFactory">Produces configured target algorithms to run with the genomes.</param> /// <param name="resultStorageActor"> /// Actor which is responsible for storing all evaluation results that have /// been observed so far. /// </param> /// <param name="configuration">Algorithm tuner configuration parameters.</param> /// <param name="parameterTree">Specifies parameters and their relationships.</param> public EvaluationActor( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IActorRef resultStorageActor, AlgorithmTunerConfiguration configuration, ParameterTree parameterTree) { this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory)); this._resultStorageActor = resultStorageActor ?? throw new ArgumentNullException(nameof(resultStorageActor)); this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._parameterTree = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree)); this._currentEvaluationProgress = new GenomeEvaluationProgress <TInstance, TResult>(); // Start in wait for instances state. this.WaitForInstances(); // Finally, volunteer for work. UntypedActor.Context.System.ActorSelection($"/*/{AkkaNames.GenomeSorter}").Tell(new Accept()); }
/// <summary> /// Creates the different <see cref="IPopulationUpdateStrategy{TInstance,TResult}"/>s that may be used to /// update the population. /// </summary> /// <param name="targetAlgorithmFactory"> /// Produces configured instances of the target algorithm to tune. /// </param> /// <param name="runEvaluator"> /// Object for evaluating target algorithm runs. /// </param> /// <returns>The created <see cref="IPopulationUpdateStrategy{TInstance,TResult}"/>s.</returns> private IEnumerable <IPopulationUpdateStrategy <TInstance, TResult> > CreatePopulationUpdateStrategies( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator) { var tournamentSelector = this._targetAlgorithmRunActors.ActorOf( Props.Create( () => new TournamentSelector <TTargetAlgorithm, TInstance, TResult>( targetAlgorithmFactory, runEvaluator, this._configuration, this._targetRunResultStorage, this._parameterTree)), AkkaNames.TournamentSelector); yield return(new GgaStrategy <TInstance, TResult>( this._configuration, this._parameterTree, this._genomeBuilder, tournamentSelector, this.GeneticEngineering)); if (this._configuration.ContinuousOptimizationMethod == ContinuousOptimizationMethod.Jade) { yield return(new DifferentialEvolutionStrategy <TInstance, TResult>( this._configuration, this._parameterTree, this._genomeBuilder, this._genomeSorter, this._targetRunResultStorage)); } if (this._configuration.ContinuousOptimizationMethod == ContinuousOptimizationMethod.CmaEs) { yield return(CovarianceMatrixAdaptationInformationFlowSwitch.CreateCovarianceMatrixAdaptationStrategy <TInstance, TResult>( this._configuration, this._parameterTree, this._genomeBuilder, this._genomeSorter, this._targetRunResultStorage)); } }
/// <summary> /// Initializes a new instance of the <see cref="ParallelPostTuningRunner{TTargetAlgorithm,TInstance,TResult}"/> class. /// </summary> /// <param name="tunerConfiguration">The tuner configuration.</param> /// <param name="postTuningConfiguration">The post tuning configuration.</param> /// <param name="targetAlgorithmFactory">The target algorithm factory.</param> /// <param name="parameterTree">The parameter tree.</param> public ParallelPostTuningRunner( AlgorithmTunerConfiguration tunerConfiguration, PostTuningConfiguration postTuningConfiguration, ITargetAlgorithmFactory <TGrayBoxTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, ParameterTree parameterTree) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); GrayBoxUtils.ValidatePostTuningConfiguration(postTuningConfiguration); GrayBoxUtils.ValidateAdditionalPostTuningParameters(tunerConfiguration, targetAlgorithmFactory, parameterTree); this._tunerConfiguration = tunerConfiguration; this._postTuningConfiguration = postTuningConfiguration; this._targetAlgorithmFactory = targetAlgorithmFactory; this._parameterTree = parameterTree; this._postTuningFile = new FileInfo(postTuningConfiguration.PathToPostTuningFile); if (!GrayBoxUtils.TryToReadGenomeInstancePairsFromFile(this._postTuningFile, out this._listOfPostTuningGenomeInstancePairs)) { throw new ArgumentException($"Cannot read genome instance pairs from {this._postTuningFile.FullName}!"); } }
/// <summary> /// Initializes a new instance of the <see cref="SinglePostTuningRunner{TTargetAlgorithm,TInstance,TResult}"/> class. /// </summary> /// <param name="tunerConfiguration">The tuner configuration.</param> /// <param name="targetAlgorithmFactory">The target algorithm factory.</param> /// <param name="parameterTree">The parameter tree.</param> /// <param name="postTuningGenomeInstancePair">The post tuning genome instance pair..</param> /// <param name="indexOfDesiredPostTuningRun">The index of the desired post tuning run.</param> internal SinglePostTuningRunner( AlgorithmTunerConfiguration tunerConfiguration, ITargetAlgorithmFactory <TGrayBoxTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, ParameterTree parameterTree, GenomeInstancePairStringRepresentation postTuningGenomeInstancePair, int indexOfDesiredPostTuningRun) { GrayBoxUtils.ValidateAdditionalPostTuningParameters(tunerConfiguration, targetAlgorithmFactory, parameterTree); this._tunerConfiguration = tunerConfiguration; this.ConfigureTargetAlgorithmAndGrayBoxHandler( targetAlgorithmFactory, parameterTree, indexOfDesiredPostTuningRun, postTuningGenomeInstancePair); if (!targetAlgorithmFactory.TryToGetInstanceFromInstanceId(postTuningGenomeInstancePair.Instance, out this._instance)) { throw new ArgumentException($"Cannot convert given instance id {postTuningGenomeInstancePair.Instance} to valid instance."); } }
/// <summary> /// Initializes a new instance of the <see cref="AlgorithmTuner{TTargetAlgorithm,TInstance,TResult,TModelLearner,TPredictorModel,TSamplingStrategy}"/> class. /// </summary> /// <param name="targetAlgorithmFactory"> /// Produces configured instances of the algorithm to tune. /// </param> /// <param name="runEvaluator"> /// Object for evaluating target algorithm runs. /// </param> /// <param name="trainingInstances"> /// The set of instances used for tuning. /// </param> /// <param name="parameterTree"> /// Provides the tunable parameters. /// </param> /// <param name="configuration"> /// Algorithm tuner configuration parameters. /// </param> /// <param name="genomeBuilder"> /// Responsible for creation, modification and crossover of genomes. /// Needs to be compatible with the given parameter tree and configuration. /// This parameter can be left out if an ordinary <see cref="GenomeBuilder"/> should be used. /// </param> public AlgorithmTuner( ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, IRunEvaluator <TResult> runEvaluator, IEnumerable <TInstance> trainingInstances, ParameterTree parameterTree, AlgorithmTunerConfiguration configuration, GenomeBuilder genomeBuilder) { ValidateParameters(targetAlgorithmFactory, runEvaluator, trainingInstances, parameterTree, configuration, genomeBuilder); LoggingHelper.WriteLine( VerbosityLevel.Info, $"Tuning target algorithm with {parameterTree.GetParameters().Count()} parameters."); this._configuration = configuration; this._runEvaluator = runEvaluator; this.GeneticEngineering = new GeneticEngineering <TModelLearner, TPredictorModel, TSamplingStrategy>(parameterTree, this._configuration); this.IncumbentQuality = new List <double>(); this._trainingInstances = trainingInstances.ToList(); this._instanceSelector = new InstanceSelector <TInstance>(this._trainingInstances, configuration); this._parameterTree = parameterTree; this._genomeBuilder = genomeBuilder; this._targetAlgorithmRunActors = ActorSystem.Create(AkkaNames.ActorSystemName, configuration.AkkaConfiguration); this._targetRunResultStorage = this._targetAlgorithmRunActors.ActorOf( Props.Create(() => new ResultStorageActor <TInstance, TResult>()), AkkaNames.ResultStorageActor); this._genomeSorter = this._targetAlgorithmRunActors.ActorOf( Props.Create(() => new GenomeSorter <TInstance, TResult>(runEvaluator)), AkkaNames.GenomeSorter); this._logWriter = new LogWriter <TInstance, TResult>(parameterTree, configuration); this._populationUpdateStrategyManager = new PopulationUpdateStrategyManager <TInstance, TResult>( this.CreatePopulationUpdateStrategies(targetAlgorithmFactory, runEvaluator).ToList(), configuration); }
/// <summary> /// Initializes a new instance of the <see cref="GrayBoxSimulation{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="configuration">The <see cref="AlgorithmTunerConfiguration"/>.</param> /// <param name="targetAlgorithmFactory">The <see cref="ITargetAlgorithmFactory{TTargetAlgorithm, TInstance, TResult}"/>.</param> /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param> /// <param name="runEvaluator">The <see cref="IRunEvaluator{TInstance, TResult}"/>.</param> /// <param name="parameterTree">The <see cref="ParameterTree"/>.</param> public GrayBoxSimulation( AlgorithmTunerConfiguration configuration, ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, ICustomGrayBoxMethods <TResult> customGrayBoxMethods, IRunEvaluator <TInstance, TResult> runEvaluator, ParameterTree parameterTree) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._customGrayBoxMethods = customGrayBoxMethods ?? throw new ArgumentNullException(nameof(customGrayBoxMethods)); this._runEvaluator = runEvaluator ?? throw new ArgumentNullException(nameof(runEvaluator)); this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory)); this._parameterTree = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree)); this._logFileDirectory = new DirectoryInfo(Path.Combine(this._configuration.DataRecordDirectoryPath, "GrayBoxSimulationLogFiles")); Directory.CreateDirectory(this._logFileDirectory.FullName); LoggingHelper.Configure( Path.Combine(this._logFileDirectory.FullName, $"consoleOutput_GrayBoxSimulation_{ProcessUtils.GetCurrentProcessId()}.log")); LoggingHelper.ChangeConsoleLoggingLevel(configuration.Verbosity); LoggingHelper.WriteLine(VerbosityLevel.Info, "Reading in and preprocessing data for gray box simulation."); if (!GrayBoxUtils.TryToReadDataRecordsFromDirectory( targetAlgorithmFactory, configuration.DataRecordDirectoryPath, 0, configuration.Generations - 1, out this._allDataRecords)) { throw new ArgumentException($"Cannot read data records from {configuration.DataRecordDirectoryPath}!"); } this.ReadGenerationCompositionFiles(); this.CreatePredictionDictionaryAndDataDictionary(); }
/// <summary> /// Sets the <see cref="ITargetAlgorithmFactory{NoOperation, TestInstance, EmptyResult}"/> to provide to /// the <see cref="EvaluationActor{NoOperation, TestInstance, EmptyResult}"/> constructor. /// Default is a factory which creates the same noop target algorithm <see cref="NoOperation"/> /// for all inputs. /// </summary> /// <param name="targetAlgorithmFactory">The target algorithm factory to provide to the evaluation actor /// constructor.</param> /// <returns>The <see cref="EvaluationActorPropsBuilder"/> in its new state.</returns> public EvaluationActorPropsBuilder SetTargetAlgorithmFactory( ITargetAlgorithmFactory <NoOperation, TestInstance, TestResult> targetAlgorithmFactory) { this._targetAlgorithmFactory = targetAlgorithmFactory; return(this); }