{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Probability distributions based on OpenTURNS\n\nIn this example,\nwe seek to create a probability distribution based on the OpenTURNS library.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from matplotlib import pyplot as plt\n\nfrom gemseo.api import configure_logger\nfrom gemseo.uncertainty.api import create_distribution, get_available_distributions\n\nconfigure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First of all,\nwe can access the names of the available probability distributions from the API:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "all_distributions = get_available_distributions()\nprint(all_distributions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and filter the ones based on the OpenTURNS library\n(their names start with the acronym 'OT'):\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ot_distributions = [dist for dist in all_distributions if dist.startswith(\"OT\")]\nprint(ot_distributions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a distribution\nThen,\nwe can create a probability distribution for a two-dimensional random variable\nwhose components are independent and distributed\nas the standard normal distribution (mean = 0 and standard deviation = 1):\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "distribution_0_1 = create_distribution(\"x\", \"OTNormalDistribution\", 2)\nprint(distribution_0_1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or create another distribution with mean = 1 and standard deviation = 2\nfor the marginal distributions:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "distribution_1_2 = create_distribution(\n \"x\", \"OTNormalDistribution\", 2, mu=1.0, sigma=2.0\n)\nprint(distribution_1_2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We could also use the generic :class:`.OTDistribution`\nwhich allows access to all the OpenTURNS distributions\nbut this requires to know the signature of the methods of this library:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "distribution_1_2 = create_distribution(\n \"x\", \"OTDistribution\", 2, interfaced_distribution=\"Normal\", parameters=(1.0, 2.0)\n)\nprint(distribution_1_2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot the distribution\nWe can plot both cumulative and probability density functions\nfor the first marginal:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "distribution_0_1.plot(show=False)\n# Workaround for HTML rendering, instead of ``show=True``\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
We can provide a marginal index\n as first argument of the :meth:`.Distribution.plot` method\n but in the current version of |g|,\n all components have the same distributions and so the plot will be the same.