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