Download data/lean/OAI/Probability/InvariantIsing/Arrays/NSpinTensorBackwardPaths.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 15.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/InvariantIsing/Arrays/NSpinTensorBackwardPaths.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/InvariantIsing/Arrays/NSpinTensorBackwardPaths.lean
-
curl -L -o NSpinTensorBackwardPaths.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/InvariantIsing/Arrays/NSpinTensorBackwardPaths.lean
15.2 kB
| import OAI.Probability.InvariantIsing.Arrays.NSpinTensorBackwardDerivative | |
| namespace OAI | |
| /-! Collapse the two independent residual paths to actual backward gradients. -/ | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory IsingPerceptron | |
| open scoped BigOperators NNReal ENNReal | |
| namespace InvariantIsing | |
| def tensorPairCoordinatePayoff {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (q : β) (zβ zβ : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) | |
| (w : Fin q β (SpinTensorIndex I degree β β) Γ (SpinTensorIndex I degree β β)) : β := | |
| tensorTerminalCoordinateMean eig U c I degree amplitude (zβ + β i, (w i).1) jβ * | |
| tensorTerminalCoordinateMean eig U c I degree amplitude (zβ + β i, (w i).2) jβ | |
| lemma tensorPairCoordinatePayoff_cons {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (q : β) (zβ zβ aβ aβ : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) | |
| (w : Fin q β (SpinTensorIndex I degree β β) Γ (SpinTensorIndex I degree β β)) : | |
| tensorPairCoordinatePayoff eig U c I degree amplitude (q + 1) zβ zβ jβ jβ (Fin.cons (aβ, aβ) w) = | |
| tensorPairCoordinatePayoff eig U c I degree amplitude q (zβ + aβ) (zβ + aβ) jβ jβ w := by | |
| simp only [tensorPairCoordinatePayoff, Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ, add_assoc] | |
| lemma tensorPairCoordinatePayoff_abs_le {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (q : β) (zβ zβ : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) | |
| (w : Fin q β (SpinTensorIndex I degree β β) Γ (SpinTensorIndex I degree β β)) : | |
| |tensorPairCoordinatePayoff eig U c I degree amplitude q zβ zβ jβ jβ w| β€ | |
| tensorFeatureCoordinateCap U I degree amplitude jβ * tensorFeatureCoordinateCap U I degree amplitude jβ := by | |
| rw [tensorPairCoordinatePayoff, abs_mul] | |
| exact mul_le_mul (tensorTerminalCoordinateMean_abs_le eig U c I degree amplitude _ jβ) | |
| (tensorTerminalCoordinateMean_abs_le eig U c I degree amplitude _ jβ) (abs_nonneg _) | |
| (Finset.sum_nonneg fun _ _ => abs_nonneg _) | |
| /-- Once the two paths have branched, each terminal gradient averages | |
| independently to its actual backward gradient. -/ | |
| theorem tensorAncestorPairPathMean_independent_coordinates {N m k : β} (hN : 0 < N) | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (hb : CascadeExponents n b) (d q i : β) (hqi : i + q = n) (hdi : d β€ i) | |
| (zβ zβ : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) : | |
| tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i zβ zβ | |
| (tensorPairCoordinatePayoff eig U c I degree amplitude q zβ zβ jβ jβ) = | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ * | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ := by | |
| induction q generalizing i zβ zβ with | |
| | zero => | |
| have hi : i = n := by omega | |
| subst i | |
| simp only [tensorAncestorPairPathMean, tensorPairCoordinatePayoff, Finset.univ_eq_empty, | |
| Finset.sum_empty, add_zero, tensorBackwardCoordinateMean, Nat.sub_self, tensorCascadeCoordinateMean] | |
| | succ q ih => | |
| have hi : i < n := by omega | |
| have hqi' : i + 1 + q = n := by omega | |
| have hdi' : d β€ i + 1 := by omega | |
| dsimp only [tensorAncestorPairPathMean] | |
| rw [ite_eq_right (by omega : Β¬i < d)] | |
| calc | |
| _ = β« aβ, β« aβ, | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (zβ + aβ) jβ * | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (zβ + aβ) jβ | |
| βtensorAncestorMarkKernel eig U c I degree amplitude n b v i zβ | |
| βtensorAncestorMarkKernel eig U c I degree amplitude n b v i zβ := by | |
| apply integral_congr_ae | |
| apply ae_of_all | |
| intro aβ | |
| apply integral_congr_ae | |
| apply ae_of_all | |
| intro aβ | |
| dsimp only | |
| have hF : (fun w => tensorPairCoordinatePayoff eig U c I degree amplitude (q + 1) | |
| zβ zβ jβ jβ (Fin.cons (aβ, aβ) w)) = | |
| tensorPairCoordinatePayoff eig U c I degree amplitude q (zβ + aβ) (zβ + aβ) jβ jβ := | |
| funext (tensorPairCoordinatePayoff_cons eig U c I degree amplitude q zβ zβ aβ aβ jβ jβ) | |
| rw [hF] | |
| exact ih (i + 1) hqi' hdi' (zβ + aβ) (zβ + aβ) | |
| _ = (β« aβ, tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (zβ + aβ) jβ | |
| βtensorAncestorMarkKernel eig U c I degree amplitude n b v i zβ) * | |
| (β« aβ, tensorBackwardCoordinateMean eig U c I degree amplitude n b v (i + 1) (zβ + aβ) jβ | |
| βtensorAncestorMarkKernel eig U c I degree amplitude n b v i zβ) := by | |
| simp_rw [integral_const_mul] | |
| rw [integral_mul_const] | |
| _ = _ := by | |
| rw [β tensorBackwardCoordinateMean_step hN eig U c I degree amplitude n b v hb i hi zβ jβ, | |
| β tensorBackwardCoordinateMean_step hN eig U c I degree amplitude n b v hb i hi zβ jβ] | |
| /-- Only the shared ancestor increments remain after the independent | |
| suffixes have been integrated. At the branching level the integrand is | |
| the product of actual backward gradients. -/ | |
| def tensorSharedCoordinateProduct {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) (d : β) | |
| (jβ jβ : SpinTensorIndex I degree) : | |
| (q : β) β β β (SpinTensorIndex I degree β β) β (SpinTensorIndex I degree β β) β β | |
| | 0, i, zβ, zβ => | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ * | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ | |
| | q + 1, i, zβ, zβ => | |
| if i < d then | |
| β« a, tensorSharedCoordinateProduct eig U c I degree amplitude n b v d jβ jβ q | |
| (i + 1) (zβ + a) (zβ + a) βtensorAncestorMarkKernel eig U c I degree amplitude n b v i zβ | |
| else | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ * | |
| tensorBackwardCoordinateMean eig U c I degree amplitude n b v i zβ jβ | |
| lemma tensorSharedCoordinateProduct_nonneg {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (d : β) (j : SpinTensorIndex I degree) (q i : β) (z : SpinTensorIndex I degree β β) : | |
| 0 β€ tensorSharedCoordinateProduct eig U c I degree amplitude n b v d j j q i z z := by | |
| induction q generalizing i z with | |
| | zero => exact mul_self_nonneg _ | |
| | succ q ih => | |
| dsimp only [tensorSharedCoordinateProduct] | |
| split_ifs | |
| Β· exact integral_nonneg fun a => ih (i + 1) (z + a) | |
| Β· exact mul_self_nonneg _ | |
| /-- The finite pair-path expectation is an expectation over the common | |
| ancestor path of the backward gradient product at branching. -/ | |
| theorem tensorAncestorPairPathMean_coordinates {N m k : β} (hN : 0 < N) | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (hb : CascadeExponents n b) (d q i : β) (hqi : i + q = n) | |
| (zβ zβ : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) : | |
| tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i zβ zβ | |
| (tensorPairCoordinatePayoff eig U c I degree amplitude q zβ zβ jβ jβ) = | |
| tensorSharedCoordinateProduct eig U c I degree amplitude n b v d jβ jβ q i zβ zβ := by | |
| induction q generalizing i zβ zβ with | |
| | zero => | |
| have hi : i = n := by omega | |
| subst i | |
| simp only [tensorAncestorPairPathMean, tensorPairCoordinatePayoff, Finset.univ_eq_empty, | |
| Finset.sum_empty, add_zero, tensorSharedCoordinateProduct, tensorBackwardCoordinateMean, | |
| Nat.sub_self, tensorCascadeCoordinateMean] | |
| | succ q ih => | |
| by_cases hid : i < d | |
| Β· dsimp only [tensorAncestorPairPathMean, tensorSharedCoordinateProduct] | |
| rw [ite_eq_left hid, ite_eq_left hid] | |
| apply integral_congr_ae | |
| apply ae_of_all | |
| intro a | |
| dsimp only | |
| have hF : (fun w => tensorPairCoordinatePayoff eig U c I degree amplitude (q + 1) | |
| zβ zβ jβ jβ (Fin.cons (a, a) w)) = | |
| tensorPairCoordinatePayoff eig U c I degree amplitude q (zβ + a) (zβ + a) jβ jβ := | |
| funext (tensorPairCoordinatePayoff_cons eig U c I degree amplitude q zβ zβ a a jβ jβ) | |
| rw [hF] | |
| exact ih (i + 1) (by omega) (zβ + a) (zβ + a) | |
| Β· rw [tensorSharedCoordinateProduct, ite_eq_right hid] | |
| exact tensorAncestorPairPathMean_independent_coordinates hN eig U c I degree amplitude | |
| n b v hb d (q + 1) i hqi (by omega) zβ zβ jβ jβ | |
| lemma tensorAncestorPairPathMean_const_mul {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (d q i : β) (zβ zβ : SpinTensorIndex I degree β β) | |
| (F : (Fin q β (SpinTensorIndex I degree β β) Γ (SpinTensorIndex I degree β β)) β β) (C : β) : | |
| tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i zβ zβ (fun w => C * F w) = | |
| C * tensorAncestorPairPathMean eig U c I degree amplitude n b v d q i zβ zβ F := by | |
| induction q generalizing i zβ zβ with | |
| | zero => rfl | |
| | succ q ih => | |
| dsimp only [tensorAncestorPairPathMean] | |
| split_ifs <;> simp_rw [ih, integral_const_mul] | |
| lemma tensorPairPathSpinMean_features {N m k : β} | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (z : SpinTensorIndex I degree β β) (jβ jβ : SpinTensorIndex I degree) | |
| (w : Fin n β (SpinTensorIndex I degree β β) Γ (SpinTensorIndex I degree β β)) : | |
| tensorPairPathSpinMean eig U c I degree amplitude n (z, w) | |
| (fun Ο => spinTensorFeature U I degree amplitude (Ο 0) jβ * | |
| spinTensorFeature U I degree amplitude (Ο 1) jβ) = | |
| tensorPairCoordinatePayoff eig U c I degree amplitude n z z jβ jβ w := by | |
| let ΞΌ := fun j : Fin 2 => gibbsProbability (uniformSpinPrior N : Measure (Spin N)) | |
| (tensorSpinBaseEnergy eig U c I degree amplitude (tensorPairPathState I degree n (z, w) j)) | |
| change (β« Ο : Fin 2 β Spin N, spinTensorFeature U I degree amplitude (Ο 0) jβ * | |
| spinTensorFeature U I degree amplitude (Ο 1) jβ βMeasure.pi ΞΌ) = _ | |
| have h := integral_fin_nat_prod_eq_prod (ΞΌ := ΞΌ) | |
| (fun j Ο => spinTensorFeature U I degree amplitude Ο (if j = 0 then jβ else jβ)) | |
| have h10 : (1 : Fin 2) β 0 := by decide | |
| simpa only [Fin.prod_univ_two, ite_eq_left rfl, ite_true, ite_eq_right h10, ΞΌ, | |
| integral_uniformSpinGibbs_eq, tensorTerminalCoordinateMean, tensorPairCoordinatePayoff, | |
| tensorPairPathState] using h | |
| /-- Actual finite tensor feature pair tests are expectations of backward | |
| gradient products along the shared ancestor path. -/ | |
| theorem tensorFeaturePair_backward_identity (hpub : PanchenkoTalagrandTensorPairInput) | |
| {N m k : β} (hN : 0 < N) | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (hb : CascadeExponents n b) (z : SpinTensorIndex I degree β β) | |
| (Ο : β β β) {B : β} (hB : 0 β€ B) (hΟ : β d, |Ο d| β€ B) | |
| (jβ jβ : SpinTensorIndex I degree) : | |
| tensorSpinPairAverage eig U c I degree amplitude n b v z Ο | |
| (fun Ο => spinTensorFeature U I degree amplitude (Ο 0) jβ * | |
| spinTensorFeature U I degree amplitude (Ο 1) jβ) = | |
| β« Ξ± : β β LabeledLeaf n, Ο (labeledCommonDepth n (Ξ± 0) (Ξ± 1)) * | |
| tensorSharedCoordinateProduct eig U c I degree amplitude n b v | |
| (labeledCommonDepth n (Ξ± 0) (Ξ± 1)) jβ jβ n 0 z z βcascadeReplicaLaw n b := by | |
| have hf (Ο : Spin N) (j : SpinTensorIndex I degree) : | |
| |spinTensorFeature U I degree amplitude Ο j| β€ tensorFeatureCoordinateCap U I degree amplitude j := by | |
| exact Finset.single_le_sum (fun Ο _ => abs_nonneg (spinTensorFeature U I degree amplitude Ο j)) | |
| (Finset.mem_univ Ο) | |
| rw [tensorSpinPair_markov_identity hpub hN eig U c I degree amplitude n b v hb z Ο _ hB hΟ | |
| (C := tensorFeatureCoordinateCap U I degree amplitude jβ * tensorFeatureCoordinateCap U I degree amplitude jβ) | |
| (fun Ο => by | |
| rw [abs_mul] | |
| exact mul_le_mul (hf (Ο 0) jβ) (hf (Ο 1) jβ) (abs_nonneg _) | |
| (Finset.sum_nonneg fun _ _ => abs_nonneg _))] | |
| apply integral_congr_ae | |
| apply ae_of_all | |
| intro Ξ± | |
| simp only [tensorPairSpinPathPayoff, tensorPairPathSpinMean_features] | |
| rw [tensorAncestorPairPathMean_const_mul, | |
| tensorAncestorPairPathMean_coordinates hN eig U c I degree amplitude n b v hb _ n 0 (by omega)] | |
| theorem tensorFeaturePair_nonneg (hpub : PanchenkoTalagrandTensorPairInput) | |
| {N m k : β} (hN : 0 < N) | |
| (eig : Fin N β β) (U : Rotation N) (c : Fin N β β) | |
| (I : Fin m β Finset (Fin N)) (degree : Fin k β Fin m β β) (amplitude : Fin k β β) | |
| (n : β) (b : β β β) (v : β β SpinTensorIndex I degree β ββ₯0) | |
| (hb : CascadeExponents n b) (z : SpinTensorIndex I degree β β) | |
| (Ο : β β β) {B : β} (hB : 0 β€ B) (hΟ : β d, |Ο d| β€ B) (hΟ0 : β d, 0 β€ Ο d) | |
| (j : SpinTensorIndex I degree) : | |
| 0 β€ tensorSpinPairAverage eig U c I degree amplitude n b v z Ο | |
| (fun Ο => spinTensorFeature U I degree amplitude (Ο 0) j * | |
| spinTensorFeature U I degree amplitude (Ο 1) j) := by | |
| rw [tensorFeaturePair_backward_identity hpub hN eig U c I degree amplitude n b v hb z Ο hB hΟ j j] | |
| exact integral_nonneg fun Ξ± => mul_nonneg (hΟ0 _) | |
| (tensorSharedCoordinateProduct_nonneg eig U c I degree amplitude n b v _ j n 0 z) | |
| end InvariantIsing | |
| end | |
| end OAI | |