Click or drag to resize

CrossEntropyContext Class

A Cross-Entropy context. This object is used to implement the varying steps of a CrossEntropyProgram.
Inheritance Hierarchy

Namespace:  Novacta.Analytics.Advanced
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public abstract class CrossEntropyContext

The CrossEntropyContext type exposes the following members.

Constructors
  NameDescription
Protected methodCrossEntropyContext
Initializes a new instance of the CrossEntropyContext class having the specified state dimension.
Top
Properties
  NameDescription
Protected propertyEliteSampleDefinition
Gets the elite sample definition for this context.
Public propertyInitialParameter
Gets the parameter initially exploited to sample from the state-space of the system defined by this context.
Public propertyStateDimension
Gets or sets the dimension of a vector representing a system's state when a CrossEntropyProgram executes in this context.
Public propertyTraceExecution
Gets or sets a value indicating whether the execution of this context must be traced.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnExecutedIteration
Called after completion of each iteration of a CrossEntropyProgram executing in this context.
Protected methodPartialSample
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.
Protected methodPerformance
Defines the performance of a specified state in this context.
Protected methodStopExecution
Specifies conditions under which a CrossEntropyProgram executing in this context should be considered as terminated.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Protected methodUpdateLevel
Updates the performance level for the current iteration of a CrossEntropyProgram executing in this context and determines the corresponding elite sample.
Protected methodUpdateParameter
Updates the sampling parameter attending the generation of the sample in the next iteration of a CrossEntropyProgram executing in this context.
Top
Remarks

A CrossEntropyProgram is executed by calling its Run method. This is a template method, in the sense that it defines the invariant parts of a Cross-Entropy program. Such method relies on an instance of class CrossEntropyContext, which is passed as a parameter to it and specifies the primitive operations of the template method, i.e. those varying steps of the algorithm that depends on the problem under study.

Class CrossEntropyContext defines the primitive operations as abstract methods, that its subclasses will override to provide the concrete behavior of the Cross-Entropy program.

A Cross-Entropy program deals with the performance of a system, and it is responsibility of a CrossEntropyContext instance to define the state-space of the system, the performance function, how a program executed in such context must update, at each iteration, its levels and parameters, how the state-space must be sampled while searching for states having relevant performances, and at what conditions the program must stop iterating.

Implementing a Cross-Entropy context

The following abstract or virtual methods should be overridden to define the context of interest in which a CrossEntropyProgram must be executed.

Sampling step

Class CrossEntropyProgram can run in parallel the generation of the points in the sampling step of a Cross-Entropy algorithm. The points are represented by the rows of the matrix returned by method Sample(CrossEntropyContext, Int32, DoubleMatrix). The matrix has a number of rows equal to the overall sample size, and a number of columns equal to the StateDimension of the system under study.

The parameter from which samples are drawn while executing the first iteration of a Cross-Entropy program in this context is given by property InitialParameter.

To enable parallel sampling procedures, the collection of row indexes of such matrix are partitioned, and each part is assigned to a thread in a specific pool for processing. Method SubSample is called when sampling locally to a given thread in the pool, and draws the specified range of sample points.

When called, it is thus expected that the method will fill the rows of the sample matrix corresponding to the indexes inside the given range.

Updating step

The updating step is implemented by overriding three methods, as follows.

Performance evaluation

The performance of a state can be defined by overriding method Performance(DoubleMatrix). It is expected that the performance function will accept a row vector as a valid representation of a system's state.

Level update

Method UpdateLevel is intended to be responsible for sorting the performances, compute the corresponding performance level for the current iteration and return the elite sample. As a consequence, a context should also give its definition of elite sample points, by overriding property EliteSampleDefinition.

Parameter update

Method UpdateParameter is expected to update the parameter of the random mechanism attending the generation of the sample in the next iteration of the program.

Optional tasks needed at iteration completion

Virtual method OnExecutedIteration is is not a mandatory step of a Cross-Entropy program. It is executed after completion of the updating step, and by default does nothing. Users can override it to add functionality to each Cross-Entropy iteration.

Stopping criterion

Each iteration executed by the Run method of a CrossEntropyProgram ends with a call to method StopExecution, and the program stops iterating if it returns true. By overriding the method in a derived context class, it determines at what conditions the Cross-Entropy program should stop at iteration completion.

Specialized contexts

Contexts specialized for the estimation of rare event probabilities and the optimization of combinatorial or multi-extremal problems are given by classes RareEventProbabilityEstimationContext and SystemPerformanceOptimizationContext, respectively. It is recommended to directly derive from such classes in order to define the problem of interest, since they override for you methods UpdateLevel, StopExecution, and property EliteSampleDefinition. Then, the problems can be solved by executing the corresponding specialized programs, represented by RareEventProbabilityEstimator or SystemPerformanceOptimizer instances.

See Also