def test_score_errors_non_broadcastable_data_shape(dist): for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) shape = d.shape() non_broadcastable_shape = (shape[0] + 1,) + shape[1:] test_data_non_broadcastable = torch.ones(non_broadcastable_shape) with pytest.raises((ValueError, RuntimeError)): d.log_prob(test_data_non_broadcastable)
def test_score_errors_non_broadcastable_data_shape(dist): for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) shape = d.shape() non_broadcastable_shape = (shape[0] + 1,) + shape[1:] test_data_non_broadcastable = torch.ones(non_broadcastable_shape) with pytest.raises((ValueError, RuntimeError)): d.log_prob(test_data_non_broadcastable)
def test_batch_log_prob(dist): if dist.scipy_arg_fn is None: pytest.skip('{}.log_prob_sum has no scipy equivalent'.format(dist.pyro_dist.__name__)) for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) test_data = dist.get_test_data(idx) log_prob_sum_pyro = d.log_prob(test_data).sum().item() log_prob_sum_np = np.sum(dist.get_scipy_batch_logpdf(-1)) assert_equal(log_prob_sum_pyro, log_prob_sum_np)
def test_batch_log_prob(dist): if dist.scipy_arg_fn is None: pytest.skip('{}.log_prob_sum has no scipy equivalent'.format(dist.pyro_dist.__name__)) for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) test_data = dist.get_test_data(idx) log_prob_sum_pyro = d.log_prob(test_data).sum().item() log_prob_sum_np = np.sum(dist.get_scipy_batch_logpdf(-1)) assert_equal(log_prob_sum_pyro, log_prob_sum_np)
def test_score_errors_non_broadcastable_data_shape(dist): for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) if dist.get_test_distribution_name() == "LKJCholesky": pytest.skip("https://github.com/pytorch/pytorch/issues/52724") shape = d.shape() non_broadcastable_shape = (shape[0] + 1, ) + shape[1:] test_data_non_broadcastable = torch.ones(non_broadcastable_shape) with pytest.raises((ValueError, RuntimeError)): d.log_prob(test_data_non_broadcastable)
def test_score_errors_event_dim_mismatch(dist): for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) test_data_wrong_dims = torch.ones(d.shape() + (1,)) if len(d.event_shape) > 0: if dist.get_test_distribution_name() == 'MultivariateNormal': pytest.skip('MultivariateNormal does not do shape validation in log_prob.') elif dist.get_test_distribution_name() == 'LowRankMultivariateNormal': pytest.skip('LowRankMultivariateNormal does not do shape validation in log_prob.') with pytest.raises((ValueError, RuntimeError)): d.log_prob(test_data_wrong_dims)
def test_score_errors_event_dim_mismatch(dist): for idx in dist.get_batch_data_indices(): dist_params = dist.get_dist_params(idx) d = dist.pyro_dist(**dist_params) test_data_wrong_dims = torch.ones(d.shape() + (1,)) if len(d.event_shape) > 0: if dist.get_test_distribution_name() == 'MultivariateNormal': pytest.skip('MultivariateNormal does not do shape validation in log_prob.') if dist.get_test_distribution_name() == 'LowRankMultivariateNormal': pytest.skip('LowRankMultivariateNormal does not do shape validation in log_prob.') with pytest.raises((ValueError, RuntimeError)): d.log_prob(test_data_wrong_dims)