forked from personal/squiggle.c
63 lines
2.7 KiB
Markdown
63 lines
2.7 KiB
Markdown
# Squiggle.c
|
|
|
|
A self-contained C99 library that provides a subset of [Squiggle](https://www.squiggle-language.com/)'s functionality in C.
|
|
|
|
## Why C?
|
|
|
|
- Because it is fast
|
|
- Because I enjoy it
|
|
- Because C is honest
|
|
- Because it will last long
|
|
- Because it can fit in my head
|
|
- Because if you can implement something in C, you can implement it anywhere else
|
|
- Because it can be made faster if need be, e.g., with a multi-threading library like OpenMP, or by adding more algorithmic complexity
|
|
|
|
## The core strategy
|
|
|
|
Have some basic building blocks, like , and return samplers. Use previous samplers to . Then use the final sampler to produce an array of samples.
|
|
|
|
## Getting started
|
|
|
|
You can follow some example usage in the examples/ folder
|
|
|
|
1. In the first example, we define a small model, and draw one sample from it
|
|
2. In the second example, we define a small model, and return many samples
|
|
3. In the third example, we use a gcc extension—nested functions—to rewrite the code from point 2. in a more linear way.
|
|
4. In the fourth example, we define some simple cdfs, and we draw samples from those cdfs. We see that this approach is slower than using the built-in samplers, e.g., the normal sampler.
|
|
5. In the fifth example, we define the cdf for the beta distribution, and we draw samples from it.
|
|
|
|
## Related projects
|
|
|
|
- [Squiggle](https://www.squiggle-language.com/)
|
|
- [SquigglePy](https://github.com/rethinkpriorities/squigglepy)
|
|
- [time to botec](https://github.com/NunoSempere/time-to-botec)
|
|
- [simple squiggle](https://nunosempere.com/blog/2022/04/17/simple-squiggle/)
|
|
|
|
## To do list
|
|
|
|
- [ ] Have some more complicated & realistic example
|
|
- [ ] Add summarization functions, like mean, std, 90% ci (or all c.i.?)
|
|
- [ ] Add README
|
|
- Schema: a function which takes a sample and manipulates it,
|
|
- and at the end, an array of samples.
|
|
- Explain boxes
|
|
- [x] Explain individual examples
|
|
- Explain nested functions
|
|
- [ ] Publish online
|
|
- [ ] Support all distribution functions in <https://www.squiggle-language.com/docs/Api/Dist>
|
|
- [ ] Support all distribution functions in <https://www.squiggle-language.com/docs/Api/Dist>, and do so efficiently
|
|
|
|
## Done
|
|
|
|
- [x] Add example for only one sample
|
|
- [x] Add example for many samples
|
|
- ~~[ ] Add a custom preprocessor to allow simple nested functions that don't rely on local scope?~~
|
|
- [x] Use gcc extension to define functions nested inside main.
|
|
- [x] Chain various mixture functions
|
|
- [x] Add beta distribution
|
|
- See <https://stats.stackexchange.com/questions/502146/how-does-numpy-generate-samples-from-a-beta-distribution> for a faster method.
|
|
- ~~[-] Use OpenMP for acceleration~~
|
|
- [x] Add function to get sample when given a cdf
|
|
- [x] Don't have a single header file.
|
|
- [x] Structure project a bit better
|