forked from personal/squiggle.c
fix dumb beta sampling bug
This commit is contained in:
parent
4dad518d3f
commit
5e39c386f7
14
squiggle.c
14
squiggle.c
|
@ -74,7 +74,8 @@ float sample_to(float low, float high, uint32_t* seed)
|
|||
return sample_lognormal(logmean, logsigma, seed);
|
||||
}
|
||||
|
||||
float sample_gamma(float alpha, uint32_t* seed){
|
||||
float sample_gamma(float alpha, uint32_t* seed)
|
||||
{
|
||||
|
||||
// A Simple Method for Generating Gamma Variables, Marsaglia and Wan Tsang, 2001
|
||||
// https://dl.acm.org/doi/pdf/10.1145/358407.358414
|
||||
|
@ -110,10 +111,11 @@ float sample_gamma(float alpha, uint32_t* seed){
|
|||
}
|
||||
}
|
||||
|
||||
float sample_beta(float a, float b, 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);
|
||||
return gamma_a / (gamma_a + gamma_b);
|
||||
}
|
||||
|
||||
// Array helpers
|
||||
|
@ -134,12 +136,14 @@ void array_cumsum(float* array_to_sum, float* array_cumsummed, int length)
|
|||
}
|
||||
}
|
||||
|
||||
float array_mean(float* array, int length){
|
||||
float array_mean(float* array, int length)
|
||||
{
|
||||
float sum = array_sum(array, length);
|
||||
return sum / length;
|
||||
}
|
||||
|
||||
float array_std(float* array, int length){
|
||||
float array_std(float* array, int length)
|
||||
{
|
||||
float mean = array_mean(array, length);
|
||||
float std = 0.0;
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user