hakaru-dev / hakaru

A probabilistic programming language
BSD 3-Clause "New" or "Revised" License
309 stars 30 forks source link

Erlang tests #149

Closed sohraa3 closed 6 years ago

sohraa3 commented 6 years ago

The tests were written for the relations in the following wikipedia page: https://en.wikipedia.org/wiki/Erlang_distribution#Related_distributions

"t_erlang_to_erlang" corresponds to the first relationship "t_erlang_to_erlang_2" corresponds to the second relationship "t_exponential_to_erlang" corresponds to the third relationship

Test results:

Failure in: 6:RoundTrip:6:0:t_erlang_to_erlang:0

haskell/Tests/TestTools.hs:130
expected:
fn scale nat:
fn shape prob:
fn a prob:
x <~ gamma(shape / a, nat2prob(scale))
return x
but got:
fn scale nat:
fn shape prob: fn a prob: gamma(shape / a, nat2prob(scale))

Failure in: 6:RoundTrip:6:0:t_erlang_to_erlang:1

haskell/Tests/TestTools.hs:130
expected:
fn scale nat:
fn shape prob:
fn a prob:
x <~ gamma(shape / a, nat2prob(scale))
return x
but got:
fn scale nat:
fn shape prob:
fn a prob:
x9 <~ gamma(shape, nat2prob(scale))
return x9 * a

Failure in: 6:RoundTrip:6:1:t_erlang_to_erlang_2:0

haskell/Tests/TestTools.hs:130
expected:
fn scale1 nat:
fn scale2 nat:
fn shape prob:
XplusY <~ gamma(shape, nat2prob(scale1 + scale2))
return XplusY
but got:
fn scale1 nat:
fn scale2 nat:
fn shape prob: gamma(shape, nat2prob(scale1) + nat2prob(scale2))

Failure in: 6:RoundTrip:6:1:t_erlang_to_erlang_2:1

haskell/Tests/TestTools.hs:130
expected:
fn scale1 nat:
fn scale2 nat:
fn shape prob:
XplusY <~ gamma(shape, nat2prob(scale1 + scale2))
return XplusY
but got:
fn scale1 nat:
fn scale2 nat:
fn shape prob:
Xb <~ gamma(shape, nat2prob(scale1))
Y9 <~ gamma(shape, nat2prob(scale2))
return Xb + Y9

Failure in: 6:RoundTrip:6:2:t_exponential_to_erlang:0

haskell/Tests/TestTools.hs:130
expected:
exponential = fn alpha prob:
              X <~ uniform(nat2real(0), nat2real(1))
              return -prob2real(nat2prob(1))
                      * prob2real(alpha)
                      * log(real2prob(X))
fn k nat:
fn lambda prob:
X <~ gamma(nat2prob(k), lambda)
return prob2real(X)
but got:
fn k nat:
fn lambda prob:
x0 <~ gamma(nat2prob(k), lambda)
return prob2real(x0)

Failure in: 6:RoundTrip:6:2:t_exponential_to_erlang:1

haskell/Tests/TestTools.hs:130
expected:
exponential = fn alpha prob:
              X <~ uniform(nat2real(0), nat2real(1))
              return -prob2real(nat2prob(1))
                      * prob2real(alpha)
                      * log(real2prob(X))
fn k nat:
fn lambda prob:
X <~ gamma(nat2prob(k), lambda)
return prob2real(X)
but got:
fn k nat:
fn lambda prob:
X7 <~ plate _ of k: uniform(+0/1, +1/1)
return (summate i from 0 to k: log(real2prob(X7[i])))
       * prob2real(lambda)
       * (-1/1)
JacquesCarette commented 6 years ago

It really would be much (much) better if your PRs were smaller. There are different comments to make, on each test. And once you resolve something on one test, we sill won't be able to pull this in until everything is fixed - and this sub-optimal.

JacquesCarette commented 6 years ago

So, in particular, your first test should pass. The main reason it doesn't is that you have written the 'expected' value in an unsimplified way. What is returned now is correct, and what you should expect.

JacquesCarette commented 6 years ago

I am guess that the same is true in the second failure - but you should double-check that...

JacquesCarette commented 6 years ago

The third 'failure' should also pass, and is an artifact of how you wrote down your expected.

JacquesCarette commented 6 years ago

The fourth should pass -- the problem is again in your 'expected'. You should not expect the results to contain intermediate function definitions.

JacquesCarette commented 6 years ago

(oops, that might have been about the fourth)

Fifth has some issues like the above, but may reflect a real failure.

sohraa3 commented 6 years ago

@JacquesCarette I'm having a difficult time figuring out how the expected should be written. for the first test, I currently have the following expected written: fn scale nat: fn shape prob: fn a prob: x <~ gamma(shape/a,nat2prob(scale)) return(x) how can this be simplified or written without intermediate functions? I tried replacing return(x) with weight(x, return ()) as I saw it was written like that for other tests but that didn't help either.

ccshan commented 6 years ago

You should simplify x <~ ...; return(x) to just ...

sohraa3 commented 6 years ago

I am closing this pull request to make individual pull requests for each of the tests