MDP and reward design
Quick answer
A Markov decision process (MDP) models sequential choices using states, actions, transition probabilities and rewards. Unlike supervised learning, a choice changes which observations and rewards arrive later. A policy specifies how the agent chooses actions. Examples are static Python snippets tested locally on CPU; Only Python standard-library modules are required. ByteMind execution is unverified.
Discounted return
from fractions import Fractiong=Fraction(1,2)r=[2,4,8]print(sum(v*g**i for i,v in enumerate(r)))Expected output (locally tested): 6. Each future reward is discounted by an additional factor of one half.
How it works
An MDP has state space S, action space A, transition/reward distribution p(s_next,r | s,a), discount gamma and an initial-state distribution. The Markov property means that the current state and action suffice to specify the next-state and reward distribution; it does not mean consecutive observations are independent. An observation may hide relevant state, making the problem partially observable. At time t the agent sees s_t, chooses a_t and receives r_(t+1) and s_(t+1). Return G_t sums future discounted rewards: r_(t+1) + gamma*r_(t+2) + ... . For episodic tasks stop at the terminal state; for continuing bounded rewards choose gamma < 1 to ensure a finite discounted return. Gamma zero values immediate rewards only. Reward design encodes the objective, not necessarily the actual desired outcome. A per-step penalty encourages short routes, but an excessive penalty may encourage premature failure. A reward for visiting a cell may encourage repeated loops rather than reaching a goal. Test reward design with counterexamples and separate success, failure and episode length metrics. A true terminal state has no future reward; an external rollout cap is a truncation, not necessarily termination. All examples here are local simulations with no real-world actions.
A reward loophole
Expected output (locally tested): 4 8. The finite reward design prefers looping even though the intended goal is reached only by the first route.
Common mistakes
Do not assume observations are Markov, reward equals human intent, or every episode cap is terminal. Specify hidden information, test reward loopholes and distinguish truncation from termination.
Practice and next steps
Compare returns for a two-step goal route [-1,10] and a four-step route [-1,-1,-1,10] at gamma=0.9. Then change the step cost and discuss incentives.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
MDP and reward design — knowledge check
Apply mdp and reward design to small examples and debugging scenarios.
What makes a state Markov?
What is a policy?
What does gamma=0 value?
What is reward hacking?
What is an external time cap?