Selecting Uniformly From a Collection #
This file defines some computations for selecting uniformly at random from a number
of different collections, using unifSpec
to make the random choices.
TODO: A lot of lemmas here could exist at the PMF
level instead.
Probably even a lot of the uniform constructions themselves (like uniformOfList
)
Typeclass to implement the notation $ xs
for selecting an object uniformly from a collection.
The container type is given by cont
with the resulting type given by β
.
NOTE: This current implementation doesn't impose any "correctness" conditions,
it purely exists to provide the notation, could revisit that in the future.
- uniformSelect : cont → ProbComp β
Instances
Given a selectable object, we can get a random element by indexing into the element vector.
Equations
Instances For
Equations
- OracleComp.«term$_» = Lean.ParserDescr.node `OracleComp.«term$_» 50 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "$") (Lean.ParserDescr.cat `term 50))
Instances For
Select a random element from a list by indexing into it with a uniform value. If the list is empty we instead just fail rather than choose a default value. This means selecting from a vector is often preferable, as we can prove at the type level that there is an element in the list, avoiding the defualt case of empty lists.
Equations
- One or more equations did not get rendered due to their size.
Select a random element from a vector by indexing into it with a uniform value. TODO: different types of vectors in mathlib now
Equations
- OracleComp.hasUniformSelectVector α n = { uniformSelect := fun (xs : Vector α (n + 1)) => OracleComp.uniformSelect α xs.toList }
Choose a random element from a finite set, by converting to a list and choosing from that. This is noncomputable as we don't have a canoncial ordering for the resulting list, so generally this should be avoided when possible.
Equations
- OracleComp.hasUniformSelectFinset α = { uniformSelect := fun (s : Finset α) => OracleComp.uniformSelect α s.toList }
A SelectableType β
instance means that β
is a finite inhabited type,
with a computation selectElem
that selects uniformly at random from the type.
This generally requires choosing some "canonical" ordering for the type,
so we include this to get a computable version of selection.
We also require that each element has the same probability of being chosen from by selectElem
,
see SelectableType.probOutput_selectElem
for the reduction when α
has a fintype instance.
NOTE: universe polymorphism of β
is hard.
- selectElem : ProbComp β
Instances
Select uniformly from the type β
using a type-class provided definition.
NOTE: naming is somewhat strange now that Fintype
isn't explicitly required.
Equations
Instances For
Equations
- OracleComp.«term$ᵗ_» = Lean.ParserDescr.node `OracleComp.«term$ᵗ_» 90 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "$ᵗ") (Lean.ParserDescr.cat `term 90))
Instances For
Equations
- OracleComp.instSelectableTypeOfUnique α = { selectElem := pure default, mem_support_selectElem := ⋯, probOutput_selectElem_eq := ⋯, probFailure_selectElem := ⋯ }
Equations
- One or more equations did not get rendered due to their size.
Select a uniform element from α × β
by independently selecting from α
and β
.
Equations
- One or more equations did not get rendered due to their size.
Version of Fin
selection using the NeZero
typeclass, avoiding the need for n + 1
.