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
getCovariance
(self)Get the covariance.
getDescription
(self)Get the description.
getDimension
(self)Get the dimension.
getMean
(self)Get the mean.
getRealization
(self)Get a realization of the random vector.
setDescription
(self, desc)Set the description.
-
__init__
(self, dim=0)¶ Initialize self. See help(type(self)) for accurate signature.
-
getCovariance
(self)¶ Get the covariance.
- Returns
- covariance
CovarianceMatrix
Covariance of the RandomVector.
- covariance
-
getDescription
(self)¶ Get the description.
- Returns
- desc
Description
desc describes the components of the RandomVector.
- desc
-
getDimension
(self)¶ Get the dimension.
- Returns
- dimpositive int
Dimension of the RandomVector.
-
getRealization
(self)¶ Get a realization of the random vector.
- Returns
- realization
Point
Sequence of values randomly determined from the RandomVector definition.
- realization
-
setDescription
(self, 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.