From 04070a934ef8318872144f6aa6331d56ed60236e Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 22 Jul 2023 19:21:20 +0200 Subject: [PATCH] give more expressive names to main functions This bash function was helpful: function replace(){ grep "$1" -rl . grep "$1" -rl . | xargs sed -i "s/$1/$2/g"; } --- README.md | 4 +- examples/01_one_sample/example | Bin 17648 -> 22024 bytes examples/01_one_sample/example.c | 6 +-- examples/02_many_samples/example | Bin 17688 -> 22064 bytes examples/02_many_samples/example.c | 6 +-- examples/03_gcc_nested_function/example | Bin 22104 -> 22088 bytes examples/03_gcc_nested_function/example.c | 6 +-- examples/04_sample_from_cdf_simple/example | Bin 22184 -> 22176 bytes examples/04_sample_from_cdf_simple/example.c | 4 +- examples/05_sample_from_cdf_beta/example | Bin 22208 -> 22200 bytes squiggle.c | 40 +++++++++---------- squiggle.h | 15 ++++--- 12 files changed, 38 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index ed47c66..217bc55 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Behaviour on error can be toggled by the `EXIT_ON_ERROR` variable. This library ## To do list -- [ ] Rename functions to something more self-explanatory, e.g,. sample_unit_normal. +- [ ] Rename functions to something more self-explanatory, e.g,. sample_sample_sample_unit_normal. - [ ] Have some more complicated & realistic example - [ ] Add summarization functions, like mean, std, 90% ci (or all c.i.?) - [ ] Publish online @@ -90,7 +90,7 @@ Behaviour on error can be toggled by the `EXIT_ON_ERROR` variable. This library - [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] Chain various sample_mixture functions - [x] Add beta distribution - See for a faster method. - ~~[-] Use OpenMP for acceleration~~ diff --git a/examples/01_one_sample/example b/examples/01_one_sample/example index 90e4a1fb8be49c4b80b023f38c78649bd7a5d9e4..12177033f1f12cb54ab0c6bc2d8c6529ea072a0f 100755 GIT binary patch literal 22024 zcmeHPe|%KcmB0A~QN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(Aa4i)o;>)o4KrL6=r5HeiiectdFn+*1HX=Gx2kw=6ZQgmsk$0>F?j{P8qZ`hk5}WUj4vKBcoWNJ4vy0sRd-}HitC!R<7-jH z>KPz!waYK7F13CziuBicL({19Gspb^`Kw(tQf*P&D`|iAO7)d%>0EV5|MdAC)%|DA z?*l#j%sfr#_{{u%qsN(RQTj@T%Ea$w(wq*XXs?D%lne>l^>qm z3J(f=So9@#r$6Yv$Mp9n{GIh3Ecs}s7e9&oD_!1f%+#r7F?k=C)47i0m<@9qNPKND#PNEJZo9 zM+F|^XCs=v{ecb(yhp^5d-pGZqu&CiuWsGNc)chb*#KcFwS;&1~+$w+q!!@+4TQS zpKt096E=}x7pz)4*rwLbo{oEi9^F6a2}ZhuUe?jQamv2zCN8(d0Tqbe5x#pvke06U z)8nh=(w|pV_II{+{YZ`?(#`t1dpEU*+aim~V14(dP5l42H-g{Za2J4{-f&l>jsFc# z#pS=jVisa>jr9`12;_jnT~jV)C5u^SxG%D~_uh0l6)(a!-%=f{U0o9l(&2`AbhhET zu^Vo=QyF_?^#(<0r&G6Y`1E6wvP n0$6AyyJenL06iAEuch2Ny2Nm3rI%VNY|dqdl&#SI)w%x#z?j3^ diff --git a/examples/01_one_sample/example.c b/examples/01_one_sample/example.c index bbea2eb..337b9ce 100644 --- a/examples/01_one_sample/example.c +++ b/examples/01_one_sample/example.c @@ -16,12 +16,12 @@ float sample_1(uint32_t* seed) float sample_few(uint32_t* seed) { - return random_to(1, 3, seed); + return sample_to(1, 3, seed); } float sample_many(uint32_t* seed) { - return random_to(2, 10, seed); + return sample_to(2, 10, seed); } int main(){ @@ -37,7 +37,7 @@ int main(){ float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; - float result_one = mixture(samplers, weights, n_dists, seed); + float result_one = sample_mixture(samplers, weights, n_dists, seed); printf("result_one: %f\n", result_one); } diff --git a/examples/02_many_samples/example b/examples/02_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z=(cI(2Ao(bZ&A3FbW>4SV?3GaL5$i@k*BHgyUCXS_9A}9?T6?N#-g6hh*RWkZ6e-x zFrHB9uGBdZ)@sgRBdYwb?s{ZvIW~iSS~ot@)8O1n<@qna1c2#WDt_+GVzJE(sijn%W|} zSZD%2F++c?$1Lud@Eo{MyUglV{Y-DYMzGZt*%~=3@D$Y471`annytW58T#uyX7Rh; zSO^#DO3dQy4HtsBzQio9l}I71t}n5P+a$vGS05az_nQ1X2rpcyUnV507t9Uik{4Dt il$*So#XckSHA{CIDFbS%bN&kt{lruN diff --git a/examples/02_many_samples/example.c b/examples/02_many_samples/example.c index 001d732..7d44ab3 100644 --- a/examples/02_many_samples/example.c +++ b/examples/02_many_samples/example.c @@ -16,12 +16,12 @@ float sample_1(uint32_t* seed) float sample_few(uint32_t* seed) { - return random_to(1, 3, seed); + return sample_to(1, 3, seed); } float sample_many(uint32_t* seed) { - return random_to(2, 10, seed); + return sample_to(2, 10, seed); } int main(){ @@ -40,7 +40,7 @@ int main(){ int n_samples = 1000000; float* result_many = (float *) malloc(n_samples * sizeof(float)); for(int i=0; ibZ}QwA0trwnA|?xeNxs<}4o=QTX(plY#$v`zO##%vrmxG|VE)xc z&dghr-Eff~f6gYeW$Jsq|7Hu?v~1P%wB_=vUOg*BXVPoVuHetV@$q5Gu>) zv&u58DZLBfQ<f-wSLZZ`qQ*CtBj^*UC&3zljY^# zQFqpSUFu(;Z-Jp?-()gnFgE%pXDl#q>_dr>J=B+7RQ|aMQ`;#ac7tP)0?Z=s{V7DV z`_hipYm1zRf^vEh0!&ph=y-Mu-%j;813IILCUS0Y?=v!Xw*hMDXP7Ak)5^o|{w;*> z!B6ImzKIX`2F>LVJb&Hn8!WG)mG%wETX514V9qhp_jZSgL7rAt9#9@yfQn?MDN-Dd z@#VC`F*N&wbYy*akDAgsdRk3c3RX>7o=$6=9W#%Bj}qo#I^fKi6ZzNfR~Wm+yXu$O zI6%!I)a4vaz;{qrJLR~p;~{EvE#S4Z&E=f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*8>(>JElo0N2fH& zOD0|NvWeVEbjC3FWDHveJ+I_lGy2;+0N2(2RU-wsZjnCZr5w#b9OUJt)5=Y}o}BK* z+)OLo$~ANyWB%pA-cS4u!QM;$JN>;sHw1Rf-3oeHsQ5C@JU!uxz2GjGz03FUX7P4# zYgzpnRdqm8IjgEwKp$`ga2yy1)_3D*T~<3? z9N5eR8Oyz?f5UJiRhE~fevFZiHk7ZOTa9Dz;aJM#YN5CS+^Q?MYH+RK9w$r1&FP0Q zIshw8RAt7@1@ETO(#kr6ry%xRWo-(OzVz4fBeCKoMFzf!mR9fK7igl|Wl##pTC<$r zO)WLy;D^|V73s&bw77a*PfLE#rty0H#C5hBEX-4&@p?Z-?izcED1lI8a@9N1oF(}_ z8AU%)h1S)ITP1qG=$&ieX=b=3^}4c#ZS-QTy$P3{Sqx5=ewDRX>UX#`Z@q}m3x8z9 zd>W4{ooxH0|6X|=^&>k>Cy~j2l9_xaeGW*?X1VrjVWn5<9Km0thi{H%`m6MaNM6C; zQZ#+HGjU*|I)nJ1i{?TtMa!m%I(yI!tC{66^HqDBtFMw#F3MGlB`^M(qAizvH7yO; zgN@Q^&ep8SyN;o_KB6M8Tvd^%^dFc0$@>rg9--#kDXnK^y@J@GXuE}#ze=y8KTPKW z_KK6bj(C`8`UCk~^6`9)Un>3iR zu4uS~wMOr)s;UbGm)smK^_Jd1J-0kXc_F{Oqci%K=Jo5t&7GamPF=7oN}EE#8>PHd zs}JgCXi08;OZye7-U`;%vaxGJXEP0jT=ZIM4k@?JkKKQ3Bai+2w)4|?Gxgsw&!|5p u@n-LM49~P>**wdU60K4?4#fJGsT_}`zhOZ}M^H1S(MZDr-c9c1MZW^!P0%?2 diff --git a/examples/03_gcc_nested_function/example.c b/examples/03_gcc_nested_function/example.c index bc862f7..354d8f9 100644 --- a/examples/03_gcc_nested_function/example.c +++ b/examples/03_gcc_nested_function/example.c @@ -16,8 +16,8 @@ int main(){ float sample_0(uint32_t* seed){ return 0; } float sample_1(uint32_t* seed) { return 1; } - float sample_few(uint32_t* seed){ return random_to(1, 3, seed); } - float sample_many(uint32_t* seed){ return random_to(2, 10, seed); } + float sample_few(uint32_t* seed){ return sample_to(1, 3, seed); } + float sample_many(uint32_t* seed){ return sample_to(2, 10, seed); } float (*samplers[])(uint32_t*) = { sample_0, sample_1, sample_few, sample_many }; float weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 }; @@ -25,7 +25,7 @@ int main(){ int n_samples = 1000000; float* result_many = (float *) malloc(n_samples * sizeof(float)); for(int i=0; iDAywC=ZiCtrTxi6>%DWpwA!uV6xF$^Xnwh`d@wNN9)8n1ZTL z!LGN`9dNh4$h4WOH*-GvPqY}O+_0(#HtOejLm7l@9iu%-dG8IzTBS?zqp0SAuGt8Q zlqHfOX?FZD=aN#BdM^A!U!I+%| zsaz%{t$HJxwMrc)F|SK-FnAe>7T5 znY~q5OJ;ErLtL^5XXB3`n`YZTLesG$l4D!y!g&3mtryJwx1dA8A1qLBYRa*TXmu75 zE%0+RDIKly8jP6BD*LAxlfT4&V}~V&Kh@5LQ1m*6)Fvfeq&QPPfJ$`7EfSf)UPu?FZz@P_ps`V%CqP4q>mwyiQ8!xL%QDZ6QV=F-y#N0naq5V;M z7@o67Rc<|K9ZTI$>k0Xd4wb%5xRX3d>4if$w4trXONZW14Q;_i9d_a058!xTfj-A( zjSppXC^!K#ole8MDQV?t>G^8Rkq6of)y|!?1HN$XD{8~3mR=ZEB07hzDiP01>4+C$ zpr~uccSxsBC}@EhF5B($&+?sUxjOLR4=$Xx)&b1QIh2LRgmx6zC8%@VrSePgqHCdw zNbsr4ar$$N9^MAdB(OQ)+6pyktX8(p0OibG0NB} zM6b-)G-3i#i=Qmc9~dh}>>9%Wh}sK`y@^Qv#n{)JA7?C*Nys2#3*tE9Cd8Hr#^SME zjLuZ^LlVH18PKVr6mOAY2ZV`T9)o1m8PfrxYNkxtC>3XvYf_`V*nO!L?L^ zz!HHeB=D<;ukO ziM<+rjp`q2?|f*z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95wj8cq_R9A z9i87yDOKG?`{fLGQLgQb>m32N|30n`zBj>*(P-5p33HfDMrNz37gBAFk4GbeHBTCO zl&*N|xi#{@`pevqUQJ1LzvVMDTIb?Z^tZYv`DV&_v~!7-4cOxc=^Z*jvvszzk5K7i zbY$2O_v-y9l)NF0Me+Raw+q^?d9`a?X?~zWIO>#Y&5GA=D22QmY<8#ehVXYUO?wf* zeCg%Y+HWg8v%!|ofk-zUH!R^{$?iCSb(+D>OwHQHdq1xz#Zr}}-pivh9+|MxcqpE; zW)T&?T|FoL-p1)XGMLb^{9MI^lxC;e8sz1i^+hA7kq%$7l05DDSxHnf|r3=$bk4@M}u5Q&&?t zG%2-R^gPt$o0Az%sN0@Y-dDiOe*L#BPU!u5O~sEbjq?{({2!#6{e<$4sBZdEzqI$I zm!GFA`2CF1{I<&5x{fm*p?^aqiXT`W=ev~xM*_Lp{X6Lyzb!K2f0I8L-qHJ`Kvz$2 zM<46x33hbX*48)r*FO??sQ97cN+!L*-GOI&cXkECyQ#gwxdQXPKrdE1dNg;SG|(3e zl(C-R)A#ND0sXn*kJQ`fwS~gLj?O)M0-fP-Fsuvq1?l6)uGLCjsWtm`H?$PDXJ_wy zs>o>f&i=kozh8;`7dY-$1jg6u6NX8rSu(&H@$`7~W5sRnh_ - float u1 = rand_0_to_1(seed); - float u2 = rand_0_to_1(seed); + float u1 = sample_unit_uniform(seed); + float u2 = sample_unit_uniform(seed); float z = sqrtf(-2.0 * log(u1)) * sin(2 * PI * u2); return z; } -float random_uniform(float from, float to, uint32_t* seed) +float sample_uniform(float from, float to, uint32_t* seed) { - return rand_0_to_1(seed) * (to - from) + from; + return sample_unit_uniform(seed) * (to - from) + from; } -float random_normal(float mean, float sigma, uint32_t* seed) +float sample_normal(float mean, float sigma, uint32_t* seed) { - return (mean + sigma * unit_normal(seed)); + return (mean + sigma * sample_unit_normal(seed)); } -float random_lognormal(float logmean, float logsigma, uint32_t* seed) +float sample_lognormal(float logmean, float logsigma, uint32_t* seed) { - return expf(random_normal(logmean, logsigma, seed)); + return expf(sample_normal(logmean, logsigma, seed)); } -float random_to(float low, float high, uint32_t* seed) +float sample_to(float low, float high, uint32_t* seed) { const float NORMAL95CONFIDENCE = 1.6448536269514722; float loglow = logf(low); float loghigh = logf(high); float logmean = (loglow + loghigh) / 2; float logsigma = (loghigh - loglow) / (2.0 * NORMAL95CONFIDENCE); - return random_lognormal(logmean, logsigma, seed); + return sample_lognormal(logmean, logsigma, seed); } // Array helpers @@ -91,7 +87,7 @@ void array_cumsum(float* array_to_sum, float* array_cumsummed, int length) } // Mixture function -float mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed) +float sample_mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed) { // You can see a simpler version of this function in the git history // or in C-02-better-algorithm-one-thread/ @@ -104,7 +100,7 @@ float mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint3 float result; int result_set_flag = 0; - float p = random_uniform(0, 1, seed); + float p = sample_uniform(0, 1, seed); for (int k = 0; k < n_dists; k++) { if (p < cumsummed_normalized_weights[k]) { result = samplers[k](seed); @@ -289,13 +285,13 @@ struct box inverse_cdf_box(struct box cdf_box(float), float p) // Sampler based on inverse cdf and randomness function struct box sampler_cdf_box(struct box cdf(float), uint32_t* seed) { - float p = rand_0_to_1(seed); + float p = sample_unit_uniform(seed); struct box result = inverse_cdf_box(cdf, p); return result; } struct box sampler_cdf_float(float cdf(float), uint32_t* seed) { - float p = rand_0_to_1(seed); + float p = sample_unit_uniform(seed); struct box result = inverse_cdf_float(cdf, p); return result; } @@ -303,7 +299,7 @@ struct box sampler_cdf_float(float cdf(float), uint32_t* seed) /* Could also define other variations, e.g., float sampler_danger(struct box cdf(float), uint32_t* seed) { - float p = rand_0_to_1(seed); + float p = sample_unit_uniform(seed); struct box result = inverse_cdf_box(cdf, p); if(result.empty){ exit(1); diff --git a/squiggle.h b/squiggle.h index ba703c6..21c6231 100644 --- a/squiggle.h +++ b/squiggle.h @@ -8,22 +8,21 @@ uint32_t xorshift32(uint32_t* seed); // Basic distribution sampling functions -float rand_0_to_1(uint32_t* seed); -float rand_float(float max, uint32_t* seed); -float unit_normal(uint32_t* seed); +float sample_unit_uniform(uint32_t* seed); +float sample_unit_normal(uint32_t* seed); // Composite distribution sampling functions -float random_uniform(float from, float to, uint32_t* seed); -float random_normal(float mean, float sigma, uint32_t* seed); -float random_lognormal(float logmean, float logsigma, uint32_t* seed); -float random_to(float low, float high, uint32_t* seed); +float sample_uniform(float from, float to, uint32_t* seed); +float sample_normal(float mean, float sigma, uint32_t* seed); +float sample_lognormal(float logmean, float logsigma, uint32_t* seed); +float sample_to(float low, float high, uint32_t* seed); // Array helpers float array_sum(float* array, int length); void array_cumsum(float* array_to_sum, float* array_cumsummed, int length); // Mixture function -float mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed); +float sample_mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed); // Box struct box {