Automata Theory and Reinforcement Learning


Automata Theory and Reinforcement Learning

Maria
Today we’re exploring a question that sounds practical but opens up some deep ideas: how can we tell a reinforcement-learning agent what we want it to do without hand-coding a complicated reward function? Sheila McIlraith’s talk connects formal languages and automata theory to reward specification and more efficient learning.

Corey
And the motivating picture is a robot in your home. It may already know how to move around and perform actions, but you still need a way to ask it for a particular behavior. The aspiration is that giving an agent a task should feel more like instructing a person than programming a reward function by hand.

Maria
Let’s establish the reinforcement-learning setup. In model-free reinforcement learning, an agent knows which actions it can take, but it doesn’t know the environment’s transition rules or its reward function. It acts, observes the resulting state and reward, and tries to learn a policy—a mapping from states to actions, or distributions over actions—that maximizes expected cumulative reward.

Corey
A familiar example is Q-learning. The agent estimates a Q-value for each state-action pair: roughly, how good is it to take this action in this state? After an experience, it updates that estimate using the reward it just received and a discounted estimate of future reward. Once those values are learned, it chooses the action with the highest Q-value.

Maria
The catch is that the agent needs a reward signal, and someone has to define it. For a simple task, that might be easy. But for complex behavior, a programmer—often a graduate student in the examples Sheila describes—has to translate the intended behavior into a numerical function of states or transitions.

Corey
That translation can be awkward. If you ask a household robot to run the dishwasher when it’s full or when dishes are needed for the next meal, the reward depends on conditions and timing. If you ask it to check bath temperature immediately before someone enters, the order and timing matter too.

Maria
The ice-cream example makes the issue especially vivid: open the freezer, take out the ice cream, serve it, put it back, and close the door. The desired reward is for completing the sequence—not for stopping halfway and leaving the freezer open. These tasks are temporally extended, conditional, and richer than a simple reward attached to one state.

Corey
And sparse rewards make learning harder. If the agent only receives a positive signal after the whole sequence is complete, it may need an enormous number of interactions before it discovers a successful behavior. The talk identifies two central challenges: specifying rewards for complex tasks, and improving sample efficiency.

Maria
There’s also a communication gap. A person shouldn’t need a PhD to task an agent. A long-term goal might be natural-language instructions, but the work in this talk focuses on formal languages: they have defined syntax and semantics, so a task can be expressed precisely.

Corey
Linear temporal logic, or LTL, is one candidate. It combines familiar logical operators such as and, or, and not with temporal operators. Those operators let us describe how properties relate over time—for example, that something must eventually happen, must always be true, or must happen next.

Maria
So ‘never vacuum while someone is sleeping’ can be expressed as a condition that must always hold: if someone is sleeping, don’t vacuum. The ice-cream task can be described as an ordered sequence of events. LTL formulas can also be translated into automata, and that connection is important because the talk’s learning methods use automata to represent reward structure.

Corey
The running example is a small office world. The agent moves among locations A, B, C, and D; there are coffee stations, a mail room, an office, and fragile furniture to avoid. One simple task is to visit A, then B, then C, then D—in that order.

Maria
The key proposal is surprisingly direct: if someone already knows the reward function, why keep it hidden inside the environment? Give its structure to the learning agent. The agent can then use that structure to learn more efficiently, rather than receiving only an opaque reward signal.

Corey
The representation Sheila focuses on is a reward machine. It’s an automata-based representation of a reward function. It has a finite set of states, an initial state, transitions, and conditions on those transitions. Each transition also has an associated reward, which could be a scalar or, in a more general version, a reward function.

Maria
The transition conditions use a vocabulary of recognizable events or properties. In the office example, that vocabulary might include being at A, B, C, or D, visiting a coffee station, entering the mail room, reaching the office, or hitting furniture. Those events can be detected from the environment, and the vocabulary is meant to be interpretable to a person.

Corey
Think of the machine as keeping track of task progress. For the A-then-B-then-C-then-D task, it moves through states that record which parts of the sequence have been completed. Reaching A changes the machine’s state, but may not yet produce reward. Reaching D after the earlier locations completes the task and earns the reward.

