LineSampling¶
- class LineSampling(*args)¶
Line sampling algorithm.
Warning
This class is experimental and likely to be modified in future releases. To use it, import the
openturns.experimental
submodule.This class implements the line sampling algorithm from [koutsourelakis2004] with adaptation of the important direction from [angelis2015], which is also known as adaptive line sampling.
Let
be a random vector of dimension
, distributed according to the measure
, and
be the limit state function (where we only write the random input parameters). We define the event
by:
The line sampling algorithm estimates the probability of the event
:
Let
be the iso-probabilistic transformation to the standard space:
. The random vector
is a
-dimensional Gaussian vector following the standard normal distribution.
For any direction
such that
, let
be the orthogonal projection from
to the one-dimensional vector space (line) spanned by
(we call
the important direction) and let
be the orthogonal projection from
to the hyperplane of
normal to the one-dimensional vector space spanned by
.
Then
can be rewritten:
Since
follows a standard multivariate normal distribution,
and
are independent.
Therefore, given that
follows the same distribution as
where
is a scalar random variable following the standard normal distribution, we have:
Now, for any vector
that is orthogonal to
, we define
as the set
We can rewrite
Letting
be the interior of
, we assume
to be the union of a finite number of open intervals.
Then there exists
and
such that
and
.
is either
or a root of
.
is either
or a root of
. All the other
are roots of
.
With
denoting the CDF of the standard normal distribution we have
The generic line sampling algorithm follows the steps for
:
Draw a sample
and project it on the hyperplane normal to
to obtain
.
Find the roots of
.
Use the roots to compute
.
The global probability
is computed from all the
probabilities.
The adaptive variant of the algorithm consists in updating the important direction
by the selecting the direction given by the nearest intersection with the frontiers of
from the origin as given by the root search for each new line explored.
- Parameters:
- event
RandomVector
Event we are computing the probability.
- initialAlphasequence of float
The initial important direction
.
- rootStrategy
RootStrategy
, optional Strategy used to evaluate the frontiers of the event along each direction in the standard space. By default
SafeAndSlow
.
- event
Methods
drawProbabilityConvergence
(*args)Draw the probability convergence at a given level.
Accessor to the adaptive important direction flag.
Accessor to the important direction history.
Accessor to the block size.
Accessor to the object's name.
Accessor to the convergence strategy.
getEvent
()Accessor to the event.
Initial important direction accessor.
Accessor to the maximum coefficient of variation.
Accessor to the maximum iterations number.
Accessor to the maximum standard deviation.
Accessor to the maximum duration.
getName
()Accessor to the object's name.
Accessor to the results.
Accessor to the root points history.
Get the root strategy.
Accessor to the root values history.
Opposite direction search flag accessor.
Accessor to the important direction history.
hasName
()Test if the object is named.
run
()Launch simulation.
Accessor to the adaptive important direction flag.
setBlockSize
(blockSize)Accessor to the block size.
setConvergenceStrategy
(convergenceStrategy)Accessor to the convergence strategy.
setInitialAlpha
(initialAlpha)Initial important direction accessor.
Accessor to the maximum coefficient of variation.
setMaximumOuterSampling
(maximumOuterSampling)Accessor to the maximum iterations number.
Accessor to the maximum standard deviation.
setMaximumTimeDuration
(maximumTimeDuration)Accessor to the maximum duration.
setName
(name)Accessor to the object's name.
setProgressCallback
(*args)Set up a progress callback.
setRootStrategy
(rootStrategy)Set the root strategy.
Opposite direction search flag accessor.
setStopCallback
(*args)Set up a stop callback.
setStoreHistory
(storeHistory)Accessor to the important direction history.
See also
Notes
Various
ResourceMap
entries allow for a more fine-grained control over the algorithm:The boolean entry LineSampling-DefaultSearchOppositeDirection sets the default value of the flag activating the additional search in the opposite direction of the important direction.
The boolean entry LineSampling-DefaultAdaptiveImportantDirection sets the default value of the flag activating the use of adaptive important direction as opposed to a fixed important direction.
- __init__(*args)¶
- drawProbabilityConvergence(*args)¶
Draw the probability convergence at a given level.
- Parameters:
- levelfloat, optional
The probability convergence is drawn at this given confidence length level. By default level is 0.95.
- Returns:
- grapha
Graph
probability convergence graph
- grapha
- getAdaptiveImportantDirection()¶
Accessor to the adaptive important direction flag.
- Returns:
- adaptiveImportantDirectionbool
Whether the important direction is adapted according to new design points.
- getAlphaHistory()¶
Accessor to the important direction history.
- Returns:
- alphaHistory
Sample
Storage strategy used to store the important direction vectors during the simulation.
- alphaHistory
- getBlockSize()¶
Accessor to the block size.
- Returns:
- blockSizeint
Number of simultaneous evaluations of the limit-state function. It is set by default to 1.
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getConvergenceStrategy()¶
Accessor to the convergence strategy.
- Returns:
- storage_strategy
HistoryStrategy
Storage strategy used to store the values of the probability estimator and its variance during the simulation algorithm.
- storage_strategy
- getEvent()¶
Accessor to the event.
- Returns:
- event
RandomVector
Event we want to evaluate the probability.
- event
- getInitialAlpha()¶
Initial important direction accessor.
- Returns:
- alpha
Point
Initial important direction.
- alpha
- getMaximumCoefficientOfVariation()¶
Accessor to the maximum coefficient of variation.
- Returns:
- coefficientfloat
Maximum coefficient of variation of the simulated sample.
- getMaximumOuterSampling()¶
Accessor to the maximum iterations number.
- Returns:
- outerSamplingint
Maximum number of iterations, each iteration performing a block of evaluations.
- getMaximumStandardDeviation()¶
Accessor to the maximum standard deviation.
- Returns:
- sigmafloat,
Maximum standard deviation of the estimator.
- sigmafloat,
- getMaximumTimeDuration()¶
Accessor to the maximum duration.
- Returns:
- maximumTimeDurationfloat
Maximum optimization duration in seconds.
- getName()¶
Accessor to the object’s name.
- Returns:
- namestr
The name of the object.
- getResult()¶
Accessor to the results.
- Returns:
- results
SimulationResult
Structure containing all the results obtained after simulation and created by the method
run()
.
- results
- getRootPointsHistory()¶
Accessor to the root points history.
- Returns:
- rootPointsHistorysequence of
Sample
The list of root points for each line.
- rootPointsHistorysequence of
- getRootStrategy()¶
Get the root strategy.
- Returns:
- strategy
RootStrategy
Root strategy used to evaluate the frontiers of the event along each direction in the standard space.
- strategy
- getRootValuesHistory()¶
Accessor to the root values history.
- Returns:
- rootValuesHistorysequence of
Point
The list of root values for each line.
- rootValuesHistorysequence of
- getSearchOppositeDirection()¶
Opposite direction search flag accessor.
- Returns:
- searchOppositeDirectionbool
Whether to search in the opposite direction of the important direction.
- getStoreHistory()¶
Accessor to the important direction history.
- Returns:
- storeHistorybool
Whether to store alpha, root values and points histories.
- hasName()¶
Test if the object is named.
- Returns:
- hasNamebool
True if the name is not empty.
- run()¶
Launch simulation.
See also
Notes
It launches the simulation and creates a
SimulationResult
, structure containing all the results obtained after simulation. It computes the probability of occurrence of the given event by computing the empirical mean of a sample of size at most outerSampling * blockSize, this sample being built by blocks of size blockSize. It allows one to use efficiently the distribution of the computation as well as it allows one to deal with a sample sizeby a combination of blockSize and outerSampling.
- setAdaptiveImportantDirection(adaptiveImportantDirection)¶
Accessor to the adaptive important direction flag.
- Parameters:
- adaptiveImportantDirectionbool
Whether the important direction is adapted according to new design points.
- setBlockSize(blockSize)¶
Accessor to the block size.
- Parameters:
- blockSizeint,
Number of simultaneous evaluations of the limit-state function. It is set by default to 1.
- blockSizeint,
Notes
If the function supports batch evaluations this parameter can be set to the number of available CPUs to benefit from parallel execution (multithreading, multiprocessing, …); except for the Directional Sampling, where we recommend to set it to 1. It also decides the frequency of the stopping criteria and progress callbacks update as they are called once the whole block of fonction evaluations is completed.
- setConvergenceStrategy(convergenceStrategy)¶
Accessor to the convergence strategy.
- Parameters:
- storage_strategy
HistoryStrategy
Storage strategy used to store the values of the probability estimator and its variance during the simulation algorithm.
- storage_strategy
- setInitialAlpha(initialAlpha)¶
Initial important direction accessor.
- Parameters:
- alphasequence of float
Initial important direction.
- setMaximumCoefficientOfVariation(maximumCoefficientOfVariation)¶
Accessor to the maximum coefficient of variation.
- Parameters:
- coefficientfloat
Maximum coefficient of variation of the simulated sample.
- setMaximumOuterSampling(maximumOuterSampling)¶
Accessor to the maximum iterations number.
- Parameters:
- outerSamplingint
Maximum number of iterations, each iteration performing a block of evaluations.
- setMaximumStandardDeviation(maximumStandardDeviation)¶
Accessor to the maximum standard deviation.
- Parameters:
- sigmafloat,
Maximum standard deviation of the estimator.
- sigmafloat,
- setMaximumTimeDuration(maximumTimeDuration)¶
Accessor to the maximum duration.
- Parameters:
- maximumTimeDurationfloat
Maximum optimization duration in seconds.
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
- setProgressCallback(*args)¶
Set up a progress callback.
Can be used to programmatically report the progress of a simulation.
- Parameters:
- callbackcallable
Takes a float as argument as percentage of progress.
Examples
>>> import sys >>> import openturns as ot >>> experiment = ot.MonteCarloExperiment() >>> X = ot.RandomVector(ot.Normal()) >>> Y = ot.CompositeRandomVector(ot.SymbolicFunction(['X'], ['1.1*X']), X) >>> event = ot.ThresholdEvent(Y, ot.Less(), -2.0) >>> algo = ot.ProbabilitySimulationAlgorithm(event, experiment) >>> algo.setMaximumOuterSampling(100) >>> algo.setMaximumCoefficientOfVariation(-1.0) >>> def report_progress(progress): ... sys.stderr.write('-- progress=' + str(progress) + '%\n') >>> algo.setProgressCallback(report_progress) >>> algo.run()
- setRootStrategy(rootStrategy)¶
Set the root strategy.
- Parameters:
- strategy
RootStrategy
Root strategy to evaluate the frontiers of the event along each direction in the standard space.
- strategy
- setSearchOppositeDirection(searchOppositeDirection)¶
Opposite direction search flag accessor.
- Parameters:
- searchOppositeDirectionbool
Whether to search in the opposite direction of the important direction.
- setStopCallback(*args)¶
Set up a stop callback.
Can be used to programmatically stop a simulation.
- Parameters:
- callbackcallable
Returns an int deciding whether to stop or continue.
- setStoreHistory(storeHistory)¶
Accessor to the important direction history.
- Parameters:
- storeHistorybool
Whether to store alpha, root values and points histories.