{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Event manipulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example we are going to define an Event."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create model f(x) = x1 + 2*x2\n",
    "model = ot.SymbolicFunction(['x1', 'x2'], ['x1+2*x2'])\n",
    "\n",
    "# Create the input distribution and random vector X\n",
    "inputDist = ot.Normal(2)\n",
    "inputDist.setDescription(['X1','X2'])\n",
    "\n",
    "inputVector = ot.RandomVector(inputDist)\n",
    "\n",
    "# Create the output random vector Y=f(X)\n",
    "outputVector = ot.RandomVector(model, inputVector)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Create the event Y > 3\n",
    "threshold = 3.0\n",
    "event = ot.Event(outputVector, ot.Greater(), threshold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "realization= [0]\n"
     ]
    }
   ],
   "source": [
    "# Realization as a Bernoulli\n",
    "print('realization=' , event.getRealization())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sample=     [ y0 ]\n",
      "0 : [ 0  ]\n",
      "1 : [ 0  ]\n",
      "2 : [ 1  ]\n",
      "3 : [ 0  ]\n",
      "4 : [ 1  ]\n",
      "5 : [ 0  ]\n",
      "6 : [ 0  ]\n",
      "7 : [ 0  ]\n",
      "8 : [ 0  ]\n",
      "9 : [ 0  ]\n"
     ]
    }
   ],
   "source": [
    "# Sample of 10 realizations as a Bernoulli\n",
    "print('sample=' , event.getSample(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Build a standard event based on an event\n",
    "standardEvent = ot.StandardEvent(event)"
   ]
  }
 ],
 "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
}
