self.action[(i,j)] vs self.action[(self.i, self.j)]

Post Reply
jonahburke
Posts: 2
Joined: Sun Apr 04, 2021 8:00 pm

self.action[(i,j)] vs self.action[(self.i, self.j)]

Post by jonahburke »

In Lecture 50, there seems to be a difference in the way you've coded get_next_state and move even though they are supposed to be almost the same thing. In get_next_state you assigned i and j to s[0] and s[1], which are previously set using set_state to self.i and self.j

Then you just loop through actions using self.action[(i, j)].

In move function you just loop through actions with self.action[(self.i, self.j)].

Is this significant? I cannot see how they might produce different results, so is it just a choice of coding style and maybe you chose to show 2 ways it can be done? The first way seems a bit roundabout though, unless it had a specific purpose.
lazyprogrammer
Site Admin
Posts: 50
Joined: Sat Jul 28, 2018 3:46 am

Re: self.action[(i,j)] vs self.action[(self.i, self.j)]

Post by lazyprogrammer »

Thanks for your question.

In one case, the function takes in the state as an argument, so you can pass in any state.

In the other case, the function uses the state stored as an attribute which represents the current state.

It would be helpful to think about why it's being stored as an attribute and what that function is actually doing.
Post Reply

Return to “Artificial Intelligence: Reinforcement Learning in Python”