Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EvaluationActor{TTargetAlgorithm, TInstance, TResult}" /> class.
        /// </summary>
        /// <param name="targetAlgorithmFactory">The target algorithm factory.</param>
        /// <param name="configuration">The algorithm tuner configuration.</param>
        /// <param name="parameterTree">The parameter tree.</param>
        /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param>
        /// <param name="generationEvaluationActor">The generation evaluation actor.</param>
        public EvaluationActor(
            ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory,
            AlgorithmTunerConfiguration configuration,
            ParameterTree parameterTree,
            ICustomGrayBoxMethods <TResult> customGrayBoxMethods,
            IActorRef generationEvaluationActor)
        {
            LoggingHelper.WriteLine(VerbosityLevel.Info, $"Starting new evaluation actor! Address: {this.Self}");

            this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory));
            this._configuration          = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._parameterTree          = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree));

            if (generationEvaluationActor == null)
            {
                throw new ArgumentNullException(nameof(generationEvaluationActor));
            }

            // No need to check for null. Might be null by purpose.
            this._customGrayBoxMethods = customGrayBoxMethods;

            this._id = Interlocked.Increment(ref EvaluationActor <TTargetAlgorithm, TInstance, TResult> .idCounter);

            this.Become(this.Ready);
            generationEvaluationActor.Tell(new HelloWorld());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenerationEvaluationActor{TTargetAlgorithm, TInstance, TResult}"/> class.
        /// </summary>
        /// <param name="targetAlgorithmFactory">The <see cref="ITargetAlgorithmFactory{TTargetAlgorithm,TInstance,TResult}"/>.</param>
        /// <param name="runEvaluator">The <see cref="IRunEvaluator{TInstance,TResult}"/>.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="resultStorageActor">The <see cref="IActorRef"/> to the result storage actor.</param>
        /// <param name="parameterTree">The parameter tree.</param>
        /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param>
        public GenerationEvaluationActor(
            ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory,
            IRunEvaluator <TInstance, TResult> runEvaluator,
            AlgorithmTunerConfiguration configuration,
            IActorRef resultStorageActor,
            ParameterTree parameterTree,
            ICustomGrayBoxMethods <TResult> customGrayBoxMethods)
        {
            this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory));
            this._runEvaluator           = runEvaluator ?? throw new ArgumentNullException(nameof(runEvaluator));
            this._configuration          = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._resultStorageActor     = resultStorageActor ?? throw new ArgumentNullException(nameof(resultStorageActor));
            this._parameterTree          = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree));

            // No need to check for null. Might be null by purpose.
            this._customGrayBoxMethods = customGrayBoxMethods;

            // If Akka.Cluster gets used, watch for disconnecting cluster members to make evaluation rollbacks possible.
            if (Context.System.HasExtension <Cluster>())
            {
                Cluster.Get(Context.System).Subscribe(this.Self, typeof(ClusterEvent.UnreachableMember));
            }

            this.Become(this.WaitingForWorkers);
            this.Self.Tell(new CheckWorkers());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrayBoxHandler{TInstance, TResult}" /> class.
        /// </summary>
        /// <param name="configuration">The <see cref="AlgorithmTunerConfiguration"/>.</param>
        /// <param name="grayBoxTargetAlgorithm">The gray box target algorithm.</param>
        /// <param name="actorId">The actor ID.</param>
        /// <param name="tunerDataRecord">The tuner data record.</param>
        /// <param name="useGrayBoxInCurrentEvaluation">Boolean indicating whether to use gray box tuning in current evaluation.</param>
        /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param>
        /// <param name="grayBoxRandomForest">The gray box random forest.</param>
        public GrayBoxHandler(
            AlgorithmTunerConfiguration configuration,
            IGrayBoxTargetAlgorithm <TInstance, TResult> grayBoxTargetAlgorithm,
            int actorId,
            TunerDataRecord <TResult> tunerDataRecord,
            bool useGrayBoxInCurrentEvaluation,
            ICustomGrayBoxMethods <TResult> customGrayBoxMethods,
            ClassificationForestModel grayBoxRandomForest)
        {
            this._configuration          = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this._grayBoxTargetAlgorithm = grayBoxTargetAlgorithm ?? throw new ArgumentNullException(nameof(grayBoxTargetAlgorithm));
            this._actorId         = actorId;
            this._tunerDataRecord = tunerDataRecord ?? throw new ArgumentNullException(nameof(tunerDataRecord));

            if (useGrayBoxInCurrentEvaluation)
            {
                this._customGrayBoxMethods          = customGrayBoxMethods ?? throw new ArgumentNullException(nameof(customGrayBoxMethods));
                this._grayBoxRandomForest           = grayBoxRandomForest ?? throw new ArgumentNullException(nameof(grayBoxRandomForest));
                this._useGrayBoxInCurrentEvaluation = true;
            }

            this._grayBoxTargetAlgorithm.OnNewDataRecord += this.HandleDataRecordUpdate;

            lock (this._lock)
            {
                this._listOfDataRecords = new List <DataRecord <TResult> >();
            }
        }
Ejemplo n.º 4
0
 /// <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>
 /// <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,
     GenomeBuilder genomeBuilder,
     ICustomGrayBoxMethods <TResult> customGrayBoxMethods = null)
     : base(targetAlgorithmFactory, runEvaluator, trainingInstances, parameterTree, configuration, genomeBuilder, customGrayBoxMethods)
 {
 }
Ejemplo n.º 5
0
        /// <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();
        }