Search
Download the updated kuimaze package kuimaze_mdp.zip.
Your task will be to implement the functions find_policy_via_value_iteration(…) and find_policy_via_policy_iteration(…) with the following inputs:
find_policy_via_value_iteration(…)
find_policy_via_policy_iteration(…)
find_policy_via_value_iteration(problem, discount_factor, epsilon)
find_policy_via_policy_iteration(problem, discount_factor)
where:
problem
kuimaze.MDPMaze
discount_factor
(0,1)
epsilon
The expected output is a dictionary where the key word is a tuple (x,y) and the value is the optimal action (only the accessible states, in cases where the key is a terminal state it is enough return None).
None
You implement the methods in the file mdp_agent.py and upload it to the Upload system. There is no need to alter any other file.
mdp_agent.py
You can look at mdp_sandbox.py in the downloaded kuimaze.zip package. It shows the basic work with MDPMaze and you can use it for inspiration.
mdp_sandbox.py
Timeout: each run of value/policy iteration in a given instance of a problem is limited to at most 30s.
The deadline is again in the Upload system.
Evaluation is divided into: * Automatic evaluation that check the correctness of the policy ( matching the correct and your actions with all the states) on a given sample of the environment, possibly checking different discount factors. * Manual evaluation for clean code.
Automatic evaluation:
Code quality (1 point):
You can follow PEP8, although we do not check all PEP8 demands. Most of the IDEs (certainly PyCharm) point out mishaps with regards to PEP8. You can also read some other sources for inspiration about clean code (e.g., here) or about idiomatic python (e.g., medium, python.net).
For the communication with the MDPMaze environment you can use the following methods:
get_all_states() : returns all the accessible states (i.e. without wall separated tiles). These states are weighted with rewards (state.x, state.y, state.reward).
get_all_states()
is_terminal_state(state) : 'True' if the given state is a terminal state. (However, it does not differentiate between the positively valued terminal state or the negatively valued terminal state, simply if it is any terminal state).
is_terminal_state(state)
get_actions(state) : For a given state it returns a list of possible actions. The result is enum, see an example in mdp_sandbox.py
get_actions(state)
get_state_reward(state): Usually not necessary, the input is the named tuple (state.x, state.y).
get_state_reward(state)
get_next_states_and_probs(state, action) : Returns for a given state and action a list of tuples and probabilities 1)
get_next_states_and_probs(state, action)
state
visualise(dictlist=None)
{'x': x_coord, 'y': y_coord, 'value: val'}
val
env.visualise(get_visualisation_values(utils))
env.visualise(get_visualisation_values(policy))
render(), reset()