def test_yield_sample_accept(sampler, old_sample): """Test function when sample is accepted""" new_sample = parameters_to_live_point([1, 1], names=sampler.model.names) sampler.proposal.draw = MagicMock(return_value=new_sample) count, next_sample = next(NestedSampler.yield_sample(sampler, old_sample)) assert count == 1 sampler.proposal.draw.assert_called_once_with(old_sample) assert next_sample == new_sample assert sampler.logLmax == sampler.model.log_likelihood(new_sample)
def test_yield_sample_not_populated(sampler, old_sample): """Test function when sample is rejected and a new sample is not drawn""" new_sample = parameters_to_live_point([6, 6], names=sampler.model.names) sampler.proposal.draw = MagicMock(return_value=new_sample) sampler.proposal.populated = False count, next_sample = next(NestedSampler.yield_sample(sampler, old_sample)) assert count == 1 assert old_sample == next_sample sampler.proposal.draw.assert_called_once_with(old_sample)
def test_yield_sample_reject(sampler, old_sample): """Test function when sample is rejected and a new sample is drawn""" new_samples = [ parameters_to_live_point([6, 6], names=sampler.model.names), parameters_to_live_point([1, 1], names=sampler.model.names) ] sampler.proposal.draw = MagicMock(side_effect=new_samples) sampler.proposal.populated = True count, next_sample = next(NestedSampler.yield_sample(sampler, old_sample)) assert count == 2 assert next_sample == new_samples[1] sampler.proposal.draw.assert_called_with(old_sample)