Maria
That also explains how a reward machine can represent a non-Markovian reward. In the physical environment, the agent might make the exact same move into D on two different occasions. But the reward can differ depending on whether it previously visited A, B, and C. The reward machine’s state encodes that relevant history.

Corey
Reward machines can capture other patterns too. For ‘get coffee and deliver it to the office while avoiding furniture,’ the machine can remember whether the agent has collected coffee, and reward delivery at the office. If it hits the furniture, it can move to a sink state where it stays and receives no reward.

Maria
And if the task is to deliver both coffee and mail, without specifying which one must come first, the machine can represent either order: coffee then mail, or mail then coffee, followed by delivery to the office. That’s a compact way to describe multiple acceptable paths through a task.

Corey
Once the reward machine is available, the next question is how to learn with it. One baseline is ordinary Q-learning on the product of the environment’s state and the reward machine’s state. That product makes the task’s history-dependent reward Markovian in the combined state.

Maria
Another comparison is hierarchical reinforcement learning, or HRL. It learns options—subpolicies or macro-actions—and a meta-controller that selects among them. In the office sequence, for example, it might learn separate policies for reaching A, B, C, and D, then learn how to compose those options.

Corey
HRL can use the reward machine to prune irrelevant options. If the machine says the next required event is reaching A, the controller can focus on the policy for A instead of considering every option. That can make learning more efficient, but there’s a limitation: options learned independently can be locally optimal without being optimal as a whole.

Maria
The coffee-delivery example shows why. One coffee station may be quickest to reach, but it can leave a long route to the office. An option that optimizes only ‘get coffee’ may choose that station, even though another station would make the complete delivery task faster. HRL’s myopic subgoals can therefore produce a suboptimal overall path.

Corey
The proposed algorithm, QRM, is designed to exploit the reward machine while retaining the value-learning approach of Q-learning. It learns a Q-function for each reward-machine state. The policy used for action selection depends on the machine’s current state, so the agent’s choices reflect how far it has progressed through the task.

Maria
QRM’s distinctive idea is to reuse experience across those Q-functions. After an action, it can update not only the Q-function for the reward-machine state it actually occupied, but also the others, by asking counterfactually what would have happened if the machine had been in a different state.

Corey
For instance, suppose the agent moves into D while the reward machine is in the state that means A, B, and C have already been visited. That transition may earn a reward and return the machine to its initial state. QRM can use the same physical transition to update the relevant Q-function with that reward, while also updating other machine-state Q-functions according to what their transitions would have been.

Maria
That is a form of counterfactual reasoning and off-policy learning: the agent gets more learning value from each experience. The reward-machine structure separates a temporally extended task into distinct reward conditions, and QRM uses the structure to update multiple estimates rather than waiting to encounter every task state in exactly the same way.

Corey
A related method adds reward shaping. The intuition is like laying breadcrumbs along a long journey toward a final reward. Instead of giving the agent a signal only at the end, shaping supplies intermediate guidance. With potential-based shaping, the intended property is that the optimal policy for the original reward is preserved while learning can become faster.

Maria
In the work described, shaping values for a reward machine were computed using value iteration over the machine, then used with QRM. In tabular settings, Q-learning has an optimality guarantee in the limit, and the talk reports that QRM and shaped QRM preserve those guarantees in that setting.

Corey
The experiments compare Q-learning, HRL, HRL with reward-machine-based pruning, QRM, and QRM with reward shaping. In the discrete office-world tasks, QRM reached the optimal policy with fewer training steps than plain Q-learning. The HRL approaches also learned, but could plateau at a suboptimal solution because of their locally optimized options.

Maria
The same broad pattern appeared in a Minecraft-like Craft World, with tasks involving collecting resources and making objects. QRM learned efficiently, while plain Q-learning struggled with the sparse rewards and did not solve the tested problems within the reported training budget. The talk emphasizes that, with enough samples, tabular Q-learning can still converge—but the point is how much experience it may require.

Corey
They also tested a continuous-state domain called Water World, using deep reinforcement learning. The agent moved among colored balls and faced tasks such as avoiding pink balls while hitting green and then yellow ones, or hitting two yellow balls and then a blue one. Here they used Double DQN, and the deep QRM approach performed better than the comparison methods in the reported experiments.

