Skip to content

Commit

Permalink
added unit test to test_control showing the effect of policy prior …
Browse files Browse the repository at this point in the history
…on policy posterior
  • Loading branch information
conorheins committed Oct 27, 2021
1 parent fd73269 commit 28816d0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,47 @@ def test_sample_action(self):

chosen_action = control.sample_action(q_pi, policies, num_controls, action_selection="deterministic")
self.assertEqual(int(chosen_action[0]), 1)

def test_update_posterior_policies_withE_vector(self):
"""
Test update posterior policies in the case that there is a prior over policies
"""

""" Construct an explicit example where policy 0 is preferred based on utility,
but action 2 also gets a bump in probability because of prior over policies
"""
num_obs = [3]
num_states = [3]
num_controls = [3]

qs = utils.to_arr_of_arr(utils.onehot(0, num_states[0]))
A = utils.to_arr_of_arr(np.eye(num_obs[0]))
B = utils.construct_controllable_B(num_states, num_controls)

C = utils.to_arr_of_arr(np.array([1.5, 1.0, 1.0]))

D = utils.to_arr_of_arr(utils.onehot(0, num_states[0]))
E = np.array([0.05, 0.05, 0.9])

policies = control.construct_policies(num_states, num_controls, policy_len=1)

q_pi, efe = control.update_posterior_policies(
qs,
A,
B,
C,
policies,
use_utility = True,
use_states_info_gain = False,
use_param_info_gain = False,
pA=None,
pB=None,
E = E,
gamma=16.0
)

self.assertGreater(q_pi[0], q_pi[1])
self.assertGreater(q_pi[2], q_pi[1])


if __name__ == "__main__":
Expand Down

0 comments on commit 28816d0

Please sign in to comment.