PythonRandomVector¶
-
class
PythonRandomVector
(dim=0)¶ Allow to overload RandomVector from Python.
- Parameters
- dimpositive int
Vector dimension. Default is 0.
See also
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
Get the covariance.
Get the description.
Get the dimension.
getMean
()Get the mean.
Get a realization of the random vector.
setDescription
(desc)Set the description.
-
__init__
(dim=0)¶ Initialize self. See help(type(self)) for accurate signature.
-
getCovariance
()¶ Get the covariance.
- Returns
- covariance
CovarianceMatrix
Covariance of the RandomVector.
- covariance
-
getDescription
()¶ Get the description.
- Returns
- desc
Description
desc describes the components of the RandomVector.
- desc
-
getDimension
()¶ Get the dimension.
- Returns
- dimpositive int
Dimension of the RandomVector.
-
getRealization
()¶ Get a realization of the random vector.
- Returns
- realization
Point
Sequence of values randomly determined from the RandomVector definition.
- realization
-
setDescription
(desc)¶ Set the description.
- Parameters
- descsequence of str
desc describes the components of the RandomVector. Its size must be equal to the dimension of the RandomVector.