Skip to content

Commit

Permalink
chore: add pre-commit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorias committed Mar 24, 2024
1 parent 311eb8a commit d5c22e0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
8 changes: 8 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
bundle exec jekyll build


test: build
bundle exec htmlproofer _site \
--check_external_hash=false \
--ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/,/fonts.googleapis.com/,/fonts.gstatic.com/,/linkedin.com\/in\/grzegorz-milka-55270490/,/twitter.com\/intent\/tweet/,/archive.ph/"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ The blog is hosted on GitHub Pages at

1. Install [rbenv](https://github.com/rbenv/rbenv) and
[direnv](https://direnv.net/) and hook them into your shell.
1. Install Lefthook.

```bash
lefthook install
```

1. Allow `.envrc`.

```bash
Expand Down
2 changes: 1 addition & 1 deletion _posts/2014-12-28-creating-ai-in-haskell.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,4 @@ easily.
[minmax]: https://en.wikipedia.org/wiki/Minimax
[github]: https://github.com/gregorias/Pentago
[outoftarpit]: https://github.com/papers-we-love/papers-we-love/blob/master/design/out-of-the-tar-pit.pdf?raw=true
[whymatters]: https://github.com/papers-we-love/papers-we-love/blob/master/functional_programming/why-functional-programming-matters.pdf
[whymatters]: https://github.com/papers-we-love/papers-we-love/blob/main/languages-paradigms/functional_programming/why-functional-programming-matters.pdf
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ then I will describe how to combine Cython and profiling to build a flexible and
efficient Python application. In the last section I will talk about pulseaudio
and how it allows me to perform user testing without using an external device.

Modulation and demodulation
===========================
## Modulation and demodulation

The module that I am building encodes and decodes voice. The encoder has one
input: a continuous stream of voice represented by audio samples. On the output
it plays audio that is transmitted by an independent voice communicator. The
Expand All @@ -30,8 +30,8 @@ producing a seemingly random bytestring. This task includes a few challenges:
voice so that it fits?
* How can I efficiently demodulate the modulated signal?

Basics of audio signals
-----------------------
### Basics of audio signals

The sound that we hear is a result of a mechanical wave of pressure and
displacement propagating through air. As such we can represent any sound as a
wave. Wave being a continuous signal needs to be discretized to be representable
Expand Down Expand Up @@ -71,8 +71,8 @@ to the other. From fundamental frequencies we can produce sampling by simply
calculating wave values at given points. To get the other way around we need to
use the discrete Fourier transform.

Discrete Fourier transform
--------------------------
### Discrete Fourier transform

Fourier transform is a general mathematical tool which transform a wave function
into a function of fundamental frequencies. That is the resulting function maps
each of its argument to its power inside the argument. The discrete version of
Expand Down Expand Up @@ -107,8 +107,7 @@ have twice that sampling rate. Since telephony was meant to transmit voice and
human voice happens in a range up to 300Hz then 8000 sampling rate was more than
enough.

Modulating data
---------------
### Modulating data

We know enough to understand important trade-offs of signal modulation. Our task
now is to encode binary data into a voice channel in such a way that the
Expand Down Expand Up @@ -138,8 +137,7 @@ before, but resigned due to lack of some libraries I would find useful. Now
after overcoming my reluctance to FFI I would simply write such a wrapper for
Haskell. End of diversion.

Demodulation
------------
### Demodulation

So far I have described how the voice is encoded into binary data and how then
this data is modulated. We are now left with possibly the most difficult part of
Expand Down Expand Up @@ -260,8 +258,7 @@ voice demodulation. In the next section I will explain how Cython works and how
it can greatly improve speed of Python for low cost of just some static type
annotations.

Cython
======
## Cython

Profiling
---------
Expand Down Expand Up @@ -505,4 +502,4 @@ streams so that multiple inputs can be mixed.
[hermes]: https://cs.nyu.edu/~jchen/publications/com31a-dhananjay.pdf
[codec2]: https://www.rowetel.com/blog/?page_id=452
[pycodec2]: https://github.com/gregorias/pycodec2
[py3vsC]: https://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=python3&lang2=gcc
[py3vsC]: https://archive.ph/Dk5Uq
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,13 @@ The measure of unexpectedness is called **p-value**.
It is the probability that our null hypothesis would produce the observed or more extreme value.
In other words, the lower the p-value, the stronger the suprise.

<figure>
<img src="/images/2017/p_value.png" alt="A diagram explaing the concept of a p-value." />
</figure>
![A diagram explaing the concept of a p-value.](/images/2017/p_value.png)

Same calculations may be used to compute a related concept - **confidence interval** of $$\hat{\theta}$$.
Confidence interval is an interval that intuitively approximates the likely range in which the parameter $$\theta$$ really lies.
In our example, the interval would be $$\hat{\theta} \pm 1.96 \hat{\sigma}$$, because $$\hat{\theta}$$ is normally distributed.

<figure>
<img src="/images/2017/normal_196.png" alt="A plot of a normal distribution with 95% confidence interval." />
</figure>
![A plot of a normal distribution with 95% confidence interval.](/images/2017/normal_196.png)

A correct intepretation of a confidence interval is not that simple:

Expand Down Expand Up @@ -177,7 +173,9 @@ First we have to agree on a prior.
Usually, we don't know much, so we might as well assign uniform probability distribution to $$\theta_A, \theta_B$$.
By applying the Bayes rule to experimental data, which consists of numbers of successes and attempts in each variant, we'll get the posterior probability distribution of variants' parameters.
In our case the posterior probability distribution is conveniently expressible by a [Beta distribution](https://en.wikipedia.org/wiki/Beta_distribution).
If you'd like to understand what happens under the hood, then I reccommend an excellent introductory series ["using baseball statistics"](https://varianceexplained.org/r/empirical_bayes_baseball/).
If you'd like to understand what happens under the hood, then I recommend an
excellent introductory series “Understanding empirical Bayes estimation (using
baseball statistics)”.

With the probability distribution we can do all kinds of stuff we couldn't do with frequentist methodology.
Like plot its density:
Expand Down Expand Up @@ -212,10 +210,8 @@ At any given time we only have probability estimates of the expected payoff, and
Experiments need to continuously balance exploration (choosing alternative variants in order to learn more about payoffs) and exploitation (choosing the variant we believe to be the best) in order to minimize the expected loss - patient is assigned the worse treatment.

Experiments using this approach are called [Multi-armed bandit experiments](https://en.wikipedia.org/wiki/Multi-armed_bandit)[^wiki_quote].
The multi-armed bandit problem generalizes the outlined approach to multiple variants with unknown payoff.

[Google Analytics uses multi-armed bandit as their experiment framework](https://support.google.com/analytics/answer/2844870?hl=en).
Their [FAQ](https://support.google.com/analytics/answer/2847021?hl=en) does a good job of explaining the reasons why a Google analytics customer might prefer this method to a classical approach.
The multi-armed bandit problem generalizes the outlined approach to multiple
variants with unknown payoff.

## Summary

Expand All @@ -236,7 +232,7 @@ Also, I heartily recommend using Bayesian methods in your experiments, quite oft

[gelmanblog]: https://andrewgelman.com

[fharrell_contradiction]: https://www.fharrell.com/2017/01/null-hypothesis-significance-testing.html
[fharrell_contradiction]: https://www.fharrell.com/post/nhst-never/index.html

[wagenmaker_conf]: https://www.ejwagenmakers.com/inpress/HoekstraEtAlPBR.pdf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ date: 2023-03-25 11:00:00
tags: neovim plenary coroutine
---

[Neovim Plenary](https://github.com/nvim-lua/plenary.nvim)'s [`async.run`](https://github.com/nvim-lua/plenary.nvim/blob/253d34830709d690f013daf2853a9d21ad7accab/lua/plenary/async/async.lua#L104) seems to be doing an impossible trick. It starts a concurrent computation that runs even after the main script has finished and calls the provided callback once it's done. It seemed impossible to me, because Lua uses [non-preemptive coroutines](https://www.lua.org/pil/9.4.html). The caller needs to orchestrate when its coroutines can resume. So when the main script is done, there should be nothing that can resume remaining coroutines.

This note is my investigation into why this is happening. Surprise is important for learning.
[Neovim Plenary](https://github.com/nvim-lua/plenary.nvim)’s
[`async.run`](https://github.com/nvim-lua/plenary.nvim/blob/253d34830709d690f013daf2853a9d21ad7accab/lua/plenary/async/async.lua#L104)
seems to be doing an impossible trick. It starts a concurrent computation that
runs even after the main script has finished and calls the provided callback
once it's done. It seemed impossible to me, because Lua uses
[non-preemptive coroutines](https://www.lua.org/pil/9.4.html).
The caller needs to orchestrate when its coroutines can resume. So when the
main script is done, there should be nothing that can resume remaining
coroutines.

This note is my investigation into why this is happening. Surprise is important
for learning.

## Testing

Expand Down
5 changes: 5 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pre-commit:
parallel: true
commands:
tests:
run: just test

0 comments on commit d5c22e0

Please sign in to comment.