{ "cells": [ { "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 __future__ import annotations\n\nfrom gemseo import configure_logger\nfrom gemseo.uncertainty import create_distribution\nfrom gemseo.uncertainty import 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()\nall_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 = get_available_distributions(\"OTDistribution\")\not_distributions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a distribution\nThen,\nwe can create a probability distribution for a two-dimensional random variable\nwith independent components that follow a normal distribution.\n\n### Case 1: the OpenTURNS distribution has a GEMSEO class\nFor 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)\ndistribution_0_1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For a normal with mean = 1 and standard deviation = 2:\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)\ndistribution_1_2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Case 2: the OpenTURNS distribution has no GEMSEO class\nWhen GEMSEO does not offer a class for the OpenTURNS distribution,\nwe can use the generic GEMSEO class :class:`.OTDistribution`\nto create any OpenTURNS distribution\nby setting ``interfaced_distribution`` to its OpenTURNS name\nand ``parameters`` as a tuple of OpenTURNS parameter values\n([see the documentation of OpenTURNS](https://openturns.github.io/openturns/latest/user_manual/_generated/\nopenturns.Normal.html#openturns.Normal)_).\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)\ndistribution_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()" ] }, { "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.