Maria
There’s an important qualification: with function approximation, the tabular optimality guarantees no longer apply. And reward shaping did not help uniformly. It improved learning in the discrete experiments, but in the continuous domain it hindered QRM in the results shown.

Corey
The discussion suggests that richer reward functions on reward-machine transitions may be useful in continuous environments. Rather than only assigning a constant reward at an event, a transition can carry a reward function. Sheila notes that such functions could provide more tailored guidance, and that combining them with shaping might be promising—but that’s presented as an avenue to explore, not a guaranteed result.

Maria
How do reward machines get created? One route is to write them directly. Another is to specify the task in a formal language that can be translated into an automaton, such as a suitable regular language or a subset of LTL. A translation tool mentioned in the talk is FLAT.

Corey
The reward machine can act as a normal-form representation. Different specification languages can be translated into the same kind of automaton, and then learning algorithms can operate on that shared representation. The advantage is that you don’t need to invent a separate learning algorithm for every language.

Maria
A second route is to use symbolic planning. A high-level goal—such as ‘get my glasses from the bedroom’—can be used by a planner to generate a plan, and that plan can populate a reward machine with guideposts or waypoints. The resulting structure can provide richer learning guidance than rewarding only the final goal.

Corey
The third route is to learn reward machines. That becomes especially relevant when the environment is partially observable, because the agent may need memory. A machine state can summarize important parts of the past and help make the agent’s decision process behave more like a Markovian one.

Maria
The talk’s toy example has three rooms and a T-junction. The agent can only see the room or corridor it is currently in. A button in the yellow room makes a cookie appear in either the blue or red room. At the junction, the right action depends on what the agent has already done and whether it has found a cookie.

Corey
If the agent has pressed the button and searched one room without finding a cookie, it needs to remember which room it checked so it can search the other one. If it finds and eats the cookie, it needs to know to return to the button. The physical observation at the junction can be the same, while the correct action differs because the history differs.

Maria
In that work, the agent had high-level event detectors—such as whether the button was pressed or whether a cookie was present—but the reward machine itself was learned using discrete optimization via Tabu search. The learned machine represented the needed memory and was interpretable enough to inspect: its states and transitions reflected button pressing, room searches, and finding or eating the cookie.

Corey
The talk reports that several deep-learning approaches available at the time, including A3C, PPO, and ACER with LSTMs, did not solve these simple-looking examples. Learning reward machines and combining them with QRM did reach the optimal behavior in the reported results. It’s a reminder that partial observability and long-range memory can make even small environments difficult.

Maria
There are still open questions. HRL can be compelling because it decomposes tasks into reusable skills, but its options may be myopic, and the discussion does not establish a general bound on how suboptimal the result might be. One proposed direction is to make options more goal-conditioned, so a subpolicy can account for the larger task it is serving.

Corey
Another concern is automaton size. Translating a high-level specification into an automaton can cause a blowup, and QRM’s work grows with the number of reward-machine states. The talk mentions possible responses, including working directly with temporal logic, exploring nondeterministic or alternating automata, using lifted representations, and considering hierarchical abstract machines.

Maria
The discussion also connects learning reward machines to demonstrations and inverse reinforcement learning. Learning a machine can involve more than identifying which behavior earns reward: in partially observable settings, it may also need to capture enough of the environment’s dynamics to support prediction. Other work discussed in the talk learns automata or temporal-logic descriptions from traces, including noisy data.

Corey
And because the representation is explicit, it may be possible for an expert to inspect or modify it. That makes reward machines potentially useful for explanations and feedback, not just learning speed. But how well a learned structure can be extended, generalized, or updated without starting over remains an open question.

Maria
So the central lesson is that task structure matters. Formal languages let us state temporally extended behavior; automata turn that behavior into a representation that tracks progress; and reward machines expose that structure to the learning agent. QRM then reuses experience across machine states, while shaping, planning, and machine learning offer additional ways to guide behavior.

Corey
The larger aspiration is to make agents easier to instruct, more sample-efficient, and more interpretable. The work does not claim that every challenge is solved—continuous reward design, automaton size, generalization, and guarantees for hierarchical methods all remain important questions. But it shows how formal-language structure can help bridge the gap between a human’s task description and an agent’s learning process.

Ask anything
We've read this whole study set, so questions about it get the best answers.