Esempio n. 1
0
    def test_uniform(self, lower, upper, size):
        def transform_params(*inputs):
            _, _, _, lower, upper = inputs
            lower = at.as_tensor_variable(lower) if lower is not None else None
            upper = at.as_tensor_variable(upper) if upper is not None else None
            return lower, upper

        interval = tr.interval(transform_params)
        model = self.build_model(pm.Uniform, {
            "lower": lower,
            "upper": upper
        },
                                 size=size,
                                 transform=interval)
        self.check_transform_elementwise_logp(model)
Esempio n. 2
0
def test_upperbound():
    def transform_params(*inputs):
        return None, 0.0

    trans = tr.interval(transform_params)
    check_transform(trans, Rminusbig)

    check_jacobian_det(trans, Rminusbig, elemwise=True)
    check_jacobian_det(trans,
                       Vector(Rminusbig, 2),
                       at.dvector, [-1, -1],
                       elemwise=True)

    vals = get_values(trans)
    close_to_logical(vals < 0, True, tol)
Esempio n. 3
0
def test_interval():
    for a, b in [(-4, 5.5), (0.1, 0.7), (-10, 4.3)]:
        domain = Unit * np.float64(b - a) + np.float64(a)

        def transform_params(z=a, y=b):
            return z, y

        trans = tr.interval(transform_params)
        check_transform(trans, domain)

        check_jacobian_det(trans, domain, elemwise=True)

        vals = get_values(trans)
        close_to_logical(vals > a, True, tol)
        close_to_logical(vals < b, True, tol)
Esempio n. 4
0
def test_lowerbound():
    def transform_params(*inputs):
        return 0.0, None

    trans = tr.interval(transform_params)
    check_transform(trans, Rplusbig)

    check_jacobian_det(trans, Rplusbig, elemwise=True)
    check_jacobian_det(trans,
                       Vector(Rplusbig, 2),
                       at.dvector, [0, 0],
                       elemwise=True)

    vals = get_values(trans)
    close_to_logical(vals > 0, True, tol)
Esempio n. 5
0
    def test_uniform_ordered(self, lower, upper, size):
        def transform_params(*inputs):
            _, _, _, lower, upper = inputs
            lower = at.as_tensor_variable(lower) if lower is not None else None
            upper = at.as_tensor_variable(upper) if upper is not None else None
            return lower, upper

        interval = tr.interval(transform_params)

        initval = np.sort(np.abs(np.random.rand(*size)))
        model = self.build_model(
            pm.Uniform,
            {
                "lower": lower,
                "upper": upper
            },
            size=size,
            initval=initval,
            transform=tr.Chain([interval, tr.ordered]),
        )
        self.check_vectortransform_elementwise_logp(model, vect_opt=1)