From 763add6b0e00eac89d9d65b6451f9e143c382b91 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 25 Feb 2024 17:47:45 -0300 Subject: [PATCH] fix mvp counting bug --- probppl.go | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/probppl.go b/probppl.go index c9208b7..96795de 100644 --- a/probppl.go +++ b/probppl.go @@ -20,7 +20,7 @@ func generatePeopleKnownDistribution(r src) map[int64]float64 { // Consider successive exponents of 1.5 l := 1.0 m := 1.5 - for i := 1; i < 22; i++ { + for i := 1; i < 20; i++ { l = l * m p := r.Float64() mapping[int64(l)] = p @@ -87,6 +87,11 @@ func drawFromDistributionWithReplacement(d pplKnownDistrib, r src) int64 { panic("Probabilities should sum up to 1") } +func aboutEq(a int64, b int64) bool { + h := int64(3) + return ((-h) <= (a - b)) && ((a - b) <= h) +} + func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src) int64 { count := make(map[int64]int64) @@ -99,35 +104,39 @@ func draw148PplFromDistributionAndCheck(d pplKnownDistrib, r src) int64 { person_i_num_birthday_matches := getMatchesDrawGivenNPeopleKnown(person_i_ppl_known, r) count[person_i_num_birthday_matches]++ } - if (count[0] == 69) && (count[1] == 46) && (count[2] == 19) && (count[3] == 14) { + // if (count[0] == 69) && (count[1] == 46) && (count[2] == 19) && (count[3] == 14) { + fmt.Println(count) + if aboutEq(count[0], 69) && aboutEq(count[1], 46) && aboutEq(count[2], 19) && aboutEq(count[3], 14) { return 1 } else { return 0 } } -func getUnnormalizedBayesianUpdateForDistribution(d pplKnownDistrib, r src) float64 { +func getUnnormalizedBayesianUpdateForDistribution(d pplKnownDistrib, r src) int64 { var sum int64 = 0 - n := 100_000 + n := 1 for i := 0; i < n; i++ { - if i%1000 == 0 { + /* if i%1000 == 0 { fmt.Println(i) - } - sum += draw148PplFromDistributionAndCheck(d, r) + } */ + draw_result := draw148PplFromDistributionAndCheck(d, r) + // fmt.Println(draw_result) + sum += draw_result } - return float64(sum) / float64(n) + return sum // float64(sum) / float64(n) } func main() { - fmt.Println("Hello world") var r = rand.New(rand.NewPCG(uint64(1), uint64(2))) - people_known_distribution := generatePeopleKnownDistribution(r) - fmt.Println(people_known_distribution) - /* for i, p := range people_known_distribution { - fmt.Print64f("%d: %.4f\n", i, p) - } */ - result := getUnnormalizedBayesianUpdateForDistribution(people_known_distribution, r) - fmt.Println(result) + + for i := 0; i < 100; i++ { + + people_known_distribution := generatePeopleKnownDistribution(r) + // fmt.Println(people_known_distribution) + result := getUnnormalizedBayesianUpdateForDistribution(people_known_distribution, r) + fmt.Println(result) + } }