{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Composite random vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this basic example we are going to create a random variable $\\underline{Y}$ which realizations are the images of the realizations of another random vector $\\underline{X}$ by a function.\n",
    "\n",
    "$$\\underline{Y} = f(\\underline{X}) $$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot\n",
    "import math as m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create a random vector based on a distribution\n",
    "dist2d = ot.Normal(2)\n",
    "X = ot.RandomVector(dist2d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[x1,x2]->[x1 + x2,x1*x2]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=SymbolicFunction name=Unnamed implementation=class=FunctionImplementation name=Unnamed description=[x1,x2,y0,y1] evaluationImplementation=class=SymbolicEvaluation name=Unnamed inputVariablesNames=[x1,x2] outputVariablesNames=[y0,y1] formulas=[x1 + x2,x1*x2] gradientImplementation=class=SymbolicGradient name=Unnamed evaluation=class=SymbolicEvaluation name=Unnamed inputVariablesNames=[x1,x2] outputVariablesNames=[y0,y1] formulas=[x1 + x2,x1*x2] hessianImplementation=class=SymbolicHessian name=Unnamed evaluation=class=SymbolicEvaluation name=Unnamed inputVariablesNames=[x1,x2] outputVariablesNames=[y0,y1] formulas=[x1 + x2,x1*x2]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create the function\n",
    "f = ot.SymbolicFunction(['x1', 'x2'], ['x1 + x2', 'x1*x2'])\n",
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create the composite random vector\n",
    "Y = ot.CompositeRandomVector(f, X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<TABLE><TR><TD></TD><TH>y0</TH><TH>y1</TH></TR>\n",
       "<TR><TD>0</TD><TD>0.6340067547705874</TD><TD>-1.738141317991343</TD></TR>\n",
       "<TR><TD>1</TD><TD>0.860261107301864</TD><TD>-0.4291467493292659</TD></TR>\n",
       "<TR><TD>2</TD><TD>-2.1455645614220247</TD><TD>1.0633942511691827</TD></TR>\n",
       "<TR><TD>3</TD><TD>-0.7883451164543616</TD><TD>-0.0922805136143649</TD></TR>\n",
       "<TR><TD>4</TD><TD>1.2403961348448758</TD><TD>0.3031904202688173</TD></TR>\n",
       "</TABLE>"
      ],
      "text/plain": [
       "class=Sample name=Unnamed implementation=class=SampleImplementation name=Unnamed size=5 dimension=2 description=[y0,y1] data=[[0.634007,-1.73814],[0.860261,-0.429147],[-2.14556,1.06339],[-0.788345,-0.0922805],[1.2404,0.30319]]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y.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": 1
}
