ContinuousOptimizationContext Class |
Namespace: Novacta.Analytics.Advanced
The ContinuousOptimizationContext type exposes the following members.
Name | Description | |
---|---|---|
ContinuousOptimizationContext |
Initializes a new instance of the
ContinuousOptimizationContext class
aimed to optimize the specified
continuous function,
with the given initial
guess argument, optimization goal,
range of iterations, and smoothing coefficients.
|
Name | Description | |
---|---|---|
EliteSampleDefinition |
Gets the elite sample definition for this context.
(Inherited from SystemPerformanceOptimizationContext.) | |
InitialArgument |
The initial argument of the function which
the search for the optimal one starts with.
| |
InitialParameter |
Gets the parameter initially exploited to sample from
the state-space of the system defined by this context.
(Inherited from CrossEntropyContext.) | |
InitialStandardDeviation |
Gets the value assigned to each standard deviation in
the initial Cross-Entropy parameter
exploited by this context.
| |
MaximumNumberOfIterations |
Gets the maximum number of iterations
allowed by this context.
(Inherited from SystemPerformanceOptimizationContext.) | |
MeanSmoothingCoefficient |
Gets the coefficient that defines the smoothing scheme
for the means of the Cross-Entropy parameters
exploited by this context.
| |
MinimumNumberOfIterations |
Gets the minimum number of iterations
required by this context.
(Inherited from SystemPerformanceOptimizationContext.) | |
OptimizationGoal |
Gets a constant specifying if the performance function
in this context must be minimized or maximized.
(Inherited from SystemPerformanceOptimizationContext.) | |
StandardDeviationSmoothingCoefficient |
Gets the coefficient that defines the base smoothing
scheme for the standard deviations of the Cross-Entropy
parameters exploited by this context.
| |
StandardDeviationSmoothingExponent |
Gets the exponent that defines the dynamic smoothing scheme
for the standard deviations of the Cross-Entropy
parameters exploited by this context.
| |
StateDimension |
Gets or sets the dimension of a vector representing a
system's state
when
a CrossEntropyProgram executes in this
context.
(Inherited from CrossEntropyContext.) | |
TerminationTolerance |
Gets the minimal value which, if greater than all the
standard deviations of a Cross-Entropy parameter,
signals that the optimization must be considered as
converged at intermediate iterations.
| |
TraceExecution |
Gets or sets a value indicating whether the
execution of this context must be traced.
(Inherited from CrossEntropyContext.) |
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetOptimalState |
Gets the argument that optimizes the objective function
in this context, according to the specified
Cross-Entropy sampling parameter.
(Overrides SystemPerformanceOptimizationContextGetOptimalState(DoubleMatrix).) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnExecutedIteration |
Called after completion of each iteration of
a CrossEntropyProgram executing in this
context.
(Inherited from SystemPerformanceOptimizationContext.) | |
PartialSample |
Draws the specified subset of a sample from a distribution
characterized by the given parameter, using the stated
random number generator. Used when executing the sampling
step of a CrossEntropyProgram running
in this context.
(Overrides CrossEntropyContextPartialSample(Double, TupleInt32, Int32, RandomNumberGenerator, DoubleMatrix, Int32).) | |
Performance |
Computes the objective function at a specified argument
as the performance defined in this context.
(Overrides CrossEntropyContextPerformance(DoubleMatrix).) | |
SmoothParameter |
Provides the smoothing of the updated sampling parameter
of a SystemPerformanceOptimizer
executing in this context.
(Overrides SystemPerformanceOptimizationContextSmoothParameter(LinkedListDoubleMatrix).) | |
StopAtIntermediateIteration |
Specifies conditions
under which
a SystemPerformanceOptimizer executing in
this context should be considered as terminated after
completing an intermediate iteration.
(Overrides SystemPerformanceOptimizationContextStopAtIntermediateIteration(Int32, LinkedListDouble, LinkedListDoubleMatrix).) | |
StopExecution |
Specifies conditions
under which
a CrossEntropyProgram executing in this
context should be considered
as terminated.
(Inherited from SystemPerformanceOptimizationContext.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
UpdateLevel |
Updates the performance level for the current iteration
of a CrossEntropyProgram executing in
this context
and determines the corresponding elite sample.
(Inherited from SystemPerformanceOptimizationContext.) | |
UpdateParameter |
Updates the
sampling parameter attending the generation
of the sample in the next iteration of a
CrossEntropyProgram executing in
this context.
(Overrides CrossEntropyContextUpdateParameter(LinkedListDoubleMatrix, DoubleMatrix).) |
Class ContinuousOptimizationContext derives from SystemPerformanceOptimizationContext, and defines a Cross-Entropy context able to solve continuous optimization problems.
Such a context is exploited by the methods exposed by the static class ContinuousOptimization, where the parameters of the algorithm are set to default values. For advanced scenarios, a context with specialized values can be instantiated and hence passed as a parameter to method Optimize(SystemPerformanceOptimizationContext, Double, Int32).
Class SystemPerformanceOptimizationContext thoroughly defines a system whose performance must be optimized. Class ContinuousOptimizationContext specializes that system by assuming the its performance is a continuous function, say .
A Cross-Entropy optimizer is designed to identify the
optimal arguments at which the performance function of a
complex system reaches
its minimum or maximum value.
To get the optimal state, the system's state-space
, i.e. the domain of
, is traversed iteratively
by sampling, at each iteration, from
a specific density function, member of a parametric
family
where is a
vector representing
a possible argument of ,
and is the set of
allowable values for parameter .
The parameter exploited at a given iteration
is referred to
as the reference parameter of such iteration and indicated
as .
A minimum number
of iterations, say , must be executed, while a
number of them up to a maximum, say , is allowed.
Implementing a context for continuous optimization
The Cross-Entropy method provides an iterative multi step procedure. In the context of continuous optimization, at each iteration a sampling step is executed in order to generate diverse candidate arguments of the objective function, sampled from a distribution characterized by the reference parameter of the iteration, say . Such sample is thus exploited in the updating step in which a new reference parameter is identified to modify the distribution from which the samples will be obtained in the next iteration: such modification is executed in order to improve the probability of sampling relevant arguments, i.e. those arguments corresponding to the function values of interest (See the documentation of class CrossEntropyProgram for a thorough discussion of the Cross-Entropy method).
When the Cross-Entropy method is applied in an optimization context, a final optimizing step is executed, in which the argument corresponding to the searched extremum is effectively identified.
These steps must be implemented as follows.
Sampling step
In a ContinuousOptimizationContext, the parametric family is defined as follows. Each component of an argument of is attached to a Gaussian distribution, say , and the j-th entry of an argument is sampled from , independently from the other, where is the dimension of . A Cross-Entropy sampling parameter can thus be represented as a matrix , whose first row stores the means of the Gaussian distributions, while the second row contains their standard deviations, so that and .
The parametric space should
include a parameter under which all possible states must have
a real chance of being selected: this parameter
must be specified as the initial reference parameter
.
A ContinuousOptimizationContext defines
as follows. The first row of
is set to an initial guess argument
of , say
,
so that
The entries in the second row of are instead
all set constantly equal to an initial, constant standard
deviation, say :
Updating step
At iteration , let us represent the sample drawn
as , where is the
Cross-Entropy sample size, and the -th sample point
is the sequence .
The parameter's
updating formula is,
where
is the elite sample in this context, i.e. the set of sample
points having the lowest performances observed during the -th
iteration, if minimizing, the highest ones, otherwise, while
is its indicator function.
The parameter's second row, that containing the standard deviations,
is instead updated as follows:
Applying a smoothing scheme to updated parameters
In a ContinuousOptimizationContext,
the sampling parameter
is smoothed applying the following formulas
(See Rubinstein and Kroese,
Remark 5.2, p. 189[1]
):
where ,
and
with
and a positive integer.
Optimizing step
The optimizing step is executed after that the underlying Cross-Entropy program has converged. In a specified context, it is expected that, given a reference parameter , a corresponding reasonable value could be guessed for the optimizing argument of , say , with a function from to . Function is defined by overriding method GetOptimalState(DoubleMatrix) that should return given a specific reference parameter .
Given the optimal parameter (the parameter corresponding to the last iteration
executed by the algorithm before stopping),
the argument at which the searched extremum is considered
as reached according to the Cross-Entropy method will be
returned as
Stopping criterion
A ContinuousOptimizationContext never stops before executing a number of iterations less than MinimumNumberOfIterations, and always stops if such number is greater than or equal to MaximumNumberOfIterations.
For intermediate iterations, method StopAtIntermediateIteration(Int32, LinkedListDouble, LinkedListDoubleMatrix) is called to check if a Cross-Entropy program executing in this context should stop or not.
In a ContinuousOptimizationContext, the method
controls if, in the currently updated reference parameter,
say , all
the standard deviations are less than a specified
termination tolerance, say , testing that
and, if so,
return true; otherwise returns false.
Instantiating a context for continuous optimization
At instantiation, the constructor of a ContinuousOptimizationContext object will receive information about the optimization under study by means of parameters representing the objective function , , , , , and a constant stating if the optimization goal is a maximization or a minimization. In addition, the smoothing parameters , , and are also passed to the constructor.
After construction, property InitialArgument represents , while and can be inspected, respectively, via properties MinimumNumberOfIterations and MaximumNumberOfIterations. The smoothing coefficients , , and the exponent are also available via properties MeanSmoothingCoefficient, StandardDeviationSmoothingCoefficient and StandardDeviationSmoothingExponent, respectively. In addition, property OptimizationGoal signals that the performance function must be maximized if it evaluates to the constant Maximization, or that a minimization is requested if it evaluates to the constant Minimization.
To evaluate the objective function at a specific argument, one can call method Performance(DoubleMatrix) passing the argument as a parameter. It is expected that the objective function will accept a row vector as a valid representation of an argument.
In the following example, function
is maximized.
The search for the maximizer starts from the initial argument .
using Novacta.Analytics.Advanced; using System; namespace Novacta.Analytics.CodeExamples.Advanced { public class ContinuousOptimizationContextExample0 { public void Main() { // Define the objective function as follows: // f(x) = exp(-(x-2)^2) + (.8) * exp(-(x+2)^2)). static double objectiveFunction(DoubleMatrix x) { double y = 0.0; var x_0 = x[0]; y += Math.Exp(-Math.Pow(x_0 - 2.0, 2.0)); y += .8 * Math.Exp(-Math.Pow(x_0 + 2.0, 2.0)); return y; } // Define the argument at which the method starts // the search for optimality. var initialArgument = DoubleMatrix.Dense(1, 1, -6.0); // Create the context. var context = new ContinuousOptimizationContext( objectiveFunction: objectiveFunction, initialArgument: initialArgument, meanSmoothingCoefficient: .8, standardDeviationSmoothingCoefficient: .7, standardDeviationSmoothingExponent: 6, initialStandardDeviation: 100.0, optimizationGoal: OptimizationGoal.Maximization, terminationTolerance: 1.0e-3, minimumNumberOfIterations: 3, maximumNumberOfIterations: 1000); // Create the optimizer. var optimizer = new SystemPerformanceOptimizer() { PerformanceEvaluationParallelOptions = { MaxDegreeOfParallelism = -1 }, SampleGenerationParallelOptions = { MaxDegreeOfParallelism = -1 } }; // Set optimization parameters. double rarity = 0.01; int sampleSize = 1000; // Solve the problem. var results = optimizer.Optimize( context, rarity, sampleSize); var maximizer = results.OptimalState; // Show the results. Console.WriteLine( "The Cross-Entropy optimizer has converged: {0}.", results.HasConverged); Console.WriteLine(); Console.WriteLine("Initial guess parameter:"); Console.WriteLine(context.InitialParameter); Console.WriteLine(); Console.WriteLine("The maximizer of the objective function is:"); Console.WriteLine(maximizer); Console.WriteLine(); Console.WriteLine("The maximum value of the objective function is:"); Console.WriteLine(objectiveFunction(maximizer)); } } } // Executing method Main() produces the following output: // // The Cross-Entropy optimizer has converged: True. // // Initial guess parameter: // -6 // 100 // // // // The maximizer of the objective function is: // 2.00000021 // // // // The maximum value of the objective function is: // 1.0000000900279427