Last active
December 24, 2019 10:36
-
-
Save fischerbach/df9113cf5e67f82791dc3bb464ef5d04 to your computer and use it in GitHub Desktop.
uniform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>[Statistics] Min of two uniform random variables: Google [Medium]</h1> | |
<div>Say we have X ~ Uniform(0, 1) and Y ~ Uniform(0, 1). What is the expected value of the minimum of X and Y?</div> | |
<div> | |
<input id="ATTEMPTS" /> | |
</div> | |
<div id="result"> | |
<ol id="results"> | |
</ol> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ATTEMPTS = 1; | |
document.getElementById("ATTEMPTS").addEventListener("keydown", function(){ | |
calculate( | |
parseInt(this.value), | |
Math.random, | |
Math.random | |
) | |
}, false); | |
var calculate = function (attempts, dist_x, dist_y) { | |
var X = 0 | |
var Y = 0 | |
var results = [] | |
var sum = 0; | |
for(var i=0; i <= attempts; i++) { | |
X = Math.random(); | |
Y = Math.random(); | |
results[i] = Math.min(X,Y); | |
sum += results[i]; | |
document.getElementById('results').innerHTML = ""; | |
document.getElementById('results').appendChild((function(r){ | |
r.appendChild(document.createTextNode(ATTEMPTS+X+" | "+Y+" | " + sum)); | |
return r; | |
})(document.createElement('li'))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment