Several Deno scripts
If you are not convinced that Deno is an amazing application platform, let this post '<3 Deno' tell you about it.
The Snake, game
#########################
# #
# #
# #
# #
# #
# #
# @ # Score: 11
# #
# #
# oo #
# ooo #
# o #
# Oooooooo #
# #
# #
# #
# #
# #
#########################
Press 'q' to quit
I was looking around for what I can do with Deno, and I got off to a tangent of the old text-based UI applications of the MS-DOS era. By nostalgia, I watched YouTube videos about the early PCs and the applications, and installed FreeDOS on QEMU and played with it a bit.
=> https://www.freedos.org/ FreeDOS
A Deno program cannot present the rich visual and interactivity of Web or native applications, at least not from within its security sandbox. But with the ANSI escape sequences, you can make the next best thing, a text-based UI application.
=> https://en.wikipedia.org/wiki/ANSI_escape_code
There are lengths of descriptions about ANSI escape codes on the Wikipedia page but the codes needed just to draw characters on the screen are few and simple. The following videos were helpful to get me started:
- ANSI Sequence video by Sebastien Filion
- 'I will teach you how to make games in your terminal' by Tom
And here is a rudimentary Snake game on Deno:
% deno run https://jaeyoung.se/toys/snake.js
Beta distribution visualizer
Given the result of a binomial experiment, for example coin tosses, the Beta distribution is the distribution of the underlying probability p
.
=> https://en.wikipedia.org/wiki/Beta_distribution
Using the Beta distribution, the posterior distribution of p
given your prior belief and observations can be calculated with the following formula:
$$ \text{Beta}(\alpha_\text{posterior}, \beta_\text{posterior}) = \text{Beta}(\alpha_\text{likelihood} + \alpha_\text{prior}, \beta_\text{likelihood} + \beta_\text{prior}) $$
The plot of a posterior distribution can be interpreted as, the pointier the distribution is, the more certain the underlying probability is.
I uploaded a Deno script that takes a result of binomial experiment and plots the posterior distribution of p
on the terminal.
% deno run https://jaeyoung.se/toys/beta_dist.js
Beta Distribution Visualizer
Enter prior alpha and beta values.
alpha = 1 and beta = 1 means an uninformed prior.
alpha = 1
beta = 1
Prior probability distribution
1.00 ┼───────────────────────────────────────────────────────────────────────────────────────────────────
Observed alpha = 0, beta = 0
Enter observed (+/-) alpha and (+/-) beta values.
alpha = 1
beta = 10
Posterior probability distribution
0.04 ┼ ╭───╮
0.03 ┤ ╭╯ ╰╮
0.03 ┤ ╭╯ ╰─╮
0.03 ┤ ╭╯ ╰╮
0.03 ┤ │ ╰╮
0.03 ┤ ╭╯ ╰╮
0.02 ┤ │ ╰╮
0.02 ┤ ╭╯ ╰╮
0.02 ┤ │ ╰╮
0.02 ┤ │ ╰╮
0.02 ┤ │ ╰─╮
0.02 ┤ ╭╯ ╰╮
0.01 ┤ │ ╰╮
0.01 ┤ │ ╰─╮
0.01 ┤ │ ╰╮
0.01 ┤╭╯ ╰─╮
0.01 ┤│ ╰─╮
0.01 ┤│ ╰──╮
0.00 ┤│ ╰───╮
0.00 ┤│ ╰──────╮
0.00 ┼╯ ╰────────────────────────────────────────────────────
Sources
- https://learning.oreilly.com/library/view/bayesian-statistics-the/9781098122492
- https://deno.land/x/chart
A/B Testing
A hypothesis test is an experiment designed to determine whether to confirm or reject a hypothesis. An A/B test is an experiment to establish which of the treatments of two groups is superior.
One way of determining if the difference between groups is actual or by chance is permutation test.
I wrote a Deno script that does a permutation test on given data. The input TSV file is expected to be in the following format:
group value
A 1
A 1.1
A 0.5
B 0.9
B 0.4
B 1.4
Here is the script:
% deno run https://jaeyoung.se/toys/hypothesis.js
A/B test
Enter the path to the TSV file containing A/B test data
(default _local/data.tsv) _local/data.tsv
✅ Granted read access to "_local/data.tsv".
Pick the type of null hypothesis
* 0) No difference between the means of group A and group B
* 1) A <= B
* 2) B is not X% greater than A
> 0
Resampling 1000 times
p-value: 0.737000