Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the step function inside MDPEnv class #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions blackhc/mdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,26 @@ def step(self, action_index):
self._previous_action = action

if not self._is_done:
reward_probs = self.transitions.rewards[self._state, action]
reward = np.random.choice(list(reward_probs.keys()), p=list(reward_probs.values()))


# Original code :

# reward_probs = self.transitions.rewards[self._state, action]
# reward = np.random.choice(list(reward_probs.keys()), p=list(reward_probs.values()))

# next_state_probs = self.transitions.next_states[self._state, action]
# self._state = np.random.choice(list(next_state_probs.keys()), p=list(next_state_probs.values()))

# Modified code :

# In the above code , chosing "next_state and reward" is not synchronized,each of them are
# independently sampled, but they are synchronized as per specs of the MDP.

reward_obj_list=self.mdp.reward_outcomes[self._state, action]
next_state_probs = self.transitions.next_states[self._state, action]
state_id=np.random.choice(list(range(len(list(next_state_probs.keys())))), p=list(next_state_probs.values()))
self._state = np.random.choice(list(next_state_probs.keys()), p=list(next_state_probs.values()))
self._state=list(next_state_probs.keys())[state_id]
reward=reward_obj_list[state_id].outcome
self._is_done = self._state.terminal_state
else:
reward = 0
Expand Down