On this page:
2.1 Measures
define-measurable
define-measurable*
infer
support
density
measure/  c
engine/  c
2.2 Measurable Spaces
immutable-set/  c
measurable-space-point
measurable-space?
8.17.0.3

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.

2.1 Measures🔗ℹ

syntax

(define-measurable id ...+ measure)

 
  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))

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

(infer v [#:engine engine #:lazy? lazy?])  (measure/c dom cod)

  v : (measurable-space-point dom)
  engine : (engine/c dom cod) = (rsdd-engine)
  lazy? : boolean? = #f
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.
> (define m (infer (if x 'apple 'banana)))
> (m (set 'apple))

0.6

If lazy? is #t then the measure is computed only as needed (e.g., when applied or when the density is applied).

procedure

(support m)  (or/c dom #f)

  m : (measure/c dom cod)
If possible, 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 #f)

> (support m)

(set 'banana 'apple)

For lazy measures, the result may be a superset of the actual support.

procedure

(density m)  (-> (measurable-space-point dom) cod)

  m : (measure/c dom cod)
If possible, returns the derivative of the given measure.
> (define d (density m))
> (d 'apple)

0.6

> (d 'banana)

0.4

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?
Equivalent to (set/c elem/c #:kind 'immutable).

Returns a predicate for points of the measurable space.

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.