{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creation of a custom random vector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we are going to create a distribution or copula.\n", "\n", "The way to go is inheriting the PythonRandomVector class and overload its methods:\n", "\n", "- getRealization\n", "- getSample\n", "- getMean\n", "- getCovariance" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function\n", "import openturns as ot\n", "import math as m" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Inherit PythonRandomVector\n", "class RVEC(ot.PythonRandomVector):\n", "\n", " def __init__(self):\n", " super(RVEC, self).__init__(2)\n", " self.setDescription(['R', 'S'])\n", "\n", " def getRealization(self):\n", " X = [ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()]\n", " return X\n", "\n", " def getSample(self, size):\n", " X = []\n", " for i in range(size):\n", " X.append(\n", " [ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()])\n", " return X\n", "\n", " def getMean(self):\n", " return [0.5, 2.5]\n", "\n", " def getCovariance(self):\n", " return [[1.0, 0.0], [0.0, 1.0]]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Instanciate our distribution\n", "randomVector = ot.RandomVector(RVEC())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
v0 | v1 | |
---|---|---|
0 | 0.6298765566077771 | 2.8828052237192603 |
1 | 0.13527635081884104 | 2.032502751204385 |
2 | 0.3470570412135219 | 2.9694230211349892 |
3 | 0.9206795933570506 | 2.5030401514493823 |
4 | 0.06320607651305044 | 2.2927568937477316 |
[0.5,2.5]
\n",
"
[[ 1 0 ]
\n",
" [ 0 1 ]]
\n",
"