cdf tweak
This commit is contained in:
@@ -411,9 +411,9 @@ func choose(p []*value) int {
|
||||
// Generation:
|
||||
// 1. Generate a uniformly-random value x in the range [0,1)
|
||||
// 2. Using a binary search, find the index of the smallest element in cdf larger than x
|
||||
var val float64
|
||||
|
||||
// multiply the sample with the largest CDF value; easier than normalizing to [0,1)
|
||||
val = rand.Float64() * cdf[len(cdf)-1]
|
||||
val := rand.Float64() * cdf[len(cdf)-1]
|
||||
// Search returns the smallest index i such that cdf[i] > val
|
||||
return sort.Search(len(cdf), func(i int) bool { return cdf[i] > val })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user