Reinforcement Learning Exercise
Implementations of various reinforcement learning algorithms including MDPs, Q-Learning, and Policy Gradients for custom environments.
Key Features
Core technologies and system features.
Markov Decision Processes (Lab 1)
Concepts: Fundamental Tabular Methods, MDPs, Value Functions, Value Iteration, and Model-Free RL (such as Tabular Q-Learning). Application: Agents learning to navigate grid worlds and play Pacman using basic tabular methods.
Function Approximation (Lab 2)
Concepts: Linear Function Approximation, LSTD, and Deep Q-Networks. Application: Scaling up RL to handle larger state spaces where tabular methods are no longer feasible by using neural networks or feature extractors.
Policy Gradients (Lab 3)
Concepts: Policy Gradient Methods, Actor-Critic Architectures, Natural Gradients, and Model-Based Exploration. Application: Training agents in environments with continuous action spaces (like controlling a pendulum).
POMDP and Multi-Agent RL (Lab 4)
Concepts: POMDPs, Belief MDPs, Deep RL for POMDPs, and Cooperative MARL algorithms. Application: Dealing with uncertainty when the environment is not fully observable and coordinating multiple agents.
Performance Graphs
Visualizations of model performance and results across experiments.
Trained on a single RTX 4090 (24 GB VRAM)
Project Source Code
Explore the primary logical modules.
1import mdp, util23from learningAgents import ValueEstimationAgent4import collections56class ValueIterationAgent(ValueEstimationAgent):7 """8 * Please read learningAgents.py before reading this.*910 A ValueIterationAgent takes a Markov decision process11 (see mdp.py) on initialization and runs value iteration12 for a given number of iterations using the supplied13 discount factor.14 """15 def __init__(self, mdp, discount = 0.9, iterations = 100):16 """17 Your value iteration agent should take an mdp on18 construction, run the indicated number of iterations19 and then act according to the resulting policy.2021 Some useful mdp methods you will use:22 mdp.getStates()23 mdp.getPossibleActions(state)24 mdp.getTransitionStatesAndProbs(state, action)25 mdp.getReward(state, action, nextState)26 mdp.isTerminal(state)27 """28 self.mdp = mdp29 self.discount = discount30 self.iterations = iterations31 self.values = util.Counter() # A Counter is a dict with default 032 self.runValueIteration()3334 def runValueIteration(self):35 # Write value iteration code here36 for _ in range(self.iterations):37 newValues = util.Counter()38 for state in self.mdp.getStates():39 if self.mdp.isTerminal(state):40 continue41 bestAction = self.computeActionFromValues(state)42 if bestAction is not None:43 newValues[state] = self.computeQValueFromValues(state, bestAction)44 for state in self.mdp.getStates():45 self.values[state] = newValues[state]46 def getValue(self, state):47 """48 Return the value of the state (computed in __init__).49 """50 return self.values[state]515253 def computeQValueFromValues(self, state, action):54 """55 Compute the Q-value of action in state from the56 value function stored in self.values.57 """58 qValue = 059 for nextState, prob in self.mdp.getTransitionStatesAndProbs(state, action):60 reward = self.mdp.getReward(state, action, nextState)61 qValue += prob * (reward + self.discount * self.values[nextState])62 return qValue6364 def computeActionFromValues(self, state):65 """66 The policy is the best action in the given state67 according to the values currently stored in self.values.6869 You may break ties any way you see fit. Note that if70 there are no legal actions, which is the case at the71 terminal state, you should return None.72 """73 if self.mdp.isTerminal(state):74 return None7576 bestAction = None77 bestQValue = float("-inf")7879 for action in self.mdp.getPossibleActions(state):80 qValue = self.computeQValueFromValues(state, action)81 if qValue > bestQValue:82 bestQValue = qValue83 bestAction = action8485 return bestAction8687 def getPolicy(self, state):88 return self.computeActionFromValues(state)8990 def getAction(self, state):91 "Returns the policy at the state (no exploration)."92 return self.computeActionFromValues(state)9394 def getQValue(self, state, action):95 return self.computeQValueFromValues(state, action)Live Simulation Output
Simulated console execution.
Source Code
GitHub repositories for this project.