From 583574020426c8e940a227e17e755c0d6991e6e8 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Mon, 14 Oct 2024 22:03:33 +0000 Subject: [PATCH] build based on a94d167 --- dev/.documenter-siteinfo.json | 2 +- dev/api/index.html | 480 +--------------------------------- dev/index.html | 462 +------------------------------- index.html | 1 - 4 files changed, 12 insertions(+), 933 deletions(-) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 5b949b5..07bb19e 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.0","generation_timestamp":"2024-10-08T13:44:19","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.0","generation_timestamp":"2024-10-14T22:03:28","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index c4abc08..f4c15d8 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,479 +1,20 @@ -API · AbstractPPL - - - - - - -

API

VarNames

AbstractPPL.VarNameType
VarName{sym}(optic=identity)

A variable identifier for a symbol sym and optic optic.

The Julia variable in the model corresponding to sym can refer to a single value or to a hierarchical array structure of univariate, multivariate or matrix variables. The field lens stores the indices requires to access the random variable from the Julia variable indicated by sym as a tuple of tuples. Each element of the tuple thereby contains the indices of one optic operation.

VarNames can be manually constructed using the VarName{sym}(optic) constructor, or from an optic expression through the @varname convenience macro.

Examples

julia> vn = VarName{:x}(Accessors.IndexLens((Colon(), 1)) ⨟ Accessors.IndexLens((2, )))
+API · AbstractPPL

API

VarNames

AbstractPPL.VarNameType
VarName{sym}(optic=identity)

A variable identifier for a symbol sym and optic optic.

The Julia variable in the model corresponding to sym can refer to a single value or to a hierarchical array structure of univariate, multivariate or matrix variables. The field lens stores the indices requires to access the random variable from the Julia variable indicated by sym as a tuple of tuples. Each element of the tuple thereby contains the indices of one optic operation.

VarNames can be manually constructed using the VarName{sym}(optic) constructor, or from an optic expression through the @varname convenience macro.

Examples

julia> vn = VarName{:x}(Accessors.IndexLens((Colon(), 1)) ⨟ Accessors.IndexLens((2, )))
 x[:, 1][2]
 
 julia> getoptic(vn)
 (@o _[Colon(), 1][2])
 
 julia> @varname x[:, 1][1+1]
-x[:, 1][2]
source
AbstractPPL.getsymFunction
getsym(vn::VarName)

Return the symbol of the Julia variable used to generate vn.

Examples

julia> getsym(@varname(x[1][2:3]))
+x[:, 1][2]
source
AbstractPPL.getsymFunction
getsym(vn::VarName)

Return the symbol of the Julia variable used to generate vn.

Examples

julia> getsym(@varname(x[1][2:3]))
 :x
 
 julia> getsym(@varname(y))
-:y
source
AbstractPPL.getopticFunction
getoptic(vn::VarName)

Return the optic of the Julia variable used to generate vn.

Examples

julia> getoptic(@varname(x[1][2:3]))
+:y
source
AbstractPPL.getopticFunction
getoptic(vn::VarName)

Return the optic of the Julia variable used to generate vn.

Examples

julia> getoptic(@varname(x[1][2:3]))
 (@o _[1][2:3])
 
 julia> getoptic(@varname(y))
-identity (generic function with 1 method)
source
AbstractPPL.inspaceFunction
inspace(vn::Union{VarName, Symbol}, space::Tuple)

Check whether vn's variable symbol is in space. The empty tuple counts as the "universal space" containing all variables. Subsumption (see subsumes) is respected.

Examples

julia> inspace(@varname(x[1][2:3]), ())
+identity (generic function with 1 method)
source
AbstractPPL.inspaceFunction
inspace(vn::Union{VarName, Symbol}, space::Tuple)

Check whether vn's variable symbol is in space. The empty tuple counts as the "universal space" containing all variables. Subsumption (see subsumes) is respected.

Examples

julia> inspace(@varname(x[1][2:3]), ())
 true
 
 julia> inspace(@varname(x[1][2:3]), (:x,))
