add initial go mixture implementation

This commit is contained in:
NunoSempere 2024-02-16 13:52:28 +01:00
parent 1f4eb1fec4
commit 6417e0aecc

View File

@ -54,7 +54,31 @@ func sample_mixture(fs []func64, weights []float64) float64 {
for _, weight := range weights {
sum_weights += weight
}
return sum_weights
var total float64 = 0
for i, weight := range weights {
total += weight / sum_weights
weights[i] = total
}
var result float64
var flag int = 0
var p float64 = r.Float64()
for i, weight := range weights {
if p < weight {
result = fs[i]()
flag = 1
break
}
}
if flag == 0 {
result = fs[len(fs)-1]()
}
return result
// return weights[0]
}
func main() {