File size: 2,554 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import OAI.Probability.FreeIsing.Posterior.FinitePosterior

namespace OAI

noncomputable section

open ProbabilityTheory
open scoped BigOperators NNReal

namespace Problem367.GaussianObservation

theorem gaussianPDFReal_spin_tilt (t : ℝβ‰₯0) (ht : t β‰  0) (spin x : ℝ)
    (hspin : spin ^ 2 = 1) :
    gaussianPDFReal ((t : ℝ) * spin) t x =
      gaussianPDFReal 0 t x * Real.exp (spin * x - (t : ℝ) / 2) := by
  have ht' : (t : ℝ) β‰  0 := by exact_mod_cast ht
  simp only [gaussianPDFReal, sub_zero, mul_assoc, ← Real.exp_add]
  congr 2
  field_simp
  nlinarith [show ((t : ℝ) * spin) ^ 2 = (t : ℝ) ^ 2 by
    rw [mul_pow, hspin, mul_one]]

variable {V : Type*} [Fintype V]

def likelihood (t : ℝβ‰₯0) (spin x : V β†’ ℝ) : ℝ :=
  ∏ v, gaussianPDFReal ((t : ℝ) * spin v) t (x v)

def referenceDensity (t : ℝβ‰₯0) (x : V β†’ ℝ) : ℝ :=
  (∏ v, gaussianPDFReal 0 t (x v)) *
    Real.exp (-(Fintype.card V : ℝ) * (t : ℝ) / 2)

lemma referenceDensity_pos (t : ℝβ‰₯0) (ht : t β‰  0) (x : V β†’ ℝ) :
    0 < referenceDensity t x := by
  apply mul_pos
  Β· exact Finset.prod_pos (fun v _ => gaussianPDFReal_pos 0 t (x v) ht)
  Β· exact Real.exp_pos _

theorem likelihood_eq_referenceDensity (t : ℝβ‰₯0) (ht : t β‰  0)
    (spin x : V β†’ ℝ) (hspin : βˆ€ v, (spin v) ^ 2 = 1) :
    likelihood t spin x =
      referenceDensity t x * Real.exp (βˆ‘ v, spin v * x v) := by
  unfold likelihood referenceDensity
  simp_rw [gaussianPDFReal_spin_tilt t ht _ _ (hspin _)]
  rw [Finset.prod_mul_distrib, ← Real.exp_sum]
  rw [Finset.sum_sub_distrib]
  simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]
  rw [mul_assoc, ← Real.exp_add]
  congr 2
  ring

variable {S : Type*} [Fintype S]

theorem normalized_gaussian_likelihood (t : ℝβ‰₯0) (ht : t β‰  0)
    (energy : S β†’ ℝ) (spin : S β†’ V β†’ ℝ) (x : V β†’ ℝ)
    (hspin : βˆ€ s v, (spin s v) ^ 2 = 1) (s : S) :
    (Real.exp (energy s) * likelihood t (spin s) x) /
        (βˆ‘ r, Real.exp (energy r) * likelihood t (spin r) x) =
      Real.exp (energy s + βˆ‘ v, spin s v * x v) /
        (βˆ‘ r, Real.exp (energy r + βˆ‘ v, spin r v * x v)) := by
  have heq (r : S) :
      Real.exp (energy r) * likelihood t (spin r) x =
      referenceDensity t x * Real.exp (energy r + βˆ‘ v, spin r v * x v) := by
    rw [likelihood_eq_referenceDensity t ht _ _ (hspin r), Real.exp_add]
    ring
  simp_rw [heq]
  rw [← Finset.mul_sum]
  exact mul_div_mul_left _ _ (ne_of_gt (referenceDensity_pos t ht x))

end Problem367.GaussianObservation

end

end OAI