Exemple #1
0
    def __add__(self, other):
        """
        Return the result of an addition.
        """

        other = qy.value_from_any(other).cast_to(self.type_)
        value = RealValue(qy.get().builder.fadd(self._value, other._value))

        if qy.get().test_for_nan:
            qy.assert_(~value.is_nan, "result of %s + %s is not a number", other, self)

        return value
Exemple #2
0
    def _ll(self, parameter, sample, out):
        """
        Compute log probability under this distribution.
        """

        p = parameter.data.load()
        k = sample.data.gep(0, 0).load()
        n = sample.data.gep(0, 1).load()

        if get_qy().test_for_nan:
            qy.assert_(p >= 0.0, "invalid p = %s", p)
            qy.assert_(p <= 1.0, "invalid p = %s", p)
            qy.assert_(k >= 0, "invalid k = %s", k)
            qy.assert_(n >= 0, "invalid n = %s", n)
            qy.assert_(k <= n, "invalid k = %s (> n = %s)", k, n)

        binomial_log_pdf(k, p, n).store(out)
Exemple #3
0
    def _ll(self, parameter, sample, out):
        """
        Compute log probability under this distribution.
        """

        p = parameter.data.load()
        k = sample.data.gep(0, 0).load()
        n = sample.data.gep(0, 1).load()

        if get_qy().test_for_nan:
            qy.assert_(p >= 0.0, "invalid p = %s"           , p   )
            qy.assert_(p <= 1.0, "invalid p = %s"           , p   )
            qy.assert_(k >= 0  , "invalid k = %s"           , k   )
            qy.assert_(n >= 0  , "invalid n = %s"           , n   )
            qy.assert_(k <= n  , "invalid k = %s (> n = %s)", k, n)

        binomial_log_pdf(k, p, n).store(out)
Exemple #4
0
 def _():
     qy.assert_(False)
Exemple #5
0
 def _():
     qy.assert_(True)