Batch RL Via Least Squares Policy Iteration: A Comparison with Online RL

Batch RL Via Least Squares Policy Iteration: A Comparison with Online RL
paly

This article compares batch RL via least squares policy iteration (LSPI) with online RL, discussing their respective methods of data collection and optimization. The benefits and drawbacks of each approach are presented, along with experimental results that highlight the strengths of batch algorithms. Topics covered include motivation, LSPI derivation from LSTD, and the exploration/exploitation problem in RL.

  • Uploaded on | 1 Views
  • glynis glynis

About Batch RL Via Least Squares Policy Iteration: A Comparison with Online RL

PowerPoint presentation about 'Batch RL Via Least Squares Policy Iteration: A Comparison with Online RL'. This presentation describes the topic on This article compares batch RL via least squares policy iteration (LSPI) with online RL, discussing their respective methods of data collection and optimization. The benefits and drawbacks of each approach are presented, along with experimental results that highlight the strengths of batch algorithms. Topics covered include motivation, LSPI derivation from LSTD, and the exploration/exploitation problem in RL.. The key topics included in this slideshow are batch RL, online RL, least squares policy iteration, LSTD, data efficiency,. Download this presentation absolutely free.

Presentation Transcript


1. Batch RL Via Least Squares Policy Iteration Alan Fern * Based in part on slides by Ronald Parr

2. Overview Motivation LSPI Derivation from LSTD Experimental results

3. Online versus Batch RL Online RL: integrates data collection and optimization Select actions in environment and at the same time update parameters based on each observed (s,a,s,r) Batch RL: decouples data collection and optimization First generate/collect experience in the environment giving a data set of state-action-reward-state pairs {(s i ,a i ,r i ,s i )} We may not even know where the data came from Use the fixed set of experience to optimize/learn a policy Online vs. Batch: Batch algorithms are often more data efficient and stable Batch algorithms ignore the exploration-exploitation problem, and do their best with the data they have

4. Batch RL Motivation There are many applications that naturally fit the batch RL model Medical Treatment Optimization: Input: collection of treatment episodes for an ailment giving sequence of observations and actions including outcomes Ouput: a treatment policy, ideally better than current practice Emergency Response Optimization: Input: collection of emergency response episodes giving movement of emergency resources before, during, and after 911 calls Output: emergency response policy

5. LSPI LSPI is a model-free batch RL algorithm Learns a linear approximation of Q-function stable and efficient Never diverges or gives meaningless answers LSPI can be applied to a dataset regardless of how it was collected But garbage in, garbage out. Least-Squares Policy Iteration , Michail Lagoudakis and Ronald Parr, Journal of Machine Learning Research (JMLR) , Vol. 4, 2003, pp. 1107-1149.

6. Notation S: state space, s: individual states R(s,a): reward for taking action a in state s : discount factor V(s): state value function P(s | s,a) = T(s,a,s): transition function Q(s,a) : state-action value function Policy: Objective: Maximize expected, total, discounted reward

7. Projection Approach to Approximation Recall the standard Bellman equation: or equivalently where T [.] is the Bellman operator Recall from value iteration, the sub-optimality of a value function can be bounded in terms of the Bellman error: This motivates trying to find an approximate value function with small Bellman error

8. Projection Approach to Approximation Suppose that we have a space of representable value functions E.g. the space of linear functions over given features Let be a projection operator for that space Projects any value function (in or outside of the space) to closest value function in the space Fixed Point Bellman Equation with approximation Depending on space this will have a small Bellman error LSPI will attempt to arrive at such a value function Assumes linear approximation and least-squares projection

10. Projected Value Iteration Nave Idea: try computing projected fixed point using VI Exact VI: (iterate Bellman backups) Projected VI: (iterated projected Bellman backups): exact Bellman backup (produced value function) Projects exact Bellman backup to closest function in our restricted function space

11. Example: Projected Bellman Backup Restrict space to linear functions over a single feature : Suppose just two states s 1 and s 2 with: Suppose exact backup of V i gives: s 1 )=1 s 2 )=2 s 1 )=1, s 2 )=2 Can we represent this exact backup in our linear space? No

12. Example: Projected Bellman Backup Restrict space to linear functions over a single feature : Suppose just two states s 1 and s 2 with: Suppose exact backup of V i gives: The backup cant be represented via our linear function: s 1 )=1 s 2 )=2 s 1 )=1, s 2 )=2 projected backup is just least-squares fit to exact backup

13. Problem: Stability Exact value iteration stability ensured by contraction property of Bellman backups: Is the projected Bellman backup a contraction: ?

14. Example: Stability Problem [Bertsekas & Tsitsiklis 1996] Problem : Most projections lead to backups that are not contractions and unstable s 2 s 1 Rewards all zero, single action, = 0.9: V* = 0 Consider linear approx. w/ single feature with weight w. Optimal w = 0 since V*=0

15. Example: Stability Problem From V i perform projected backup for each state Cant be represented in our space so find w i+1 that gives least-squares approx. to exact backup After some math we can get: w i+1 = 1.2 w i What does this mean? s 2 s 1 s 1 )=1 V i (s 1 ) = w i s 2 )=2 V i (s 2 ) = 2w i weight value at iteration i

16. Example: Stability Problem 1 2 Iteration # S V(x) Each iteration of Bellman backup makes approximation worse! Even for this trivial problem projected VI diverges.

