Xie–Ma–Xin bounded inventory, shattering and risk definitions
DefinitionXMX_NonstationaryInventoryBounded trajectories and base-stock levels; finite maximum inventory formula with lead time; normalized inventory; average K=0 backlog loss; fat shattering; true and empirical risks; one-sided GE and expected EE over IID trajectories.
import Mathlib.Analysis.SpecialFunctions.Sqrt
import Mathlib.MeasureTheory.Integral.Bochner.Basic
import Mathlib.MeasureTheory.Constructions.Pi
import Mathlib.Data.Finset.Lattice.Fold
set_option autoImplicit false
open scoped BigOperators
open MeasureTheory
namespace XMX
/-- A trajectory has T+L coordinates; coordinate 0 is period 1. -/
abbrev Demand (T L : ℕ) (U : ℝ) := Fin (T + L) → Set.Icc (0 : ℝ) U
abbrev Levels (T L : ℕ) (U : ℝ) := Fin (T + L) → Set.Icc (0 : ℝ) (((L : ℝ) + 1) * U)
/-- Formula for post-replenishment inventory in period L+k+1.
The maximum is nonempty because its index type is Fin (k+1).
For valid k<T the formula uses only the trajectory and level coordinates. -/
noncomputable def inventory (T L : ℕ) (U : ℝ)
(S : Levels T L U) (d : Demand T L U) (k : ℕ) : ℝ :=
let sv : ℕ → ℝ := fun j => if hj : j < T + L then (S ⟨j, hj⟩ : ℝ) else 0
let dv : ℕ → ℝ := fun j => if hj : j < T + L then (d ⟨j, hj⟩ : ℝ) else 0
(Finset.univ : Finset (Fin (k + 1))).sup'
Finset.univ_nonempty
(fun j => sv j - ∑ r ∈ Finset.Ico (j : ℕ) (k + L), dv r)
noncomputable def normalizedInventory (T L : ℕ) (U : ℝ)
(k : ℕ) (S : Levels T L U) (d : Demand T L U) : ℝ :=
inventory T L U S d k / (((L : ℝ) + 1) * U)
/-- Holding/backlog cost, with no fixed ordering cost. -/
def cost (h b x : ℝ) : ℝ := h * max x 0 + b * max (-x) 0
/-- Time average over periods L+1,...,T+L; not total cost. -/
noncomputable def loss (T L : ℕ) (U h b : ℝ)
(S : Levels T L U) (d : Demand T L U) : ℝ :=
(∑ k : Fin T,
cost h b (inventory T L U S d k -
(d ⟨L + k, by omega⟩ : ℝ))) / (T : ℝ)
/-- Witnessed fat shattering, using the paper's strict/non-strict convention. -/
def Shatters {P X : Type*} (f : P → X → ℝ) (γ : ℝ) (m : ℕ)
(x : Fin m → X) (τ : Fin m → ℝ) : Prop :=
∀ A : Fin m → Bool, ∃ p : P, ∀ i,
if A i then τ i + γ < f p (x i) else f p (x i) ≤ τ i - γ
noncomputable def risk {P X : Type*} [MeasurableSpace X]
(μ : Measure X) (f : P → X → ℝ) (p : P) : ℝ := ∫ x, f p x ∂μ
noncomputable def empiricalRisk {P X : Type*}
(N : ℕ) (f : P → X → ℝ) (data : Fin N → X) (p : P) : ℝ :=
(∑ i, f p (data i)) / (N : ℝ)
/-- One-sided GE; this supremum is not the absolute uniform deviation. -/
noncomputable def generalizationError {P X : Type*} [MeasurableSpace X]
(N : ℕ) (μ : Measure X) (f : P → X → ℝ) (data : Fin N → X) : ℝ :=
⨆ p, risk μ f p - empiricalRisk N f data p
noncomputable def expectedGE {P X : Type*} [MeasurableSpace X]
(N : ℕ) (μ : Measure X) [IsProbabilityMeasure μ] (f : P → X → ℝ) : ℝ :=
∫ data, generalizationError N μ f data ∂Measure.pi (fun _ : Fin N => μ)
/-- Excess risk of an actual selected policy relative to a fixed comparison policy. -/
noncomputable def expectedEE {P X : Type*} [MeasurableSpace X]
(N : ℕ) (μ : Measure X) [IsProbabilityMeasure μ] (f : P → X → ℝ)
(select : (Fin N → X) → P) (pstar : P) : ℝ :=
∫ data, risk μ f (select data) - risk μ f pstar
∂Measure.pi (fun _ : Fin N => μ)
end XMX
Read-back
What the Lean code literally says, in plain math · gpt-6
For arbitrary natural numbers and real , set and . A demand trajectory is a function , and a level vector is a function ; indices start at zero. Extend each such function to all natural indices by setting and for , and both extensions to zero for . For every natural , define and its normalized version . The maximum always has entries; the sum is over natural indices and is zero when its index interval is empty. There is no requirement that in these definitions, so the zero extensions apply when needed. For arbitrary real , the cost is , with no sign restrictions on or . The trajectory loss is the time average ; these demand indices lie below whenever the corresponding summand exists. All real division is total: division by zero is zero, so the normalized inventory is zero when , and the loss is zero when . When and , neither trajectories nor level vectors exist; when , each of their function types has its unique empty function even if the target interval is empty. For arbitrary types , function , real margin , natural , indexed points , and real thresholds , the shattering predicate means that for every Boolean labeling of these indices there exists such that, for every , implies and implies . No positivity restriction on or distinctness restriction on the indexed points is part of this definition; for , the predicate is equivalent to being nonempty. If has any measurable-space structure and is any measure on , define the risk . For arbitrary natural and data , define the empirical risk , which is zero for , and the generalization error , with no absolute value. This is the total real supremum: it agrees with the usual supremum for a nonempty set bounded above and is zero for an empty set or a set unbounded above. If additionally is a probability measure, let on ; define the expected generalization error as and, for any function and any , define the expected excess error as . The selector and comparison parameter have no optimality requirements in these definitions. No measurable-space structure on , measurability of or the selector, or integrability hypotheses are imposed by the definitions; the integrals are total real Bochner integrals, equal to zero when their integrands are not integrable. For , the data space consists of the single empty function and the product measure is the empty product measure.