{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Compare unconditional and conditional histograms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we compare unconditional and conditional histograms for a simulation. We consider the flooding model. Let $g$ be a function which takes four inputs $Q$, $K_s$, $Z_v$ and $Z_m$ and returns one output $H$. \n", "\n", "We first consider the (unconditional) distribution of the input $Q$. \n", "\n", "Let $t$ be a given threshold on the output $H$: we consider the event $H>t$. Then we consider the conditional distribution of the input $Q$ given that $H>t$ : $Q|H>t$. \n", "\n", "If these two distributions are significantly different, we conclude that the input $Q$ has an impact on the event $H>t$. \n", "\n", "In order to approximate the distribution of the output $H$, we perform a Monte-Carlo simulation with size 500. The threshold $t$ is chosen as the 90% quantile of the empirical distribution of $H$. In this example, the distribution is aproximated by its empirical histogram (but this could be done with another distribution approximation as well, such as kernel smoothing for example)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import openturns as ot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create the marginal distributions of the parameters." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "dist_Q = ot.TruncatedDistribution(ot.Gumbel(558., 1013.), 0, ot.TruncatedDistribution.LOWER)\n", "dist_Ks = ot.TruncatedDistribution(ot.Normal(30.0, 7.5), 0, ot.TruncatedDistribution.LOWER)\n", "dist_Zv = ot.Uniform(49.0, 51.0)\n", "dist_Zm = ot.Uniform(54.0, 56.0)\n", "marginals = [dist_Q, dist_Ks, dist_Zv, dist_Zm]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create the joint probability distribution." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "distribution = ot.ComposedDistribution(marginals)\n", "distribution.setDescription(['Q', 'Ks', 'Zv', 'Zm'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create the model." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "model = ot.SymbolicFunction(['Q', 'Ks', 'Zv', 'Zm'],\n", " ['(Q/(Ks*300.*sqrt((Zm-Zv)/5000)))^(3.0/5.0)'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a sample." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "size = 500\n", "inputSample = distribution.getSample(size)\n", "outputSample = model(inputSample)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Merge the input and output samples into a single sample." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
v0 | v1 | v2 | v3 | v4 | |
---|---|---|---|---|---|
0 | 1443.602798325532 | 30.156613494725274 | 49.11713595070338 | 55.59185930777356 | 2.4439424253360924 |
1 | 2174.8898945480146 | 34.67890291392808 | 50.764851072298455 | 55.87647205461956 | 3.085132426791521 |
2 | 626.1023680891167 | 35.75352992912951 | 50.03020209989136 | 54.661879004882564 | 1.478061905093236 |
3 | 325.8123641551359 | 36.665987740324184 | 49.026338291130784 | 55.366752716918725 | 0.8953760185932061 |
4 | 981.3994326290226 | 41.10229410031924 | 49.39776320365176 | 54.84770660838047 | 1.6954636957219766 |