{"size": 3024, "ext": "scrbl", "max_stars_repo_path": "gamble/scribblings/internal/interfaces.scrbl", "max_stars_repo_name": "lambdageek/prob", "max_stars_repo_stars_event_min_datetime": "2015-02-12T00:29:59.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T02:36:47.000Z", "max_issues_repo_path": "gamble/scribblings/internal/interfaces.scrbl", "max_issues_repo_name": "lambdageek/prob", "max_issues_repo_issues_event_min_datetime": "2015-02-05T17:43:25.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-14T15:02:32.000Z", "max_forks_repo_path": "gamble/scribblings/internal/interfaces.scrbl", "max_forks_repo_name": "lambdageek/prob", "max_forks_repo_forks_event_min_datetime": "2015-02-26T18:57:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-14T14:56:46.000Z"}
{"max_stars_count": 35, "max_issues_count": 13, "max_forks_count": 10, "avg_line_length": 26.2956521739, "max_line_length": 70, "alphanum_fraction": 0.7258597884}
;; Copyright (c) 2014 Ryan Culpepper
;; Released under the terms of the 2-clause BSD license.
;; See the file COPYRIGHT for details.

#lang scribble/manual
@(require scribble/manual
          scribble/basic
          (for-label racket/contract
                     gamble
                     (only-in gamble/private/interfaces
                              weighted-sampler<%>
                              sampler<%>)))

@title[#:tag "interfaces"]{Gamble Internal Interfaces}

@defmodule[gamble/private/interfaces]

Defines the interfaces representing samplers as well as related
auxiliary interfaces, base classes, and types.

@section[#:tag "sampler-ifc"]{Sampler Interfaces}

@definterface[weighted-sampler<%> ()]{

Represents a weighted sampler.

@defmethod[(sample/weight) (cons/c any/c (>=/c 0))]{

Produce a weighted sample @racket[(cons _value _weight)].
}

@defmethod[(info) void?]{

Print diagnostic information about the sampler to standard output.
}
}

@definterface[sampler<%> (weighted-sampler<%>)]{

Represents a sampler. Samplers are applicable objects; that is, they
can be applied like procedures; doing so calls the @method[sampler<%>
sample] method.

@defmethod[(sample) any/c]{

Produce an unweighted sample.
}
}


@section[#:tag "stochastic-ctx"]{Stochastic Contexts}

@definterface[stochastic-ctx<%> ()]{

Represents an execution context within a sampler/solver. Provides
implementations of stochastic behavior via
@racket[(current-stochastic-ctx)], which is set by the enclosing
sampler/solver before executing the probabilistic program.

May be stateful. For example, the @racket[db-stochastic-ctx%] class
records and replays @method[stochastic-ctx<%> sample] choices, adjusts
trace likelihoods on @method[stochastic-ctx<%> observe-sample], etc.

@defmethod[(sample [d dist?]) any/c]{

Samples from @racket[dist]. Implements @racket[sample].
}

@defmethod[(observe-sample [d dist?] [v any/c]) void?]{

Represents observing the value @racket[v] from the distribution
@racket[d], whose parameters typically depend on previous random
choices within the trace. The effect is typically to adjust the
current trace's likelihood.

Implements @racket[observe-sample].
}

@defmethod[(fail [reason any/c]) none/c]{

Represents condition failure. Causes the current trace to
terminate. Typically, a new trace is then started with different
choices.

Implements @racket[fail].
}

@defmethod[(mem [f procedure?]) procedure?]{

Returns a memoized version of @racket[f]. The memoized function may
only be used while the stochastic context is still active.

Implements @racket[mem].
}
}

@defparam[current-stochastic-ctx ctx (is-a?/c stochastic-ctx<%>)]{

Holds the stochastic context of the current execution of the current
running sampler/solver.
}

@section[#:tag "zones"]{Zones}

A Zone is any value other than @racket[#f].

A ZonePattern is either a Zone---which matches itself---or
@racket[#f], which matches any Zone.

@defparam[current-zones zones list?]{

The current zones, nearest enclosing first.
}
 
