add efficient beta distribution

This commit is contained in:
NunoSempere 2023-07-22 22:24:22 +02:00
parent 3f70915903
commit 4dad518d3f

View File

@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#define MAX_ERROR_LENGTH 500
@ -109,6 +110,12 @@ float sample_gamma(float alpha, uint32_t* seed){
}
}
float sample_beta(float a, float b, uint32_t* seed){
float gamma_a = sample_gamma(a, seed);
float gamma_b = sample_gamma(b, seed);
return a / (a + b);
}
// Array helpers
float array_sum(float* array, int length)
{