9.2
2 Reference
Roulette augments Racket with first-class measurable values. A variable can be bound to a measurable value of a given type and then be used in computations, just as any ordinary concrete value of that type. An engine is then used to perform inference on derived values. The examples in this section use the RSDD backend.
| #lang roulette | package: roulette-lib |
| #lang roulette/safe | |
2.1 Measures
syntax
(define-measurable id ...+ maybe-option measure)
maybe-option =
| #:affine? bool-expr
measure : (measure/c dom cod)
Binds each provided identifier to a value of type (measurable-space-point dom) with the given measure.
The identifiers are bound to the same constants every time the form is evaluated.
One way to think about define-measurable is that it reflects a measure into the meta level.
> (require roulette/engine/rsdd) > (define-measurable x (bernoulli-measure 0.4 0.6))
If #:affine? is set,
then dropping the newly generated value is forced to be
equivalent to not generating the value at all.
This option should be considered unsafe.
syntax
(define-measurable* id ...+ measure)
measure : (measure/c dom cod)
Like define-measurable, but constructs a new value each time the form is evaluated.
procedure
v : (measurable-space-point dom) engine : (engine/c dom cod) = (rsdd-engine)
Returns the measure associated with v using engine.
One way to think about infer is that it reifies a measure from the meta level.
If x is defined by (define-measurable x m),
then (infer x) should be equal to m.
Returns the largest (measurable) set
such that every open neighborhood of every point in the set has positive measure.
> (support (bernoulli-measure 0 1)) (set #t)
> (support m) (set 'banana 'apple)
procedure
(density m) → (-> (measurable-space-point dom) cod)
m : (measure/c dom cod)
If possible, returns the derivative of the given measure.
procedure
(measure/c dom cod) → chaperone-contract?
dom : measurable-space? cod : flat-contract?
Contract for measures. A measure acts like functions from the measurable space dom to a commutative monoid cod.
procedure
(engine/c dom cod) → chaperone-contract?
dom : measurable-space? cod : flat-contract?
Contract for engines that permits inference on measurable values.
2.2 Measurable Spaces
procedure
(immutable-set/c elem/c) → measurable-space?
elem/c : chaperone-contract?
procedure
c : measurable-space?
Returns a predicate for points of the measurable space.
> (measurable-space-point (immutable-set/c boolean?)) boolean?
procedure
(measurable-space? c) → boolean?
c : any/c
Returns whether c is a measurable space. A measurable space acts like a contract that recognizes elements of a σ-algebra.