Modeling Syntax Reference¶
Introduction¶
The VentureScript modeling language is the language in which model
expressions, namely the arguments to the assume
, observe
, and
predict
instructions are written. The VentureScript inference language is
the same language, but with a few additional predefined procedures and
special forms.
The VentureScript modeling language is a pure-functional dialect of JavaScript. The major differences from JavaScript are
- No mutation (only inference can effect mutation, and that only in a restricted way)
- A spare set of predefined procedures and syntactic constructs
- Several constructs relating specifically to probabilistic modeling or functional programming
- Predefined procedures for random choices according to various distributions.
Special Forms¶
The special forms in VentureScript are as follows:
-
quote
(<datum>)¶ Literal data.
The datum must be a VentureScript expression. As in Scheme, a
quote
form returns a representation of the given expression as VentureScript data structures.
-
proc(<param>, ...) { <body> }
Construct a procedure.
The formal parameters must be VentureScript symbols. The body must be a VentureScript expression. The semantics are like
function
in JavaScript – produces an anonymous function that may read its lexical environment.Creation of variable arity procedures is not yet supported.
-
if (<predicate>) { <consequent> } else { <alternate> }
Branch control.
The predicate, consequent, and alternate must be VentureScript expressions.
-
(cond (<predicate> <expression>) ...)
Multiple branching.
Each predicate and each expression must be a VentureScript expression. If none of the predicates match, returns nil. The above is the parsed form; no special concrete syntax for
cond
is provided.
-
and
(<exp1>, <exp2>)¶ Short-circuiting and.
-
or
(<exp1>, <exp2>)¶ Short-circuiting or.
-
(let ((<param> <exp>) ...) <body>)
Evaluation with local scope.
Each parameter must be a VentureScript symbol. Each exp must be a VentureScript expression. The body must be a VentureScript expression. The semantics are as JavaScript’s variable declaration and Scheme’s
let*
: eachexp
is evaluated in turn, its result is bound to theparam
, and made available to subsequentexp
s and thebody
.The concrete syntax is:
<param> = <exp>; ... <body>
-
(letrec ((<param> <exp>) ...) <body>)
Evaluation with local scope.
Each parameter must be a VentureScript symbol. Each exp must be a VentureScript expression that evaluates to a procedure. The body must be a VentureScript expression. The semantics are as Scheme’s
letrec
(TODO). This is useful for defining locally-scoped mutually recursive procedures.No concrete syntax is provided (yet).
-
values_list(<exp>, <exp>, ...)
Returns a list of references (see
ref
) corresponding to the results of evaluating each of its arguments.
-
quasiquote
(<datum>)¶ Data constructed by template instantiation.
If the datum contains no
unquote
expressions,quasiquote
is the same asquote
. Otherwise, the unquoted expressions are evaluated and their results spliced in. This is particularly useful for constructing model program fragments in inference programs – so much so, that the modeling inference SPs automatically quasiquote their model arguments.TODO: Nested quasiquotation does not work properly: all unquoted expressions are evaluated regardless of quasiquotation level.
-
ref
(<object>)¶
Create a reference to the given object.
The use of references is that the reference itself is deterministic even if the object is stochastic, and constraint back-propagates from dereferencing to the random choice generating the object. A reference may therefore be stored in data structures without causing them to be resampled if the object changes, and without preventing the object from being observed after being taken out of the data structure.
For example:
[assume lst (list (ref (normal 0 1)) (ref (normal 0 1)))]
[observe (deref (first lst)) 3]
-
deref
(<object>)¶
Dereference a reference created with ref
.
The use of references is that the reference itself is deterministic even if the object is stochastic, and constraint back-propagates from dereferencing to the random choice generating the object. A reference may therefore be stored in data structures without causing them to be resampled if the object changes, and without preventing the object from being observed after being taken out of the data structure.
For example:
[assume lst (list (ref (normal 0 1)) (ref (normal 0 1)))]
[observe (deref (first lst)) 3]
In addition, macros intended for the inference programming language are (as of this writing) expanded in expressions of the modeling language as well. The results are generally not useful, so it’s appropriate to treat those as reserved words when writing models:
do
,begin
,call_back
,collect
,assume
,observe
,predict
,force
,sample
,sample_all
Built-in Procedures¶
The following modeling procedures are built in to Venture (as of the generation date of this manual):
-
add
(<integer>, ...)¶ Return type: <integer> add returns the sum of all its arguments
Deterministic
-
sub
(<number>, <number>)¶ Return type: <number> sub returns the difference between its first and second arguments
Deterministic
-
mul
(<number>, ...)¶ Return type: <number> mul returns the product of all its arguments
Deterministic
-
div
(<number>, <number>)¶ Return type: <number> div returns the ratio of its first argument to its second
Deterministic
-
int_div
(<number>, <number>)¶ Return type: <integer> int_div(n, d) = floor(n/d)
Deterministic
-
int_mod
(<number>, <number>)¶ Return type: <integer> int_mod(n, d) = r, where n = d*q + r and q = floor(n/d)
Deterministic
-
min
(<number>, <number>)¶ Return type: <number> min returns the minimum value of its arguments
Deterministic
-
max
(<number>, <number>)¶ Return type: <number> max returns the maximum value of its arguments
Deterministic
-
floor
(<number>)¶ Return type: <number> floor returns the largest integer less than or equal to its argument (as a VentureNumber)
Deterministic
-
sin
(<number>)¶ Return type: <number> Returns the sin of its argument
Deterministic
-
cos
(<number>)¶ Return type: <number> Returns the cos of its argument
Deterministic
-
tan
(<number>)¶ Return type: <number> Returns the tan of its argument
Deterministic
-
hypot
(<number>, <number>)¶ Return type: <number> Returns the hypot of its arguments
Deterministic
-
exp
(<number>)¶ Return type: <number> Returns the exp of its argument
Deterministic
-
expm1
(<number>)¶ Return type: <number> Returns the exp of its argument, minus one
Deterministic
-
log
(<number>)¶ Return type: <number> Returns the log of its argument
Deterministic
-
log1p
(<number>)¶ Return type: <number> Returns the log of one plus its argument
Deterministic
-
pow
(<number>, <number>)¶ Return type: <number> pow returns its first argument raised to the power of its second argument
Deterministic
-
sqrt
(<number>)¶ Return type: <number> Returns the sqrt of its argument
Deterministic
-
atan2
(<number>, <number>)¶ Return type: <number> atan2(y,x) returns the angle from the positive x axis to the point x,y. The order of arguments is conventional.
Deterministic
-
negate
(<number>)¶ Return type: <number> negate(x) returns -x, the additive inverse of x.
Deterministic
-
abs
(<number>)¶ Return type: <number> abs(x) returns the absolute value of x.
Deterministic
-
signum
(<number>)¶ Return type: <number> signum(x) returns the sign of x (1 if positive, -1 if negative, 0 if zero).
Deterministic
-
logistic
(<number>)¶ Return type: <number> The logistic function: 1/(1+exp(-x))
Deterministic
-
logisticv
(<array <number>>)¶ Return type: <array <number>> The logistic function: 1/(1+exp(-x))
Deterministic
-
logit
(<number>)¶ Return type: <number> The logit (inverse logistic) function: log(x/(1-x))
Deterministic
-
log_logistic
(<number>)¶ Return type: <number> The log of the logistic function: -log (1 + exp(-x))
Deterministic
-
logit_exp
(<number>)¶ Return type: <number> The logit of exp: -log (exp(-x) - 1)
Deterministic
-
logsumexp
(<array <number>>)¶ Return type: <number> Equivalent to log(apply(add, mapv(exp, x)))
Deterministic
-
eq
(<object>, <object>)¶ Return type: <bool> eq compares its two arguments for equality
Deterministic
-
neq
(<object>, <object>)¶ Return type: <bool> neq checkes whether its arguments are not equal
Deterministic
-
gt
(<object>, <object>)¶ Return type: <bool> gt returns true if its first argument compares greater than its second
Deterministic
-
gte
(<object>, <object>)¶ Return type: <bool> gte returns true if its first argument compares greater than or equal to its second
Deterministic
-
lt
(<object>, <object>)¶ Return type: <bool> lt returns true if its first argument compares less than its second
Deterministic
-
lte
(<object>, <object>)¶ Return type: <bool> lte returns true if its first argument compares less than or equal to its second
Deterministic
-
real
(<number>)¶ Return type: <number> real explicitly coerces its argument to a number
Deterministic
-
atom
(<integer>)¶ Return type: <atom> atom returns the identity of its argument integer as an atom
Deterministic
-
atom_index
(<atom>)¶ Return type: <integer> atom_index returns the identity of its argument atom as an integer
Deterministic
-
integer
(<number>)¶ Return type: <integer> integer returns the floor of its argument number as an integer
Deterministic
-
probability
(<probability>)¶ Return type: <probability> probability converts its argument to a probability (in direct space)
Deterministic
-
not
(<bool>)¶ Return type: <bool> not returns the logical negation of its argument
Deterministic
-
xor
(<bool>, <bool>)¶ Return type: <bool> xor(x,y) returns true if exactly one of x and y is true
Deterministic
-
all_p
(<list <bool>>)¶ Return type: <bool> all returns true if all of the elements in the input are true
Deterministic
-
any_p
(<list <bool>>)¶ Return type: <bool> any returns true if any of the elements in the input are true
Deterministic
-
is_number
(<object>)¶ Return type: <bool> is_number returns true iff its argument is a <number>
Deterministic
-
is_integer
(<object>)¶ Return type: <bool> is_integer returns true iff its argument is a <integer>
Deterministic
-
is_probability
(<object>)¶ Return type: <bool> is_probability returns true iff its argument is a <probability>
Deterministic
-
is_atom
(<object>)¶ Return type: <bool> is_atom returns true iff its argument is a <atom>
Deterministic
-
is_boolean
(<object>)¶ Return type: <bool> is_boolean returns true iff its argument is a <bool>
Deterministic
-
is_symbol
(<object>)¶ Return type: <bool> is_symbol returns true iff its argument is a <symbol>
Deterministic
-
is_procedure
(<object>)¶ Return type: <bool> is_procedure returns true iff its argument is a <SP <object> … -> <object>>
Deterministic
-
list
(<object>, ...)¶ Return type: <list> list returns the list of its arguments
Deterministic
-
pair
(<object>, <object>)¶ Return type: <pair <object> <object>> pair returns the pair whose first component is the first argument and whose second component is the second argument
Deterministic
-
is_pair
(<object>)¶ Return type: <bool> is_pair returns true iff its argument is a <pair <object> <object>>
Deterministic
-
first
(<pair <object> <object>>)¶ Return type: <object> first returns the first component of its argument pair
Deterministic
-
rest
(<pair <object> <object>>)¶ Return type: <object> rest returns the second component of its argument pair
Deterministic
-
second
(<pair <object> <pair <object> <object>>>)¶ Return type: <object> second returns the first component of the second component of its argument
Deterministic
-
to_list
(<sequence <object>>)¶ Return type: <list <object>> to_list converts its argument sequence to a list
Deterministic
-
zip
(<list>, ...)¶ Return type: <list <list>> zip returns a list of lists, where the i-th nested list contains the i-th element from each of the input arguments
Deterministic
-
reverse
(<list>)¶ Return type: <list> reverse reverses the order of its argument list
Deterministic
-
set_difference
(<list>, <list>)¶ Return type: <list> set_difference returns the elements in the first list that do not appear in the second
Deterministic
-
dict
(2-tuple(k, v), ...)¶ Return type: <dict k v> dict returns the dictionary mapping each of the given keys to their respective given values.
Deterministic
-
is_dict
(<object>)¶ Return type: <bool> is_dict returns true iff its argument is a <dict>
Deterministic
-
to_dict
(<list 2-tuple(k, v)>)¶ Return type: <dict k v> to_dict returns the dictionary mapping each of the given keys to their respective given values.
Deterministic
-
keys
(<dict k v>)¶ Return type: <list k> keys returns a list of keys of the given dictionary.
Deterministic
-
values
(<dict k v>) Return type: <list v> values returns a list of values of the given dictionary.
Deterministic
-
lookup
(<mapping k v>, k)¶ Return type: v lookup looks the given key up in the given mapping and returns the result. It is an error if the key is not in the mapping. Lists and arrays are viewed as mappings from indices to the corresponding elements. Environments are viewed as mappings from symbols to their values.
Deterministic
-
contains
(<mapping k v>, k)¶ Return type: <bool> contains reports whether the given key appears in the given mapping or not.
Deterministic
-
size
(<mapping k v>)¶ Return type: <integer> size returns the number of elements in the given collection (lists and arrays work too)
Deterministic
-
is_empty
(<mapping k v>)¶ Return type: <bool> is_empty returns whether the given collection is empty (lists and arrays work too)
Deterministic
-
take
(<integer>, <sequence k>)¶ Return type: <sequence k> take returns the requested number of elements from the beginning of the given sequence, as another sequence of the same type.
Deterministic
-
debug
(<string>, k)¶ Return type: k Print the given value, labeled by a string. Return the value. Intended for debugging or for monitoring execution.
Deterministic
-
value_error
(<object>)¶ Return type: <object> deterministic value_error
Deterministic
-
name
(<symbol>, <number>)¶ Return type: <symbol> Programmatically synthesize a variable name. The name is determined by the given prefix and index.
Deterministic
-
dump_data
(<object>, <string>)¶ Return type: () - Dump the given object to the given file as a pickled Python data structure.
- The object must be backed by a picklable instance of
VentureValue
. The object is dumped as aVentureValue
with no conversion, so this is convenient for persisting values for later consumption byload_data
. If you want to dump values for use by a non-VentureScript client, considerdump_py_data
.
Deterministic
-
load_data
(<string>)¶ Return type: <object> - Load a Venture value from a pickled Python data structure in the
given file. The object is loaded as a
VentureValue
with no conversion, so this is the inverse ofdump_data
. If you want to load values dumped by a non-VentureScript client, considerload_py_data
.As always, remember that loading untrusted pickle files leaves you vulnerable to remote code execution.
Deterministic
-
dump_py_data
(<data>, <string>)¶ Return type: () - Dump the given object to the given file as a pickled Python data structure.
- The object must be a ‘plain data’ object – no traces, SPs, or any such stuff.
The object is converted to an equivalent Python data structure prior to dumping,
so it is convenient to consume by a non-VentureScript client program.
If you want to persist data for future consumption be VentureScript, use
dump_data
andload_data
.
Deterministic
-
load_py_data
(<string>)¶ Return type: <data> - Load a pickled Python data structure from the given file.
The object must be a ‘plain data’ object – no classes, functions, or any such stuff. The object is converted to an equivalent Venture data structure after loading, so this is convenient for consuming data produced by a non-VentureScript program. If you want to load data persisted from VentureScript, use
load_data
anddump_data
.As always, remember that loading untrusted pickle files leaves you vulnerable to remote code execution.
Deterministic
-
array
(<object>, ...)¶ Return type: <array> array returns an array initialized with its arguments
Deterministic
-
vector
(<number>, ...)¶ Return type: <array <number>> vector returns an unboxed numeric array initialized with its arguments
Deterministic
-
is_array
(<object>)¶ Return type: <bool> is_array returns true iff its argument is a <array>
Deterministic
-
is_vector
(<object>)¶ Return type: <bool> is_vector returns true iff its argument is a <array <number>>
Deterministic
-
to_array
(<sequence <object>>)¶ Return type: <array> to_array converts its argument sequence to an array
Deterministic
-
to_vector
(<sequence <number>>)¶ Return type: <array <number>> to_vector converts its argument sequence to a vector
Deterministic
-
matrix
(<list <list <number>>>)¶ Return type: <matrix> matrix returns a matrix formed from the given list of rows. It is an error if the given list is not rectangular.
Deterministic
-
is_matrix
(<object>)¶ Return type: <bool> is_matrix returns true iff its argument is a <matrix>
Deterministic
-
simplex
(<probability>, ...)¶ Return type: <simplex> simplex returns the simplex point given by its argument coordinates.
Deterministic
-
is_simplex
(<object>)¶ Return type: <bool> is_simplex returns true iff its argument is a <simplex>
Deterministic
-
normalize
(<list <number>>)¶ Return type: <simplex> normalize converts its argument sequence to a simplex by scalingits elements so that they sum to 1.
Deterministic
-
arange
(<integer>[, <integer>])¶ Return type: <array <integer>> arange([start], stop) returns an array of n consecutive integers from start (inclusive) up to stop (exclusive).
Deterministic
-
fill
(<integer>, <number>)¶ Return type: <array <number>> fill(n, x) returns an array with the number x repeated n times
Deterministic
-
linspace
(<number>, <number>, <count>)¶ Return type: <array <number>> linspace(start, stop, n) returns an array of n evenly spaced numbers over the interval [start, stop].
Deterministic
-
zero_matrix
(<count>, <count>)¶ Return type: <matrix> zero_matrix(n, m) returns a zero matrix of shape n by m.
Deterministic
-
id_matrix
(<count>)¶ Return type: <matrix> id_matrix(n) returns an identity matrix of dimension n.
Deterministic
-
diag_matrix
(<array <number>>)¶ Return type: <matrix> diag_matrix(v) returns a diagonal array whose diagonal is v.
Deterministic
-
ravel
(<matrix>)¶ Return type: <array <number>> ravel(m) returns a 1-D array containing the elements of the matrix m.
Deterministic
-
transpose
(<matrix>)¶ Return type: <matrix> transpose(m) returns the transpose of the matrix m.
Deterministic
-
vector_add
(<array <number>>, <array <number>>)¶ Return type: <array <number>> vector_add(x, y) returns the sum of vectors x and y.
Deterministic
-
hadamard
(<array <number>>, <array <number>>)¶ Return type: <array <number>> hadamard(x, y) returns the Haramard (elementwise) product of vectors x and y.
Deterministic
-
matrix_add
(<matrix>, <matrix>)¶ Return type: <matrix> matrix_add(x, y) returns the sum of matrices x and y.
Deterministic
-
scale_vector
(<number>, <array <number>>)¶ Return type: <array <number>> scale_vector(x, y) returns the product of scalar x and vector y.
Deterministic
-
scale_matrix
(<number>, <matrix>)¶ Return type: <matrix> scale_matrix(x, y) returns the product of scalar x and matrix y.
Deterministic
-
vector_dot
(<array <number>>, <array <number>>)¶ Return type: <number> vector_dot(x, y) returns the dot product of vectors x and y.
Deterministic
-
matrix_mul
(<matrix>, <matrix>)¶ Return type: <matrix> matrix_mul(x, y) returns the product of matrices x and y.
Deterministic
-
matrix_times_vector
(<matrix>, <array <number>>)¶ Return type: <array <number>> matrix_times_vector(M, v) returns the matrix-vector product Mv.
Deterministic
-
vector_times_matrix
(<array <number>>, <matrix>)¶ Return type: <array <number>> vector_times_matrix(v, M) returns the vector-matrix product vM.
Deterministic
-
matrix_inverse
(<matrix>)¶ Return type: <matrix> matrix_inverse(M) returns the (multiplicative) inverse of the matrix M.
Deterministic
-
matrix_solve
(<matrix>, <matrix>)¶ Return type: <matrix> matrix_solve(A, B) returns the solution to the matrix equation AX = B.
Deterministic
-
matrix_trace
(<matrix>)¶ Return type: <number> matrix_trace(x) returns the trace (in the algebraic sense) of matrix x.
Deterministic
-
row
(<matrix>, <integer>)¶ Return type: <array <number>> row(A, i) returns the ith row of the matrix A.
Deterministic
-
col
(<matrix>, <integer>)¶ Return type: <array <number>> col(A, j) returns the jth column of the matrix A.
Deterministic
-
sum
(<array <number>>)¶ Return type: <number> sum(v) returns the sum of the elements of the vector v.
Deterministic
-
append
(<array>, <array>)¶ Return type: <array> append(a, b) returns the concatenation of a and b.
Deterministic
-
inference_action
(<object>)¶ Return type: <inference_action> inference_action constructs a inference_action record
Deterministic
-
is_inference_action
(<object>)¶ Return type: <bool> is_inference_action returns true iff its argument is a <inference_action>
Deterministic
-
action_func
(<inference_action>)¶ Return type: <object> action_func extracts the 0 field of a inference_action record
Deterministic
-
make_ref
(<object>)¶ Return type: <make_ref> make_ref constructs a make_ref record
Deterministic
-
is_make_ref
(<object>)¶ Return type: <bool> is_make_ref returns true iff its argument is a <make_ref>
Deterministic
-
ref_get
(<make_ref>)¶ Return type: <object> ref_get extracts the 0 field of a make_ref record
Deterministic
-
apply
(proc(a, ...) -> b, <array a>)¶ Return type: b apply(func, vals) returns the result of applying a variadic function to an array of operands
Deterministic
-
mapv
(proc(a) -> b, <array a>)¶ Return type: <array b> mapv(func, vals) returns the results of applying a function to each value in an array
Deterministic
-
mapv2
(proc(a, b) -> c, <array a>, <array b>)¶ Return type: <array c> mapv2(func, vals1, vals2) returns the results of applying a binary function to each pair of values in the given two arrays
Deterministic
-
imapv
(proc(index, a) -> b, <array a>)¶ Return type: <array b> imapv(func, vals) returns the results of applying a function to each value in an array, together with its index
Deterministic
-
fix
(<array <symbol>>, <array <exp>>)¶ Return type: <environment> - fix
- Used internally in the implementation of letrec.
Deterministic
-
assess
(<val>, proc(<args>, ...) -> <val>, <args>, ...)¶ Return type: <number> assess(val, func, arg1, arg2, …) returns the log probability (density) of simulating val from func(arg1, arg2, …)
Deterministic
-
biplex
(<bool>, <object>, <object>)¶ Return type: <object> biplex returns either its second or third argument, depending on the first.
Deterministic
-
make_csp
(<array <symbol>>, <exp>)¶ Return type: a compound SP - make_csp
- Used internally in the implementation of compound procedures.
Deterministic
-
get_current_environment
()¶ Return type: <environment> get_current_environment returns the lexical environment of its invocation site
Deterministic
-
get_empty_environment
()¶ Return type: <environment> get_empty_environment returns the empty environment
Deterministic
-
is_environment
(<object>)¶ Return type: <bool> is_environment returns true iff its argument is a <environment>
Deterministic
-
extend_environment
(<environment>, <symbol>, <object>)¶ Return type: <environment> extend_environment returns an extension of the given environment where the given symbol is bound to the given object
Deterministic
-
eval
(<exp>, <environment>)¶ Return type: <object> eval evaluates the given expression in the given environment and returns the result. Is itself deterministic, but the given expression may involve a stochasitc computation.
Deterministic
-
address_of
(<object>)¶ Return type: <string> address_of returns a string representing the address of the top nontrivial node of its argument
Deterministic
-
mem
(proc(a, ...) -> b)¶ Return type: proc(a, ..) -> b mem returns the stochastically memoized version of the input SP.
Deterministic
-
tag
(<scope>, <block>, <object>)¶ Return type: <object> tag returns its third argument unchanged at runtime, but tags the subexpression creating the object as being within the given scope and block.
Deterministic
-
tag_exclude
(<scope>, <object>)¶ Return type: <object> tag_exclude returns its second argument unchanged at runtime, but tags the subexpression creating the object as being outside the given scope.
Deterministic
-
flip
([<probability>])¶ Return type: <bool> flip(p) returns true with probability p and false otherwise. If omitted, p is taken to be 0.5. If you are tempted to write (flip (exp x)), write (log_flip x) instead. If you are tempted to write (flip (logistic x)), write (log_odds_flip x) instead.
Stochastic
-
bernoulli
([<probability>])¶ Return type: <integer> bernoulli(p) returns true with probability p and false otherwise. If omitted, p is taken to be 0.5. If you are tempted to write (bernoulli (exp x)), write (log_bernoulli x) instead. If you are tempted to write (bernoulli (logistic x)), write (log_odds_bernoulli x) instead.
Stochastic
-
log_flip
(<nonpositive>)¶ Return type: <bool> log_flip(logp) returns true with probability exp(logp) and false otherwise. Equivalent to (flip (exp logp)), but reduces the chance of pathologies due to rounding (exp logp) to 0 or 1.
Stochastic
-
log_bernoulli
(<nonpositive>)¶ Return type: <integer> log_bernoulli(logp) returns true with probability exp(logp) and false otherwise. Equivalent to (bernoulli (exp logp)), but reduces the chance of pathologies due to rounding (exp logp) to 0 or 1.
Stochastic
-
log_odds_flip
(<number>)¶ Return type: <bool> log_odds_flip(x) returns true with log odds x and false otherwise. Equivalent to (flip (logistic x)), but reduces the chance of pathologies due to rounding (logistic x) to 0 or 1.
Stochastic
-
log_odds_bernoulli
(<number>)¶ Return type: <integer> log_odds_bernoulli(x) returns true with log odds x and false otherwise. Equivalent to (bernoulli (logistic x)), but reduces the chance of pathologies due to rounding (logistic x) to 0 or 1.
Stochastic
-
binomial
(<count>, <probability>)¶ Return type: <count> binomial(n, p) simulates flipping n Bernoulli trials independently with probability p and returns the total number of successes.
Stochastic
-
categorical
(<simplex>[, <array>])¶ Return type: <object> categorical(weights, objects) samples a categorical with the given weights. In the one argument case, returns the index of the chosen option as an integer; in the two argument case returns the item at that index in the second argument. It is an error if the two arguments have different length.
Stochastic
-
log_categorical
(<array <number>>[, <array>])¶ Return type: <object> log_categorical(log_weights, objects) samples a categorical with the given weights, interpreted in log space. In the one argument case, returns the index of the chosen option as an integer; in the two argument case returns the item at that index in the second argument. It is an error if the two arguments have different length.
Stochastic
-
uniform_categorical
(<array>)¶ Return type: <object> uniform_categorical(objects) chooses one of the given objects uniformly at random.
Stochastic
-
uniform_discrete
(<integer>, <integer>)¶ Return type: <integer> uniform_discrete(start, end) samples a uniform discrete on the (start, start + 1, …, end - 1)
Stochastic
-
poisson
(<positive>)¶ Return type: <count> poisson(mu) samples a Poisson with rate mu
Stochastic
-
make_beta_bernoulli
(<positive>, <positive>)¶ Return type: proc() -> <bool> make_beta_bernoulli(alpha, beta) returns a collapsed Beta Bernoulli sampler with pseudocounts alpha (for true) and beta (for false). While this procedure itself is deterministic, the returned sampler is stochastic.
Deterministic, children can absorb at applications
-
make_uc_beta_bernoulli
(<positive>, <positive>)¶ Return type: proc() -> <bool> make_uc_beta_bernoulli(alpha, beta) returns an uncollapsed Beta Bernoulli sampler with pseudocounts alpha (for true) and beta (for false).
Stochastic, children can absorb at applications
-
make_suff_stat_bernoulli
(<number>)¶ Return type: proc() -> <bool> make_suff_stat_bernoulli(weight) returns a Bernoulli sampler (weighted coin) with given weight. The latter maintains application statistics sufficient to absorb changes to the weight in O(1) time (without traversing all the applications).
Deterministic, children can absorb at applications
-
exactly
(<object>[, <number>])¶ Return type: <object> Force a variable to be treated as random even though its value is known. This deterministically returns the first argument when simulated, but is willing to pretend to be able to stochastically return any object. The second argument, if given, is the penalty (in log space) for a mismatch. If not given, taken to be -infinity.
Stochastic
-
make_gamma_poisson
(<positive>, <positive>)¶ Return type: proc() -> <count> make_gamma_poisson(alpha, beta) returns a collapsed Gamma Poisson sampler. While this procedure itself is deterministic, the returned sampler is stochastic.
Deterministic, children can absorb at applications
-
make_uc_gamma_poisson
(<positive>, <positive>)¶ Return type: proc() -> <count> make_uc_gamma_poisson(alpha, beta) returns an uncollapsed Gamma Poisson sampler.
Stochastic, children can absorb at applications
-
make_suff_stat_poisson
(<positive>)¶ Return type: proc() -> <count> make_suff_stat_poisson(mu) returns Poisson sampler with given mu. While this procedure itself is deterministic, the returned sampler is stochastic. The latter maintains application statistics sufficient to absorb changes to the weight in O(1) time (without traversing all the applications.
Deterministic, children can absorb at applications
-
multivariate_normal
(<array <number>>, <symmetricmatrix>)¶ Return type: <array <number>> multivariate_normal(mean, covariance) samples a vector according to the given multivariate Gaussian distribution. It is an error if the dimensionalities of the arguments do not line up.
Stochastic
-
inv_wishart
(<symmetricmatrix>, <positive>)¶ Return type: <symmetricmatrix> inv_wishart(scale_matrix, degree_of_freedeom) samples a positive definite matrix according to the given inverse Wishart distribution.
Stochastic
-
wishart
(<symmetricmatrix>, <positive>)¶ Return type: <symmetricmatrix> wishart(scale_matrix, degree_of_freedeom) samples a positive definite matrix according to the given inverse Wishart distribution.
Stochastic
-
normalss
(<number>, <number>)¶ Return type: <number> normalss(mu, sigma) samples a normal distribution with mean mu and standard deviation sigma.
Stochastic, variationable
-
normalsv
(<number>, <array <number>>)¶ Return type: <array <number>> normalsv(mu, sigma) samples a vector of normal variates, all with the same mean mu, and a vector of standard deviations sigma.
Stochastic
-
normalvs
(<array <number>>, <number>)¶ Return type: <array <number>> normalvs(mu, sigma) samples a vector of normal variates, with a a vector of means mu, and all the same standard deviation sigma.
Stochastic
-
normalvv
(<array <number>>, <array <number>>)¶ Return type: <array <number>> normalvv(mu, sigma) samples a vector of normal variates with means mu and corresponding standard deviations sigma.
Stochastic
-
normal
(<number>, <number>)¶ Return type: <number> normal(mu, sigma) samples a normal distribution with mean mu and standard deviation sigma.
Stochastic, variationable
-
lognormal
(<number>, <positive>)¶ Return type: <positive> lognormal(mu, sigma) samples a normal distribution with mean mu and standard deviation sigma, and yields its exponential.
Stochastic
-
vonmises
(<number>, <positive>)¶ Return type: <number> vonmises(mu, kappa) samples a von Mises distribution with mean mu and shape kappa. The output is normalized to the interval [-pi,pi].
Stochastic
-
uniform_continuous
(<number>, <number>)¶ Return type: <number> uniform_continuous(low, high) samples a uniform real number between low and high.
Stochastic
-
log_odds_uniform
()¶ Return type: <number> log_odds_uniform() samples a log-odds representation of a uniform real number between 0 and 1. This is also called the “logistic distribution”, named differently to avoid confusion with the logistic function.
Stochastic
-
beta
(<positive>, <positive>)¶ Return type: <probability> beta(alpha, beta) returns a sample from a Beta distribution with shape parameters alpha and beta.
Stochastic
-
log_beta
(<positive>, <positive>)¶ Return type: <number> log_beta(alpha, beta) returns the log-space representation of a sample from a Beta distribution with shape parameters alpha and beta.
Stochastic
-
log_odds_beta
(<positive>, <positive>)¶ Return type: <number> log_odds_beta(alpha, beta) returns the log-odds representation of a sample from a Beta distribution with shape parameters alpha and beta.
Stochastic
-
expon
(<positive>)¶ Return type: <positive> expon(theta) returns a sample from an exponential distribution with rate (inverse scale) parameter theta.
Stochastic
-
gamma
(<positive>, <positive>)¶ Return type: <positive> gamma(alpha, beta) returns a sample from a Gamma distribution with shape parameter alpha and rate parameter beta.
Stochastic
-
student_t
(<positive>[, <number>[, <number>]])¶ Return type: <number> student_t(nu, loc, shape) returns a sample from Student’s t distribution with nu degrees of freedom, with optional location and scale parameters.
Stochastic
-
inv_gamma
(<positive>, <positive>)¶ Return type: <positive> inv_gamma(alpha, beta) returns a sample from an inverse Gamma distribution with shape parameter alpha and scale parameter beta
Stochastic
-
laplace
(<number>, <positive>)¶ Return type: <number> laplace(a, b) returns a sample from a Laplace (double exponential) distribution with shape parameter a and scale parameter b
Stochastic
-
make_nig_normal
(<number>, <positive>, <positive>, <positive>)¶ Return type: proc() -> <number> make_nig_normal(m,V,a,b) returns collapsed NormalInverseGamma Normal sampler. While this procedure itself is deterministic, the returned sampler is stochastic.
Deterministic, children can absorb at applications
-
make_uc_nig_normal
(<number>, <positive>, <positive>, <positive>)¶ Return type: proc() -> <number> make_uc_nig_normal(alpha, beta) returns an uncollapsed Normal-InverseGamma Normal sampler.
Stochastic, children can absorb at applications
-
make_suff_stat_normal
(<number>, <positive>)¶ Return type: proc() -> <number> make_suff_stat_normal(mu, sigma) returns Normal sampler with given mean and sigma. While this procedure itself is deterministic, the returned sampler is stochastic. The latter maintains application statistics sufficient to absorb changes to the weight in O(1) time (without traversing all the applications.
Deterministic, children can absorb at applications
-
dirichlet
(<array <positive>>)¶ Return type: <simplex> dirichlet(alphas) samples a simplex point according to the given Dirichlet distribution.
Stochastic
-
symmetric_dirichlet
(<positive>, <count>)¶ Return type: <simplex> symmetric_dirichlet(alpha, n) samples a simplex point according to the symmetric Dirichlet distribution on n dimensions with concentration parameter alpha.
Stochastic
-
make_dir_cat
(<array <positive>>[, <array>])¶ Return type: proc() -> <object> make_dir_cat(alphas, objects) returns a sampler for a collapsed Dirichlet categorical model. If the objects argument is given, the sampler will return one of those objects on each call; if not, it will return the index into the corresponding alpha, as an integer. It is an error if the list of objects is supplied and has different length from the list of alphas. While this procedure itself is deterministic, the returned sampler is stochastic.
Deterministic, children can absorb at applications
-
make_uc_dir_cat
(<array <positive>>[, <array>])¶ Return type: proc() -> <object> make_uc_dir_cat is an uncollapsed variant of make_dir_cat.
Stochastic, children can absorb at applications
-
make_sym_dir_cat
(<positive>, <count>[, <array>])¶ Return type: proc() -> <object> make_sym_dir_cat is a symmetric variant of make_dir_cat.
Deterministic, children can absorb at applications
-
make_uc_sym_dir_cat
(<positive>, <count>[, <array>])¶ Return type: proc() -> <object> make_uc_sym_dir_cat is an uncollapsed symmetric variant of make_dir_cat.
Stochastic, children can absorb at applications
-
make_crp
(<number>[, <number>])¶ Return type: proc() -> <atom> - make_crp(alpha, d) -> <SP () <number>>
- Chinese Restaurant Process with hyperparameters alpha, and d (defaults to zero, recovering the one-parameter CRP). Returns a sampler for the table number.
Deterministic, children can absorb at applications
-
make_lazy_hmm
(<simplex>, <matrix>, <matrix>)¶ Return type: proc(<count>) -> <integer> Discrete-state HMM of unbounded length with discrete observations. The inputs are the probability distribution of the first state, the transition matrix, and the observation matrix. It is an error if the dimensionalities do not line up. Returns observations from the HMM encoded as a stochastic procedure that takes the time step and samples a new observation at that time step.
Stochastic, children can absorb at applications
-
make_niw_normal
(<array <number>>, <number>, <number>, <matrix>)¶ Return type: proc() -> <array <number>> - make_niw_normal(m0, k0, v0, S0) -> <SP () <float array>>
- Collapsed multivariate normal with hyperparameters m0, k0, v0, S0, where parameters are named as in (Murphy, section 4.6.3.3, page 134).
Deterministic, children can absorb at applications
-
apply_function
()¶ apply_function
Deterministic
-
make_gp
(mean function, covariance kernel)¶ Return type: proc(<array <numarray>>) -> <array <number>> Constructs a Gaussian Process with the given mean and covariance functions. Note that each application of the GP involves a matrix inversion, so when sampling at many inputs it is much more efficient to batch-query by passing a vector of input values. Wrap the GP in a mem if input points might be sampled multiple times. Global Logscore is broken with GPs, as it is with all SPs that have auxen.
Deterministic, children can absorb at applications
-
gp_mean_const
(o)¶ Return type: <mean> Constant mean function, everywhere equal to c.
Deterministic
-
gp_cov_const
(c)¶ Return type: <covariance> Constant kernel: everywhere equal to c.
Deterministic
-
gp_cov_delta
(t^2)¶ Return type: <covariance> Delta kernel: 1 if r^2 is at most tolerance, else 0.
Deterministic
-
gp_cov_deltoid
(t^2, s)¶ Return type: <covariance> Deltoid kernel: 1 - e^{-1/(r/t)^s}.
Shaped kinda like a sigmoid, but not quite. Behaves kinda like a delta, but smoothly.
Tolerance is in units of squared distance and determines at what squared radius the covariance kernel attains 1/2.
Deterministic
-
gp_cov_bump
(t_0, t_1)¶ Return type: <covariance> Bump kernel: 1 if r^2 < min_tolerance, 0 if r^2 > max_tolerance.
Deterministic
-
gp_cov_se
(l^2)¶ Return type: <covariance> Squared-exponential kernel: e^(-r^2 / (2 l^2))
Deterministic
-
gp_cov_periodic
(l^2, T)¶ Return type: <covariance> Periodic kernel: e^(-(2 sin(2pi r / T))^2 / (2 l^2))
Deterministic
-
gp_cov_rq
(l^2, alpha)¶ Return type: <covariance> Rational quadratic kernel: (1 + r^2/(2 alpha l^2))^-alpha
Deterministic
-
gp_cov_matern
(l^2, df)¶ Return type: <covariance> Matérn kernel with squared length-scale l2 and nu = df/2.
Deterministic
-
gp_cov_matern_32
(l^2)¶ Return type: <covariance> Matérn kernel specialized with three degrees of freedom.
Deterministic
-
gp_cov_matern_52
(l^2)¶ Return type: <covariance> Matérn kernel specialized with five degrees of freedom.
Deterministic
-
gp_cov_linear
(x)¶ Return type: <covariance> Linear covariance kernel: k(x, y) = (x - c) (y - c).
Deterministic
-
gp_cov_bias
(s^2, K)¶ Return type: <covariance> Kernel K biased by the constant squared bias s^2.
Every covariance, including variance/self-covariance, has s^2 added.Deterministic
-
gp_cov_scale
(s^2, K)¶ Return type: <covariance> Kernel K scaled by squared output factor s^2.
Deterministic
-
gp_cov_sum
(K, H)¶ Return type: <covariance> Sum of kernels K and H.
Deterministic
-
gp_cov_product
(K, H)¶ Return type: <covariance> Product of kernels K and H.
Deterministic
You can ask your Venture installation for a current version of this
list by running the vendoc
program (with no arguments).
Built-in Helpers¶
true
: The boolean True value.false
: The boolean False value.