コード例 #1
0
        /// <summary>
        /// Configures the current gray box handler.
        /// </summary>
        private void ConfigureGrayBoxHandler()
        {
            var genomeTransformation       = new GenomeTransformation <CategoricalBinaryEncoding>(this._parameterTree);
            var genomeDoubleRepresentation =
                genomeTransformation.ConvertGenomeToArray(this._currentEvaluation.GenomeInstancePair.Genome.CreateMutableGenome());

            var tunerDataRecord = new TunerDataRecord <TResult>(
                NetworkUtils.GetFullyQualifiedDomainName(),
                this._currentEvaluation.GenerationId,
                this._currentEvaluation.TournamentId,
                this._currentEvaluation.GenomeInstancePair.Instance.ToId(),
                double.NaN,
                genomeTransformation.GetConverterColumnHeader(),
                genomeDoubleRepresentation,
                null);

            this._grayBoxHandler = new GrayBoxHandler <TInstance, TResult>(
                this._configuration,
                this._configuredTargetAlgorithm as IGrayBoxTargetAlgorithm <TInstance, TResult>,
                this._id,
                tunerDataRecord,
                this._currentEvaluation.UseGrayBoxInEvaluation && this._successfullyDeserializedGrayBoxRandomForest,
                this._customGrayBoxMethods,
                this._grayBoxRandomForest);
        }
コード例 #2
0
        /// <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);
        }
コード例 #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> >();
            }
        }
コード例 #4
0
        public void CorrectGrayBoxFeaturesAreSelected()
        {
            var gurobiGrayBoxMethods = new GurobiGrayBoxMethods();

            var runtimeFeatures       = new GurobiRuntimeFeatures(DateTime.Now);
            var instanceFeatures      = new GurobiInstanceFeatures();
            var adapterFeatures       = GurobiUtils.ComposeAdapterFeatures(runtimeFeatures, runtimeFeatures, instanceFeatures);
            var adapterFeaturesHeader = GurobiUtils.ComposeAdapterFeaturesHeader(runtimeFeatures, runtimeFeatures, instanceFeatures);
            var result = new GurobiResult(double.NaN, TimeSpan.MaxValue, TargetAlgorithmStatus.CancelledByTimeout, false);

            var adapterDataRecord = new AdapterDataRecord <GurobiResult>(
                "Gurobi901",
                TargetAlgorithmStatus.Running,
                TimeSpan.Zero,
                TimeSpan.Zero,
                DateTime.Now,
                adapterFeaturesHeader,
                adapterFeatures,
                result);

            var tunerDataRecord = new TunerDataRecord <GurobiResult>(
                "Node",
                0,
                0,
                "Instance",
                0.5,
                new[] { "Genome" },
                (GenomeDoubleRepresentation) new[] { 0D },
                result);

            var dataRecord = new DataRecord <GurobiResult>(tunerDataRecord, adapterDataRecord);

            var featureNames = gurobiGrayBoxMethods.GetGrayBoxFeatureNamesFromDataRecord(dataRecord);

            var correctFeatureNames = new[]
            {
                "ExpendedWallClockTime",
                "RuntimeFeature_CuttingPlanesCount_Current",
                "RuntimeFeature_ExploredNodeCount_Current",
                "RuntimeFeature_FeasibleSolutionsCount_Current",
                "RuntimeFeature_MipGap_Current",
                "RuntimeFeature_SimplexIterationsCount_Current",
                "RuntimeFeature_UnexploredNodeCount_Current",
                "RuntimeFeature_CuttingPlanesCount_Last",
                "RuntimeFeature_ExploredNodeCount_Last",
                "RuntimeFeature_FeasibleSolutionsCount_Last",
                "RuntimeFeature_MipGap_Last",
                "RuntimeFeature_SimplexIterationsCount_Last",
                "RuntimeFeature_UnexploredNodeCount_Last",
                "InstanceFeature_NumberOfIntegerVariables",
                "InstanceFeature_NumberOfLinearConstraints",
                "InstanceFeature_NumberOfNonZeroCoefficients",
                "InstanceFeature_NumberOfVariables",
            };

            featureNames.SequenceEqual(correctFeatureNames).ShouldBeTrue();
        }