MemoizeEvaluation¶
- class MemoizeEvaluation(*args)¶
Evaluation which keeps tracks of input and output.
Usually we use
MemoizeFunction
(aa function provides both the evaluation, the gradient and the hessian). that relies on aFunction
passed as argument, and store input and outputSample
. It also has a caching behavior, enabled by default.- Parameters:
- function
Evaluation
Delegate evaluation
- historyStrategy
HistoryStrategy
(optional) Strategy used to store points, default is
Full
.
- function
See also
Examples
>>> import openturns as ot >>> f = ot.SymbolicEvaluation(['x'], ['y'], ['x^2']) >>> inputSample = ot.Sample([[1], [2], [3], [4]]) >>> f = ot.MemoizeEvaluation(f) >>> outputSample = f(inputSample)
Retrieve input sample:
>>> print(f.getInputHistory()) 0 : [ 1 ] 1 : [ 2 ] 2 : [ 3 ] 3 : [ 4 ]
Retrieve output sample:
>>> print(f.getOutputHistory()) 0 : [ 1 ] 1 : [ 4 ] 2 : [ 9 ] 3 : [ 16 ]
Methods
addCacheContent
(inSample, outSample)Add input and output points to the cache.
Empty the content of the cache.
Clear input and output history.
Disable the cache.
Disable the history.
Enable the cache.
Enable the history.
Accessor to the number of computations saved thanks to the cache.
Accessor to the input points stored in the cache.
Accessor to the output points stored in the cache.
Accessor to the object's name.
Get the input sample history.
getMarginal
(*args)Accessor to marginal.
Get the output sample history.
Test whether the cache is enabled or not.
Test whether the history is enabled or not.
setEvaluation
(evaluation)Set the evaluation.
getEvaluation
- __init__(*args)¶
- addCacheContent(inSample, outSample)¶
Add input and output points to the cache.
- Parameters:
- input_sample2-d sequence of float
Input points to be added to the cache.
- output_sample2-d sequence of float
Output points associated with the input_sample to be added to the cache.
- clearCache()¶
Empty the content of the cache.
- clearHistory()¶
Clear input and output history.
- disableCache()¶
Disable the cache.
- disableHistory()¶
Disable the history.
- enableCache()¶
Enable the cache.
- enableHistory()¶
Enable the history.
- getCacheHits()¶
Accessor to the number of computations saved thanks to the cache.
- Returns:
- cacheHitsint
Integer that counts the number of computations saved thanks to the cache.
- getCacheInput()¶
Accessor to the input points stored in the cache.
- Returns:
- cacheInput
Sample
The input points stored in the cache.
- cacheInput
- getCacheOutput()¶
Accessor to the output points stored in the cache.
- Returns:
- cacheInput
Sample
The output points stored in the cache.
- cacheInput
- getClassName()¶
Accessor to the object’s name.
- Returns:
- class_namestr
The object class name (object.__class__.__name__).
- getInputHistory()¶
Get the input sample history.
- Returns:
- inputSample
Sample
Input points which have been evaluated.
- inputSample
- getMarginal(*args)¶
Accessor to marginal.
- Parameters:
- indicesint or list of ints
Set of indices for which the marginal is extracted.
- Returns:
- marginal
Function
Function corresponding to either or , with and .
- marginal
- getOutputHistory()¶
Get the output sample history.
- Returns:
- outputSample
Sample
Output points which have been evaluated.
- outputSample
- isCacheEnabled()¶
Test whether the cache is enabled or not.
- Returns:
- isCacheEnabledbool
Flag telling whether the cache is enabled. It is enabled by default.
- isHistoryEnabled()¶
Test whether the history is enabled or not.
- Returns:
- isHistoryEnabledbool
Flag telling whether the history is enabled.
- setEvaluation(evaluation)¶
Set the evaluation.
- Parameters:
- evaluation
Evaluation
Evaluation.
- evaluation
Notes
This sets a new evaluation of interest. Cache and history are cleaned and the class will stores new one accounting for the given evaluation and store input and output
Sample
. It also has a caching behavior, enabled by default.