Creation of a custom random vectorΒΆ

In this example we are going to create a distribution or copula.

The way to go is inheriting the PythonRandomVector class and overload its methods:

• getRealization

• getSample

• getMean

• getCovariance

```from __future__ import print_function
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
import math as m
ot.Log.Show(ot.Log.NONE)
```

Inherit PythonRandomVector

```class RVEC(ot.PythonRandomVector):

def __init__(self):
super(RVEC, self).__init__(2)
self.setDescription(['R', 'S'])

def getRealization(self):
X = [ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()]
return X

def getSample(self, size):
X = []
for i in range(size):
X.append(
[ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()])
return X

def getMean(self):
return [0.5, 2.5]

def getCovariance(self):
return [[1.0, 0.0], [0.0, 1.0]]
```

Instanciate our distribution

```randomVector = ot.RandomVector(RVEC())
```

Get a sample

```randomVector.getSample(5)
```
v0 v1 0.2001577 2.751968 0.374857 2.529779 0.7119889 2.497759 0.9211765 2.555468 0.3753769 2.568851

Get mean

```randomVector.getMean()
```

[0.5,2.5]

Compute the probability contained in an interval

```randomVector.getCovariance()
```

[[ 1 0 ]
[ 0 1 ]]

Total running time of the script: ( 0 minutes 0.002 seconds)

Gallery generated by Sphinx-Gallery