Skip to content
Snippets Groups Projects
Commit cd50125f authored by Robert Lanzafame's avatar Robert Lanzafame
Browse files

remove thebe-init tag from first visible cell

parent 1dfd72ae
No related branches found
No related tags found
2 merge requests!80check toc purge,!53Exercise checking
%% Cell type:markdown id: tags:
# Gumbel Distribution Exercise
Imagine you are concerned with the concentration of an airborne contaminant, $X$, measured in ppm. A previous benchmark study estimates that there is a 10% and 1% chance, respectively, of exceeding 4 and 10 ppm, respectively. You have been asked by the regulatory agency to estimate the contaminant concentration with 0.1% probability of being exceeded. Prior studies suggest that a Gumbel distribution can be used to model contaminant concentration, given by the CDF:
$$
F_X(x) = \exp{\Bigg( -\exp{\Big(-\frac{x-\mu}{\beta}\Big)}\Bigg)}
$$
Using the cell blocks below as a guide (and also to check your analysis): Task 1) find the parameters of a Gumbel distribution that matches the information provided above, then, Task 2) use it to estimate the concentration with exceedance probability 0.1%.
To complete this assignment, you can use `numpy`, `matplotlib` and from the `math` library, `log` and `e` (these are imported for you when you inialize the notebook).
%% Cell type:code id: tags:thebe-remove-input-init
``` python
%pip install ipywidgets
import matplotlib.pyplot as plt
from math import log, e
import numpy as np
from example_gumbel import check_example
```
%% Cell type:markdown id: tags:
**Task 0:** fill in the appropriate fitting points:
%% Cell type:code id: tags:thebe-init
%% Cell type:code id: tags:
``` python
x_1 = 4
p_e_1 = _
x_2 = 10
p_e_2 = _
```
%% Cell type:markdown id: tags:
**Task 1:** derive the distribution parameters:
%% Cell type:code id: tags:
``` python
def gumbel_2_points(x_1, p_e_1, x_2, p_e_2):
"""Compute Gumbel distribution parameters from two points of the CDF.
Arguments:
x_1 (float): point one
p_e_1 (float): probability of exceedance for point one
x_2 (float): point two
p_e_2 (float): probability of exceedance for point two
"""
# YOUR CODE GOES HERE #
beta = _
mu = _
#######################
return mu, beta
```
%% Cell type:markdown id: tags:
The cell below will print your parameter values and show a plot to help confirm you have the right implementation.
%% Cell type:code id: tags:
``` python
mu, beta = gumbel_2_points(x_1, p_e_1, x_2, p_e_2)
print(f"Your mu: {mu:0.5f}\nYour beta: {beta:0.5f}")
gumbel_distribution = lambda x: e**(-e**(-(x - mu)/beta))
plt.title("Gumbel Distribution, $1-F_X(x)$")
plt.xlabel("Contaminant Concentration, $X$ [ppm]")
plt.ylabel("Exceedance Probability [--]")
plt.grid(color='black', linestyle='-', linewidth=0.3)
x_axis = np.arange(0, 15, 0.1)
plt.plot(x_axis, np.vectorize(gumbel_distribution)(x_axis), linewidth=2)
plt.plot(x_1, p_e_1, 'ro')
plt.annotate("Point 1", (x_1 + 0.4, p_e_1 + 0.02))
plt.plot(x_2, p_e_2, 'ro')
plt.annotate("Point 2", (x_2 + 0.4, p_e_2 + 0.001))
plt.yscale("log")
plt.show()
```
%% Cell type:markdown id: tags:
**Task 2:** write a function to solve for the desired random variable value (it will be tested for you with the Check answer button, along with the distribution parameters).
%% Cell type:code id: tags:
``` python
def find_x_with_probability_p(p):
""" Compute point in the gumbel distribution for which the CDF is p
Use the variables mu and beta defined above!
Hint: they have been defined globally, so you don't need to
include them as arguments.
"""
# YOUR CODE GOES HERE #
x = _
#######################
return x
```
%% Cell type:code id: tags:thebe-remove-input-init
``` python
check_example(globals())
```
%% Output
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment