Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bookOutline.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"continuous":"Continuous Distribution",
"uniform":"Uniform Distribution",
"exponential":"Exponential Distribution",
"erlang":"Erlang Distribution",
"normal":"Normal Distribution",
"binomial_approx":"Binomial Approximation"
},
Expand Down
43 changes: 43 additions & 0 deletions chapters/part2/erlang/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

% rebase('templates/chapter.html', title="Erlang Distribution")

<center><h1>Erlang Distribution</h1></center>
<hr/>

<p>
If events are occurring sequentially with the same mean rate of occurrence after each event,
an Erlang random variable measures the amount of time until the $k^{th}$ event occurs.
The random variable is the summation of $k$ independent and identically distributed (IID) Exponential random variables.
</p>

<%
include('templates/rvCards/erlang.html')
%>
<div style="height: 20px"></div>

<p>
If you set $k$ equal to 50 up above, that is the equivalent of summing together 50 Exponential random variables with a mean rate of $\lambda$. Notice
how the resulting PDF resembles that of a Gaussian. We will explore why that is when we cover the <a href="{{pathToLang}}part4/clt/">Central Limit Theorem</a>.
</p>

<div class="purpleBox">
<p><b><i>Example</i></b>:
Agner Krarup Erlang wants to reward the 10th customer who walks into his gag foam-phone store, "Phoney Foam Phones".
Agner needs 15 minutes to prepare the prize. Since a YouTube video went viral showcasing how foam-phones can be used to clean dishes,
the store has become surprisingly popular. People are walking in at a mean rate
of one person per minute. What is the probability that Erlang will have the time to prepare his prize?
</p>
Let $X$ be the number of minutes until the 10th customer walks in. Since a customer walking in is an event that is
occurring at a mean rate of once per minute, $X \sim {\rm Erlang}(k = 10, \lambda = 1)$.
The question is asking us to calculate P(X > 15):

\begin{align*}
P(X > 15) &= 1 - P(X < 15) \\
&= 1 - F_{X}(15) \\
&= 1 - (1 - \sum_{n=0}^{10-1}{\frac{1}{n!} e^{-1 \cdot 15} (1 \cdot 15)^{n}}) \\
&= 1 - (1 - \sum_{n=0}^{9}{\frac{1}{n!} e^{-15} (15)^{n}}) \\
&= 0.070
\end{align*}

Sorry Agner!
</div>
1 change: 1 addition & 0 deletions templates/chapterList.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<a id=sidebar-continuous href="{{pathToLang}}part2/continuous">Continuous Distribution</a>
<a id=sidebar-uniform href="{{pathToLang}}part2/uniform">Uniform Distribution</a>
<a id=sidebar-exponential href="{{pathToLang}}part2/exponential">Exponential Distribution</a>
<a id=sidebar-erlang href="{{pathToLang}}part2/erlang">Erlang Distribution</a>
<a id=sidebar-normal href="{{pathToLang}}part2/normal">Normal Distribution</a>
<a id=sidebar-binomial_approx href="{{pathToLang}}part2/binomial_approx">Binomial Approximation</a>

Expand Down
104 changes: 104 additions & 0 deletions templates/rvCards/erlang.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!-- Template that renders a single random variable card -->

<div class="bordered">
<p><b>Erlang Random Variable</b></p>


<table>
<tbody class="rvCardBody">
<tr>
<th style="width:150px">Notation:</td>
<td>$X \sim {\rm Erlang}(k, \lambda)$</td>
</tr>
<tr>
<th>Description:</td>
<td>Time until $k^{th}$ event occurs if (a) the events occur with a constant mean rate and (b) they occur independently of time since last event.</td>
</tr>
<tr>
<th>Parameters:</td>
<td>$k \in \{1, 2, \dots\}$, occurrence of event <br/>
$\lambda \in \{0, 1, \dots\}$, the constant average rate</td>
</tr>


<tr>
<th>Support:</td>
<td>$x \in \mathbb{R}^+$</td>
</tr>
<tr>
<th>PDF equation:</th>
<td class="mathLeft">$$f(x) = \frac{\lambda^{k}x^{k-1}e^{- \lambda x}}{(k-1)!}$$</td>
</tr>
<tr>
<th>CDF equation:</th>
<td class="mathLeft">$$F(x) = 1 - \sum_{n=0}^{k-1}{\frac{1}{n!} e^{-\lambda x} (\lambda x )^{n}}$$</td>
</tr>
<tr>
<th>Expectation:</th>
<td>$\E[X] = k/\lambda$</td>
</tr>
<tr>
<th>Variance:</th>
<td>$\var(X) = k/\lambda^2$</td>
</tr>
<tr>
<th>PDF graph:</th>
</tr>
</tbody>
</table>
<div class="d-flex">
<div class="mr-2">
Parameter $k$: <input onchange="redrawErlangPdf()" type="number" class="form-control example-inline-input mb-3" id="erlangPdfK" min="1" max="130" value="5" step = "1">
</div>
<div class="mr-2">
Parameter $\lambda$: <input onchange="redrawErlangPdf()" type="number" class="form-control example-inline-input mb-3" id="erlangPdfLambda" min="0" max="130" value="5" step = "1">
</div>
</div>
<canvas id="exponentialPdf" style="max-height: 400px"></canvas>
</div>

<script>

$(document).ready(function(){
redrawErlangPdf()
})

function redrawErlangPdf() {
let parentDivId = 'exponentialPdf'
let k = parseFloat($("#erlangPdfK").val())
let lambda = parseFloat($("#erlangPdfLambda").val())
drawErlangPdf(parentDivId, k, lambda)
}

function drawErlangPdf(parentDivId, k, lambda) {
if(window.myExpLine) {
window.myExpLine.destroy()
}

var expectation = k / lambda
var xValues = []
var yValues = []
var i = 0
if (k < 1 || lambda <= 0) {
xValues.push(0)
yValues.push(0)
}
else {
while (true) {
let pr_x = jStat.gamma.pdf(i, k, 1 / lambda).toFixed(5)
xValues.push(i.toFixed(3))
yValues.push(pr_x)
i += expectation / 100
if (pr_x < 0.001 && expectation < i) {
break;
}
}
}
let xLabel = 'Values that X can take on'
let yLabel = 'Probability'

var config = standardPDFConfig(xValues, yValues, xLabel, yLabel)
var ctx = document.getElementById(parentDivId).getContext('2d');
window.myExpLine = new Chart(ctx, config);
}
</script>