def test_log_pdf_1d_1n_change(self): mu = asarray([0], dtype=numpy.bool8) spread = rand() dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[1]], dtype=numpy.bool8) expected = log(1.) self.assertAlmostEqual(dist.log_pdf(X), expected)
def test_log_pdf_returned_array_dimension_multiple_X_2d(self): n = 2 mu = asarray([0, 1], dtype=numpy.bool8) spread = .5 dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[1, 0], [0, 0]], dtype=numpy.bool8) self.assertEqual(dist.log_pdf(X).shape, (n,))
def test_log_pdf_returned_array_dimension_1d_X(self): n = 1 mu = asarray([0], dtype=numpy.bool8) spread = .5 dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[0]], dtype=numpy.bool8) self.assertEqual(dist.log_pdf(X).shape, (n,))
def test_log_pdf_1d_2n(self): mu = asarray([0], dtype=numpy.bool8) spread = rand() dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[1], [0]], dtype=numpy.bool8) log_liks = dist.log_pdf(X) expected = asarray([log(1.), -inf]) self.assertAlmostEqual(norm(log_liks[0] - expected[0]), 0) self.assertEqual(log_liks[1], expected[1])
def test_log_pdf_2d_1n_change2(self): mu = asarray([0, 0], dtype=numpy.bool8) spread = rand() dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[1, 1]], dtype=numpy.bool8) self.assertTrue(all(dist.log_pdf(X) == log(spread)))
def test_log_pdf_2d_1n_change1(self): mu = asarray([0, 0], dtype=numpy.bool8) spread = rand() dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[1, 0]], dtype=numpy.bool8) self.assertAlmostEqual(dist.log_pdf(X)[0], log(1. - spread))
def test_log_pdf_no_change(self): mu = asarray([0], dtype=numpy.bool8) spread = rand() dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[0]], dtype=numpy.bool8) self.assertAlmostEqual(dist.log_pdf(X), -inf)
def test_log_pdf_type(self): mu = asarray([0], dtype=numpy.bool8) spread = .5 dist = DiscreteRandomWalkProposal(mu, spread) X = asarray([[0]], dtype=numpy.bool8) self.assertEqual(type(dist.log_pdf(X)), numpy.ndarray)