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

GA 1.8 solutions

parent 3a8a31cb
No related branches found
No related tags found
No related merge requests found
Pipeline #252160 passed
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@
<html lang="en">
<head><meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>GA_1_8_solution</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script><script>
<title>GA_1_8_solution_hu</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script><script>
(function() {
function addWidgetsRenderer() {
var mimeElement = document.querySelector('script[type="application/vnd.jupyter.widget-view+json"]');
......@@ -7358,12 +7358,11 @@ a.anchor-link {
if (!diagrams.length) {
return;
}
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjs")).default;
const mermaid = (await import("https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.6.0/mermaid.esm.min.mjs")).default;
const parser = new DOMParser();
 
mermaid.initialize({
maxTextSize: 100000,
maxEdges: 100000,
startOnLoad: false,
fontFamily: window
.getComputedStyle(document.body)
......@@ -7434,8 +7433,7 @@ a.anchor-link {
let results = null;
let output = null;
try {
let { svg } = await mermaid.render(id, raw, el);
svg = cleanMermaidSvg(svg);
const { svg } = await mermaid.render(id, raw, el);
results = makeMermaidImage(svg);
output = document.createElement("figure");
results.map(output.appendChild, output);
......@@ -7450,38 +7448,6 @@ a.anchor-link {
parent.appendChild(output);
}
 
/**
* Post-process to ensure mermaid diagrams contain only valid SVG and XHTML.
*/
function cleanMermaidSvg(svg) {
return svg.replace(RE_VOID_ELEMENT, replaceVoidElement);
}
/**
* A regular expression for all void elements, which may include attributes and
* a slash.
*
* @see https://developer.mozilla.org/en-US/docs/Glossary/Void_element
*
* Of these, only `<br>` is generated by Mermaid in place of `\n`,
* but _any_ "malformed" tag will break the SVG rendering entirely.
*/
const RE_VOID_ELEMENT =
/<\s*(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\s*([^>]*?)\s*>/gi;
/**
* Ensure a void element is closed with a slash, preserving any attributes.
*/
function replaceVoidElement(match, tag, rest) {
rest = rest.trim();
if (!rest.endsWith('/')) {
rest = `${rest} /`;
}
return `<${tag} ${rest}>`;
}
void Promise.all([...diagrams].map(renderOneMarmaid));
});
</script>
......@@ -7571,10 +7537,9 @@ a.anchor-link {
<li>Validate the distribution using the distribution of the function of random variables, $Z(X_1,X_2)$.</li>
</ol>
<h3 id="Multivariate-Distribution-(Task-1)">Multivariate Distribution (Task 1)<a class="anchor-link" href="#Multivariate-Distribution-(Task-1)">¶</a></h3><p>As with WS 1.8, we will build a multivariate distribution, but this time we will include non-Gaussian marginal distributions using a Gaussian Copula:</p>
<p>$$
$$
F_{X_1,X_2}(x_1,x_2) = C[F_{X_1}(x_1)F_{X_2}(x_2)]
$$</p>
<p>In this case, the Copula requires one parameter: the Pearson correlation coefficient, $\rho$.</p>
$$<p>In this case, the Copula requires one parameter: the Pearson correlation coefficient, $\rho$.</p>
<p>This distribution has been implemented in the class <code>Bivariate</code> within <code>helper.py</code>. You can define an instance of the class using:</p>
<pre><code>my_bivariate_dist = Bivariate(marginal_1, marginal_2, rho)
</code></pre>
......@@ -7582,14 +7547,12 @@ $$</p>
<p>Note that the function <code>plot_contours</code> will also work, but due to the way <code>Bivariate</code> is implemented, it is slow to make the plots, so you may want to use small sample sizes.</p>
<h4 id="Python-Package:-pyvinecopulib">Python Package: <code>pyvinecopulib</code><a class="anchor-link" href="#Python-Package:-pyvinecopulib">¶</a></h4><p>A package <code>pyvinecopulib</code> is required for the Bivariate class. It is only available on PyPI, so it has to be installed using <code>pip</code>. Fortunately you should already have done this as part of PA 1.8, so all you need to do is remember to use your environment <code>mude-week-8</code>.</p>
<h3 id="Probability-Calculations-for-3-Cases-(Task-2)">Probability Calculations for 3 Cases (Task 2)<a class="anchor-link" href="#Probability-Calculations-for-3-Cases-(Task-2)">¶</a></h3><p>For each data set, we will use the 90th percentile of each random variable to evaluate the AND, OR and function of random variable cases. In other words:</p>
<p>$$
$$
x_{1,90} = F_{X_1}^{-1}(0.90) \;\;\textrm{and}\;\; x_{2,90} = F_{X_2}^{-1}(0.90)
$$</p>
<p>Since there were three data sets to choose from last week, each with different functions and variables, this notebook uses the notation $Z(X_1,X_2)$ to represent the function of random variables for your particular case. As we did in WS 1.8, we would like to evaluate $Z$ for a threshold condition (in WS 1.8 it was $Z&lt;0$ for the Thingamajig). For this assignment, consider the threshold case to be all combinations of $x_1$ and $x_2$ such that:</p>
<p>$$
$$<p>Since there were three data sets to choose from last week, each with different functions and variables, this notebook uses the notation $Z(X_1,X_2)$ to represent the function of random variables for your particular case. As we did in WS 1.8, we would like to evaluate $Z$ for a threshold condition (in WS 1.8 it was $Z&lt;0$ for the Thingamajig). For this assignment, consider the threshold case to be all combinations of $x_1$ and $x_2$ such that:</p>
$$
Z&gt;Z(x_{1,90},z_{2,90})
$$</p>
<h3 id="Propagating-Uncertainty-(Task-3)">Propagating Uncertainty (Task 3)<a class="anchor-link" href="#Propagating-Uncertainty-(Task-3)">¶</a></h3><p>This proceeds as in WS 1.8 as well, where you will use the samples generated in Task 2 to evaluate the distribution of $Z$ and compare to the empirical data set.</p>
$$<h3 id="Propagating-Uncertainty-(Task-3)">Propagating Uncertainty (Task 3)<a class="anchor-link" href="#Propagating-Uncertainty-(Task-3)">¶</a></h3><p>This proceeds as in WS 1.8 as well, where you will use the samples generated in Task 2 to evaluate the distribution of $Z$ and compare to the empirical data set.</p>
</div>
</div>
</div>
......@@ -8010,7 +7973,6 @@ Build the bivariate distribution by instantiating the <code>Bivariate</code> cla
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<div style="background-color:#facb8e; color: black; width: 95%; vertical-align: middle; padding:15px; margin: 10px; border-radius: 10px"> <p>Note that the optional arguments in the helper function <code>plot_contour</code> will be useful here.
<p>Here is an example code that shows you what it can do (the values are meaningless)</p>
</p></div>
</div>
......@@ -8102,10 +8064,9 @@ Build the bivariate distribution by instantiating the <code>Bivariate</code> cla
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<p>The equation can be defined as follows:</p>
<p>$$
$$
\textrm{WRITE THE EQUATION HERE}
$$</p>
<p>which is then defined in Python and included in the <code>plot_contours</code> function as an array for the keyword argument <code>region</code>.</p>
$$<p>which is then defined in Python and included in the <code>plot_contours</code> function as an array for the keyword argument <code>region</code>.</p>
</div>
</div>
</div>
......@@ -8711,7 +8672,6 @@ The c.o.v. is of p is 0.408.
<span style="font-size: 75%">
© Copyright 2024 <a href="http://mude.citg.tudelft.nl/" rel="MUDE">MUDE</a> TU Delft. This work is licensed under a <a href="http://creativecommons.org/licenses/by/4.0/" rel="license">CC BY 4.0 License</a>.
 
</span></div>
</div>
</div>
......
This diff is collapsed.
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