17. Understanding the Problem What went wrong? Exact Bellman backups reduces error in max-norm Least squares (= projection) non-expansive in L 2 norm But may increase max-norm distance! Conclusion: Alternating Bellman backups and projection is risky business

18. Overview Motivation LSPI Derivation from Least-Squares Temporal Difference Learning Experimental results

19. How does LSPI fix these? LSPI performs approximate policy iteration PI involves policy evaluation and policy improvement Uses a variant of least-squares temporal difference learning (LSTD) for approx. policy evaluation [Bratdke & Barto 96] Stability: LSTD directly solves for the fixed point of the approximate Bellman equation for policy values With singular-value decomposition (SVD), this is always well defined Data efficiency LSTD finds best approximation for any finite data set Makes a single pass over the data for each policy Can be implemented incrementally

20. OK, Whats LSTD?

21. Deriving LSTD is a linear function in the column space of 1 k , that is, K basis functions # states 1 (s1) 2 (s1)... 1 (s2) 2 (s2) . . . = assigns a value to every state

22. Suppose we know true value of policy We would like the following: Least squares weights minimizes squared error Least squares projection is then Textbook least squares projection operator Sometimes called pseudoinverse

23. But we dont know V Recall fixed-point equation for policies Will solve a projected fixed-point equation: Substituting least squares projection into this gives: Solving for w:

24. Almost there Matrix to invert is only K x K But Expensive to construct matrix (e.g. P is |S|x|S|) Presumably we are using LSPI because |S| is enormous We dont know P We dont know R

25. Using Samples for K basis functions 1 (s1) 2 (s1)... 1 (s2) 2 (s2) . . . Idea: Replace enumeration of states with sampled states states samples Suppose we have state transition samples of the policy running in the MDP: {(s i ,a i ,r i ,s i )}

26. Using Samples for R r 1 r 2 . . . Idea: Replace enumeration of reward with sampled rewards samples Suppose we have state transition samples of the policy running in the MDP: {(s i ,a i ,r i ,s i )} R =

27. Using Samples for P K basis functions 1 (s1) 2 (s1)... 1 (s2) 2 (s2) . . . Idea: Replace expectation over next states with sampled next states. s from (s,a,r,s)

28. Putting it Together LSTD needs to compute: The hard part of which is B the kxk matrix: Both B and b can be computed incrementally for each (s,a,r,s) sample: (initialize to zero) from previous slide

29. LSTD Algorithm Collect data by executing trajectories of current policy For each (s,a,r,s) sample:

30. LSTD Summary Does O(k 2 ) work per datum Linear in amount of data. Approaches model-based answer in limit Finding fixed point requires inverting matrix Fixed point almost always exists Stable; efficient

31. Approximate Policy Iteration with LSTD Start with random weights w (i.e. value function) Repeat Until Convergence Evaluate using LSTD Generate sample trajectories of Use LSTD to produce new weights w ( w gives an approx. value function of ) = greedy( ) // policy improvement Policy Iteration: iterates between policy improvement and policy evaluation Idea: use LSTD for approximate policy evaluation in PI

32. What Breaks? No way to execute greedy policy without a model Approximation is biased by current policy We only approximate values of states we see when executing the current policy LSTD is a weighted approximation toward those states Can result in Learn-forget cycle of policy iteration Drive off the road; learn that its bad New policy never does this; forgets that its bad Not truly a batch method Data must be collected from current policy for LSTD

33. LSPI LSPI is similar to previous loop but replaces LSTD with a new algorithm LSTDQ LSTD: produces a value function Requires samples from policy under consideration LSTDQ: produces a Q-function for current policy Can learn Q-function for policy from any (reasonable) set of samples---sometimes called an off-policy method No need to collect samples from current policy Disconnects policy evaluation from data collection Permits reuse of data across iterations! Truly a batch method.

34. Implementing LSTDQ Both LSTD and LSTDQ compute: But LSTDQ basis functions are indexed by actions defines greedy policy: For each (s,a,r,s) sample:

35. Running LSPI There is a Matlab implementation available! 1. Collect a database of (s,a,r,s) experiences (this is the magic step) 2. Start with random weights (= random policy) 3. Repeat Evaluate current policy against database Run LSTDQ to generate new set of weights New weights imply new Q-function and hence new policy Replace current weights with new weights Until convergence

36. Results: Bicycle Riding Watch random controller operate simulated bike Collect ~40,000 (s,a,r,s) samples Pick 20 simple feature functions ( 5 actions) Make 5-10 passes over data (PI steps) Reward was based on distance to goal + goal achievement Result: Controller that balances and rides to goal

37. Bicycle Trajectories

38. What about Q-learning? Ran Q-learning with same features Used experience replay for data efficiency

39. Q-learning Results

40. LSPI Robustness

41. Some key points LSPI is a batch RL algorithm Can generate trajectory data anyway you want Induces a policy based on global optimization over full dataset Very stable with no parameters that need tweaking

42. So, whats the bad news? LSPI does not address the exploration problem It decouples data collection from policy optimization This is often not a major issue, but can be in some cases k 2 can sometimes be big Lots of storage Matrix inversion can be expensive Bicycle needed shaping rewards Still havent solved Feature selection (issue for all machine learning, but RL seems even more sensitive)

Related