add bc version without comments or extraneous newlines.
This commit is contained in:
parent
90b8804884
commit
5473a6aeda
27
bc/comments_stripped/estimate.bc
Normal file
27
bc/comments_stripped/estimate.bc
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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
|
32
bc/comments_stripped/squiggle.bc
Normal file
32
bc/comments_stripped/squiggle.bc
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
scale = 16
|
||||||
|
pi = 4 * atan(1)
|
||||||
|
normal90confidence=1.64485362695
|
||||||
|
define sample_unit_uniform(){
|
||||||
|
return rand()/maxrand()
|
||||||
|
}
|
||||||
|
define sample_unit_normal(){
|
||||||
|
u1=sample_unit_uniform()
|
||||||
|
u2=sample_unit_uniform()
|
||||||
|
z = sqrt(-2 * l(u1)) * sin(2 * pi * u2)
|
||||||
|
return z
|
||||||
|
}
|
||||||
|
define sample_uniform(min, max){
|
||||||
|
return (min + sample_unit_uniform()*(max-min))
|
||||||
|
}
|
||||||
|
define sample_normal(mean, sigma){
|
||||||
|
return (mean + sigma * sample_unit_normal())
|
||||||
|
}
|
||||||
|
define sample_lognormal(logmean, logstd){
|
||||||
|
return e(sample_normal(logmean, logstd))
|
||||||
|
}
|
||||||
|
define sample_normal_from_90_confidence_interval(low, high){
|
||||||
|
mean = (high + low) / 2
|
||||||
|
std = (high - low) / (2 * normal90confidence)
|
||||||
|
return sample_normal(mean, std)
|
||||||
|
}
|
||||||
|
define sample_to(low, high){
|
||||||
|
loglow = l(low)
|
||||||
|
loghigh = l(high)
|
||||||
|
return e(sample_normal_from_90_confidence_interval(loglow, loghigh))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user