Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform sampling from singleton list generates unused labels #8

Open
gstew5 opened this issue Sep 17, 2019 · 1 comment
Open

Uniform sampling from singleton list generates unused labels #8

gstew5 opened this issue Sep 17, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@gstew5
Copy link
Collaborator

gstew5 commented Sep 17, 2019

leading to OOB errors in the SparseLinAlg backend on programs like:

main:
  p <~ uniform([1]:[int])
  x <~ bernoulli(1/2)
  y <~ bernoulli(1/2)
  return x

which produces output:

TREE:
VDist Tree: Leaf EVal VInteger 1
VDist Tree: Split (Just 1) (Leaf EVal VBool True) (Leaf EVal VBool False)
VDist Tree: Split (Just 2) (Leaf EVal VBool True) (Leaf EVal VBool False)
VDist Tree: Split (Just 3) (Leaf EVal VBool True) (Leaf EVal VBool False)
(0 (2 (EVal VBool True) (EVal VBool True)) (3 (EVal VBool False) (EVal VBool False)))
size: 7
TREE SAMPLING INFERENCE:
[(EVal VBool True,0.494),(EVal VBool False,0.506)]
0.5
eqs: [{ 3 = [] },{ 2 = [(1 % 2,Nothing),(1 % 2,Nothing)] },{ 0 = [(1 % 2,Just 2),(1 % 2,Just 3)] }]
mateqs: [([(1 % 1,3)],0 % 1),([(1 % 1,2)],1 % 1),([(1 % 1,0),((-1) % 2,2),((-1) % 2,3)],0 % 1)]
ltree: (0 (2 (True) (True)) (3 (False) (False)))

eqs: [([(1 % 1,3)],0 % 1),([(1 % 1,2)],1 % 1),([(1 % 1,0),((-1) % 2,2),((-1) % 2,3)],0 % 1)]
n: 3
l: [(0,3,1.0),(1,2,1.0),(2,0,1.0),(2,2,-0.5),(2,3,-0.5)]
zar-exe: insertSpMatrix : index out of bounds
CallStack (from HasCallStack):
  error, called at src/Data/Sparse/SpMatrix.hs:208:17 in sparse-linear-algebra-0.3.1-60PEPJsn9866VHk9xIHXYW:Data.Sparse.SpMatrix

The main issue is the use of out-of-bounds label 3 in the generated matrix equations.

The following version of the program (where p is sampled from uniform[1,2]) produces no error:

main:
  p <~ uniform([1, 2]:[int])
  x <~ bernoulli(1/2)
  y <~ bernoulli(1/2)
  return x

My working hypothesis is that there's a label generated for uniform[1] but no corresponding equation (because uniform[1] is essentially p <- 1), leading to the OOB error. This violates an assumption of the SparseLinAlg backend, that the highest occurring label is less than the total number of subtrees.

Two possible solutions:

  1. Do alpha-renaming of labels before generating equations.
  2. Desugar x <~ uniform([c]) to x <- c.

Solution 2 is easier but doesn't solve the more general issue (the assumption on labels made by the SparseLinAlg backend).

@gstew5 gstew5 added the bug Something isn't working label Sep 17, 2019
gstew5 added a commit that referenced this issue Sep 17, 2019
This is solution #2 of issue #8.
@gstew5
Copy link
Collaborator Author

gstew5 commented Sep 17, 2019

5f1bd13 implements solution 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant