PythonRandomVector

class PythonRandomVector(dim=0)

Allow to overload RandomVector from Python.

Parameters:

dim : positive int

Vector dimension. Default is 0.

See also

RandomVector

Examples

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)

Overload RandomVector from Python:

>>> class RVEC(ot.PythonRandomVector):
...    def __init__(self):
...        super(RVEC, self).__init__(2)
...        self.setDescription(['R', 'S'])
...
...    def getRealization(self):
...        X = [ot.RandomGenerator.Generate(), 2 + ot.RandomGenerator.Generate()]
...        return X
...
...    def getSample(self, size):
...        X = []
...        for i in range(size):
...            X.append([ot.RandomGenerator.Generate(), 2 + ot.RandomGenerator.Generate()])
...        return X
...
...    def getMean(self):
...        return [0.5, 2.5]
...
...    def getCovariance(self):
...        return [[0.0833333, 0.], [0., 0.0833333]]

Use the overloaded class:

>>> R = RVEC()
>>> # Instance creation
>>> myRV = ot.RandomVector(R)
>>> # Realization
>>> print(myRV.getRealization())
[0.629877,2.88281]
>>> # Sample
>>> print(myRV.getSample(5))
0 : [ 0.135276  2.0325    ]
1 : [ 0.347057  2.96942   ]
2 : [ 0.92068   2.50304   ]
3 : [ 0.0632061 2.29276   ]
4 : [ 0.714382  2.38336   ]
>>> # Mean
>>> print(myRV.getMean())
[0.5,2.5]
>>> # Covariance
>>> print(myRV.getCovariance())
[[ 0.0833333 0         ]
 [ 0         0.0833333 ]]

Methods

getCovariance() Get the covariance.
getDescription() Get the description.
getDimension() Get the dimension.
getMean() Get the mean.
getRealization() Get a realization of the random vector.
setDescription(desc) Set the description.
__init__(dim=0)
getCovariance()

Get the covariance.

Returns:

covariance : CovarianceMatrix

Covariance of the RandomVector.

getDescription()

Get the description.

Returns:

desc : Description

desc describes the components of the RandomVector.

getDimension()

Get the dimension.

Returns:

dim : positive int

Dimension of the RandomVector.

getMean()

Get the mean.

Returns:

mean : Point

Mean of the RandomVector.

getRealization()

Get a realization of the random vector.

Returns:

realization : Point

Sequence of values randomly determined from the RandomVector definition.

setDescription(desc)

Set the description.

Parameters:

desc : sequence of str

desc describes the components of the RandomVector. Its size must be equal to the dimension of the RandomVector.