time-to-botec/bc/comments_stripped/estimate.bc

28 lines
467 B
Plaintext
Raw Normal View History

p_a = 0.8
p_b = 0.5
p_c = p_a * p_b
weights[0] = 1 - p_c
weights[1] = p_c / 2
weights[2] = p_c / 4
weights[3] = p_c / 4
define mixture(){
p = sample_unit_uniform()
if(p <= weights[0]){
return 0
}
if(p <= (weights[0] + weights[1])){
return 1
}
if(p<= (weights[0] + weights[1] + weights[2])){
return sample_to(1, 3)
}
return sample_to(2, 10)
}
n_samples = 1000000
sum=0
for(i=0; i < n_samples; i++){
sum += mixture()
}
sum/n_samples
halt