Skip to content

Commit 21944cf

Browse files
committed
Start drafting a new post
1 parent 8375ef0 commit 21944cf

20 files changed

+402
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ _site/
77
_cache/
88

99
.ignore
10+
__pycache__
11+
12+
lab/advantage/media
90.3 KB
Binary file not shown.
41.5 KB
Loading
84 KB
Binary file not shown.
70 KB
Loading
115 KB
Binary file not shown.
100 KB
Loading
299 KB
Binary file not shown.
159 KB
Binary file not shown.
66.2 KB
Loading
104 KB
Binary file not shown.
56.1 KB
Loading
Binary file not shown.
65.5 KB
Loading
149 KB
Binary file not shown.
70.2 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Advantage and disadvantage
3+
category: probability
4+
---
5+
6+
TODO: into
7+
8+
<!--more-->
9+
10+
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.umd.js" integrity="sha512-6HrPqAvK+lZElIZ4mZ64fyxIBTsaX5zAFZg2V/2WT+iKPrFzTzvx6QAsLW2OaLwobhMYBog/+bvmIEEGXi0p1w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
11+
12+
<div style="width: 800px;">
13+
<canvas id="plot1"></canvas>
14+
<canvas id="plot2"></canvas>
15+
<canvas id="plot3"></canvas>
16+
</div>
17+
18+
<script type="module" src="/scripts/advantage.js">
19+
</script>
20+
21+
Another paragraph

hakyll/scripts/advantage.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
const plotAbsCanvas = document.getElementById('plot1');
2+
3+
const calcProbAdvantage = function (p) {
4+
return 1 - Math.pow(1 - p, 2);
5+
}
6+
7+
const calcPropDisadvantage = function (p) {
8+
return Math.pow(p, 2);
9+
}
10+
11+
const resolution = 20;
12+
const dieRolls = Array.from(Array(resolution + 1).keys());
13+
const probs = dieRolls.map(x => x / resolution);
14+
const probsAdvantage = probs.map(calcProbAdvantage);
15+
const probsDisadvantage = probs.map(calcPropDisadvantage);
16+
17+
const labels = probs.map(x => (x * 100).toFixed(0) + '%');
18+
19+
const plotAbs = new Chart(plotAbsCanvas, {
20+
type: 'line',
21+
data: {
22+
labels: labels, // x-axis labels should be the possible die rolls
23+
datasets: [
24+
{
25+
label: 'Normal',
26+
data: probs,
27+
borderColor: 'rgba(0, 123, 255, 1)', // blue
28+
fill: false
29+
},
30+
{
31+
label: 'Advantage',
32+
data: probsAdvantage,
33+
borderColor: 'rgba(40, 167, 69, 1)', // green
34+
fill: false
35+
},
36+
{
37+
label: 'Disadvantage',
38+
data: probsDisadvantage,
39+
borderColor: 'rgba(220, 53, 69, 1)', // red
40+
fill: false
41+
}
42+
]
43+
},
44+
options: {
45+
scales: {
46+
y: {
47+
beginAtZero: true
48+
}
49+
}
50+
}
51+
});
52+
53+
var plotUpliftCanvas = document.getElementById('plot2');
54+
55+
const eps = 1e-10;
56+
const divCheck0 = function (x, y) { return Math.abs(y) < eps ? 0 : x / y; }
57+
const advantageUplift = probsAdvantage.map((pa, i) => divCheck0(pa, probs[i]));
58+
const disadvantageDrop = probsDisadvantage.map((pd, i) => divCheck0(probs[i], pd));
59+
60+
const plotUplift = new Chart(plotUpliftCanvas, {
61+
type: 'line',
62+
data: {
63+
labels: labels, // x-axis labels should be the possible die rolls
64+
datasets: [
65+
{
66+
label: 'Advantage Uplift',
67+
data: advantageUplift,
68+
borderColor: 'rgba(40, 167, 69, 1)', // green
69+
fill: false
70+
}
71+
]
72+
},
73+
options: {
74+
scales: {
75+
y: {
76+
beginAtZero: true
77+
}
78+
}
79+
}
80+
});
81+
82+
var plotDropCanvas = document.getElementById('plot3');
83+
const plotDrop = new Chart(plotDropCanvas, {
84+
type: 'line',
85+
data: {
86+
labels: labels, // x-axis labels should be the possible die rolls
87+
datasets: [
88+
{
89+
label: 'Disadvantage Drop',
90+
data: disadvantageDrop,
91+
borderColor: 'rgba(220, 53, 69, 1)', // red
92+
fill: false
93+
}
94+
]
95+
},
96+
options: {
97+
scales: {
98+
y: {
99+
beginAtZero: true
100+
}
101+
}
102+
}
103+
});

hakyll/site.hs

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ main =
1616
route idRoute
1717
compile copyFileCompiler
1818

19+
match "scripts/**" $ do
20+
route idRoute
21+
compile copyFileCompiler
22+
1923
match "css/*" $ do
2024
route idRoute
2125
compile compressCssCompiler

0 commit comments

Comments
 (0)