@@ -489,7 +30,7 @@
 true
 
 julia> inspace(@varname(x[1][2:3]), (@varname(x[1:10]),))
-true
source
AbstractPPL.subsumesFunction
subsumes(u::VarName, v::VarName)

Check whether the variable name v describes a sub-range of the variable u. Supported indexing:

  • Scalar:

```jldoctest julia> subsumes(@varname(x), @varname(x[1, 2])) true

julia> subsumes(@varname(x[1, 2]), @varname(x[1, 2][3])) true ```

  • Array of scalar: basically everything that fulfills issubset.

```jldoctest julia> subsumes(@varname(x[[1, 2], 3]), @varname(x[1, 3])) true

julia> subsumes(@varname(x[1:3]), @varname(x[2][1])) true ```

  • Slices:

jldoctest julia> subsumes(@varname(x[2, :]), @varname(x[2, 10][1])) true

Currently not supported are:

  • Boolean indexing, literal CartesianIndex (these could be added, though)
  • Linear indexing of multidimensional arrays: x[4] does not subsume x[2, 2] for a matrix x
  • Trailing ones: x[2, 1] does not subsume x[2] for a vector x
source
AbstractPPL.@varnameMacro
@varname(expr, concretize=false)

A macro that returns an instance of VarName given a symbol or indexing expression expr.

If concretize is true, the resulting expression will be wrapped in a concretize() call.

Note that expressions involving dynamic indexing, i.e. begin and/or end, will always need to be concretized as VarName only supports non-dynamic indexing as determined by is_static_optic. See examples below.

Examples

Dynamic indexing

julia> x = (a = [1.0 2.0; 3.0 4.0; 5.0 6.0], );
+true
source
AbstractPPL.subsumesFunction
subsumes(u::VarName, v::VarName)

Check whether the variable name v describes a sub-range of the variable u. Supported indexing:

  • Scalar:

```jldoctest julia> subsumes(@varname(x), @varname(x[1, 2])) true

julia> subsumes(@varname(x[1, 2]), @varname(x[1, 2][3])) true ```

  • Array of scalar: basically everything that fulfills issubset.

```jldoctest julia> subsumes(@varname(x[[1, 2], 3]), @varname(x[1, 3])) true

julia> subsumes(@varname(x[1:3]), @varname(x[2][1])) true ```

  • Slices:

jldoctest julia> subsumes(@varname(x[2, :]), @varname(x[2, 10][1])) true

Currently not supported are:

  • Boolean indexing, literal CartesianIndex (these could be added, though)
  • Linear indexing of multidimensional arrays: x[4] does not subsume x[2, 2] for a matrix x
  • Trailing ones: x[2, 1] does not subsume x[2] for a vector x
source
AbstractPPL.@varnameMacro
@varname(expr, concretize=false)

A macro that returns an instance of VarName given a symbol or indexing expression expr.

If concretize is true, the resulting expression will be wrapped in a concretize() call.

Note that expressions involving dynamic indexing, i.e. begin and/or end, will always need to be concretized as VarName only supports non-dynamic indexing as determined by is_static_optic. See examples below.

Examples

Dynamic indexing

julia> x = (a = [1.0 2.0; 3.0 4.0; 5.0 6.0], );
 
 julia> @varname(x.a[1:end, end][:], true)
 x.a[1:3, 2][:]
@@ -543,21 +84,21 @@
 a.x[1]
 
 julia> @varname(b.$name.x[1])
-b.a.x[1]
source
AbstractPPL.@vsymMacro
@vsym(expr)

A macro that returns the variable symbol given the input variable expression expr. For example, @vsym x[1] returns :x.

Examples

julia> @vsym x
+b.a.x[1]
source
AbstractPPL.@vsymMacro
@vsym(expr)

A macro that returns the variable symbol given the input variable expression expr. For example, @vsym x[1] returns :x.

Examples

julia> @vsym x
 :x
 
 julia> @vsym x[1,1][2,3]
 :x
 
 julia> @vsym x[end]
