tweak: move to log scale
This commit is contained in:
parent
c4e37643de
commit
f5380ac47a
28
probppl.go
28
probppl.go
|
@ -13,8 +13,29 @@ import rand "math/rand/v2"
|
||||||
type src = *rand.Rand
|
type src = *rand.Rand
|
||||||
|
|
||||||
func generateRandomMapping(r src) map[int]float64 {
|
func generateRandomMapping(r src) map[int]float64 {
|
||||||
current_probability := 0.0
|
|
||||||
mapping := make(map[int]float64)
|
mapping := make(map[int]float64)
|
||||||
|
sum := 0.0
|
||||||
|
|
||||||
|
// Consider zero case separately
|
||||||
|
p0 := r.Float64()
|
||||||
|
mapping[0.0] = p0
|
||||||
|
sum += p0
|
||||||
|
|
||||||
|
// Consider successive exponents of 1.5
|
||||||
|
l := 1.0
|
||||||
|
m := 1.5
|
||||||
|
for i := 1; i < 22; i++ {
|
||||||
|
l = l * m
|
||||||
|
p := r.Float64()
|
||||||
|
mapping[int(l)] = p
|
||||||
|
sum += p
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range mapping {
|
||||||
|
mapping[key] = value / sum
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for i := 0; i <= 1000; i++ {
|
for i := 0; i <= 1000; i++ {
|
||||||
if current_probability < 1.0 {
|
if current_probability < 1.0 {
|
||||||
num_possible_steps := int((1-current_probability)/0.001) + 1
|
num_possible_steps := int((1-current_probability)/0.001) + 1
|
||||||
|
@ -24,6 +45,7 @@ func generateRandomMapping(r src) map[int]float64 {
|
||||||
}
|
}
|
||||||
mapping[i] = current_probability
|
mapping[i] = current_probability
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return mapping
|
return mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +54,8 @@ func main() {
|
||||||
|
|
||||||
var r = rand.New(rand.NewPCG(uint64(1), uint64(2)))
|
var r = rand.New(rand.NewPCG(uint64(1), uint64(2)))
|
||||||
randomMapping := generateRandomMapping(r)
|
randomMapping := generateRandomMapping(r)
|
||||||
for i := 0; i <= 1000; i++ {
|
for i, value := range randomMapping {
|
||||||
fmt.Printf("%d: %.4f\n", i, randomMapping[i])
|
fmt.Printf("%d: %.4f\n", i, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user