Uniform Selection Over a Type #
This file defines a typeclass SampleableType β for types β with a canonical uniform selection
operation, using the ProbComp monad.
As compared to HasUniformSelect this provides much more structure on the behavior,
enforcing that every possible output has the same output probability never fails.
A SampleableType β 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 SampleableType.probOutput_uniformSample for the reduction when α has a fintype instance
involving the explicit cardinality of the type.
- 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
Select a uniform element from α × β by independently selecting from α and β.
Equations
Select a uniform element from Vector α n by independently selecting α at each index.
Equations
Select a uniform element from Matrix α n by independently selecting α at each index.
Equations
A type equivalent to a SampleableType is also SampleableType.
Equations
Instances For
A function from Fin n to a SampleableType is also SampleableType.
Equations
Given an independent probabilistic computation ob : ProbComp Bool, the probability that its
output b' differs from a uniformly chosen boolean b is the same as the probability that they
are equal. In other words, P(b ≠ b') = P(b = b') where b is uniform.