-:x
source

VarName serialisation

VarName serialisation

AbstractPPL.index_to_dictFunction
index_to_dict(::Integer)
 index_to_dict(::AbstractVector{Int})
 index_to_dict(::UnitRange)
 index_to_dict(::StepRange)
 index_to_dict(::Colon)
 index_to_dict(::ConcretizedSlice{T, Base.OneTo{I}}) where {T, I}
-index_to_dict(::Tuple)

Convert an index i to a dictionary representation.

source
AbstractPPL.dict_to_indexFunction
dict_to_index(dict)
-dict_to_index(symbol_val, dict)

Convert a dictionary representation of an index dict to an index.

Users can extend the functionality of dict_to_index (and hence VarName de/serialisation) by extending this method along with index_to_dict. Specifically, suppose you have a custom index type MyIndexType and you want to be able to de/serialise a VarName containing this index type. You should then implement the following two methods:

  1. AbstractPPL.index_to_dict(i::MyModule.MyIndexType) should return a dictionary representation of the index i. This dictionary must contain the key "type", and the corresponding value must be a string that uniquely identifies the index type. Generally, it makes sense to use the name of the type (perhaps prefixed with module qualifiers) as this value to avoid clashes. The remainder of the dictionary can have any structure you like.

  2. Suppose the value of index_to_dict(i)["type"] is "MyModule.MyIndexType". You should then implement the corresponding method AbstractPPL.dict_to_index(::Val{Symbol("MyModule.MyIndexType")}, dict), which should take the dictionary representation as the second argument and return the original MyIndexType object.

To see an example of this in action, you can look in the the AbstractPPL test suite, which contains a test for serialising OffsetArrays.

source
AbstractPPL.varname_to_stringFunction
varname_to_string(vn::VarName)

Convert a VarName as a string, via an intermediate dictionary. This differs from string(vn) in that concretised slices are faithfully represented (rather than being pretty-printed as colons).

For VarNames which index into an array, this function will only work if the indices can be serialised. This is true for all standard Julia index types, but if you are using custom index types, you will need to implement the index_to_dict and dict_to_index methods for those types. See the documentation of dict_to_index for instructions on how to do this.

julia> varname_to_string(@varname(x))
+index_to_dict(::Tuple)

Convert an index i to a dictionary representation.

source
AbstractPPL.dict_to_indexFunction
dict_to_index(dict)
+dict_to_index(symbol_val, dict)

Convert a dictionary representation of an index dict to an index.

Users can extend the functionality of dict_to_index (and hence VarName de/serialisation) by extending this method along with index_to_dict. Specifically, suppose you have a custom index type MyIndexType and you want to be able to de/serialise a VarName containing this index type. You should then implement the following two methods:

  1. AbstractPPL.index_to_dict(i::MyModule.MyIndexType) should return a dictionary representation of the index i. This dictionary must contain the key "type", and the corresponding value must be a string that uniquely identifies the index type. Generally, it makes sense to use the name of the type (perhaps prefixed with module qualifiers) as this value to avoid clashes. The remainder of the dictionary can have any structure you like.

  2. Suppose the value of index_to_dict(i)["type"] is "MyModule.MyIndexType". You should then implement the corresponding method AbstractPPL.dict_to_index(::Val{Symbol("MyModule.MyIndexType")}, dict), which should take the dictionary representation as the second argument and return the original MyIndexType object.

To see an example of this in action, you can look in the the AbstractPPL test suite, which contains a test for serialising OffsetArrays.

source
AbstractPPL.varname_to_stringFunction
varname_to_string(vn::VarName)

Convert a VarName as a string, via an intermediate dictionary. This differs from string(vn) in that concretised slices are faithfully represented (rather than being pretty-printed as colons).

For VarNames which index into an array, this function will only work if the indices can be serialised. This is true for all standard Julia index types, but if you are using custom index types, you will need to implement the index_to_dict and dict_to_index methods for those types. See the documentation of dict_to_index for instructions on how to do this.

