-
Notifications
You must be signed in to change notification settings - Fork 12
Add randomSampling
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RemyDegenne
merged 5 commits into
LeanMachineLearning:main
from
gaetanserre:randomSampling
Apr 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6f1dde
`randomSampling`
gaetanserre 6da1c61
Update LeanMachineLearning/SequentialLearning/Algorithms/RandomSampli…
gaetanserre 815c3f2
suggestions
gaetanserre a8669a1
`lake exe mk_all --module`
gaetanserre 92f1062
docstring
gaetanserre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
LeanMachineLearning/SequentialLearning/Algorithms/RandomSampling.lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /- | ||
| Copyright (c) 2026 Gaëtan Serré. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Gaëtan Serré | ||
| -/ | ||
| module | ||
|
|
||
| public import LeanMachineLearning.Probability.Independence.IndepFun | ||
| public import LeanMachineLearning.SequentialLearning.Algorithm | ||
|
|
||
| /-! | ||
| # Random Sampling | ||
|
|
||
| Implementation of the _Random Sampling_ algorithm, which samples from a fixed probability | ||
| measure at each iteration. | ||
|
|
||
| ## Main definitions | ||
|
|
||
| * `randomSampling`: The random sampling algorithm that samples from a fixed distribution at | ||
| each iteration. | ||
|
|
||
| ## Main statements | ||
|
|
||
| * `hasLaw_action`: Each action follows the distribution μ. | ||
| * `iIndep_action`: Actions are mutually independent across time steps. | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open MeasureTheory ProbabilityTheory Learning Finset ENNReal Filter | ||
|
|
||
| open scoped Topology | ||
|
|
||
| namespace Learning | ||
|
|
||
| variable {α β Ω : Type*} [MeasurableSpace α] [MeasurableSpace β] [StandardBorelSpace α] [Nonempty α] | ||
| [StandardBorelSpace β] [Nonempty β] {μ : Measure α} [IsProbabilityMeasure μ] [MeasurableSpace Ω] | ||
| {P : Measure Ω} [IsProbabilityMeasure P] | ||
|
|
||
| open Set in | ||
| /-- The _Random Sampling_ algorithm, which samples from a fixed probability | ||
| measure at each iteration. -/ | ||
| @[simps] | ||
| noncomputable def randomSampling (μ : Measure α) [IsProbabilityMeasure μ] : Algorithm α β where | ||
| policy _ := Kernel.const _ μ | ||
| p0 := μ | ||
|
|
||
| namespace randomSampling | ||
|
|
||
| variable {A : ℕ → Ω → α} {R : ℕ → Ω → β} {env : Environment α β} | ||
|
|
||
| /-- Each action follows the distribution μ. -/ | ||
| lemma hasLaw_action (h : IsAlgEnvSeq A R (randomSampling μ) env P) (n : ℕ) : | ||
| HasLaw (A n) μ P := by | ||
| by_cases hn : n = 0 | ||
| · rw [hn] | ||
| exact h.hasLaw_action_zero | ||
| · push Not at hn | ||
| obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn | ||
| exact hasLaw_of_hasCondDistrib_const <| h.hasCondDistrib_action k | ||
|
|
||
| /-- Actions are mutually independent. -/ | ||
| lemma iIndep_action (h : IsAlgEnvSeq A R (randomSampling μ) env P) : | ||
| iIndepFun A P := by | ||
| have hA := h.measurable_A | ||
| rw [iIndepFun_nat_iff_forall_indepFun (by fun_prop)] | ||
| intro n | ||
| have condDistrib_eq := (h.hasCondDistrib_action n).condDistrib_eq | ||
| simp only [randomSampling_policy] at condDistrib_eq | ||
| have law_eq := (hasLaw_action h (n + 1)).map_eq | ||
| rw [← law_eq, ← indepFun_iff_condDistrib_eq_const ?_ (by fun_prop)] at condDistrib_eq | ||
| · have meas_fst : Measurable (fun (f : Iic n → α × β) ↦ (fun i ↦ (f i).1)) := by | ||
| fun_prop | ||
| exact (condDistrib_eq.comp meas_fst measurable_id).symm | ||
| · exact (IsAlgEnvSeq.measurable_hist (h.measurable_A) (h.measurable_R) n).aemeasurable | ||
|
|
||
| end randomSampling | ||
|
|
||
| end Learning |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.