Policy iteration
DefinitionPolicy improvement step#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards \(r(s, a)\) and stochastic transition probabilities \(P(s' \mid s, a)\), and let \(0 \le \gamma < 1\). The improvement of a deterministic policy \(\pi : S \to A\) is a fixed choice of policy greedy for the value \(V^\pi\) of \(\pi\): in each state \(s\) it takes a chosen action \(a\) maximizing \(r(s, a) + \gamma \sum_{s'} P(s' \mid s, a) V^\pi(s')\) over \(A\) (ties broken arbitrarily).
noncomputable def improve (π : S → A) : S → A :=
greedy M γ (policyValue M γ hM hγ0 hγ1 π)
noncomputable def greedy (M : MDP S A K) (γ : K) (V : S → K) (s : S) : A :=
(Finset.univ.exists_max_image (qValue M γ V s) Finset.univ_nonempty).choose
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:105
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
Uses 4 · Used by 6
DefinitionPolicy iteration#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Policy iteration run for \(n\) steps from a deterministic policy \(\pi : S \to A\) is the policy obtained from \(\pi\) by applying the policy improvement step \(n\) times.
noncomputable def policyIteration (n : ℕ) (π : S → A) : S → A :=
(improve hM hγ0 hγ1)^[n] π
noncomputable def improve (π : S → A) : S → A :=
greedy M γ (policyValue M γ hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:54
Uses 3 · Used by 3
TheoremValues below their Bellman image lie below the policy value#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Let \(\pi\) be a deterministic policy, with Bellman operator \(T^\pi\) and value \(V^\pi\). If \(V : S \to \mathbb{R}\) satisfies \(V(s) \le (T^\pi V)(s)\) for every state \(s\), then \(V(s) \le V^\pi(s)\) for every state \(s\).
theorem le_policyValue_of_le_policyBellman (π : S → A) {V : S → ℝ}
(h : V ≤ policyBellman M γ π V) : V ≤ policyValue M γ hM hγ0 hγ1 π
def policyBellman (M : MDP S A K) (γ : K) (π : S → A) (V : S → K) : S → K :=
fun s => qValue M γ V s (π s)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:90
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
Uses 5 · Used by 1
TheoremPolicy improvement theorem#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\). For every deterministic policy \(\pi\), the improved policy \(\pi'\), which is greedy for \(V^\pi\), satisfies \(V^\pi(s) \le V^{\pi'}(s)\) for every state \(s\).
theorem policyValue_le_policyValue_improve (π : S → A) :
policyValue M γ hM hγ0 hγ1 π ≤ policyValue M γ hM hγ0 hγ1 (improve hM hγ0 hγ1 π)
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def improve (π : S → A) : S → A :=
greedy M γ (policyValue M γ hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:54
Uses 11 · Used by 2
TheoremImprovement stalls exactly at optimal policies#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\) and \(V^*\) for the optimal value. For every deterministic policy \(\pi\), with improved policy \(\pi'\), we have \(V^{\pi'} = V^\pi\) if and only if \(V^\pi = V^*\) (as functions on \(S\)).
theorem policyValue_improve_eq_iff (π : S → A) :
policyValue M γ hM hγ0 hγ1 (improve hM hγ0 hγ1 π) = policyValue M γ hM hγ0 hγ1 π ↔
policyValue M γ hM hγ0 hγ1 π = optimalValue M γ hM hγ0 hγ1
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def improve (π : S → A) : S → A :=
greedy M γ (policyValue M γ hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:54
noncomputable def optimalValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) : S → ℝ :=
ContractingWith.fixedPoint _ (bellman_contracting hM hγ0 hγ1)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:225
Uses 13 · Used by 1
TheoremAway from optimality, improvement changes the value#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\) and \(V^*\) for the optimal value. If \(V^\pi \ne V^*\), then the improved policy \(\pi'\) satisfies \(V^{\pi'} \ne V^\pi\) (as functions on \(S\)).
theorem policyValue_improve_ne (π : S → A)
(h : policyValue M γ hM hγ0 hγ1 π ≠ optimalValue M γ hM hγ0 hγ1) :
policyValue M γ hM hγ0 hγ1 (improve hM hγ0 hγ1 π) ≠ policyValue M γ hM hγ0 hγ1 π
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def optimalValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) : S → ℝ :=
ContractingWith.fixedPoint _ (bellman_contracting hM hγ0 hγ1)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:225
noncomputable def improve (π : S → A) : S → A :=
greedy M γ (policyValue M γ hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:54
Uses 6 · Used by 1
TheoremPolicy iteration never decreases the value#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\), and \(\pi_k\) for the policy after \(k\) steps of policy iteration from \(\pi\). If \(i \le j\), then \(V^{\pi_i}(s) \le V^{\pi_j}(s)\) for every state \(s\).
theorem policyValue_policyIteration_mono (π : S → A) {i j : ℕ} (hij : i ≤ j) :
policyValue M γ hM hγ0 hγ1 (policyIteration hM hγ0 hγ1 i π) ≤
policyValue M γ hM hγ0 hγ1 (policyIteration hM hγ0 hγ1 j π)
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def policyIteration (n : ℕ) (π : S → A) : S → A :=
(improve hM hγ0 hγ1)^[n] π
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:58
Uses 6 · Used by 2
TheoremOnce optimal, policy iteration stays optimal#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\), \(V^*\) for the optimal value, and \(\pi_k\) for the policy after \(k\) steps of policy iteration from \(\pi\). If \(i \le j\) and \(V^{\pi_i} = V^*\), then \(V^{\pi_j} = V^*\).
theorem policyValue_policyIteration_of_eq (π : S → A) {i j : ℕ} (hij : i ≤ j)
(h : policyValue M γ hM hγ0 hγ1 (policyIteration hM hγ0 hγ1 i π) =
optimalValue M γ hM hγ0 hγ1) :
policyValue M γ hM hγ0 hγ1 (policyIteration hM hγ0 hγ1 j π) =
optimalValue M γ hM hγ0 hγ1
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def policyIteration (n : ℕ) (π : S → A) : S → A :=
(improve hM hγ0 hγ1)^[n] π
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:58
noncomputable def optimalValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) : S → ℝ :=
ContractingWith.fixedPoint _ (bellman_contracting hM hγ0 hγ1)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:225
Uses 7 · Used by 1
TheoremPolicy iteration terminates#✓fully proved
Let \(M\) be a Markov decision process with a finite set of states \(S\), a finite nonempty set of actions \(A\), real rewards and stochastic transition probabilities, and let \(0 \le \gamma < 1\). Write \(V^\pi\) for the value of a deterministic policy \(\pi : S \to A\), \(V^*\) for the optimal value, and \(N = |A|^{|S|}\) for the number of deterministic policies. For every deterministic policy \(\pi\), the policy \(\pi_N\) obtained after \(N\) steps of policy iteration from \(\pi\) is optimal: \(V^{\pi_N} = V^*\).
theorem policyValue_policyIteration [DecidableEq S] (π : S → A) :
policyValue M γ hM hγ0 hγ1 (policyIteration hM hγ0 hγ1 (Fintype.card (S → A)) π) =
optimalValue M γ hM hγ0 hγ1
noncomputable def policyValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) (π : S → A) : S → ℝ :=
ContractingWith.fixedPoint _ (policyBellman_contracting hM hγ0 hγ1 π)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:230
noncomputable def policyIteration (n : ℕ) (π : S → A) : S → A :=
(improve hM hγ0 hγ1)^[n] π
CSLibExt/Algorithms/Lean/MDP/PolicyIteration.lean:58
noncomputable def optimalValue (M : MDP S A ℝ) (γ : ℝ) (hM : M.Stochastic) (hγ0 : 0 ≤ γ)
(hγ1 : γ < 1) : S → ℝ :=
ContractingWith.fixedPoint _ (bellman_contracting hM hγ0 hγ1)
CSLibExt/Algorithms/Lean/MDP/ValueIteration.lean:225
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.