julia> varname_to_string(@varname(x))
 "{\"optic\":{\"type\":\"identity\"},\"sym\":\"x\"}"
 
 julia> varname_to_string(@varname(x.a))
@@ -567,5 +108,4 @@
 "{\"optic\":{\"indices\":{\"values\":[{\"type\":\"Base.Colon\"}],\"type\":\"Base.Tuple\"},\"type\":\"index\"},\"sym\":\"y\"}"
 
 julia> y = ones(2); varname_to_string(@varname(y[:], true))
-"{\"optic\":{\"indices\":{\"values\":[{\"range\":{\"stop\":2,\"type\":\"Base.OneTo\"},\"type\":\"AbstractPPL.ConcretizedSlice\"}],\"type\":\"Base.Tuple\"},\"type\":\"index\"},\"sym\":\"y\"}"
source
AbstractPPL.string_to_varnameFunction
string_to_varname(str::AbstractString)

Convert a string representation of a VarName back to a VarName. The string should have been generated by varname_to_string.

source

Abstract model functions

AbstractPPL.conditionFunction
condition(model, observations)

Condition the generative model model on some observed data, creating a new model of the (possibly unnormalized) posterior distribution over them.

observations can be of any supported internal trace type, or a fixed probability expression.

The invariant

m = decondition(condition(m, obs))

should hold for generative models m and arbitrary obs.

source
AbstractPPL.deconditionFunction
decondition(conditioned_model)

Remove the conditioning (i.e., observation data) from conditioned_model, turning it into a generative model over prior and observed variables.

The invariant

m == condition(decondition(m), obs)

should hold for models m with conditioned variables obs.

source
DensityInterface.logdensityofFunction
logdensityof(model, trace)

Evaluate the (possibly unnormalized) density of the model specified by the probabilistic program in model, at specific values for the random variables given through trace.

trace can be of any supported internal trace type, or a fixed probability expression.

logdensityof should interact with conditioning and deconditioning in the way required by probability theory.

source

Abstract traces

- +"{\"optic\":{\"indices\":{\"values\":[{\"range\":{\"stop\":2,\"type\":\"Base.OneTo\"},\"type\":\"AbstractPPL.ConcretizedSlice\"}],\"type\":\"Base.Tuple\"},\"type\":\"index\"},\"sym\":\"y\"}"
source
AbstractPPL.string_to_varnameFunction
string_to_varname(str::AbstractString)

Convert a string representation of a VarName back to a VarName. The string should have been generated by varname_to_string.

source

Abstract model functions

AbstractPPL.conditionFunction
condition(model, observations)

Condition the generative model model on some observed data, creating a new model of the (possibly unnormalized) posterior distribution over them.

observations can be of any supported internal trace type, or a fixed probability expression.

The invariant

m = decondition(condition(m, obs))

should hold for generative models m and arbitrary obs.

source
AbstractPPL.deconditionFunction
decondition(conditioned_model)

Remove the conditioning (i.e., observation data) from conditioned_model, turning it into a generative model over prior and observed variables.

The invariant

m == condition(decondition(m), obs)

should hold for models m with conditioned variables obs.

source
DensityInterface.logdensityofFunction
logdensityof(model, trace)

Evaluate the (possibly unnormalized) density of the model specified by the probabilistic program in model, at specific values for the random variables given through trace.

trace can be of any supported internal trace type, or a fixed probability expression.

logdensityof should interact with conditioning and deconditioning in the way required by probability theory.

source

Abstract traces

diff --git a/dev/index.html b/dev/index.html index 0ff22e4..65b6b20 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,462 +1,2 @@ -Home · AbstractPPL - - - - - - -

AbstractPPL.jl

A lightweight package containing interfaces and associated APIs for modelling languages for probabilistic programming.

- +Home · AbstractPPL

AbstractPPL.jl

A lightweight package containing interfaces and associated APIs for modelling languages for probabilistic programming.

diff --git a/index.html b/index.html index 3ac2596..6a5afc3 100644 --- a/index.html +++ b/index.html @@ -1,3 +1,2 @@ -