Esempio n. 1
0
    def make_pdf(self, pars):
        """
        Args:
            pars (:obj:`tensor`): The model parameters

        Returns:
            pdf: The pdf object for the Normal Constraint
        """
        tensorlib, _ = get_backend()
        if not self.param_viewer.index_selection:
            return None
        if self.batch_size is None:
            flat_pars = pars
        else:
            flat_pars = tensorlib.reshape(pars, (-1, ))

        normal_means = tensorlib.gather(flat_pars, self.access_field)

        # pdf pars are done, now get data and compute
        if self.batch_size is None:
            normal_means = normal_means[0]

        result = prob.Independent(prob.Normal(normal_means, self.sigmas),
                                  batch_size=self.batch_size)
        return result
Esempio n. 2
0
def test_normal(backend):
    tb, _ = backend
    result = probability.Normal(tb.astensor([10.0]),
                                tb.astensor([1])).log_prob(tb.astensor(2.0))
    assert result.shape == (1, )

    result = probability.Normal(tb.astensor([10.0, 10.0]),
                                tb.astensor([1, 1])).log_prob(tb.astensor(2.0))
    assert result.shape == (2, )

    result = probability.Normal(tb.astensor([10.0, 10.0]),
                                tb.astensor([10.0, 10.0])).log_prob(
                                    tb.astensor([2.0, 3.0]))
    assert result.shape == (2, )

    result = probability.Normal(tb.astensor([10.0, 10.0]),
                                tb.astensor([10.0, 10.0])).log_prob(
                                    tb.astensor([[2.0, 3.0]]))
    assert result.shape == (1, 2)