Theory Gaussian_Process
theory Gaussian_Process
imports Gaussian_Finite_Dimensional "HOL-Probability.Projective_Limit"
begin
section ‹From consistent laws to a Gaussian process›
definition ordered_times :: "real set ⇒ real list" where
"ordered_times T = sorted_list_of_set T"
definition time_index :: "real set ⇒ real ⇒ nat" where
"time_index T t = (THE i. i < length (ordered_times T) ∧ ordered_times T ! i = t)"
lemma ordered_times_finite:
assumes "finite T"
shows "set (ordered_times T) = T" "distinct (ordered_times T)"
"sorted (ordered_times T)" "length (ordered_times T) = card T"
using assms by (simp_all add: ordered_times_def)
lemma time_index_unique:
assumes finite: "finite T" and t: "t ∈ T"
shows "time_index T t < length (ordered_times T)"
"ordered_times T ! time_index T t = t"
proof -
have membership: "t ∈ set (ordered_times T)"
using ordered_times_finite[OF finite] t by simp
then obtain i where i: "i < length (ordered_times T)"
"ordered_times T ! i = t" by (auto simp: in_set_conv_nth)
have unique: "j = i" if "j < length (ordered_times T)"
"ordered_times T ! j = t" for j
using ordered_times_finite(2)[OF finite] that i
by (auto simp: distinct_conv_nth)
have equivalence: "(j < length (ordered_times T) ∧ ordered_times T ! j = t) ⟷ j = i"
for j using i unique by blast
have index: "time_index T t = i"
unfolding time_index_def by (simp only: equivalence; rule the_equality; simp)
show "time_index T t < length (ordered_times T)"
"ordered_times T ! time_index T t = t" using index i by auto
qed
lemma ordered_times_delete:
assumes finite: "finite T" and t: "t ∈ T"
shows "ordered_times (T - {t}) =
delete_time (ordered_times T) (time_index T t)"
proof -
let ?xs = "ordered_times T"
let ?j = "time_index T t"
have j: "?j < length ?xs" and nth: "?xs ! ?j = t"
using time_index_unique[OF finite t] by auto
have absent: "t ∉ set (take ?j ?xs)"
proof
assume "t ∈ set (take ?j ?xs)"
then obtain k where k: "k < ?j" "?xs ! k = t"
by (auto simp: in_set_conv_nth)
have "k = ?j"
using k nth j ordered_times_finite(2)[OF finite]
by (auto simp: distinct_conv_nth)
with k show False by simp
qed
have split: "?xs = take ?j ?xs @ t # drop (Suc ?j) ?xs"
using id_take_nth_drop[OF j] nth by simp
have remove: "remove1 t ?xs = delete_time ?xs ?j"
by (subst split) (simp add: delete_time_def remove1_append absent)
have "ordered_times (T - {t}) = remove1 t ?xs"
using finite by (simp add: ordered_times_def sorted_list_of_set_remove)
with remove show ?thesis by simp
qed
definition set_coordinates :: "real set ⇒ (nat ⇒ real) ⇒ real ⇒ real" where
"set_coordinates T w = (λt∈T. w (time_index T t))"
lemma set_coordinates_delete:
assumes finite: "finite T" and t: "t ∈ T"
shows "set_coordinates (T - {t})
(delete_coordinate (length (ordered_times T)) (time_index T t) w) =
restrict (set_coordinates T w) (T - {t})"
proof (rule ext)
fix s
show "set_coordinates (T - {t})
(delete_coordinate (length (ordered_times T)) (time_index T t) w) s =
restrict (set_coordinates T w) (T - {t}) s"
proof (cases "s ∈ T - {t}")
case False
have lhs: "set_coordinates (T - {t})
(delete_coordinate (length (ordered_times T)) (time_index T t) w) s = undefined"
using False by (simp only: set_coordinates_def restrict_def if_False)
have rhs: "restrict (set_coordinates T w) (T - {t}) s = undefined"
using False by (simp only: restrict_def if_False)
show ?thesis using lhs rhs by simp
next
case True
let ?xs = "ordered_times T"
let ?ys = "ordered_times (T - {t})"
let ?j = "time_index T t"
let ?i = "time_index (T - {t}) s"
let ?k = "if ?i < ?j then ?i else Suc ?i"
have j: "?j < length ?xs" by (rule time_index_unique(1)[OF finite t])
have i: "?i < length ?ys" and y: "?ys ! ?i = s"
using time_index_unique[OF _ True] finite by auto
have deletion: "?ys = delete_time ?xs ?j"
by (rule ordered_times_delete[OF finite t])
have len: "length ?ys = length ?xs - 1"
by (simp add: deletion delete_time_length[OF j])
have k: "?k < length ?xs" using i len by auto
have xy: "?ys ! ?i = ?xs ! ?k"
using delete_time_nth[OF j, of ?i] i deletion
by (cases "?i < ?j") auto
have x: "?xs ! ?k = s" using xy y by simp
have s_index: "time_index T s < length ?xs" "?xs ! time_index T s = s"
using time_index_unique[OF finite] True by auto
have inj: "inj_on (nth ?xs) {..<length ?xs}"
using ordered_times_finite(2)[OF finite]
by (auto simp: distinct_conv_nth inj_on_def)
have index: "time_index T s = ?k"
by (rule inj_onD[OF inj]) (use s_index k x in auto)
show ?thesis using True i len index
by (simp add: set_coordinates_def delete_coordinate_def restrict_def)
qed
qed
lemma ordered_times_set:
assumes sorted: "sorted ts" and distinct: "distinct ts"
shows "ordered_times (set ts) = ts"
using assms by (simp add: ordered_times_def sorted_list_of_set_sort_remdups sorted_sort_id)
lemma time_index_nth:
assumes sorted: "sorted ts" and distinct: "distinct ts" and i: "i < length ts"
shows "time_index (set ts) (ts ! i) = i"
proof -
have finite: "finite (set ts)" by simp
have member: "ts ! i ∈ set ts" using i by simp
have nth: "ordered_times (set ts) ! time_index (set ts) (ts ! i) = ts ! i"
using time_index_unique(2)[OF finite member] .
have bound: "time_index (set ts) (ts ! i) < length ts"
using time_index_unique(1)[OF finite member]
ordered_times_set[OF sorted distinct] by simp
show ?thesis using distinct nth bound i ordered_times_set[OF sorted distinct]
by (metis distinct_conv_nth)
qed
definition list_coordinates :: "real list ⇒ (real ⇒ real) ⇒ nat ⇒ real" where
"list_coordinates ts w = (λi∈{..<length ts}. w (ts ! i))"
lemma measurable_list_coordinates:
"list_coordinates ts ∈
measurable (PiM (set ts) (λ_. borel))
(PiM {..<length ts} (λ_. borel))"
proof (rule measurable_PiM_single')
fix i assume i: "i ∈ {..<length ts}"
have coord: "(λw :: real ⇒ real. w (ts ! i)) ∈
borel_measurable (PiM (set ts) (λ_. borel))"
by (rule measurable_component_singleton) (use i in auto)
show "(λw. list_coordinates ts w i) ∈
borel_measurable (PiM (set ts) (λ_. borel))"
using i coord by (simp add: list_coordinates_def)
next
show "list_coordinates ts ∈
space (PiM (set ts) (λ_. borel)) →
(Π⇩E i∈{..<length ts}. space borel)"
by (auto simp: list_coordinates_def space_PiM PiE_iff split: if_splits)
qed
lemma list_coordinates_set_coordinates:
assumes sorted: "sorted ts" and distinct: "distinct ts"
shows "list_coordinates ts (set_coordinates (set ts) w) =
restrict w {..<length ts}"
using assms
by (auto simp: list_coordinates_def set_coordinates_def restrict_def
fun_eq_iff time_index_nth)
definition gaussian_set_law :: "real set ⇒ (real ⇒ real) measure" where
"gaussian_set_law T =
distr (gaussian_finite_law (ordered_times T)) (PiM T (λ_. borel))
(set_coordinates T)"
lemma measurable_set_coordinates:
assumes finite: "finite T"
shows "set_coordinates T ∈
measurable (PiM {..<length (ordered_times T)} (λ_. borel))
(PiM T (λ_. borel))"
proof (rule measurable_PiM_single')
fix t assume t: "t ∈ T"
show "(λw. set_coordinates T w t) ∈
borel_measurable (PiM {..<length (ordered_times T)} (λ_. borel))"
using time_index_unique(1)[OF finite t]
by (simp add: set_coordinates_def measurable_component_singleton t)
next
show "set_coordinates T ∈
space (PiM {..<length (ordered_times T)} (λ_. borel)) →
(Π⇩E t∈T. space borel)"
by (auto simp: set_coordinates_def space_PiM PiE_iff split: if_splits)
qed
lemma prob_space_gaussian_set_law:
assumes "finite T"
shows "prob_space (gaussian_set_law T)"
proof -
have measurable: "set_coordinates T ∈
measurable (gaussian_finite_law (ordered_times T)) (PiM T (λ_. borel))"
using measurable_set_coordinates[OF assms]
by (simp only: measurable_cong_sets[OF sets_gaussian_finite_law refl])
show ?thesis unfolding gaussian_set_law_def
by (rule prob_space.prob_space_distr[OF prob_space_gaussian_finite_law measurable])
qed
lemma sets_gaussian_set_law:
"sets (gaussian_set_law T) = sets (PiM T (λ_. borel))"
by (simp add: gaussian_set_law_def)
lemma gaussian_set_law_ordered_list:
assumes sorted: "sorted ts" and distinct: "distinct ts"
shows "distr (gaussian_set_law (set ts))
(PiM {..<length ts} (λ_. borel)) (list_coordinates ts) =
gaussian_finite_law ts"
proof -
let ?I = "{..<length ts}"
let ?B = "λ_. borel"
let ?T = "set ts"
have ordered: "ordered_times ?T = ts"
by (rule ordered_times_set[OF sorted distinct])
have set_meas: "set_coordinates ?T ∈
measurable (gaussian_finite_law ts) (PiM ?T ?B)"
using measurable_set_coordinates[of ?T]
by (simp add: ordered measurable_cong_sets[OF sets_gaussian_finite_law refl])
have list_meas: "list_coordinates ts ∈
measurable (PiM ?T ?B) (PiM ?I ?B)"
by (rule measurable_list_coordinates)
have identity: "restrict w ?I = w" if "w ∈ space (gaussian_finite_law ts)" for w
proof -
have space: "space (gaussian_finite_law ts) = space (PiM ?I ?B)"
by (rule sets_eq_imp_space_eq) (rule sets_gaussian_finite_law)
show ?thesis using that by (auto simp: space space_PiM PiE_iff
extensional_def restrict_def fun_eq_iff)
qed
have "distr (gaussian_set_law ?T) (PiM ?I ?B) (list_coordinates ts) =
distr (gaussian_finite_law ts) (PiM ?I ?B)
(list_coordinates ts ∘ set_coordinates ?T)"
unfolding gaussian_set_law_def
using distr_distr[OF list_meas set_meas] by (simp only: ordered)
also have "... = distr (gaussian_finite_law ts) (PiM ?I ?B)
(λw. restrict w ?I)"
using list_coordinates_set_coordinates[OF sorted distinct]
by (intro distr_cong) (auto simp: comp_def)
also have "... = distr (gaussian_finite_law ts) (PiM ?I ?B) id"
by (rule distr_cong) (use identity in auto)
also have "... = gaussian_finite_law ts"
by (simp add: id_def distr_id2)
finally show ?thesis .
qed
lemma gaussian_set_law_delete:
assumes finite: "finite T" and nonnegative: "T ⊆ {0..}"
and t: "t ∈ T"
shows "distr (gaussian_set_law T) (PiM (T - {t}) (λ_. borel))
(λw. restrict w (T - {t})) = gaussian_set_law (T - {t})"
proof -
let ?S = "T - {t}"
let ?xs = "ordered_times T"
let ?ys = "ordered_times ?S"
let ?j = "time_index T t"
let ?B = "λ_. borel"
let ?del = "delete_coordinate (length ?xs) ?j"
have j: "?j < length ?xs" by (rule time_index_unique(1)[OF finite t])
have deletion: "?ys = delete_time ?xs ?j"
by (rule ordered_times_delete[OF finite t])
have ordered: "sorted ?xs" using ordered_times_finite(3)[OF finite] .
have nonneg: "∀u∈set ?xs. 0 ≤ u"
using nonnegative ordered_times_finite(1)[OF finite] by auto
have finite_S: "finite ?S" using finite by simp
have coord_meas: "set_coordinates T ∈
measurable (gaussian_finite_law ?xs) (PiM T ?B)"
using measurable_set_coordinates[OF finite]
by (simp only: measurable_cong_sets[OF sets_gaussian_finite_law refl])
have restrict_meas: "(λw. restrict w ?S) ∈
measurable (PiM T ?B) (PiM ?S ?B)"
by (rule measurable_restrict_subset) auto
have del_meas: "?del ∈ measurable (gaussian_finite_law ?xs)
(PiM {..<length ?ys} ?B)"
using measurable_delete_coordinate[of ?j ?xs, OF j]
by (simp only: deletion measurable_cong_sets[OF sets_gaussian_finite_law refl])
have set_meas: "set_coordinates ?S ∈
measurable (PiM {..<length ?ys} ?B) (PiM ?S ?B)"
by (rule measurable_set_coordinates[OF finite_S])
have "distr (gaussian_set_law T) (PiM ?S ?B) (λw. restrict w ?S) =
distr (gaussian_finite_law ?xs) (PiM ?S ?B)
((λw. restrict w ?S) ∘ set_coordinates T)"
unfolding gaussian_set_law_def
by (rule distr_distr[OF restrict_meas coord_meas])
also have "... = distr (gaussian_finite_law ?xs) (PiM ?S ?B)
(set_coordinates ?S ∘ ?del)"
using set_coordinates_delete[OF finite t]
by (intro distr_cong) (auto simp: comp_def)
also have "... = distr (distr (gaussian_finite_law ?xs)
(PiM {..<length ?ys} ?B) ?del) (PiM ?S ?B) (set_coordinates ?S)"
by (rule distr_distr[OF set_meas del_meas, symmetric])
also have "... = gaussian_set_law ?S"
using gaussian_finite_law_delete_time_any[OF ordered nonneg j]
by (simp only: deletion gaussian_set_law_def)
finally show ?thesis .
qed
lemma gaussian_set_law_consistent:
assumes subset: "J ⊆ H" and finite: "finite H"
and nonnegative: "H ⊆ {0..}"
shows "gaussian_set_law J =
distr (gaussian_set_law H) (PiM J (λ_. borel)) (λw. restrict w J)"
proof -
let ?B = "λ_. borel"
have finite_J: "finite J" by (rule finite_subset[OF subset finite])
have J_nonnegative: "J ⊆ {0..}" using subset nonnegative by auto
have consistent: "distr (gaussian_set_law (J ∪ K)) (PiM J ?B)
(λw. restrict w J) = gaussian_set_law J"
if finK: "finite K" and nonnegK: "K ⊆ {0..}" and disjK: "K ∩ J = {}"
for K
using finK nonnegK disjK
proof (induction K rule: finite_induct)
case empty
have space: "space (gaussian_set_law J) = space (PiM J ?B)"
using sets_gaussian_set_law by (rule sets_eq_imp_space_eq)
have identity: "restrict w J = w" if "w ∈ space (gaussian_set_law J)" for w
using that by (auto simp: space space_PiM PiE_iff extensional_def
restrict_def fun_eq_iff)
have "distr (gaussian_set_law J) (PiM J ?B) (λw. restrict w J) =
distr (gaussian_set_law J) (PiM J ?B) id"
by (rule distr_cong) (use identity in auto)
also have "... = gaussian_set_law J"
by (simp add: id_def distr_id2 sets_gaussian_set_law)
finally show ?case by (simp only: Un_empty_right)
next
case (insert t K)
let ?M = "J ∪ K"
let ?L = "J ∪ insert t K"
have t: "t ∉ ?M" using insert by auto
have nonnegM: "?M ⊆ {0..}" using insert J_nonnegative by auto
have nonnegL: "?L ⊆ {0..}" using insert J_nonnegative by auto
have finiteL: "finite ?L" using insert finite_J by simp
have del: "?L - {t} = ?M" using t by auto
have one: "distr (gaussian_set_law ?L) (PiM ?M ?B)
(λw. restrict w ?M) = gaussian_set_law ?M"
using gaussian_set_law_delete[OF finiteL nonnegL, of t]
by (simp only: del) simp
have IH: "distr (gaussian_set_law ?M) (PiM J ?B)
(λw. restrict w J) = gaussian_set_law J"
by (rule insert.IH) (use insert in auto)
have restrict_J: "(λw. restrict w J) ∈
measurable (PiM ?M ?B) (PiM J ?B)"
by (rule measurable_restrict_subset) auto
have restrict_M_base: "(λw. restrict w ?M) ∈
measurable (PiM ?L ?B) (PiM ?M ?B)"
by (rule measurable_restrict_subset) auto
have restrict_M: "(λw. restrict w ?M) ∈
measurable (gaussian_set_law ?L) (PiM ?M ?B)"
using restrict_M_base
by (simp only: measurable_cong_sets[OF sets_gaussian_set_law refl])
have "distr (gaussian_set_law ?L) (PiM J ?B) (λw. restrict w J) =
distr (gaussian_set_law ?L) (PiM J ?B)
((λw. restrict w J) ∘ (λw. restrict w ?M))"
by (intro distr_cong) (auto simp: comp_def restrict_def fun_eq_iff)
also have "... = distr (distr (gaussian_set_law ?L) (PiM ?M ?B)
(λw. restrict w ?M)) (PiM J ?B) (λw. restrict w J)"
by (rule distr_distr[OF restrict_J restrict_M, symmetric])
also have "... = gaussian_set_law J" using one IH by simp
finally show ?case .
qed
have diff: "finite (H - J)" using finite by simp
have H_eq: "H = J ∪ (H - J)" using subset by auto
have law: "distr (gaussian_set_law (J ∪ (H - J))) (PiM J ?B)
(λw. restrict w J) = gaussian_set_law J"
by (rule consistent[OF diff]) (use nonnegative in auto)
show ?thesis using law H_eq by metis
qed
interpretation gaussian: projective_family "{0..} :: real set"
gaussian_set_law "λ_. borel :: real measure"
proof (intro projective_family.intro)
fix J H :: "real set"
assume "J ⊆ H" "finite H" "H ⊆ {0..}"
then show "gaussian_set_law J =
distr (gaussian_set_law H) (PiM J (λ_. borel)) (λw. restrict w J)"
by (rule gaussian_set_law_consistent)
next
fix J :: "real set"
assume "finite J" "J ⊆ {0..}"
show "prob_space (gaussian_set_law J)"
by (rule prob_space_gaussian_set_law[OF ‹finite J›])
qed