From f5380ac47ab369339bd0b784c1833a9bb0c8e492 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 25 Feb 2024 16:32:12 -0300 Subject: [PATCH] tweak: move to log scale --- probppl.go | 44 +++++++++++++++++++++++++++++++++----------- todo.md | 5 +++++ 2 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 todo.md diff --git a/probppl.go b/probppl.go index 8eaca79..057b002 100644 --- a/probppl.go +++ b/probppl.go @@ -13,17 +13,39 @@ import rand "math/rand/v2" type src = *rand.Rand func generateRandomMapping(r src) map[int]float64 { - current_probability := 0.0 mapping := make(map[int]float64) - for i := 0; i <= 1000; i++ { - if current_probability < 1.0 { - num_possible_steps := int((1-current_probability)/0.001) + 1 - fmt.Println("num possible steps: %d", num_possible_steps) - step := float64(r.IntN(num_possible_steps)) * 0.001 - current_probability += step - } - mapping[i] = current_probability + 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++ { + if current_probability < 1.0 { + num_possible_steps := int((1-current_probability)/0.001) + 1 + fmt.Println("num possible steps: %d", num_possible_steps) + step := float64(r.IntN(num_possible_steps)) * 0.001 + current_probability += step + } + mapping[i] = current_probability + } + */ return mapping } @@ -32,8 +54,8 @@ func main() { var r = rand.New(rand.NewPCG(uint64(1), uint64(2))) randomMapping := generateRandomMapping(r) - for i := 0; i <= 1000; i++ { - fmt.Printf("%d: %.4f\n", i, randomMapping[i]) + for i, value := range randomMapping { + fmt.Printf("%d: %.4f\n", i, value) } } diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..8faa9ce --- /dev/null +++ b/todo.md @@ -0,0 +1,5 @@ +- [ ] MVP of mappings +- [ ] Try as cdfs: too much prob at the beginning +- [ ] Try as pdfs: too evenly distributed +- [ ] Try as pdfs over log space; 1, 2, 4, 8, 16, 32, ... + - Or maybe even more coarse, 1.x^n