Dtnorm
Random samples from a doubly-truncated Normal distribution.
Install / Use
/learn @alanrogers/DtnormREADME
dtnorm
Random samples from a doubly-truncated Normal distribution. In other words, a Normal distribution truncated to a finite interval.
I started with the C++ code of G. Dolle and V Mazet, which implements Chopin's algorithm for sampling from the doubly-truncated Normal distribution. My C translation of their code is available on github. I then did numerical experiments with various algorithms, and discovered that other algorithms work better in some regions of parameter space.
The code in this repository combines 4 algorithms:
-
Rejection sampling with a Gaussian proposal distribution
-
Rejection sampling with an exponential proposal distribution.
-
Chopin's algorithm, as implemented by Dolle and Mazet.
Each of these algorithms is used in a different region of parameter space.
The dtnorm function is in src/dtnorm.h, src/dtnorm_data.h, and src/dtnorm.c. For a usage example, see test/example.c. A unit test is in test/xdtnorm.c.
To compile and run the example:
cd test
make example
./example
To compile and run the unit test
cd test
make xdtnorm
./xdtnorm
The unit test takes a single optional argument, -v, which will
provide verbose output.
Related Skills
node-connect
348.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
