Skip to content

Graded monad prototype - #10

Closed
paulorauber wants to merge 37 commits into
mainfrom
gradedMonadPrototype
Closed

paulorauber wants to merge 37 commits into
mainfrom
gradedMonadPrototype

Conversation

@paulorauber

Copy link
Copy Markdown
Collaborator

No description provided.

RemyDegenne and others added 7 commits September 18, 2026 16:53
`lake update LeanMachineLearning` moves LML to dde3322, and Mathlib to
217ba06 with it.

LML's rounds now have an observation before the action: `Algorithm 𝓞 𝓐 𝓨`,
`Environment 𝓞 𝓐 𝓨`, `IsAlgEnvSeq O A Y alg env P`, with histories
`Hist 𝓞 𝓐 𝓨 n = Fin n → Round 𝓞 𝓐 𝓨` and the action at step `n` drawn given
the history and the observation `O n`. `AlgTrace` and `alg_env_trace` are
ported to it. The first action is now the policy at the empty history, so
the separate `K0`/`out0` fields of `AlgTrace` and the step-zero lemmas go:
`hasCondDistrib_trace` and `action_ae_eq` hold uniformly in `n`, and the
tactic introduces `Ω P O A Y T hseq htr hT hA`. The toy bandit of
`Test/AlgTrace.lean` is an `Algorithm Unit (Fin K) ℝ`.

Mathlib's `Measure.map` along a non-measurable function is now a Dirac mass,
so `IsProbabilityMeasure (μ.map f)` is an instance (`isProbabilityMeasure_map`
is gone) and `Measure.bind_smul` asks for measurability; `measurable_pi_lambda`
is now `Measurable.of_eval`. An `extend_space` error test relied on
`P.map Y` not being known to be a probability measure, and now uses `μ + μ`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ε-greedy's policy is an rdo program drawing a coin of bias ε and a uniform
arm. With `rdo_trace` and `alg_env_trace`, its draws give that every arm is
pulled with probability at least ε / K at every round (`le_map_action`), hence
a linear lower bound on the regret (`le_integral_regret`).

The bandit programs gain a randomized step, `banditStepRand` and
`banditRunRand`, where the arm is itself a program, and `banditRunRand_eq_map`
extends the law of the program to it, so that the lower bound holds for the
program that runs (`le_integral_regret_banditRunRand`). The greedy arm pulls
the arms never pulled first, so that it never compares undefined means.

`lake exe bandits` runs ε-greedy with ε = 0.1, and `scripts/bandit_plot.py`
replays it with numpy and draws its regret against the lower bound.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`lake exe mk_all --check` wants the root files of `MetropolisHastings` and
`Bandits` to be the import lists it generates. They carried a docstring, and
the executables `MetropolisHastings/Main.lean` and `Bandits/Main.lean`, being
in the library directories, were picked up as modules of the libraries.

The executables move to the top level, as `RunMetropolisHastings.lean` and
`RunBandits.lean`, like the other executables of the repository; the root
files are regenerated by `mk_all`, and their overview moves to the docstrings
of `MetropolisHastings.Defs` and `Bandits.Defs`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`MetropolisHastings` and `Bandits` become default targets, so that `lake build`
and `lake lint`, and hence CI, build and lint them along with `RandomDo`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ib/ForLML

pseudoRegret takes the reward kernel, as LML's regret does, and the ETC,
UCB and ε-greedy bounds are stated with LML's gap, replacing gapOf.

General lemmas move out of Bandits.Theory into files mirroring their
upstream homes, generalized where the statement allows: RandomDo/ForMathlib
(map_compProd_eq_bind, bind_map, Measurable.finSnoc,
hasSubgaussianMGF_gaussianReal) and RandomDo/ForLML (pullCount'_snoc,
sumRewards'_snoc, IT.hist_succ_eq_snoc, IT.map_hist_succ). The Vector
measurability lemmas join RandomDo.Measurable. Duplicates are removed:
RDo.map_compProd and RDo.bind_map of Trace.lean are now the ForMathlib
lemmas, and LML's Measure.dirac_compProd replaces dirac_compProd_eq_map.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@paulorauber

paulorauber commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

I am now quite convinced that this is not a promising approach - I will explain in our next meeting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants