Пример #1
0
    def test_add_factor(self):
        """
		Testing output of add_factor() function
		"""
        expected_logmass = torch.tensor(-100.0)
        val = torch.tensor(-1.0)

        def model():
            add_factor(val, 'exp_util_test')  # alpha is 100.0

        posterior = Importance(model, num_samples=1).run()
        actual_logmass = next(posterior._traces())[1]
        self.assertEqual(actual_logmass, expected_logmass)
Пример #2
0
    def test_action_model_add_logmass(self):
        """
		Test to see if add_factor() changes logmass
		to desired output with Importance sampling
		"""
        agent = Agent()
        state = torch.tensor(1.0)
        time_left = torch.tensor(0.0)
        dummy_utility = torch.tensor(1.0)

        # Create dummy utility function
        def dummy_utility_func(state, action, time_left):
            return dummy_utility

        # Set expected utility to the dummy function
        agent.expected_utility = dummy_utility_func

        posterior = Importance(agent.action_model,
                               num_samples=1).run(state, time_left)

        actual_logmass = next(posterior._traces(state, time_left))[1]
        expected_logmass = 100 * dummy_utility
        self.assertEqual(actual_logmass, expected_logmass)