/// <summary>Initializes a new instance of the /// <see cref="TestablePartitionOptimizationContext"/> /// class.</summary> /// <param name="context">The context to test.</param> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> /// <param name="optimizationGoal">The expected optimization goal.</param> /// <param name="initialParameter">The expected initial parameter.</param> /// <param name="minimumNumberOfIterations"> /// The expected minimum number of iterations.</param> /// <param name="maximumNumberOfIterations"> /// The expected maximum number of iterations.</param> /// <param name="optimalState">The expected optimal state.</param> /// <param name="optimalPerformance">The expected optimal performance.</param> /// <param name="objectiveFunction">The expected objective function.</param> /// <param name="partitionDimension">The expected partition dimension.</param> /// <param name="probabilitySmoothingCoefficient">The expected probability smoothing coefficient.</param> public TestablePartitionOptimizationContext( PartitionOptimizationContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution, OptimizationGoal optimizationGoal, DoubleMatrix initialParameter, int minimumNumberOfIterations, int maximumNumberOfIterations, DoubleMatrix optimalState, double optimalPerformance, Func <DoubleMatrix, double> objectiveFunction, int partitionDimension, double probabilitySmoothingCoefficient ) : base( context, stateDimension, eliteSampleDefinition, traceExecution, optimizationGoal, initialParameter, minimumNumberOfIterations, maximumNumberOfIterations, optimalState, optimalPerformance) { this.ObjectiveFunction = objectiveFunction; this.PartitionDimension = partitionDimension; this.ProbabilitySmoothingCoefficient = probabilitySmoothingCoefficient; }
/// <summary>Initializes a new instance of the /// <see cref="TestableCrossEntropyContext"/> /// class.</summary> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> public TestableCrossEntropyContext( TCrossEntropyContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution ) { this.Context = context; this.StateDimension = stateDimension; this.EliteSampleDefinition = eliteSampleDefinition; this.TraceExecution = traceExecution; }
/// <summary>Initializes a new instance of the /// <see cref="TestablePartitionOptimizationContext"/> /// class.</summary> /// <param name="context">The context to test.</param> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> /// <param name="optimizationGoal">The expected optimization goal.</param> /// <param name="initialParameter">The expected initial parameter.</param> /// <param name="minimumNumberOfIterations"> /// The expected minimum number of iterations.</param> /// <param name="maximumNumberOfIterations"> /// The expected maximum number of iterations.</param> /// <param name="optimalState">The expected optimal state.</param> /// <param name="optimalPerformance">The expected optimal performance.</param> /// <param name="objectiveFunction">The expected objective function.</param> /// <param name="featureVariables"> /// The expected feature variables.</param> /// <param name="responseVariable"> /// The expected response variable.</param> /// <param name="numberOfResponseCategories"> /// The expected number of response categories</param> /// <param name="numberOfCategoricalEntailments"> /// The expected number of categorical entailments. /// </param> /// <param name="allowEntailmentPartialTruthValues"> /// The expected allowance for entailment partial truth values. /// </param> /// <param name="probabilitySmoothingCoefficient"> /// The expected probability smoothing coefficient.</param> public TestableCategoricalEntailmentEnsembleOptimizationContext( CategoricalEntailmentEnsembleOptimizationContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution, OptimizationGoal optimizationGoal, DoubleMatrix initialParameter, int minimumNumberOfIterations, int maximumNumberOfIterations, DoubleMatrix optimalState, double optimalPerformance, Func <DoubleMatrix, double> objectiveFunction, List <CategoricalVariable> featureVariables, CategoricalVariable responseVariable, int numberOfResponseCategories, int numberOfCategoricalEntailments, bool allowEntailmentPartialTruthValues, double probabilitySmoothingCoefficient ) : base( context, stateDimension, eliteSampleDefinition, traceExecution, optimizationGoal, initialParameter, minimumNumberOfIterations, maximumNumberOfIterations, optimalState, optimalPerformance) { this.ObjectiveFunction = objectiveFunction; this.FeatureVariables = featureVariables; this.ResponseVariable = responseVariable; var featureCategoryCounts = new List <int>(featureVariables.Count); for (int i = 0; i < featureVariables.Count; i++) { featureCategoryCounts.Add(featureVariables[i].NumberOfCategories); } this.FeatureCategoryCounts = featureCategoryCounts; this.NumberOfResponseCategories = numberOfResponseCategories; this.NumberOfCategoricalEntailments = numberOfCategoricalEntailments; this.AllowEntailmentPartialTruthValues = allowEntailmentPartialTruthValues; this.ProbabilitySmoothingCoefficient = probabilitySmoothingCoefficient; }
/// <summary>Initializes a new instance of the /// <see cref="TestableRareEventProbabilityEstimationContext"/> /// class.</summary> /// <param name="context">The context to test.</param> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> /// <param name="thresholdLevel">The expected elite threshold level.</param> /// <param name="rareEventPerformanceBoundedness">The expected rare event performance boundedness.</param> /// <param name="initialParameter">The expected nominal parameter.</param> /// <param name="rareEventProbability">The expected rare event probability.</param> public TestableRareEventProbabilityEstimationContext( RareEventProbabilityEstimationContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution, double thresholdLevel, RareEventPerformanceBoundedness rareEventPerformanceBoundedness, DoubleMatrix initialParameter, double rareEventProbability ) : base( context, stateDimension, eliteSampleDefinition, traceExecution) { this.ThresholdLevel = thresholdLevel; this.RareEventPerformanceBoundedness = rareEventPerformanceBoundedness; this.NominalParameter = initialParameter; this.RareEventProbability = rareEventProbability; }
/// <summary>Initializes a new instance of the /// <see cref="TestableContinuousOptimizationContext"/> /// class.</summary> /// <param name="context">The context to test.</param> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> /// <param name="optimizationGoal">The expected optimization goal.</param> /// <param name="initialParameter">The expected initial parameter.</param> /// <param name="minimumNumberOfIterations"> /// The expected minimum number of iterations.</param> /// <param name="maximumNumberOfIterations"> /// The expected maximum number of iterations.</param> /// <param name="optimalState">The expected optimal state.</param> /// <param name="optimalPerformance">The expected optimal performance.</param> /// <param name="objectiveFunction">The expected objective function.</param> /// <param name="initialArgument">The expected initial argument.</param> /// <param name="meanSmoothingCoefficient">The expected mean smoothing coefficient.</param> /// <param name="standardDeviationSmoothingCoefficient">The expected standard deviation smoothing coefficient.</param> /// <param name="standardDeviationSmoothingExponent">The expected standard deviation smoothing exponent.</param> /// <param name="initialStandardDeviation">The expected initial standard deviation.</param> /// <param name="terminationTolerance">The expected termination tolerance.</param> public TestableContinuousOptimizationContext( ContinuousOptimizationContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution, OptimizationGoal optimizationGoal, DoubleMatrix initialParameter, int minimumNumberOfIterations, int maximumNumberOfIterations, DoubleMatrix optimalState, double optimalPerformance, Func <DoubleMatrix, double> objectiveFunction, DoubleMatrix initialArgument, double meanSmoothingCoefficient, double standardDeviationSmoothingCoefficient, int standardDeviationSmoothingExponent, double initialStandardDeviation, double terminationTolerance ) : base( context, stateDimension, eliteSampleDefinition, traceExecution, optimizationGoal, initialParameter, minimumNumberOfIterations, maximumNumberOfIterations, optimalState, optimalPerformance) { this.ObjectiveFunction = objectiveFunction; this.InitialArgument = initialArgument; this.MeanSmoothingCoefficient = meanSmoothingCoefficient; this.StandardDeviationSmoothingCoefficient = standardDeviationSmoothingCoefficient; this.StandardDeviationSmoothingExponent = standardDeviationSmoothingExponent; this.InitialStandardDeviation = initialStandardDeviation; this.TerminationTolerance = terminationTolerance; }
/// <summary>Initializes a new instance of the /// <see cref="TestableSystemPerformanceOptimizationContext"/> /// class.</summary> /// <param name="context">The context to test.</param> /// <param name="stateDimension">The expected state dimension.</param> /// <param name="eliteSampleDefinition">The expected elite sample definition.</param> /// <param name="traceExecution">The expected value about tracing context execution.</param> /// <param name="optimizationGoal">The expected optimization goal.</param> /// <param name="initialParameter">The expected initial parameter.</param> /// <param name="minimumNumberOfIterations"> /// The expected minimum number of iterations.</param> /// <param name="maximumNumberOfIterations"> /// The expected maximum number of iterations.</param> /// <param name="optimalState">The expected optimal state.</param> /// <param name="optimalPerformance">The expected optimal performance.</param> public TestableSystemPerformanceOptimizationContext( TCrossEntropyContext context, int stateDimension, EliteSampleDefinition eliteSampleDefinition, bool traceExecution, OptimizationGoal optimizationGoal, DoubleMatrix initialParameter, int minimumNumberOfIterations, int maximumNumberOfIterations, DoubleMatrix optimalState, double optimalPerformance ) : base( context, stateDimension, eliteSampleDefinition, traceExecution) { this.OptimizationGoal = optimizationGoal; this.InitialParameter = initialParameter; this.MinimumNumberOfIterations = minimumNumberOfIterations; this.MaximumNumberOfIterations = maximumNumberOfIterations; this.OptimalState = optimalState; this.OptimalPerformance = optimalPerformance; }
/// <summary> /// Updates the performance level for the current iteration /// of a <see cref="CrossEntropyProgram"/> executing in /// this context /// and determines the corresponding elite sample. /// </summary> /// <param name="performances"> /// The performances of the /// points in the current sample. /// </param> /// <param name="sample"> /// The current sample. /// </param> /// <param name="eliteSampleDefinition"> /// The elite sample mode. /// </param> /// <param name="rarity"> /// The rarity applied to define the elite sample. /// </param> /// <param name="eliteSample"> /// The elite sample. /// </param> /// <returns> /// The performance level for the current iteration. /// </returns> /// <remarks> /// <inheritdoc cref="CrossEntropyContext" /// path="para[@id='LevelUpdate']"/> /// </remarks> protected internal abstract double UpdateLevel( DoubleMatrix performances, DoubleMatrix sample, EliteSampleDefinition eliteSampleDefinition, double rarity, out DoubleMatrix eliteSample);
/// <inheritdoc/> /// <exception cref="ArgumentNullException"> /// <paramref name="performances"/> is <b>null</b>.<br/> /// -or-<br/> /// <paramref name="sample"/> is <b>null</b>. /// </exception> protected internal override sealed double UpdateLevel( DoubleMatrix performances, DoubleMatrix sample, EliteSampleDefinition eliteSampleDefinition, double rarity, out DoubleMatrix eliteSample) { if (performances is null) { throw new ArgumentNullException(nameof(performances)); } if (sample is null) { throw new ArgumentNullException(nameof(sample)); } var performanceArray = performances.GetStorage(); SortHelper.Sort( performanceArray, SortDirection.Ascending, out int[] indexTable); if (this.TraceExecution) { Trace.WriteLine( "Sample points ordered by performance:"); var sampleInfo = DoubleMatrix.Dense( numberOfRows: sample.NumberOfRows, numberOfColumns: this.StateDimension + 1); sampleInfo.SetColumnName(0, "Performance"); for (int j = 1; j < sampleInfo.NumberOfColumns; j++) { sampleInfo.SetColumnName(j, "S" + j); } sampleInfo[":", 0] = performances; sampleInfo[":", IndexCollection.Range(1, this.StateDimension)] = sample[ IndexCollection.FromArray(indexTable, false), ":"]; Trace.WriteLine(sampleInfo); } int eliteFirstIndex = 0; int eliteLastIndex = 0; int sampleSize = sample.NumberOfRows; double level = Double.NaN; double thresholdLevel = this.ThresholdLevel; // Compute the relevant sample percentile (the level) // and achieved performance switch (eliteSampleDefinition) { case EliteSampleDefinition.HigherThanLevel: eliteFirstIndex = Convert.ToInt32( Math.Ceiling(sampleSize * (1 - rarity))); eliteLastIndex = sampleSize - 1; level = performanceArray[eliteFirstIndex]; if (level > thresholdLevel) { level = thresholdLevel; } break; case EliteSampleDefinition.LowerThanLevel: eliteFirstIndex = 0; eliteLastIndex = Convert.ToInt32( Math.Ceiling(sampleSize * rarity)); level = performanceArray[eliteLastIndex]; if (level < thresholdLevel) { level = thresholdLevel; } break; } // Update the reference parameter var eliteSamplePositions = IndexCollection.Range(eliteFirstIndex, eliteLastIndex); if (this.TraceExecution) { Trace.WriteLine( string.Format( CultureInfo.InvariantCulture, "Elite positions: {0} - {1}.", eliteFirstIndex, eliteLastIndex)); } var sortedIndexes = IndexCollection.FromArray(indexTable, false); eliteSample = sample[sortedIndexes[eliteSamplePositions], ":"]; return(level); }