File size: 4,365 Bytes
b317718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import OAI.Probability.GaussianReplacement.CompletedKernel

namespace OAI

open MeasureTheory ProbabilityTheory Set Filter
open scoped ENNReal NNReal RealInnerProductSpace Topology
noncomputable section
universe u
namespace CurrentProjection

namespace StreamKernel
open NoiselessRegression unitInterval





structure CompletedLearner (d M T : ℕ) where
  initial : Measure (Bool × State M)
  initial_probability : IsProbabilityMeasure initial
  transition : ℕ → State M → (NoiselessRegression.Vector d × ℝ) → Measure (Bool × State M)
  transition_probability : ∀ n a o, IsProbabilityMeasure (transition n a o)
  transition_completed : ∀ n a, AEMeasurable (transition n a) (observationReference d)
  output : ℕ → State M → Measure (UnitSphere d)
  output_probability : ∀ n a, IsProbabilityMeasure (output n a)

instance runStatus_singletons (M : ℕ) :
    MeasurableSingletonClass (NoiselessRegression.Learner.RunStatus M) where
  measurableSet_singleton x := by
    rw [measurableSet_sum_iff]
    cases x with
    | inl a =>
      constructor
      · simp
      · have h : (Sum.inr : ℕ × State M → NoiselessRegression.Learner.RunStatus M) ⁻¹' {Sum.inl a} = ∅ := by
          ext z
          simp
        rw [h]
        exact MeasurableSet.empty
    | inr a =>
      constructor
      · simp
      · have h : (Sum.inr : ℕ × State M → NoiselessRegression.Learner.RunStatus M) ⁻¹' {Sum.inr a} = {a} := by
          ext z
          simp
        rw [h]
        exact measurableSet_singleton a

namespace CompletedLearner
variable {d M T : ℕ} (K : CompletedLearner d M T)


def startStatus (a : Bool × State M) : NoiselessRegression.Learner.RunStatus M :=
  if a.1 then Sum.inr (0,a.2) else Sum.inl a.2

def choiceStatus (n : ℕ) (a : Bool × State M) : NoiselessRegression.Learner.RunStatus M :=
  if a.1 then Sum.inr (n,a.2) else Sum.inl a.2


def nextLaw (s : UnitSphere d) (x : Samples d T) (n : ℕ) :
    NoiselessRegression.Learner.RunStatus M → Measure (NoiselessRegression.Learner.RunStatus M)
  | .inr done => Measure.dirac (.inr done)
  | .inl a => if hn : n < T then
      (K.transition (n+1) a (x ⟨n,hn⟩, ⟪x ⟨n,hn⟩,s.val⟫)).map (choiceStatus (n+1))
    else Measure.dirac (.inl a)



def runLaw (s : UnitSphere d) (x : Samples d T) :
    ℕ → Measure (NoiselessRegression.Learner.RunStatus M)
  | 0 => K.initial.map startStatus
  | n+1 => (runLaw s x n).bind (K.nextLaw s x n)

def terminalStatus : NoiselessRegression.Learner.RunStatus M → ℕ × State M
  | .inl a => (T,a)
  | .inr done => done


def estimateLaw (s : UnitSphere d) (x : Samples d T) : Measure (UnitSphere d) :=
  ((K.runLaw s x T).map (terminalStatus (T:=T))).bind
    (fun a => K.output a.1 a.2)



def uniformSuccess (ε : ℝ) : ℝ≥0∞ :=
  ∫⁻ z : UnitSphere d × Samples d T,
    K.estimateLaw z.1 z.2 {v | NoiselessRegression.Learner.angularError z.1 v ≤ ε}
      ∂(NoiselessRegression.uniformSphere d).prod (sampleLaw d T)



def borel : CompletedLearner d M T where
  initial := K.initial
  initial_probability := K.initial_probability
  transition := fun n a => borelKernel (K.transition n a) (K.transition_completed n a)
  transition_probability := fun _ _ _ => inferInstance
  transition_completed := fun n a =>
    (borelKernel (K.transition n a) (K.transition_completed n a)).measurable.aemeasurable
  output := K.output
  output_probability := K.output_probability

lemma borel_transition_ae (n : ℕ) (a : State M) :
    K.borel.transition n a =ᵐ[observationReference d] K.transition n a :=
  borelKernel_ae _ _ (K.transition_probability n a)


def transitionKernel : Kernel ((ℕ × State M) × (NoiselessRegression.Vector d × ℝ))
    (Bool × State M) :=
  ⟨fun p => K.borel.transition p.1.1 p.1.2 p.2,
    measurable_from_prod_countable_right fun a =>
      (borelKernel (K.transition a.1 a.2) (K.transition_completed a.1 a.2)).measurable⟩

instance transitionKernel_markov : IsMarkovKernel K.transitionKernel :=
  ⟨fun _ => K.borel.transition_probability _ _ _⟩

def outputKernel : Kernel (ℕ × State M) (UnitSphere d) :=
  ⟨fun a => K.output a.1 a.2, measurable_of_countable _⟩
instance outputKernel_markov : IsMarkovKernel K.outputKernel :=
  ⟨fun _ => K.output_probability _ _⟩

end CompletedLearner
end StreamKernel




end CurrentProjection

end

end OAI