From 7a2015e3e0b21813debbd6752ce2a77bd370b4ec Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 16 Jul 2023 21:32:17 +0200 Subject: [PATCH] divide simple and complex examples into two different examples. --- examples/04_sample_from_cdf/example | Bin 22456 -> 0 bytes examples/04_sample_from_cdf_simple/example | Bin 0 -> 22192 bytes examples/04_sample_from_cdf_simple/example.c | 102 ++++++++++++++++++ .../makefile | 0 examples/05_sample_from_cdf_beta/example | Bin 0 -> 22176 bytes .../example.c | 91 +--------------- examples/05_sample_from_cdf_beta/makefile | 57 ++++++++++ 7 files changed, 163 insertions(+), 87 deletions(-) delete mode 100755 examples/04_sample_from_cdf/example create mode 100755 examples/04_sample_from_cdf_simple/example create mode 100644 examples/04_sample_from_cdf_simple/example.c rename examples/{04_sample_from_cdf => 04_sample_from_cdf_simple}/makefile (100%) create mode 100755 examples/05_sample_from_cdf_beta/example rename examples/{04_sample_from_cdf => 05_sample_from_cdf_beta}/example.c (68%) create mode 100644 examples/05_sample_from_cdf_beta/makefile diff --git a/examples/04_sample_from_cdf/example b/examples/04_sample_from_cdf/example deleted file mode 100755 index 03e23d9d29fee8c498194405321ac2c71bbcb16b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22456 zcmeHP3wYDzx&PX| z=oD1-aeW1%o+ZI;!v$VJBOm#uV5X=qn4buHrC-7lDn2R_pHuQVC7*&!(MzcONj{-Z zk@ROWw4#oZmH%ffnXg>(CBqU)uOR85wCF8=_1~j!q2%i>6mpVbHaQ$gL8b3T@R46W zYf{~Olhl{0A9|!86_n~(ew}Z{^r`uE)syOc4T084twqx(O`qy$X>?5HCXijEgJNpl z4U4H;LWGlUc$CzTA+Ni>v*Uv)8+DL)1u zq7m)C8##d^xZnF?J;7AzDO7xJh|0gFz<)IbeiZOle3H`xKnx|nAqD>DDe&7;;FqSr zdsE;Kroev@cq=~1sSJpr?DwR=Kb8Vdy)u-XmK69cDe%*Qx8jqW76LJp{N2D`kxWcw z#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r6BQF7ip3r>3s4((l28IR569M1FcL^Ltz1pN49W9}o6CO2mrBR_5_mSK>ik zGgWet;*~81ZWu_ljrHmYAhj;xEiZ$_Q` z3^i9NUy7I3(0gDEwXh}m(IWy34G^!50dK+!Z|e9fZ4CTVKvCV&=&416@P3@+$C{qf z1rSv2Yw!eGywyy^UR9vJB~UNkiDM82Qw+UM0VrQ{lSnhP=Y^-GTm6l!6$7KzSL2^D zS#*_8Je#HN_3&QutY~SGZIlD>TtXp~zd6Tacss0dTWXo3dQAgV2ne#s=9=pK%)vv#fvjU?BZ`!1@m4X1 z-`k2JO>UrW4u$6y)C_h;!54S0n|0mc*~_dlXc3N`xva_;?b(x))NA8>g57 z6`z819x&Rk_RR{8QI3`}6rU3LOcKAkXHrnzb1VAf@v~dQ;ZZgi0lJ&oU zIwDd0>fTC0`YwzyCF?(eN+Z9z-%>D?#Gv9w$$SeLdQFHN_VIf#^`6OOdR12NJ@9G< zes#ZJBoDrd4kSFOvVv!UrPx*a)xDZ}Z>Vw%%^#E$pYr1`fTQ-u`4fEm?6u%Lw z*ikeDola3w?~kQ(Jn2yOs9`YzIAy!w5dZb-1pH=F{3yMOHW!(p_z&M8C@x82NGh`b E1~()T5&!@I diff --git a/examples/04_sample_from_cdf_simple/example b/examples/04_sample_from_cdf_simple/example new file mode 100755 index 0000000000000000000000000000000000000000..37f99c995c2b72506a88f0c7a7631c0a13973801 GIT binary patch literal 22192 zcmeHPeRNaDl^4Z^gwTALe3gdH#z1H!Oj2qRN=b%p(s$aM9Nt}Nw0!3Iq1~_W{N5ciIQHv)IC9zD9UVtC%t0I zO5RKt$o?v-$}{a%i+Y%e+QE($X&yWnR`(-9W?nx=@CqNjZ&{s>M6>ko}$X1 z`-{J=>Yz4Bh7#$k zAts*k6q+O>`hPES0wa1j@LUJceCbCh_*jm@qj_*&9()pTJ3i+0RRFo_Z_a~%ClB72 z2XD-Se=!gKbRPVZ!0q^$Qxkw(_Wwg3d_x|*Ef3z42fqop9UpW0C4l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ieay~V!Y`tL zVpp}V&Xd&pGL>U!{!vnTY8-zAjQp3;UqVv2y__c~#g{QDeMQGX*{GknFLeto)sCt| z=_#Jx2S=D{U)_J$+(N=EPi+|!or4f2!zELs^woW{Dp2}Hs$xgU5Ouo+w^km&)9oJJ qV=8;p`a{LacA+8u@1_e2Qne}IRJ)>-?)7r(4=xfCSDF+|Ec-8~ZoV%7 literal 0 HcmV?d00001 diff --git a/examples/04_sample_from_cdf_simple/example.c b/examples/04_sample_from_cdf_simple/example.c new file mode 100644 index 0000000..ab6ac61 --- /dev/null +++ b/examples/04_sample_from_cdf_simple/example.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include +#include "../../squiggle.h" + +#define NUM_SAMPLES 1000000 + +// Example cdf +float cdf_uniform_0_1(float x) +{ + if (x < 0) { + return 0; + } else if (x > 1) { + return 1; + } else { + return x; + } +} + +float cdf_squared_0_1(float x) +{ + if (x < 0) { + return 0; + } else if (x > 1) { + return 1; + } else { + return x * x; + } +} + +float cdf_normal_0_1(float x) +{ + float mean = 0; + float std = 1; + return 0.5 * (1 + erf((x - mean) / (std * sqrt(2)))); // erf from math.h +} + +// Some testers +void test_inverse_cdf_float(char* cdf_name, float cdf_float(float)) +{ + struct box result = inverse_cdf_float(cdf_float, 0.5); + if (result.empty) { + printf("Inverse for %s not calculated\n", cdf_name); + exit(1); + } else { + printf("Inverse of %s at %f is: %f\n", cdf_name, 0.5, result.content); + } +} + +void test_and_time_sampler_float(char* cdf_name, float cdf_float(float), uint32_t* seed) +{ + printf("\nGetting some samples from %s:\n", cdf_name); + clock_t begin = clock(); + for (int i = 0; i < NUM_SAMPLES; i++) { + struct box sample = sampler_float_cdf(cdf_float, seed); + if (sample.empty) { + printf("Error in sampler function for %s", cdf_name); + } else { + // printf("%f\n", sample.content); + } + } + clock_t end = clock(); + float time_spent = (float)(end - begin) / CLOCKS_PER_SEC; + printf("Time spent: %f\n", time_spent); +} + +int main() +{ + // Test inverse cdf float + test_inverse_cdf_float("cdf_uniform_0_1", cdf_uniform_0_1); + test_inverse_cdf_float("cdf_squared_0_1", cdf_squared_0_1); + test_inverse_cdf_float("cdf_normal_0_1", cdf_normal_0_1); + + // Testing samplers + // set randomness seed + uint32_t* seed = malloc(sizeof(uint32_t)); + *seed = 1000; // xorshift can't start with 0 + + // Test float sampler + test_and_time_sampler_float("cdf_uniform_0_1", cdf_uniform_0_1, seed); + test_and_time_sampler_float("cdf_squared_0_1", cdf_squared_0_1, seed); + test_and_time_sampler_float("cdf_normal_0_1", cdf_normal_0_1, seed); + + // Get some normal samples using a previous approach + printf("\nGetting some samples from unit_normal\n"); + + clock_t begin_2 = clock(); + + for (int i = 0; i < NUM_SAMPLES; i++) { + float normal_sample = unit_normal(seed); + // printf("%f\n", normal_sample); + } + + clock_t end_2 = clock(); + float time_spent_2 = (float)(end_2 - begin_2) / CLOCKS_PER_SEC; + printf("Time spent: %f\n", time_spent_2); + + free(seed); + return 0; +} diff --git a/examples/04_sample_from_cdf/makefile b/examples/04_sample_from_cdf_simple/makefile similarity index 100% rename from examples/04_sample_from_cdf/makefile rename to examples/04_sample_from_cdf_simple/makefile diff --git a/examples/05_sample_from_cdf_beta/example b/examples/05_sample_from_cdf_beta/example new file mode 100755 index 0000000000000000000000000000000000000000..1ad5fec3996dfb9477adc1f8ea7c9f36f073abee GIT binary patch literal 22176 zcmeHPdw5&LmA|&+#3Z(^T;gJ$QK`}jN@Ob!ngr5V#&)i$0w!_52_}kS%dw~}8(T^o z7Sd41NkksFyIr7#{Ytm}+U#!IO~1ZE7m93$;Di>O@Tg08m?RVlC*UdpOdz@YJM)mQ z6r1+zcK46{JfE#I^P6+doH=vu%-p%s{d$?FJToIhk;$ZdMWIsVXE;(UDh6*78IWRS zo|22t>B<$#B$UkzC}cgN;dYXDCu(5LN1+_3Vunc4NA-23f28B?Nti71{c?pPLFd~ zkyN&K3*>~W1;?ioIm}B%d*h8mRQOX;8gEL4je#}S&M9oHo7or$hTCVh&%1W!wR4

