quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
148 stars 22 forks source link

`Dist.sampleN` produces the same set of samples when called multiple times #3258

Open OAGr opened 1 month ago

OAGr commented 1 month ago

It seems that when sampleN(dist,n) is called multiple times with the same inputs, it gives the same exact output. This isn't expected.

sampleDist = 1% to 10%
symDist = Sym.normal(5, 2)
mySampleFn() = sample(sampleDist)
incrementally = [sample(sampleDist), sample(sampleDist)] // ✔ different results, as expected
try2 = [sampleN(sampleDist, 2), sampleN(sampleDist, 2)] // 𐄂 produces same results, but wouldn't expect to
try3 = [sampleN(symDist, 2), sampleN(symDist, 2)] // ✔ different results, as expected
asFn = List.make(2, sample(sampleDist)) // ✔ makes same results, as one would expect
asFn2 = List.make(2, {|| sample(sampleDist)}) // ✔ produdes different results
asFn3 = List.make(3, mySampleFn) // ✔ produces different results

list2 = List.make(2, {|| sampleN(sampleDist, 1) -> List.first}) // 𐄂 fails, same results
list3 = List.make(2, {|| sampleN(symDist, 1) -> List.first}) // ✔ produces different results
list4 = List.make(2, {|| sampleN(normal(5, 2), 1) -> List.first}) // ✔ succeeds

https://www.squiggle-language.com/playground?v=0.9.4#code=eNqNk8FOg0AURX%2FlhaQREmwt6MZEN5qujJsuxcXIPBLizEBmhihpuzF%2BgAuXfp1f4Cc4MFAKJej25b5zL%2FcNG4diQgqmbzKKzqWjCM8Z3qZKwxUsZ6AzWJ7NIqFK3gzXJZ%2BLTHLC3AsfAi8SvFzXWyvhekZgEW5HMpJUxBI5Ck0YK43m4Vjkjyw%2BwmIB31%2BfQNMkQWn2QaIyaZUPRAG%2B5hhrpJHQsgw67P0Bo4rYoofzGv%2Fz8f4GucxoEaOqhNh5PBUaXrKCUXGiGzfTSG0X9uxsOwOvbvjv7yBqJQz4zuzNOXlGNxirxWtxlWSY2fAygTZ2Q7bcYAjebLcj8N2eXpdCjcFRagsMe8DQh%2B4h9BnxOCMSzGxPxOrfa%2BnB6bWVJqlU2gatz5eQlCm%2FV4SFh5Pw9kDj5L%2FiV%2FzzKf7hXzJlooo4RqQG6ex%2BAQkqQUA%3D

OAGr commented 1 month ago

Looks like this is exactly what the code does. I say we change it to pick randomly (ideally, still using the prgn).

I think that if we went this way, we'd just have a function called firstN() that only works for sample Sets.