AI Wiki中文/EN

Markov decision processes

马尔可夫决策过程

Model actions with uncertain outcomes, distinguish policies from fixed plans, and evaluate a two-attempt delivery decision.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A plan must say what to do after a failed attempt

A digital package must be delivered. A standard attempt costs 1 and succeeds with probability 0.75. A priority attempt costs 3 and always succeeds. Successful delivery earns 5 once; after success, the process ends. If a standard attempt fails, the package remains pending.

With only one attempt left, standard delivery has expected reward 0.75(5−1)+0.25(−1)=2.750.75(5-1)+0.25(-1)=2.75, above priority delivery’s reward 2. With another attempt available after failure, the future opportunity changes the total value. A Markov decision process, or MDP, makes those transitions, rewards, and choices explicit.

State, action, transition, reward, and return

Here the state is pending or done. In pending, choose standard or priority. An outcome specifies the next state and the reward received on that transition. A finite MDP can represent these jointly:

p(s′,r∣s,a)=P(St+1=s′,Rt+1=r∣St=s,At=a),∑s′,rp(s′,r∣s,a)=1.p(s',r\mid s,a)=P(S_{t+1}=s',R_{t+1}=r\mid S_t=s,A_t=a),\qquad \sum_{s',r}p(s',r\mid s,a)=1.

The Markov assumption says that, once the present state and action are given, earlier history does not further change this next-outcome distribution. In our model, every failed standard attempt leaves the same future success probability 0.75. If repeated failures indicated a damaged connection and changed that probability, pending alone would be insufficient state information. Sutton and Barto, second-edition working draft, Sections 3.5–3.6

A policy specifies actions conditional on the state: π(a∣s)\pi(a\mid s) is an action probability, or a deterministic rule chooses one action. A fixed list such as “standard, then priority” does not by itself say to stop if the first attempt succeeds. A policy does: act only while pending. For a finite horizon, the policy may also depend on the number of steps remaining. CS188, Markov Decision Processes

For a discount 0≤γ<10\le\gamma<1, the continuing return is:

Gt=∑k=0∞γkRt+k+1=Rt+1+γGt+1.G_t=\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}=R_{t+1}+\gamma G_{t+1}.

Bounded rewards make this sum well-defined and bounded in absolute value by Rmax⁡/(1−γ)R_{\max}/(1-\gamma). A finite-horizon return instead stops after a specified number of transitions and may use γ=1\gamma=1. Discounting expresses how the objective weights later rewards; it is not the transition success probability. An absorbing terminal state with zero subsequent reward is one way to unify episodic and continuing notation. Sutton and Barto, working draft, Sections 3.3–3.4

Enumerate outcomes before building a learner

The complete program below evaluates the fixed policy “choose standard whenever pending” for two undiscounted attempts. It enumerates outcomes rather than sampling, so its answer has no Monte Carlo noise. The model stores reward after cost: standard success gives 4, standard failure gives -1, and priority success gives 2.

Current stateActionNext stateProbabilityNet reward
pendingstandarddone0.754
pendingstandardpending0.25-1
pendingprioritydone12
donestopdone10
import math

model = {
    'pending': {
        'standard': [(0.75,'done',4), (0.25,'pending',-1)],
        'priority': [(1.0,'done',2)]},
    'done': {'stop': [(1.0,'done',0)]}}
policy = {'pending':'standard','done':'stop'}

def validate(model):
    for actions in model.values():
        if not actions:
            raise ValueError("each state needs an action, including terminal stop")
        for outcomes in actions.values():
            if not outcomes or any(not math.isfinite(p) or p < 0 or s not in model
                                   or not math.isfinite(r) for p,s,r in outcomes):
                raise ValueError("invalid transition outcome")
            if not math.isclose(sum(p for p,_,_ in outcomes),1,abs_tol=1e-12,rel_tol=0):
                raise ValueError("transition probabilities must sum to one")

def evaluate_two_attempts():
    validate(model)
    leaves = [(1.0,'pending',0)]
    for _ in range(2):
        leaves = [(mass*p,next_state,total+reward)
                  for mass,state,total in leaves
                  for p,next_state,reward in model[state][policy[state]]]
    return leaves