3M7% z{DE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?xu%@|P z@%rn0co^17l}rJDL5e{dty67tlQ$d;;F(qvnV#}al~Lw73V1@^Ah>*uTxpRv)a-T9 z8(T)%X3bZUkKyQ5E{2*fOGoiH!_Zq-47KD5FB!~V%7Q}5TVxv9dtwayvx&W}+1r2) z&`W13ZiZl8Am|OZ`Rf!OIJM!Xwr~@Fv5Y~KHI*DPiXQROm{cC&nozUSj>v5Y)Q4uz z;_eRchmtfPUgl}l-bpmpiRLl(d)+&s>!PnNH zIO{e9(FCWVR$fDoh4CmhrQk(ftH04l0wUMa7*d>Uh@Hqf*EXX_nKpl|;tcuQQKXp$ z+|BH2arzs?+|p17ZL-95@JWVC$UK_zH3guIiz5&eCnmTiOj=`1y?+x#%N4dt*n9FM z?`I{I=P#m~@ya|=S{CT2L(0qhUP*1JGbVY?Au-zb8Re_7eo&Is&Wp)UxqeE39)=s` z<$biIHpwVxy8Lax@p!jc+Aq(QB$e%pG%tvVD2~E~z}X0t-t*oh&MMAxCFIQeNKYOX?7u(tgP&=|=~VB{02ADcg(1Qpvc z0diZD1!Nw@zfs;MXclO;A= z;j{xzX}?taRGPdzPmxrf-%9@U>*r}9FUMcrXGq#W#u-w2`@csWu}FD&J|pRIgDhp! z+dl%#C@;@(B+X6}kntnczJ&~a-oUOw!sLCte4k=Ezbs4oXUM1qd3kQFi5o)6N4hD= zvZQB$QS6FoFL}No-;XIBL)RZADJT8-AHb;pN%@HO4|G3AN&i;N)hQvOS6xRf_i89PSS;$mJ}Ee_o2 twvyVA_Q?5%s-^8*f`2|n3k%ZpwD^(j@>;sL8(aP // erf, sqrt +#include #include #include #include @@ -9,36 +9,7 @@ #define STOP_BETA 1.0e-8 #define TINY_BETA 1.0e-30 -// Example cdf -float cdf_uniform_0_1(float x) -{ - if (x < 0) { - return 0; - } else if (x > 1) { - return 1; - } else { - return x; - } -} - -float cdf_squared_0_1(float x) -{ - if (x < 0) { - return 0; - } else if (x > 1) { - return 1; - } else { - return x * x; - } -} - -float cdf_normal_0_1(float x) -{ - float mean = 0; - float std = 1; - return 0.5 * (1 + erf((x - mean) / (std * sqrt(2)))); // erf from math.h -} - +// Incomplete beta function struct box incbeta(float a, float b, float x) { // Descended from , @@ -149,16 +120,6 @@ struct box cdf_beta(float x) } // Some testers -void test_inverse_cdf_float(char* cdf_name, float cdf_float(float)) -{ - struct box result = inverse_cdf_float(cdf_float, 0.5); - if (result.empty) { - printf("Inverse for %s not calculated\n", cdf_name); - exit(1); - } else { - printf("Inverse of %s at %f is: %f\n", cdf_name, 0.5, result.content); - } -} void test_inverse_cdf_box(char* cdf_name, struct box cdf_box(float)) { struct box result = inverse_cdf_box(cdf_box, 0.5); @@ -170,23 +131,6 @@ void test_inverse_cdf_box(char* cdf_name, struct box cdf_box(float)) } } -void test_and_time_sampler_float(char* cdf_name, float cdf_float(float), uint32_t* seed) -{ - printf("\nGetting some samples from %s:\n", cdf_name); - clock_t begin = clock(); - for (int i = 0; i < NUM_SAMPLES; i++) { - struct box sample = sampler_float_cdf(cdf_float, seed); - if (sample.empty) { - printf("Error in sampler function for %s", cdf_name); - } else { - // printf("%f\n", sample.content); - } - } - clock_t end = clock(); - float time_spent = (float)(end - begin) / CLOCKS_PER_SEC; - printf("Time spent: %f\n", time_spent); -} - void test_and_time_sampler_box(char* cdf_name, struct box cdf_box(float), uint32_t* seed) { printf("\nGetting some samples from %s:\n", cdf_name); @@ -206,44 +150,17 @@ void test_and_time_sampler_box(char* cdf_name, struct box cdf_box(float), uint32 int main() { - // Test inverse cdf float - test_inverse_cdf_float("cdf_uniform_0_1", cdf_uniform_0_1); - test_inverse_cdf_float("cdf_squared_0_1", cdf_squared_0_1); - test_inverse_cdf_float("cdf_normal_0_1", cdf_normal_0_1); - // Test inverse cdf box test_inverse_cdf_box("cdf_beta", cdf_beta); - // Testing samplers - // set randomness seed + // Test box sampler uint32_t* seed = malloc(sizeof(uint32_t)); *seed = 1000; // xorshift can't start with 0 - - // Test float sampler - test_and_time_sampler_float("cdf_uniform_0_1", cdf_uniform_0_1, seed); - test_and_time_sampler_float("cdf_squared_0_1", cdf_squared_0_1, seed); - test_and_time_sampler_float("cdf_normal_0_1", cdf_normal_0_1, seed); - - // Get some normal samples using a previous approach - printf("\nGetting some samples from unit_normal\n"); - - clock_t begin_2 = clock(); - - for (int i = 0; i < NUM_SAMPLES; i++) { - float normal_sample = unit_normal(seed); - // printf("%f\n", normal_sample); - } - - clock_t end_2 = clock(); - float time_spent_2 = (float)(end_2 - begin_2) / CLOCKS_PER_SEC; - printf("Time spent: %f\n", time_spent_2); - - // Test box sampler test_and_time_sampler_box("cdf_beta", cdf_beta, seed); // Ok, this is slower than python!! // Partly this is because I am using a more general algorithm, // which applies to any cdf - // But I am also using really anal convergence conditions. + // But I am also using absurdly precise convergence conditions. // This could be optimized. free(seed); diff --git a/examples/05_sample_from_cdf_beta/makefile b/examples/05_sample_from_cdf_beta/makefile new file mode 100644 index 0000000..69adb6d --- /dev/null +++ b/examples/05_sample_from_cdf_beta/makefile @@ -0,0 +1,57 @@ +# Interface: +# make +# make build +# make format +# make run + +# Compiler +CC=gcc # required for nested functions +# CC=tcc # <= faster compilation + +# Main file +SRC=example.c ../../squiggle.c +OUTPUT=./example + +## Dependencies +MATH=-lm +DEPENDENCIES=$(MATH) +# OPENMP=-fopenmp + +## Flags +DEBUG= #'-g' +STANDARD=-std=gnu99 ## allows for nested functions. +EXTENSIONS= #-fnested-functions +WARNINGS=-Wall +OPTIMIZED=-O3#-Ofast +CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED) + +## Formatter +STYLE_BLUEPRINT=webkit +FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT) + +## make build +build: $(SRC) + # gcc -std=gnu99 example.c -lm -o example + $(CC) $(CFLAGS) $(SRC) $(DEPENDENCIES) -o $(OUTPUT) + +format: $(SRC) + $(FORMATTER) $(SRC) + +run: $(SRC) $(OUTPUT) + ./$(OUTPUT) && echo + +time-linux: + @echo "Requires /bin/time, found on GNU/Linux systems" && echo + + @echo "Running 100x and taking avg time $(OUTPUT)" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo + +## Profiling + +profile-linux: + echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar" + echo "Must be run as sudo" + $(CC) $(SRC) $(MATH) -o $(OUTPUT) + sudo perf record $(OUTPUT) + sudo perf report + rm perf.data