go: remove prints
This commit is contained in:
parent
5029f67429
commit
14e298c3c9
|
@ -51,7 +51,7 @@ type func64 func() float64
|
||||||
|
|
||||||
func sample_mixture(fs []func64, weights []float64) float64 {
|
func sample_mixture(fs []func64, weights []float64) float64 {
|
||||||
|
|
||||||
fmt.Println("weights initially: ", weights)
|
// fmt.Println("weights initially: ", weights)
|
||||||
var sum_weights float64 = 0
|
var sum_weights float64 = 0
|
||||||
for _, weight := range weights {
|
for _, weight := range weights {
|
||||||
sum_weights += weight
|
sum_weights += weight
|
||||||
|
@ -75,17 +75,20 @@ func sample_mixture(fs []func64, weights []float64) float64 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(cumsummed_normalized_weights)
|
// fmt.Println(cumsummed_normalized_weights)
|
||||||
|
|
||||||
if flag == 0 {
|
if flag == 0 {
|
||||||
result = fs[len(fs)-1]()
|
result = fs[len(fs)-1]()
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
// return weights[0]
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var p_a float64 = 0.8
|
||||||
|
var p_b float64 = 0.5
|
||||||
|
var p_c float64 = p_a * p_b
|
||||||
|
ws := [4](float64){1 - p_c, p_c / 2, p_c / 4, p_c / 4}
|
||||||
|
|
||||||
sample_0 := func() float64 { return 0 }
|
sample_0 := func() float64 { return 0 }
|
||||||
sample_1 := func() float64 { return 1 }
|
sample_1 := func() float64 { return 1 }
|
||||||
|
@ -93,18 +96,10 @@ func main() {
|
||||||
sample_many := func() float64 { return sample_to(2, 10) }
|
sample_many := func() float64 { return sample_to(2, 10) }
|
||||||
fs := [4](func64){sample_0, sample_1, sample_few, sample_many}
|
fs := [4](func64){sample_0, sample_1, sample_few, sample_many}
|
||||||
|
|
||||||
var p_a float64 = 0.8
|
|
||||||
var p_b float64 = 0.5
|
|
||||||
var p_c float64 = p_a * p_b
|
|
||||||
ws := [4](float64){1 - p_c, p_c / 2, p_c / 4, p_c / 4}
|
|
||||||
fmt.Println("weights #1", ws)
|
|
||||||
|
|
||||||
var n_samples int = 1_000_000
|
var n_samples int = 1_000_000
|
||||||
var avg float64 = 0
|
var avg float64 = 0
|
||||||
for i := 0; i < n_samples; i++ {
|
for i := 0; i < n_samples; i++ {
|
||||||
x := sample_mixture(fs[0:], ws[0:])
|
avg += sample_mixture(fs[0:], ws[0:])
|
||||||
fmt.Printf("%v\n", x)
|
|
||||||
avg += x
|
|
||||||
}
|
}
|
||||||
avg = avg / float64(n_samples)
|
avg = avg / float64(n_samples)
|
||||||
fmt.Printf("Average: %v\n", avg)
|
fmt.Printf("Average: %v\n", avg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user