outcomes = evaluate_two_attempts()
assert math.isclose(sum(p for p,_,_ in outcomes),1)
assert sum(p*r for p,_,r in outcomes) == 3.4375
assert sum(p for p,s,_ in outcomes if s == 'done') == 0.9375
assert sorted((p,r) for p,_,r in outcomes) == [(0.0625,-2),(0.1875,3),(0.75,4)]
assert sum(p*r for p,_,r in model['pending']['standard']) == 2.75
try:
    validate({'s':{'a':[(0.2,'s',1)]}})
except ValueError:
    pass
else:
    raise AssertionError("unnormalized transition accepted")

The final outcomes have total returns 4, 3, and -2 with probabilities 0.75, 0.1875, and 0.0625. Their expected return is 3.4375. The success probability is 0.9375, which is a different quantity from expected reward. Adding costs to the model makes that distinction visible.

Enumerating a horizon of HH with at most bb outcomes per chosen action takes O(bH)O(b^H) work in the worst case, with comparable leaf storage here. This deliberately small exact calculation is useful for checking a dynamic-programming implementation. It does not scale to long horizons, and it is policy evaluation, not policy learning or an optimality proof.

Reward design and state sufficiency are modeling choices

A model can be internally consistent while omitting the real objective. If a missed deadline has a penalty, the terminal outcome needs that penalty. If a late delivery is worth less, remaining time affects decisions. Finite-horizon policies can depend on time even when the physical transition probabilities do not change; include the horizon index in the decision rule or augment the state.

The Markov assumption concerns the chosen state representation, not a claim that the world has no history. Hidden conditions can require a partially observable model or a belief state. Likewise, specifying transition probabilities does not mean they are known accurately. They may be estimated with substantial uncertainty.

An MDP is a problem model. Dynamic programming assumes access to a transition model; reinforcement learning can estimate values or policies from interaction data. A recorded trajectory alone is not a full MDP. Finally, a true terminal state and an artificial data-collection cutoff differ: a cutoff need not imply that future value is zero.

Keep reward, probability, and horizon separate

  1. What is the standard attempt’s immediate expected reward? Answer: 2.75, including the failure cost.
  2. Under the two-attempt standard policy, what is the probability of no delivery? Answer: 0.252=0.06250.25^2=0.0625, under the stated unchanged transition probability after failure.
  3. If the first attempt succeeds, should the policy earn another success reward at done? Answer: no. The terminal self-loop has zero reward; delivery earns its benefit once.
  4. Does the code establish that its fixed policy is optimal for every horizon and reward setting? Answer: no. It evaluates one specified policy in one specified model.

The model makes comparisons possible

The Bellman equations turn the return recursion into equations for state and action values. Model-based planning, temporal-difference learning, and policy optimization then address different parts of the solution process. Before comparing them, make the state, action availability, reward timing, horizon, and terminal behavior agree. This article cites an explicitly identified 2014–2015 working draft of Sutton and Barto, not the final 2018 edition.

Make a prediction, then check

A standard attempt succeeds with probability 0.75, earning 4 on success and −1 on failure. What is its immediate expected reward?

Choose one answer

Learning objectives

  • Specify states, actions, joint outcomes, reward timing, and the Markov assumption.
  • Enumerate finite-horizon policy returns and distinguish success probability from expected reward.

Prerequisites & connections

Explore related knowledge →

References

  1. CS188 Textbook — Markov Decision Processes
    UC Berkeley CS188 course contributors
  2. Reinforcement Learning: An Introduction — second-edition working draft (2014–2015)
    Richard S. Sutton; Andrew G. Barto · 2015

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.

  • Enumerated two-attempt returns 4, 3, −2 and their probabilities; recalculated expectation 3.4375, success probability 0.9375, and immediate expectation 2.75.
  • Checked zero reward on terminal self-loops, rejection of unnormalized probabilities, and horizon/policy-evaluation boundaries; identified the actual source as a draft rather than the final second edition.
  • Compared arguments, modeling assumptions, numbers, and exercise answers across languages; structural checks separately compare display formulas, code, references, and main sections. No independent human peer review.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.