From 05d17db793d04971ef0711b9ca9283c98fa22036 Mon Sep 17 00:00:00 2001 From: Ivan Bocharov Date: Fri, 30 Aug 2019 15:50:02 +0200 Subject: [PATCH] Updated documentation. Bumped version to 0.10.0 --- Project.toml | 2 +- docs/make.jl | 4 ++-- .../{internal-api.md => developer-api.md} | 15 +++++-------- .../library/{public-api.md => user-api.md} | 8 +++---- .../expectation_propagation.jl | 15 +++++++------ src/algorithms/sum_product/sum_product.jl | 22 +++++++++---------- .../variational_bayes/joint_marginals.jl | 8 +++---- .../naive_variational_bayes.jl | 15 +++++++------ .../recognition_factorization.jl | 20 ++++++++--------- .../structured_variational_bayes.jl | 13 ++++++----- src/edge.jl | 2 +- src/factor_graph.jl | 2 +- src/factor_nodes/bernoulli.jl | 3 +++ src/factor_nodes/beta.jl | 3 +++ src/factor_nodes/categorical.jl | 3 +++ src/factor_nodes/clamp.jl | 2 +- src/factor_nodes/contingency.jl | 3 +++ src/factor_nodes/dirichlet.jl | 3 +++ .../gaussian_weighted_mean_precision.jl | 2 ++ src/factor_nodes/poisson.jl | 3 +++ src/factor_nodes/sigmoid.jl | 2 ++ src/factor_nodes/wishart.jl | 2 +- src/helpers.jl | 10 ++++----- src/interface.jl | 4 ++-- src/marginals.jl | 6 ++--- src/probability_distribution.jl | 13 ++++++----- src/variable.jl | 2 +- 27 files changed, 104 insertions(+), 83 deletions(-) rename docs/src/library/{internal-api.md => developer-api.md} (75%) rename docs/src/library/{public-api.md => user-api.md} (86%) diff --git a/Project.toml b/Project.toml index 07c1f737..b2df8df9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ForneyLab" uuid = "9fc3f58a-c2cc-5bff-9419-6a294fefdca9" -version = "0.9.2" +version = "0.10.0" [compat] julia = "≥ 0.7.0" diff --git a/docs/make.jl b/docs/make.jl index 1c1a6868..ad8f58c6 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -11,8 +11,8 @@ makedocs(modules = [ForneyLab], "Getting started" => "getting-started.md", "User guide" => "user-guide.md", "Library" => Any[ - "Public API" => "library/public-api.md", - "Internal API" => "library/internal-api.md" + "User API" => "library/user-api.md", + "Developer API" => "library/developer-api.md" ], "Contributing" => "contributing.md", "Internals" => "internals.md" diff --git a/docs/src/library/internal-api.md b/docs/src/library/developer-api.md similarity index 75% rename from docs/src/library/internal-api.md rename to docs/src/library/developer-api.md index 766f0e4f..339960f9 100644 --- a/docs/src/library/internal-api.md +++ b/docs/src/library/developer-api.md @@ -1,26 +1,21 @@ -# Internal API +# Developer API -Documentation for `ForneyLab.jl`'s internal API. +Documentation for `ForneyLab.jl`'s developer API. ## Contents ```@contents -Pages = ["internal-api.md"] +Pages = ["developer-api.md"] Depth = 5 ``` ## Index ```@index Modules = [ForneyLab] -Pages = ["internal-api.md"] +Pages = ["developer-api.md"] Order = [:macro, :module, :constant, :type, :function] ``` -## Extended factor nodes -```@docs -ForneyLab.@composite -``` - -## Extended rules +## Extended rules registration ```@docs ForneyLab.@expectationPropagationRule ForneyLab.@marginalRule diff --git a/docs/src/library/public-api.md b/docs/src/library/user-api.md similarity index 86% rename from docs/src/library/public-api.md rename to docs/src/library/user-api.md index 13cb7a86..9b32f5f6 100644 --- a/docs/src/library/public-api.md +++ b/docs/src/library/user-api.md @@ -1,19 +1,19 @@ # User API -Documentation for `ForneyLab.jl`'s public API. +Documentation for `ForneyLab.jl`'s user API. -See [Internal API](@ref) for internal package docs. +If you want to know how you can extend `ForneyLab.jl` (e.g. register new update rules), see [Developer API](@ref). ## Contents ```@contents -Pages = ["public-api.md"] +Pages = ["user-api.md"] Depth = 5 ``` ## Index ```@index Modules = [ForneyLab] -Pages = ["public-api.md"] +Pages = ["user-api.md"] Order = [:macro, :module, :constant, :type, :function] ``` diff --git a/src/algorithms/expectation_propagation/expectation_propagation.jl b/src/algorithms/expectation_propagation/expectation_propagation.jl index 4636fd66..650310c2 100644 --- a/src/algorithms/expectation_propagation/expectation_propagation.jl +++ b/src/algorithms/expectation_propagation/expectation_propagation.jl @@ -6,9 +6,10 @@ variationalExpectationPropagationSchedule, abstract type ExpectationPropagationRule{factor_type} <: MessageUpdateRule end -""" -expectationPropagationSchedule() generates a expectation propagation message passing schedule. -""" +""" +`expectationPropagationSchedule()` generates a expectation propagation +message passing schedule. +""" function expectationPropagationSchedule(variables::Vector{Variable}) ep_sites = collectEPSites(nodes(current_graph)) breaker_sites = Interface[site.partner for site in ep_sites] @@ -30,7 +31,7 @@ function expectationPropagationSchedule(variables::Vector{Variable}) end """ -variationalExpectationPropagationSchedule() generates an expectation propagation message passing schedule +`variationalExpectationPropagationSchedule()` generates an expectation propagation message passing schedule that is limited to the `recognition_factor`. Updates on EP sites are computed with an `ExpectationPropagationRule`. """ function variationalExpectationPropagationSchedule(recognition_factor::RecognitionFactor) @@ -140,9 +141,9 @@ function collectInboundTypes(entry::ScheduleEntry, end """ -@expectationPropagationRule registers a expectation propagation update -rule by defining the rule type and the corresponding methods for the outboundType -and isApplicable functions. If no name (type) for the new rule is passed, a +`@expectationPropagationRule` registers a expectation propagation update +rule by defining the rule type and the corresponding methods for the `outboundType` +and `isApplicable` functions. If no name (type) for the new rule is passed, a unique name (type) will be generated. Returns the rule type. """ macro expectationPropagationRule(fields...) diff --git a/src/algorithms/sum_product/sum_product.jl b/src/algorithms/sum_product/sum_product.jl index 98d232ab..ea837c28 100644 --- a/src/algorithms/sum_product/sum_product.jl +++ b/src/algorithms/sum_product/sum_product.jl @@ -5,10 +5,10 @@ sumProductSchedule, abstract type SumProductRule{factor_type} <: MessageUpdateRule end -""" -sumProductSchedule() generates a sum-product message passing schedule that computes the -marginals for each of the argument variables. -""" +""" +`sumProductSchedule()` generates a sum-product message passing schedule that +computes the marginals for each of the argument variables. +""" function sumProductSchedule(variables::Vector{Variable}) # Generate a feasible summary propagation schedule schedule = summaryPropagationSchedule(variables) @@ -26,9 +26,9 @@ end sumProductSchedule(variable::Variable) = sumProductSchedule([variable]) """ -internalSumProductSchedule() generates a sum-product message passing schedule -for the inner graph of a CompositeNode. This schedule produces the sum-product -message out of the specified outbound_interface. +`internalSumProductSchedule()` generates a sum-product message passing schedule +for the inner graph of a `CompositeNode`. This schedule produces the sum-product +message out of the specified `outbound_interface`. """ function internalSumProductSchedule(cnode::CompositeNode, outbound_interface::Interface, @@ -120,10 +120,10 @@ function collectInboundTypes(entry::ScheduleEntry, end """ -@sumProductRule registers a sum-product update rule by defining the rule type -and the corresponding methods for the outboundType and isApplicable functions. -If no name (type) for the new rule is passed, a unique name (type) will be -generated. Returns the rule type. +`@sumProductRule` registers a sum-product update rule by defining the rule type +and the corresponding methods for the `outboundType` and `isApplicable` +functions. If no name (type) for the new rule is passed, a unique name (type) +will be generated. Returns the rule type. """ macro sumProductRule(fields...) # Init required fields in macro scope diff --git a/src/algorithms/variational_bayes/joint_marginals.jl b/src/algorithms/variational_bayes/joint_marginals.jl index bb890eba..6ef22ef2 100644 --- a/src/algorithms/variational_bayes/joint_marginals.jl +++ b/src/algorithms/variational_bayes/joint_marginals.jl @@ -3,13 +3,13 @@ MarginalRule, @marginalRule """ -MarginalRule{factor_type} specifies a joint marginal update rule with respect +`MarginalRule{factor_type}` specifies a joint marginal update rule with respect to a node of type `factor_type`. """ abstract type MarginalRule{factor_type} <: MarginalUpdateRule end """ -Construct a MarginalScheduleEntry for computing the marginal over `cluster` +Construct a `MarginalScheduleEntry` for computing the marginal over `cluster` through a node-specific joint marginal update rule. """ function MarginalScheduleEntry(cluster::Cluster, outbound_types::Dict{Interface, Type}) @@ -103,8 +103,8 @@ end marginalSchedule(q_factor::RecognitionFactor, schedule::Schedule) = marginalSchedule([q_factor], schedule) """ -@marginalRule registers a marginal update rule for a (joint) marginal -by defining the rule type and the corresponding methods for the isApplicable functions. +`@marginalRule` registers a marginal update rule for a (joint) marginal +by defining the rule type and the corresponding methods for the `isApplicable` function. If no name (type) for the new rule is passed, a unique name (type) will be generated. Returns the rule type. """ diff --git a/src/algorithms/variational_bayes/naive_variational_bayes.jl b/src/algorithms/variational_bayes/naive_variational_bayes.jl index 13eb911d..b7c41223 100644 --- a/src/algorithms/variational_bayes/naive_variational_bayes.jl +++ b/src/algorithms/variational_bayes/naive_variational_bayes.jl @@ -6,7 +6,7 @@ variationalSchedule, abstract type NaiveVariationalRule{factor_type} <: MessageUpdateRule end """ -variationalSchedule() generates a variational message passing schedule that computes the +`variationalSchedule()` generates a variational message passing schedule that computes the marginals for each of the recognition distributions in the recognition factor. """ function variationalSchedule(recognition_factors::Vector{RecognitionFactor}) @@ -86,12 +86,13 @@ function collectInboundTypes( entry::ScheduleEntry, return inbound_types end -""" -@naiveVariationalRule registers a variational update rule for the naive (mean-field) -factorization by defining the rule type and the corresponding methods for the -outboundType and isApplicable functions. If no name (type) for the new rule is -passed, a unique name (type) will be generated. Returns the rule type. -""" +""" +`@naiveVariationalRule` registers a variational update rule for the naive +(mean-field) factorization by defining the rule type and the corresponding +methods for the `outboundType` and `isApplicable` functions. If no name (type) +for the new rule is passed, a unique name (type) will be generated. Returns the +rule type. +""" macro naiveVariationalRule(fields...) # Init required fields in macro scope node_type = :unknown diff --git a/src/algorithms/variational_bayes/recognition_factorization.jl b/src/algorithms/variational_bayes/recognition_factorization.jl index 497c788f..6a12dd98 100644 --- a/src/algorithms/variational_bayes/recognition_factorization.jl +++ b/src/algorithms/variational_bayes/recognition_factorization.jl @@ -1,8 +1,8 @@ export RecognitionFactor, RecognitionFactorization, currentRecognitionFactorization """ -A Cluster specifies a collection of `edges` adjacent to `node` that belong to the same -RecognitionFactor. A joint marginal can be computed over a cluster. +A `Cluster` specifies a collection of `edges` adjacent to `node` that belong to the same +`RecognitionFactor`. A joint marginal can be computed over a cluster. """ mutable struct Cluster <: AbstractCluster id::Symbol @@ -19,7 +19,7 @@ end Base.isless(c1::Cluster, c2::Cluster) = isless("$(c1.id)", "$(c2.id)") """ -A RecognitionFactor specifies the subset of variables that comprise +A `RecognitionFactor` specifies the subset of variables that comprise a joint factor in the recognition factorization. """ mutable struct RecognitionFactor @@ -138,7 +138,7 @@ end """ Find the smallest legal subgraph that includes the argument edges. Default setting terminates the search at soft factors -and does not constrain the search to a limiting set (as specified by an empty limit_set argument). +and does not constrain the search to a limiting set (as specified by an empty `limit_set` argument). """ function extend(edge_set::Set{Edge}; terminate_at_soft_factors=true, limit_set=Set{Edge}()) cluster = Set{Edge}() # Set to fill with edges in cluster @@ -164,7 +164,7 @@ end extend(edge::Edge; terminate_at_soft_factors=true, limit_set=Set{Edge}()) = extend(Set{Edge}([edge]), terminate_at_soft_factors=terminate_at_soft_factors, limit_set=limit_set) """ -A RecognitionFactorization holds a collection of (non-overlapping) recognition factors that +A `RecognitionFactorization` holds a collection of (non-overlapping) recognition factors that specify the recognition factorization over a factor graph that is used for variational inference. """ mutable struct RecognitionFactorization @@ -177,7 +177,7 @@ mutable struct RecognitionFactorization end """ -Return currently active RecognitionFactorization. +Return currently active `RecognitionFactorization`. Create one if there is none. """ function currentRecognitionFactorization() @@ -198,8 +198,8 @@ RecognitionFactorization() = setCurrentRecognitionFactorization( Dict{Tuple{FactorNode, Edge}, Symbol}())) """ -Construct a RecognitionFactorization consisting of one -RecognitionFactor for each argument +Construct a `RecognitionFactorization` consisting of one +`RecognitionFactor` for each argument """ function RecognitionFactorization(args::Vararg{Union{T, Set{T}, Vector{T}} where T<:Variable}; ids=Symbol[]) rf = RecognitionFactorization() @@ -215,7 +215,7 @@ function RecognitionFactorization(args::Vararg{Union{T, Set{T}, Vector{T}} where end """ -Return the id of the RecognitionFactor that `edge` belongs to +Return the id of the `RecognitionFactor` that `edge` belongs to """ function recognitionFactorId(edge::Edge) dict = current_recognition_factorization.edge_to_recognition_factor @@ -253,7 +253,7 @@ Return the ids of the clusters/variables to which edges connected to `node` belo localClusterIds(node::FactorNode) = [clusterId(node, interface.edge) for interface in node.interfaces] """ -Return a dictionary from recognition factor-id to variable/cluster-ids local to node +Return a dictionary from recognition factor-id to variable/cluster-ids local to `node` """ function localRecognitionFactorization(node::FactorNode) # For each edge connected to node, collect the recognition factor and cluster id diff --git a/src/algorithms/variational_bayes/structured_variational_bayes.jl b/src/algorithms/variational_bayes/structured_variational_bayes.jl index 403d3d10..e8db3515 100644 --- a/src/algorithms/variational_bayes/structured_variational_bayes.jl +++ b/src/algorithms/variational_bayes/structured_variational_bayes.jl @@ -64,12 +64,13 @@ function collectInboundTypes(entry::ScheduleEntry, return inbound_types end -""" -@structuredVariationalRule registers a variational update rule for the structured -factorization by defining the rule type and the corresponding methods for the -outboundType and isApplicable functions. If no name (type) for the new rule is -passed, a unique name (type) will be generated. Returns the rule type. -""" +""" +`@structuredVariationalRule` registers a variational update rule for the +structured factorization by defining the rule type and the corresponding methods +for the `outboundType` and `isApplicable` functions. If no name (type) for the +new rule is passed, a unique name (type) will be generated. Returns the rule +type. +""" macro structuredVariationalRule(fields...) # Init required fields in macro scope node_type = :unknown diff --git a/src/edge.jl b/src/edge.jl index bbbbfab7..f4911052 100644 --- a/src/edge.jl +++ b/src/edge.jl @@ -1,7 +1,7 @@ export Edge """ -An Edge joins two interfaces (half-edges) `a` and `b`. +An `Edge` joins two interfaces (half-edges) `a` and `b`. """ mutable struct Edge <: AbstractEdge variable::AbstractVariable diff --git a/src/factor_graph.jl b/src/factor_graph.jl index 8fea241d..144bca7d 100644 --- a/src/factor_graph.jl +++ b/src/factor_graph.jl @@ -20,7 +20,7 @@ mutable struct FactorGraph end """ -Return currently active FactorGraph. +Return currently active `FactorGraph`. Create one if there is none. """ function currentGraph() diff --git a/src/factor_nodes/bernoulli.jl b/src/factor_nodes/bernoulli.jl index a11ed119..199e20bd 100644 --- a/src/factor_nodes/bernoulli.jl +++ b/src/factor_nodes/bernoulli.jl @@ -2,6 +2,7 @@ export Bernoulli """ Description: + Bernoulli factor node out ∈ {0, 1} @@ -10,10 +11,12 @@ Description: f(out, p) = Ber(out|p) = p^out (1 - p)^{1 - out} Interfaces: + 1. out 2. p Construction: + Bernoulli(id=:some_id) """ mutable struct Bernoulli <: SoftFactor diff --git a/src/factor_nodes/beta.jl b/src/factor_nodes/beta.jl index 7662879e..2619fa2f 100644 --- a/src/factor_nodes/beta.jl +++ b/src/factor_nodes/beta.jl @@ -2,6 +2,7 @@ export Beta """ Description: + Beta factor node Real scalars @@ -11,11 +12,13 @@ Description: f(out, a, b) = Beta(out|a, b) = Γ(a + b)/(Γ(a) Γ(b)) out^{a - 1} (1 - out)^{b - 1} Interfaces: + 1. out 2. a 3. b Construction: + Beta(id=:some_id) """ mutable struct Beta <: SoftFactor diff --git a/src/factor_nodes/categorical.jl b/src/factor_nodes/categorical.jl index 618bdd7a..9509a471 100644 --- a/src/factor_nodes/categorical.jl +++ b/src/factor_nodes/categorical.jl @@ -2,6 +2,7 @@ export Categorical """ Description: + Categorical factor node The categorical node defines a one-dimensional probability @@ -14,10 +15,12 @@ Description: = Π_i p_i^{out_i} Interfaces: + 1. out 2. p Construction: + Categorical(id=:some_id) """ mutable struct Categorical <: SoftFactor diff --git a/src/factor_nodes/clamp.jl b/src/factor_nodes/clamp.jl index d3ec5834..7976518f 100644 --- a/src/factor_nodes/clamp.jl +++ b/src/factor_nodes/clamp.jl @@ -52,7 +52,7 @@ function constant(value::Any; id=generateId(Clamp{variateType(value)})) end """ -@ensureVariables(...) casts all non-Variable arguments to Variable through constant(arg). +`@ensureVariables(...)` casts all non-`Variable` arguments to `Variable` through constant(arg). """ macro ensureVariables(args...) lines = ["isa($arg, Variable) || ($arg = constant($arg))" for arg in args] diff --git a/src/factor_nodes/contingency.jl b/src/factor_nodes/contingency.jl index 2c86b0db..6965a967 100644 --- a/src/factor_nodes/contingency.jl +++ b/src/factor_nodes/contingency.jl @@ -2,6 +2,7 @@ export Contingency """ Description: + Contingency factor node The contingency distribution is a multivariate generalization of @@ -21,11 +22,13 @@ Description: higher-order tensors as parameters; these are not implemented in ForneyLab. Interfaces: + 1. out1 2. out2 3. p Construction: + Contingency(id=:some_id) """ mutable struct Contingency <: SoftFactor diff --git a/src/factor_nodes/dirichlet.jl b/src/factor_nodes/dirichlet.jl index a6fc62db..f8a89155 100644 --- a/src/factor_nodes/dirichlet.jl +++ b/src/factor_nodes/dirichlet.jl @@ -2,6 +2,7 @@ export Dirichlet """ Description: + Dirichlet factor node Multivariate: @@ -14,10 +15,12 @@ Description: where 'a' represents a left-stochastic matrix with every a_jk > 0 Interfaces: + 1. out 2. a Construction: + Dirichlet(id=:some_id) """ mutable struct Dirichlet <: SoftFactor diff --git a/src/factor_nodes/gaussian_weighted_mean_precision.jl b/src/factor_nodes/gaussian_weighted_mean_precision.jl index a5f540b1..99b2816f 100644 --- a/src/factor_nodes/gaussian_weighted_mean_precision.jl +++ b/src/factor_nodes/gaussian_weighted_mean_precision.jl @@ -5,6 +5,8 @@ Description: A Gaussian with weighted-mean-precision parameterization: + f(out,xi,w) = 𝒩(out|xi,w) = (2π)^{-D/2} |w|^{1/2} exp(-1/2 xi' w^{-1} xi) exp(-1/2 xi' w xi + out' xi) + Interfaces: 1. out diff --git a/src/factor_nodes/poisson.jl b/src/factor_nodes/poisson.jl index 8dac1e29..9e2b169b 100644 --- a/src/factor_nodes/poisson.jl +++ b/src/factor_nodes/poisson.jl @@ -2,6 +2,7 @@ export Poisson """ Description: + Poisson factor node Real scalars @@ -10,10 +11,12 @@ Description: f(out, l) = Poisson(out|l) = 1/(x!) * l^x * exp(-l) Interfaces: + 1. out 2. l Construction: + Poisson(id=:some_id) """ mutable struct Poisson <: SoftFactor diff --git a/src/factor_nodes/sigmoid.jl b/src/factor_nodes/sigmoid.jl index 8742c758..84e50326 100644 --- a/src/factor_nodes/sigmoid.jl +++ b/src/factor_nodes/sigmoid.jl @@ -7,10 +7,12 @@ Description: f(bin, real) = σ(bin⋅real) Interfaces: + 1. bin 2. real Construction: + Sigmoid(id=:some_id) """ mutable struct Sigmoid <: SoftFactor diff --git a/src/factor_nodes/wishart.jl b/src/factor_nodes/wishart.jl index 654c3d8a..eb665752 100644 --- a/src/factor_nodes/wishart.jl +++ b/src/factor_nodes/wishart.jl @@ -2,7 +2,7 @@ export Wishart """ Description: - + A Wishart node: f(out,v,nu) = W(out|v, nu) = B(v, nu) |out|^{(nu - D - 1)/2} exp(-1/2 tr(v^{-1} out)) diff --git a/src/helpers.jl b/src/helpers.jl index add4d8f4..198e6c56 100644 --- a/src/helpers.jl +++ b/src/helpers.jl @@ -1,6 +1,6 @@ export huge, tiny, cholinv, diageye, eye, format, *, ^, mat -"""ensureMatrix: cast input to a Matrix if necessary""" +"""Cast input to a `Matrix` if necessary""" ensureMatrix(arr::AbstractMatrix{T}) where T<:Number = arr ensureMatrix(arr::Vector{T}) where T<:Number = Diagonal(arr) ensureMatrix(n::Number) = fill!(Array{typeof(n)}(undef,1,1), n) @@ -102,10 +102,10 @@ function format(v::Vector{Any}) return str end -"""isApproxEqual: check approximate equality""" +"""Check if arguments are approximately equal""" isApproxEqual(arg1, arg2) = maximum(abs.(arg1-arg2)) < tiny -"""isRoundedPosDef: is input matrix positive definite? Round to prevent fp precision problems that isposdef() suffers from.""" +"""Checks if input matrix is positive definite. We also perform rounding in order to prevent floating point precision problems that `isposdef()`` suffers from.""" isRoundedPosDef(arr::AbstractMatrix{Float64}) = ishermitian(round.(Matrix(arr), digits=round(Int, log10(huge)))) && isposdef(Hermitian(Matrix(arr), :L)) function viewFile(filename::AbstractString) @@ -114,7 +114,7 @@ function viewFile(filename::AbstractString) end """ -trigammaInverse(x): solve `trigamma(y) = x` for `y`. +Solve `trigamma(y) = x` for `y`. Uses Newton's method on the convex function 1/trigramma(y). Iterations converge monotonically. @@ -194,6 +194,6 @@ function leaftypes(datatype::Type) end """ -Helper function to construct 1x1 Matrix +Helper function to construct 1x1 `Matrix` """ mat(sc) = reshape([sc],1,1) \ No newline at end of file diff --git a/src/interface.jl b/src/interface.jl index 2a57ceb5..9d4efa22 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -2,8 +2,8 @@ export Interface export handle """ -An Interface belongs to a FactorNode and represents a half-edge. -An Interface has at most one partner interface, with wich it forms an edge. +An `Interface` belongs to a `FactorNode` and represents a half-edge. +An `Interface` has at most one partner interface, with wich it forms an edge. """ mutable struct Interface node::FactorNode diff --git a/src/marginals.jl b/src/marginals.jl index dee7ec74..6821d499 100644 --- a/src/marginals.jl +++ b/src/marginals.jl @@ -7,7 +7,7 @@ marginalSchedule abstract type AbstractCluster end """ -A MarginalUpdateRule specifies how a (joint) marginal is calculated from +A `MarginalUpdateRule` specifies how a (joint) marginal is calculated from incoming messages (and a node function). """ abstract type MarginalUpdateRule end @@ -30,7 +30,7 @@ A `MarginalSchedule` defines the update order for marginal computations. const MarginalSchedule = Vector{MarginalScheduleEntry} """ -Construct a MarginalScheduleEntry for computing the marginal over `variable` +Construct a `MarginalScheduleEntry` for computing the marginal over `variable` through multiplication of colliding messages. """ function MarginalScheduleEntry(variable::Variable) @@ -47,7 +47,7 @@ function MarginalScheduleEntry(variable::Variable) end """ -marginalSchedule() generates a marginal schedule that computes the marginals for each target entry +`marginalSchedule()` generates a marginal schedule that computes the marginals for each target entry """ marginalSchedule(targets::Vector{Variable}) = [MarginalScheduleEntry(target) for target in targets] diff --git a/src/probability_distribution.jl b/src/probability_distribution.jl index 88fecadb..283eec52 100644 --- a/src/probability_distribution.jl +++ b/src/probability_distribution.jl @@ -22,7 +22,7 @@ abstract type Univariate <: VariateType end abstract type Multivariate <: VariateType end abstract type MatrixVariate <: VariateType end -"""Encodes a probability distribution as a FactorNode of type `family` with fixed interfaces""" +"""Encodes a probability distribution as a `FactorNode` of type `family` with fixed interfaces""" struct ProbabilityDistribution{var_type<:VariateType, family<:FactorNode} params::Dict end @@ -40,10 +40,11 @@ mode(dist::ProbabilityDistribution) = isProper(dist) ? unsafeMode(dist) : error( var(dist::ProbabilityDistribution) = isProper(dist) ? unsafeVar(dist) : error("var($(dist)) is undefined because the distribution is improper.") cov(dist::ProbabilityDistribution) = isProper(dist) ? unsafeCov(dist) : error("cov($(dist)) is undefined because the distribution is improper.") -""" -PointMass is an abstract type used to describe point mass distributions. -It never occurs in a FactorGraph, but it is used as a probability distribution type. -""" +""" +`PointMass` is an abstract type used to describe point mass distributions. +It never occurs in a `FactorGraph`, but it is used as a probability distribution +type. +""" abstract type PointMass <: DeltaFactor end slug(::Type{PointMass}) = "δ" @@ -93,7 +94,7 @@ Compute conditional differential entropy: H(Y|X) = H(Y, X) - H(X) conditionalDifferentialEntropy(marg_joint::ProbabilityDistribution{Multivariate}, marg_condition::Vararg{ProbabilityDistribution}) = differentialEntropy(marg_joint) - sum([differentialEntropy(marg) for marg in marg_condition]) """ -@RV provides a convenient way to add Variables and FactorNodes to the graph. +`@RV` provides a convenient way to add `Variable`s and `FactorNode`s to the graph. Examples: diff --git a/src/variable.jl b/src/variable.jl index 7f07b7d3..db29d826 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -2,7 +2,7 @@ export Variable """ -A Variable encompasses one or more edges in a FactorGraph. +A `Variable` encompasses one or more edges in a `FactorGraph`. """ mutable struct Variable <: AbstractVariable id::Symbol