solve bug which makes this computationally tractable

This commit is contained in:
NunoSempere 2024-02-25 18:15:29 -03:00
parent 763add6b0e
commit 1b552ffc9a

View File

@ -1,9 +1,11 @@
package main
import "fmt"
import "git.nunosempere.com/NunoSempere/probppl/choose"
import "math"
import rand "math/rand/v2"
import (
"fmt"
"git.nunosempere.com/NunoSempere/probppl/choose"
"math"
rand "math/rand/v2"
)
type src = *rand.Rand
type pplKnownDistrib = map[int64]float64
@ -13,17 +15,18 @@ func generatePeopleKnownDistribution(r src) map[int64]float64 {
sum := 0.0
// Consider zero case separately
p0 := r.Float64()
/*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 < 20; i++ {
l = l * m
num := 16.0
base := 2.0
for i := 1; i < 8; i++ {
num = num * base
p := r.Float64()
mapping[int64(l)] = p
mapping[int64(num)] = p
sum += p
}
@ -77,7 +80,7 @@ func drawFromDistributionWithReplacement(d pplKnownDistrib, r src) int64 {
sum := 0.0
for i, p := range d {
sum += p
if p <= sum {
if pp <= sum {
return int64(i)
}
@ -92,7 +95,7 @@ func aboutEq(a int64, b int64) bool {
return ((-h) <= (a - b)) && ((a - b) <= h)
}
func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src) int64 {
func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src, show bool) int64 {
count := make(map[int64]int64)
count[0] = 0
@ -105,7 +108,9 @@ func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src) int64 {
count[person_i_num_birthday_matches]++
}
// if (count[0] == 69) && (count[1] == 46) && (count[2] == 19) && (count[3] == 14) {
fmt.Println(count)
if show {
// fmt.Println(count)
}
if aboutEq(count[0], 69) && aboutEq(count[1], 46) && aboutEq(count[2], 19) && aboutEq(count[3], 14) {
return 1
} else {
@ -115,12 +120,12 @@ func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src) int64 {
func getUnnormalizedBayesianUpdateForDistribution(d pplKnownDistrib, r src) int64 {
var sum int64 = 0
n := 1
n := 100
for i := 0; i < n; i++ {
/* if i%1000 == 0 {
fmt.Println(i)
} */
draw_result := draw148PplFromDistributionAndCheck(d, r)
draw_result := draw148PplFromDistributionAndCheck(d, r, i == 0)
// fmt.Println(draw_result)
sum += draw_result
}
@ -131,12 +136,20 @@ func main() {
var r = rand.New(rand.NewPCG(uint64(1), uint64(2)))
for i := 0; i < 100; i++ {
sum := int64(0)
for i := 0; i < 1000; i++ {
people_known_distribution := generatePeopleKnownDistribution(r)
// fmt.Println(people_known_distribution)
result := getUnnormalizedBayesianUpdateForDistribution(people_known_distribution, r)
fmt.Println(result)
fmt.Println(i)
if result > 0 {
fmt.Println(people_known_distribution)
fmt.Println(result)
}
sum += result
// fmt.Println(result)
}
fmt.Println(sum)
}