From 8f69dd1e588db16d8f59a523dbe2ebc448683663 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 16 Jul 2023 21:00:30 +0200 Subject: [PATCH] move to squiggle.c file, instead of just squiggle.h --- examples/01_one_sample/example | Bin 17608 -> 17648 bytes examples/01_one_sample/makefile | 2 +- examples/02_many_samples/example | Bin 17648 -> 17688 bytes examples/02_many_samples/makefile | 2 +- examples/03_gcc_nested_function/example | Bin 17672 -> 17704 bytes examples/03_gcc_nested_function/makefile | 2 +- squiggle.c | 113 ++++++++++++++++++++++ squiggle.h | 118 +++-------------------- 8 files changed, 132 insertions(+), 105 deletions(-) create mode 100644 squiggle.c diff --git a/examples/01_one_sample/example b/examples/01_one_sample/example index 0be17e76fca55db27a76312134d65b3cae0dc51d..57b62677c294e5590afef0ceab52330bc4d3ffff 100755 GIT binary patch delta 2667 zcma)8e{2+09)C04mfdYTGfTTaN=v)e)odZOT_~l!qp(xA+@J*;ZLuiUYK5ZbCDnr* zxo~Xn3S1UkuKGNMOHR>fL=zKm#UBykwpK(_$bzCI#aR1?*$Q_pEYi|e=00!cE!Su+ zxob>lZ4YDf`xbG@BT7G&?p|SSRM+HFEUn;TLcJ_EOn} zPmX+Ze(AZFg|gW844WjpPIo(&He6JRn zhD#+SI~skKWEq4o#}a_WC;R)7t|_|BGrxEld<7CfLq5wUc`VK%a2x*D=elh)=2>Ik ze%*{@(27V3UG-22`K;_(&sljO^g2DAS4h_tNOLA95zLb7^tT05;rrBet0Sk?mer9T z)n+yFWeX3>v+Jz9Zx8Amt=D@dMR~VPB&6>L5djQok#VhW#3K8@(1a_S%F{WL6{7XT z71@6>CAWSq`xEksL`!<<#4e5t8UnC0T5V$MsZcmF+%r6*UK_~R63{vlDOGN5{yT{_ z32N<^^1it^U+XyA6BoHatsU55)Ak#?U1Uwi46?Gpmvd)y`Ej$69L+v!a?1o#smjV4 zb68l_y;+g|zLDHOKdmm3gVAQ+jgN2?!tWP*nPuoWOxyYqC+^~C zJPygHf>!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zt=FoJw%fURLV2E$ZfF4S6UA;gLs23C_c>C>D4lw*yme(f+c+vX`KK3QDdqGfQv8PEW&f0Jf92>2O&|_j#y;VCW2U!(boq|WI(xtF2 zX-!hFNm805*OolSiiW+#|1`}6bfmORe9t3GEl2+FQLZjB&PoDn| z>!0W|u+G6MfY(FpE(a&nJCnyd*pSSP4=txqIrdZQ*FL>Vfy z(Ut21&+OqlBYt~Jwu8@cyocjMJmQNS-&SY?*^Vj<7ri9IGvMx|$2#jIJ-0p(dYA82 zc+Bh#I%oMLt?xMd7TE=DxVElZwcyMUX`}o#ya%6h>t*0x)U9eZ z;NbWu_wNeWz%`CfSZvH>&*EHJuLd5s=*qf4XpzMP&q{=E;=)b0*9F$E!fy`axeKjg zBl|KdIj-;;vs~2yFQex~m7c3R9p76oIpSRnlR4sBd31-q+LOIJcsj@QVX>ec{~*{{ cfw`LQjXv%ktg`^pN{>f3h%+1MX!Oy40m1w4X8-^I diff --git a/examples/01_one_sample/makefile b/examples/01_one_sample/makefile index 302a149..963cdac 100644 --- a/examples/01_one_sample/makefile +++ b/examples/01_one_sample/makefile @@ -9,7 +9,7 @@ CC=gcc # CC=tcc # <= faster compilation # Main file -SRC=example.c +SRC=example.c ../../squiggle.c OUTPUT=example ## Dependencies diff --git a/examples/02_many_samples/example b/examples/02_many_samples/example index 02502b3b753cd118cfbab22037ece7328f563d5d..1f69607e2e82ad8b06a00c514c7528ce7892eb14 100755 GIT binary patch delta 3434 zcma)8eNa@_6~FJXgxv-9y_JvMm9IzK7%&Q~ph6qsKDydRx*Ck2q*aSws2!SO0%<$V z6q*&2Cs~WRla95`jA{RA)6_A8)7mCZ7evL3W;WI)&fo`{rhV3QKrxDnzW(m}VEm(< z>7BXn-1|Ep_ndRjxx3>kw|5uU=l71zAjSxrgf#Cdz2xr9Fn669{WG{$&f6lH`)Nv5 z{!;e4L)9CeS-vB*@U!n;?um_DoKtIAnv~G7-(@G`w zMe`=5*YQ{hIEoqxDxpL)-Vqd|@wT9(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g#A$#W$+^wIHq}$BIvOG?cjY9c`t9I_}p= z T)LyIz){>LK#cV1W2|n{rl^*kv diff --git a/examples/02_many_samples/makefile b/examples/02_many_samples/makefile index 302a149..963cdac 100644 --- a/examples/02_many_samples/makefile +++ b/examples/02_many_samples/makefile @@ -9,7 +9,7 @@ CC=gcc # CC=tcc # <= faster compilation # Main file -SRC=example.c +SRC=example.c ../../squiggle.c OUTPUT=example ## Dependencies diff --git a/examples/03_gcc_nested_function/example b/examples/03_gcc_nested_function/example index 1935e2d997cdd332b21720c63f88ffccce2cfb60..b912c362a06373a1e7beb0d48508ce232378b46c 100755 GIT binary patch delta 2865 zcmYjT4Nz3q6~6DWl-=cL7Z!NC{P`AE6r;$pfDi}WrDz^?O|gO@Z9qsA(U24ysY#ou zo1zm}+!S)BGseke=+9&tC)1d&<2ap6vxr(U(GE>BjninsPVBtY%!q)9ioSmLz56nr z+55hGzH{z*=broX_V5wm4@ZO{cjiHn?A^EeuG7C4?oFAy`a$K``|($kUQNnNxD5ZEdIPNnkccau zmGX-HKxkX2HPq6&RT=oEZHF>wS-Kn!O0?0Z_!HsSKA$rj>-EX%aZS^dSdL31b4n~Z1$wvQc=0TIjDz?NBOJY>OrLO+HTq=M8wGWiX%&v;$t4Fe z2w{p-tz&P%d#y_Jyb>J?$Ih_#IF>|M!r|z(KU;L14@YmR?J3A{;Jjtlk-1?pT=$@V zQi)Z+pN`xFIQbLm;zI-*?Dbj0v8BHQue^4C2&Qhwl7lQ9IyV#H=zl*JHbGGa#w=&p zz*)x+zq_c8vaxkn`>!am`X6Jg8q|ZKB0H3TQJ?-yW#C+!Kk=jX&@-X-P)BI{nELob zy3bYI+HFI?So%%W8RK8ZP%Y=Pm4wUNICf%<1zSBYNVm!=HXcSBLj9%!1n1Mj?$+`f`F zXV*4Xq!EIMm|M}kS%)*-2OXF!1HXP9i^tz)+S9mwAr6(lEr83 zbjrQmcF!1+VW$tWJ(6XAJ<_rGW)bBJ)DCNqQ0MQ_W9}72$Ki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jT%Kxtzd@{=&agmlOe3r&%5aa)l;a>_~z&1yX z%gPO}Bd;P!p?7K=-bL_9XL;eL3y+UhnrL3F+q525BsD`Mb#!^HTiDK6fwFJMZ(*|| zul4{R!r@J>xGz&D_;DmhI6uPqA?`oO`F^)f7{_xd<3$JAWt@BN|AFRDXko3xJIcpK zxu$U)?r3o))8IU};9+0ye5{#8O9EVmLx}E&wFy>-=p~jZ))x9#SU19|&c9KOrQ3u3PU$b_cmUYHT00bq`IcMqK<5O`q^mP z`n8p1HPw|>Mz3}KR@SdI`p-VS;dw^*sZ_To{&wAXQv7%IpCyUrRN5UZvl(Xy55-V$ z2_6b-W4YD1E>Rk6obRZ}(<3nOVm#KU3aL^2OJQXuY8BlbDzWzaHG*uT?}p|JbEvSm F@V`{XUx@$! diff --git a/examples/03_gcc_nested_function/makefile b/examples/03_gcc_nested_function/makefile index f02429c..5fe6a84 100644 --- a/examples/03_gcc_nested_function/makefile +++ b/examples/03_gcc_nested_function/makefile @@ -9,7 +9,7 @@ CC=gcc # required for nested functions # CC=tcc # <= faster compilation # Main file -SRC=example.c +SRC=example.c ../../squiggle.c OUTPUT=example ## Dependencies diff --git a/squiggle.c b/squiggle.c new file mode 100644 index 0000000..0ca98e2 --- /dev/null +++ b/squiggle.c @@ -0,0 +1,113 @@ +#include +#include +#include + +// PI constant +const float PI = M_PI;// 3.14159265358979323846; + +// Pseudo Random number generator + +uint32_t xorshift32 +(uint32_t* seed) +{ + // Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" + // See + // https://en.wikipedia.org/wiki/Xorshift + // Also some drama: , + + uint32_t x = *seed; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + return *seed = x; +} + +// Distribution & sampling functions + +float rand_0_to_1(uint32_t* seed){ + return ((float) xorshift32(seed)) / ((float) UINT32_MAX); +} + +float rand_float(float max, uint32_t* seed) +{ + return rand_0_to_1(seed) * max; +} + +float ur_normal(uint32_t* seed) +{ + float u1 = rand_0_to_1(seed); + float u2 = rand_0_to_1(seed); + float z = sqrtf(-2.0 * log(u1)) * sin(2 * PI * u2); + return z; +} + +float random_uniform(float from, float to, uint32_t* seed) +{ + return rand_0_to_1(seed) * (to - from) + from; +} + +float random_normal(float mean, float sigma, uint32_t* seed) +{ + return (mean + sigma * ur_normal(seed)); +} + +float random_lognormal(float logmean, float logsigma, uint32_t* seed) +{ + return expf(random_normal(logmean, logsigma, seed)); +} + +float random_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); +} + +// Array helpers +float array_sum(float* array, int length) +{ + float output = 0.0; + for (int i = 0; i < length; i++) { + output += array[i]; + } + return output; +} + +void array_cumsum(float* array_to_sum, float* array_cumsummed, int length) +{ + array_cumsummed[0] = array_to_sum[0]; + for (int i = 1; i < length; i++) { + array_cumsummed[i] = array_cumsummed[i - 1] + array_to_sum[i]; + } +} + +// Mixture function +float 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/ + float sum_weights = array_sum(weights, n_dists); + float* cumsummed_normalized_weights = (float*) malloc(n_dists * sizeof(float)); + cumsummed_normalized_weights[0] = weights[0]/sum_weights; + for (int i = 1; i < n_dists; i++) { + cumsummed_normalized_weights[i] = cumsummed_normalized_weights[i - 1] + weights[i]/sum_weights; + } + + float result; + int result_set_flag = 0; + float p = random_uniform(0, 1, seed); + for (int k = 0; k < n_dists; k++) { + if (p < cumsummed_normalized_weights[k]) { + result = samplers[k](seed); + result_set_flag = 1; + break; + } + } + if(result_set_flag == 0) result = samplers[n_dists-1](seed); + + free(cumsummed_normalized_weights); + return result; +} diff --git a/squiggle.h b/squiggle.h index d887b21..96e70c1 100644 --- a/squiggle.h +++ b/squiggle.h @@ -1,112 +1,26 @@ -#include -#include -#include +#ifndef SQUIGGLEC +#define SQUIGGLEC -const float PI = 3.14159265358979323846; +// uint32_t header +#include // Pseudo Random number generator - -uint32_t xorshift32 -(uint32_t* seed) -{ - // Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" - // See - // https://en.wikipedia.org/wiki/Xorshift - // Also some drama: , - - uint32_t x = *seed; - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - return *seed = x; -} +uint32_t xorshift32(uint32_t* seed); // Distribution & sampling functions - -float rand_0_to_1(uint32_t* seed){ - return ((float) xorshift32(seed)) / ((float) UINT32_MAX); -} - -float rand_float(float max, uint32_t* seed) -{ - return rand_0_to_1(seed) * max; -} - -float ur_normal(uint32_t* seed) -{ - float u1 = rand_0_to_1(seed); - float u2 = rand_0_to_1(seed); - float z = sqrtf(-2.0 * log(u1)) * sin(2 * PI * u2); - return z; -} - -float random_uniform(float from, float to, uint32_t* seed) -{ - return rand_0_to_1(seed) * (to - from) + from; -} - -float random_normal(float mean, float sigma, uint32_t* seed) -{ - return (mean + sigma * ur_normal(seed)); -} - -float random_lognormal(float logmean, float logsigma, uint32_t* seed) -{ - return expf(random_normal(logmean, logsigma, seed)); -} - -float random_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); -} +float rand_0_to_1(uint32_t* seed); +float rand_float(float max, uint32_t* seed); +float ur_normal(uint32_t* seed); +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); // Array helpers -float array_sum(float* array, int length) -{ - float output = 0.0; - for (int i = 0; i < length; i++) { - output += array[i]; - } - return output; -} - -void array_cumsum(float* array_to_sum, float* array_cumsummed, int length) -{ - array_cumsummed[0] = array_to_sum[0]; - for (int i = 1; i < length; i++) { - array_cumsummed[i] = array_cumsummed[i - 1] + array_to_sum[i]; - } -} +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) -{ - // You can see a simpler version of this function in the git history - // or in C-02-better-algorithm-one-thread/ - float sum_weights = array_sum(weights, n_dists); - float* cumsummed_normalized_weights = (float*) malloc(n_dists * sizeof(float)); - cumsummed_normalized_weights[0] = weights[0]/sum_weights; - for (int i = 1; i < n_dists; i++) { - cumsummed_normalized_weights[i] = cumsummed_normalized_weights[i - 1] + weights[i]/sum_weights; - } +float mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed); - float result; - int result_set_flag = 0; - float p = random_uniform(0, 1, seed); - for (int k = 0; k < n_dists; k++) { - if (p < cumsummed_normalized_weights[k]) { - result = samplers[k](seed); - result_set_flag = 1; - break; - } - } - if(result_set_flag == 0) result = samplers[n_dists-1](seed); - - free(cumsummed_normalized_weights); - return result; -} +#endif