Skip to content

Commit

Permalink
type properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Petrik committed Dec 19, 2024
1 parent a1efc62 commit 86eb095
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LeanMDPs/Expected.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variable [DecidableEq σ] [DecidableEq α]

variable {m : MDP σ α}

#check (1 : ℝ≥0) * (1 : ℝ)
#check Subtype

/--
Value function type for value functions that are
Expand Down
10 changes: 4 additions & 6 deletions LeanMDPs/FinPr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ structure FinPr (τ : Type u) : Type u where
prob : FinP Ω


#check (HMul ℝ≥0 ℝ ℝ)

/- --------------------------------------------------------------- -/
namespace FinP

-- This is the random variable output type
variableρ': Type}
variable [HMul ρ' ρ ρ] [HMul ℕ ρ ρ] [AddCommMonoid ρ] [Coe ℝ≥0 ρ']
variable {ρ : Type}
variable [HMul ℝ≥0 ρ ρ] [HMul ℕ ρ ρ] [AddCommMonoid ρ]


/-- Probability of a sample -/
def prob (pr : FinPr τ) (t : pr.Ω) := pr.prob.p t.1

/-- Expected value of random variable x : Ω → ρ -/
def expect (pr : FinPr τ) (x : τ → ρ) : ρ := ∑ ω ∈ pr.Ω, (↑(pr.prob.p ω) : ρ') * x ω

def expect (pr : FinPr τ) (x : τ → ρ) : ρ := ∑ ω ∈ pr.Ω, pr.prob.p ω * x ω

/-- Boolean indicator function -/
def 𝕀 (cond : τ → Bool) (ω : τ) : ℕ := (cond ω).rec 0 1
Expand Down Expand Up @@ -79,7 +77,7 @@ IMPORTANT: conditional expectation for zero probability event is zero
noncomputable
def expect_cnd (pr : FinPr τ) (x : τ → ρ) (c : τ → Bool) : ρ :=
let f := (fun ω ↦ (𝕀 c ω) * x ω)
↑((1:ℝ≥0)/(ℙ pr c) : ρ') * (expect (ρ' := ρ') pr f)
(1:ℝ≥0)/(ℙ pr c) * (expect pr f)

noncomputable
abbrev 𝔼c : FinPr τ → (τ → ρ) → (τ → Bool) → ρ := expect_cnd
Expand Down

0 comments on commit 86eb095

Please sign in to comment.