{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create a conditional random vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this basic example we are going to build a conditional random vector\n",
    "\n",
    "$$\\underline{X}|\\underline{\\Theta}$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# create the random vector Theta (parameters of X)\n",
    "gammaDist = ot.Uniform(1.0, 2.0)\n",
    "alphaDist = ot.Uniform(0.0, 0.1)\n",
    "thetaDist = ot.ComposedDistribution([gammaDist, alphaDist])\n",
    "thetaRV = ot.RandomVector(thetaDist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# create the XgivenTheta distribution\n",
    "XgivenThetaDist = ot.Exponential()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# create the X distribution\n",
    "XDist = ot.ConditionalRandomVector(XgivenThetaDist, thetaRV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<TABLE><TR><TD></TD><TH>X0</TH></TR><TR><TH>0</TH><TD>0.24533256712233908</TD></TR><TR><TH>1</TH><TD>0.6896032414525822</TD></TR><TR><TH>2</TH><TD>0.9303475410201311</TD></TR><TR><TH>3</TH><TD>1.501481272030759</TD></TR><TR><TH>4</TH><TD>0.6301145017187071</TD></TR></TABLE>"
      ],
      "text/plain": [
       "class=Sample name=Unnamed implementation=class=SampleImplementation name=Unnamed size=5 dimension=1 description=[X0] data=[[0.245333],[0.689603],[0.930348],[1.50148],[0.630115]]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# draw a sample\n",
    "XDist.getSample(5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
