fix mvp counting bug
This commit is contained in:
parent
c1c47966c2
commit
763add6b0e
35
probppl.go
35
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)
|
||||
} */
|
||||
draw_result := draw148PplFromDistributionAndCheck(d, r)
|
||||
// fmt.Println(draw_result)
|
||||
sum += draw_result
|
||||
}
|
||||
sum += draw148PplFromDistributionAndCheck(d, r)
|
||||
}
|
||||
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)))
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
|
||||
people_known_distribution := generatePeopleKnownDistribution(r)
|
||||
fmt.Println(people_known_distribution)
|
||||
/* for i, p := range people_known_distribution {
|
||||
fmt.Print64f("%d: %.4f\n", i, p)
|
||||
} */
|
||||
// fmt.Println(people_known_distribution)
|
||||
result := getUnnormalizedBayesianUpdateForDistribution(people_known_distribution, r)
|
||||
fmt.Println(result)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user