# Reinforcement learning with subgoals

The usual reinforcement learning task is that an agent starts from a start position with the ultimate aim to reach a goal. More often than not, RL algorithms involve planning and learning optimal policies to reach this goal and rewards are only awarded when the goal is attained. Sometimes, there is a penalty for each time step when the goal is not reached.

Now, I am interested in a reinforcement learning task with a start and goal, but with one additional requirement: there are some subgoals that need to be achieved.

The subgoals will have to be achieved first (and perhaps in a certain order) before the actual goal will be achieved.

1. If this is a totally new field/area, or a modification of the existing RL that I know.
2. What added conditions can be put in place to include the "subgoals" as specified?
• I wonder if there's something you're leaving out: Is there some reason you can't account for these subgoals in a standard MDP state space and transition function? Meaning, add dimensions to your state space corresponding to the goals already achieved. (E.g. Link cannot transition to the state of having the Master Sword unless he's in the state of standing behind it with all three pendants in hand.) – Sean Easter Jun 22 '16 at 2:07
• I am interested in learning this. This is exactly the same scenario I am troubled with. I am relatively new to this, and I do not know how you can put the \emph{ three pendants in hand} into the state function. – cgo Jun 22 '16 at 5:02
• Answer below. A small note: There is no 'state function.' The state space of an MDP is a set; the transition function is just that, a function. – Sean Easter Jun 24 '16 at 1:40

Sure, standard MDPs can hack that. You just need to carefully define the state space so that it includes all possible states, and ensure that the transition function reflects that order.

Consider a simple, square grid with length three on each side. The agent begins at the bottom left. The reward for the top-right—where the Master Sword resides—is some positive constant; other rewards are uniformly $0$.

There's little to this problem. You can be in any of nine states, and can transition to each state from any of its adjacent states. You can index them by an integer, or row and column. Row and column is intuitive: You can quickly tell from the row and column indices of two states whether a move between the two is legal. So, we'll define each state as a tuple $(i,j)$. Value iteration, or any planning algorithm, would make short work of it.

Let's add the possibility that the top-right is not a terminal state, and that the agent can move about after retrieving the sword. Changing the state space is easy enough: States are now $(i,j,m)$, $m$ being a boolean indicating whether the sword has been retrieved. (If it helps, you can think of this as two grids, one corresponding to having the sword, one not.)

Our transition function also needs an upgrade, since our agent will never drop the sword. (It's very precious.) Easy enough: $T(s,a,s') = 0$ for any $s = (i_0,j_0,1), s' = (i_1,j_1,0)$.

Now, say that in each square in the diagonal from the top-left to bottom-right are the pendants of Courage, Power and Wisdom, respectively, and that the agent must collect these, in order, prior to retrieving the Master Sword. The new states are $(i,j,n)$, $n$ being the number of artifacts (pendants & sword) retrieved.

You can visualize this state space as a stack of grids; gathering the next pendant or sword is loosely like 'moving up' a level. (We're up to 45 states total.) Your transition function should again account for this, returning $0$ for any transition that would represent giving up an artifact. Value iteration would propagate value out and down from the Master Sword.

If unordered gathering is allowed, we'll need more states still. Before, having the Pendant of Power implied having the Pendant of Courage. Since that's no longer the case, we'll need a boolean for each pendant and the Master Sword; states are now $(i,j,c,p,w,m)$ tuples, with any state with $m=1$ having $c = p = w = 1$.

Important point being, your state space is, intuitively, just a list of unique, exclusive conditions. This representation can capture order, once you put enough thought into your problem's full realm of possible states, and adjust your transition function accordingly.

• This is very intuitive and clever. Thanks. Can you point me to a paper (or book) where I can find this kind of example? – cgo Jul 14 '16 at 6:32
• @cgo I don't know of one offhand, sadly. I improvised this example myself, and I've never worked directly through examples in a reinforcement learning text. Though, you might try the Sutton & Barto book. – Sean Easter Jul 14 '16 at 20:27
• that's not a problem. Thank you very much for your intuition. – cgo Jul 15 '16 at 5:57