Skip to content

Commit 1a498ac

Browse files
RemyDegenneclaude
andcommitted
Fix the mk_all check: executables out of the libraries
`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>
1 parent 389e0f7 commit 1a498ac

7 files changed

Lines changed: 16 additions & 51 deletions

File tree

‎Bandits.lean‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
/-
2-
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3-
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Rémy Degenne
5-
-/
61
module -- shake: keep-all --deprecated_module: ignore
72

83
public import Bandits.Defs
94
public import Bandits.EpsGreedy
105
public import Bandits.Theory
11-
12-
/-!
13-
# A Gaussian bandit, written in `rdo`, proved and run
14-
15-
* `Bandits.Defs`: one round of interaction, and `n` rounds, as `rdo` programs polymorphic in the
16-
monad and the scalars; explore-then-commit and UCB as the algorithms choosing the arm.
17-
* `Bandits.Theory`: read at `Measure`, the programs have the law of LeanMachineLearning's
18-
interaction, so its regret bounds hold for them.
19-
* `Bandits.EpsGreedy`: ε-greedy, a randomized algorithm whose policy is an `rdo` program; with
20-
`alg_env_trace`, its internal draws give an exploration bound and a linear regret lower bound.
21-
22-
To run them and draw the regret against the bounds, from the root of the repository:
23-
24-
```
25-
lake exe bandits # 300 seeds × 5000 rounds; writes bandit_output/
26-
python3 scripts/bandit_plot.py # checks them against numpy, draws bandit_output/*.png
27-
```
28-
-/

‎Bandits/Defs.lean‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ arm pulled. One round of interaction is `banditStep`, and `banditRun n` plays `n
2020
2121
The programs are polymorphic in the monad and in the scalars, as those of
2222
`RandomDo.Tactic.Computable.Polymorphic`: read at `Measure` and `ℝ`, they are what
23-
`Bandits.Theory` proves things about; run at `RandM` and `Float`, they sample.
23+
`Bandits.Theory` and `Bandits.EpsGreedy` prove things about; run at `RandM` and `Float`, they
24+
sample. To run them and draw the regret against the bounds, from the root of the repository:
25+
26+
```
27+
lake exe bandits # 300 seeds × 5000 rounds; writes bandit_output/
28+
python3 scripts/bandit_plot.py # checks them against numpy, draws bandit_output/*.png
29+
```
2430
2531
The two algorithms, `etcArm` (explore-then-commit) and `ucbArm` (upper confidence bound), mirror
2632
the definitions of `Bandits.ETC.nextArm` and `Bandits.UCB.nextArm` in LeanMachineLearning, with the

‎MetropolisHastings.lean‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
1-
/-
2-
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3-
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Rémy Degenne
5-
-/
61
module -- shake: keep-all --deprecated_module: ignore
72

83
public import MetropolisHastings.Computable
94
public import MetropolisHastings.Defs
105
public import MetropolisHastings.Polymorphic
116
public import MetropolisHastings.Targets
127
public import MetropolisHastings.Theory
13-
14-
/-!
15-
# Random-walk Metropolis–Hastings, written in `rdo`, proved and run
16-
17-
* `MetropolisHastings.Defs`: the algorithm, as `rdo` programs over the Giry monad.
18-
* `MetropolisHastings.Theory`: they are Markov kernels, satisfy detailed balance with respect to the
19-
target, and leave it invariant after any number of steps.
20-
* `MetropolisHastings.Computable`: the samplers `@[computable]` writes from them.
21-
* `MetropolisHastings.Polymorphic`: the same algorithm, polymorphic in the monad; at `Measure` it
22-
is the one of `Defs`, so the theorems carry over, and at `RandM` it samples.
23-
* `MetropolisHastings.Targets`: two targets to run the chain on, for both routes.
24-
25-
To run it and draw the plots, from the root of the repository:
26-
27-
```
28-
lake exe mh # runs both samplers, checks they agree, writes mh_output/
29-
python3 scripts/mh_plot.py # checks them against numpy, draws mh_output/*.png
30-
```
31-
-/

‎MetropolisHastings/Defs.lean‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ chain stays at `x`. The chain runs `n` such steps from `x₀`.
1717
1818
Both programs denote Markov kernels, written over the Giry monad. `MetropolisHastings.Theory`
1919
proves what they satisfy, `MetropolisHastings.Computable` and `MetropolisHastings.Polymorphic` turn
20-
them into programs that run.
20+
them into programs that run, and `MetropolisHastings.Targets` gives two targets to run them on.
21+
To run them and draw the plots, from the root of the repository:
22+
23+
```
24+
lake exe mh # runs both samplers, checks they agree, writes mh_output/
25+
python3 scripts/mh_plot.py # checks them against numpy, draws mh_output/*.png
26+
```
2127
2228
## Main definitions
2329
File renamed without changes.

‎lakefile.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ root = "Polymorphic"
4646

4747
[[lean_exe]]
4848
name = "mh"
49-
root = "MetropolisHastings.Main"
49+
root = "RunMetropolisHastings"
5050

5151
[[lean_exe]]
5252
name = "bandits"
53-
root = "Bandits.Main"
53+
root = "RunBandits"

0 commit comments

Comments
 (0)