hakaru-dev / hakaru

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

RoundTrip/{t60, t60'} failure #99

Closed yuriy0 closed 7 years ago

yuriy0 commented 7 years ago
expected:
fn x2 real:
x1 <~ uniform(nat2real(0), nat2real(1))
x0 <~ uniform(nat2real(0), nat2real(1))
if if nat2real(0) < x2 / (x0 + x1): x2 / (x0 + x1) < nat2real(1)
   else: false:
  weight(1/ real2prob(x0 + x1), return ())
else: reject. measure(unit)
but got:
fn x2 real:
if +1/1 <= x2 && x2 < +2/1:
  weight
    (real2prob
       (log(real2prob(x2)) * (-2/1) + x2 + log(2/1) * (+2/1) + (-2/1)),
     return ())
else:
  if +0/1 < x2 && x2 < +1/1:
    weight(real2prob(log(2/1) * (+2/1) + x2 * (-1/1)), return ())
  else: reject. measure(unit)

and

expected:
fn x2 real:
x1 <~ uniform(nat2real(0), nat2real(1))
x0 <~ uniform(nat2real(0), nat2real(1))
if if nat2real(0) < x2 / (x0 + x1): x2 / (x0 + x1) < nat2real(1)
   else: false:
  weight(1/ real2prob(x0 + x1), return ())
else: reject. measure(unit)
but got:
fn x2 real:
if +1/1 <= x2 && x2 < +2/1:
  weight
    (real2prob
       (log(real2prob(x2)) * (-2/1) + x2 + log(2/1) * (+2/1) + (-2/1)),
     return ())
else:
  if +0/1 < x2 && x2 < +1/1:
    weight(real2prob(log(2/1) * (+2/1) + x2 * (-1/1)), return ())
  else: reject. measure(unit)

The new result is clearly more efficient as a sampler, so if somebody can confirm they are the same measure (it seems to me they are) I think this result should be accepted.

ccshan commented 7 years ago

Confirmed. Nice.

(These two expected/got pairs are identical.)