For Developers
On this page you can finde more detailed, developer oriented documentation on internal functions which are not necessarily exported to the main API.
MCPhylo.setinits!
— Functionsetinits!(m::Model, inits::Dict{Symbol})
Set the initial values of stochastic model nodes.
Returns the model with stochastic nodes initialized and the iter field set equal to 0.
m
: model with nodes to be initialized.inits
: initial values for stochastic model nodes. Dictionary keys and values should be given for each stochastic node.
setinits!(m::Model, inits::Vector{V} where V<:Dict{Symbol})
MCPhylo.setmonitor!
— Functionsetmonitor!(d::AbstractDependent, monitor::Bool)
Specify node elements to be included in monitored MCMC sampler output.
Returns d with its monitor field updated to reflect the specified monitoring.
d
: node whose elements contain sampled MCMC values.monitor
: boolean indicating whether all elements are monitored.
setmonitor!(d::AbstractDependent, monitor::Vector{Int})
Specify node elements to be included in monitored MCMC sampler output.
Returns d with its monitor field updated to reflect the specified monitoring.
d
: node whose elements contain sampled MCMC values.monitor
: vector of element-wise indices of elements to monitor.
setmonitor!(d::TreeVariate, monitor::Bool)
Specify node elements to be included in monitored MCMC sampler output.
Returns d
with its monitor
field updated to reflect the specified monitoring.
d
: node whose elements contain sampled MCMC values.monitor
: boolean indicating whether all elements are monitored.
setmonitor!(d::TreeVariate, monitor::Vector{Int})
Specify node elements to be included in monitored MCMC sampler output.
Returns d
with its monitor
field updated to reflect the specified monitoring.
d
: node whose elements contain sampled MCMC values.monitor
: vector of element-wise indices of elements to monitor.
MCPhylo.update!
— Functionupdate!(l::AbstractLogical, m::Model)
Update the values of a logical node according to its relationship with others in a model.
Returns the node with its values updated.
l
: logical node to update.m
: model containing the node.
update!(s::AbstractStochastic, m::Model)
Update the values of a stochastic node according to its relationship with others in a model.
Returns the node with its values updated.
s
: stochastic node to update.m
: model containing the node.
update!(m::Model, block::Integer=0)
update!(m::Model, nodekeys::Vector{Symbol})
Update values of logical and stochastic model node according to their relationship with others in a model.
Returns the model with updated nodes.
m
: mode with nodes to be updated.block
: sampling block of nodes to be updated (default: all blocks).nodekeys
: nodes to be updated in the given order.
Base.keys
— FunctionBase.keys(m::Model, ntype::Symbol, at...)
Extract the symbols (keys) for all existing nodes or for nodes of a specified type.
m
: model containing the nodes of interest.ntype
: type of nodes to return. Options are:all
: all input, logical, and stochastic model nodes.:assigned
: nodes that have been assigned values.:block
: stochastic nodes being updated by the sampling block(s)at::Integer=0
(default: all blocks).:dependent
: logical and stochastic (dependent) nodes in topologically sorted order.:independent
or:input
: input (independent) nodes.:logical
: logical nodes.:monitor
: stochastic nodes being monitored in MCMC sampler output.:output
: stochastic nodes upon which no other stochastic nodes depend.:source
: nodes upon which the nodeat::Symbol
or vector of nodesat::Vector{Symbol}
depends.:stochastic
: stochastic nodes.:target
: topologically sorted nodes that depend on the sampling block(s)at::Integer=0
(default: all blocks), nodeat::Symbol
, or vector of nodesat::Vector{Symbol}
.
at...
: additional positional arguments to be passed to thentype
options, as described above.
Base.keys(c::AbstractChains)
Returns names of parameter elements.
c
: Chain to return names of.
Base.show
— FunctionBase.show(io::IO, m::Model)
Write a text representation of the model, nodes, and attributes to the current output stream.
Base.show(io::IO, c::AbstractChains)
Prints header and values of Chain.
io
: IO stream on which to print.AbstractChains
: Chain to print.
MCPhylo.showall
— Functionshowall(io::IO, m::Model)
Write a verbose text representation of the model, nodes, and attributes to the current output stream.
Simulation
MCPhylo.gettune
— Functiongettune(m::Model, block::Integer)
gettune(m::Model)
Get block-sampler tuning parameters.
Returns a Vector{Any}
of all block-specific tuning parameters without block
input, and turning parameters for the specified block
otherwise.
MCPhylo.settune!
— Functionsettune!(m::Model, tune, block::Integer)
settune!(m::Model, tune::Vector{Any})
Set tuning parameters for one or all blocks.
Assigns desired tune values to model.
m
: model containing the nodes of interest.tune
: tune values to be assigned to models; if noblock
value is input,tune
must be a Vector with length equal tom.samplers
.block
: Integer denoting which block's tune value is to be reassigned.
Distributions.gradlogpdf
— Functiongradlogpdf(m::Model, block::Integer=0, transform::Bool=false;
dtype::Symbol=:forward)
gradlogpdf(m::Model, targets::Array{Symbol, 1})::Tuple{Float64, Array{Float64}}
Compute the gradient of log-densities for stochastic nodes.
Returns the resulting gradient vector. Method gradlogpdf!()
additionally updates model m
with supplied values x
.
m
: model containing the stochastic nodes for which to compute the gradient.block
: sampling block of stochastic nodes for which to compute the gradient (default: all stochastic nodes).x
: value (possibly different than the current one) at which to compute the gradient.transform
: whether to compute the gradient of block parameters on the link–transformed scale.dtype
: type of differentiation for gradient calculations. Options are:central
: central differencing.:forward
: forward differencing.
MCPhylo.gradlogpdf!
— Functiongradlogpdf!(m::Model, x::AbstractVector{T}, block::Integer=0,
transform::Bool=false; dtype::Symbol=:forward) where {T<:Real}
gradlogpdf!(m::Model, x::AbstractArray{T}, block::Integer=0,transform::Bool=false)
where T<:GeneralNode
gradlogpdf!(m::Model, x::N, block::Integer=0,transform::Bool=false)::Tuple{Float64, Vector{Float64}}
where N<:GeneralNode
Returns the resulting gradient vector. Method gradlogpdf!()
additionally updates model m
with supplied values x
.
Distributions.logpdf
— Functionlogpdf(m::Model, block::Integer=0, transform::Bool=false)
logpdf(m::Model, nodekeys::Vector{Symbol}, transform::Bool=false)
Compute the sum of log-densities for stochastic nodes.
Returns the resulting numeric value of summed log-densities.
m
: model containing the stochastic nodes for which to evaluate log-densities.block
: sampling block of stochastic nodes over which to sum densities (default: all stochastic nodes).nodekeys
: nodes over which to sum densities.x
: value (possibly different than the current one) at which to evaluate densities.transform
: whether to evaluate evaluate log-densities of block parameters on the link–transformed scale.
logpdf(m::Model, x::AbstractArray{T}, block::Integer=0,
transform::Bool=false) where {T<:Real}
logpdf(mc::ModelChains, f::Function, nodekeys::Vector{Symbol})
Compute the sum of log-densities at each iteration of MCMC output for stochastic nodes.
Returns a ModelChains
object of resulting summed log-densities at each MCMC iteration of the supplied chain.
mc
: sampler output from a model fit with themcmc()
` function.nodekey/nodekeys
: stochastic model node(s) over which to sum densities (default: all).f
: ??
logpdf(mc::ModelChains,
nodekeys::Vector{Symbol}=keys(mc.model, :stochastic))
Distributions.logpdf!
— Functionlogpdf!(m::Model, x::N, block::Integer=0,
transform::Bool=false) where N<:GeneralNode
Missing docstring for MCPhylo.sample!(::Main.MCPhylo.Model, ::Integer)
. Check Documenter's build log for details.
MCPhylo.unlist
— Functionunlist(m::Model, block::Integer=0, transform::Bool=false)
unlist(m::Model, monitoronly::Bool)
unlist(m::Model, nodekeys::Vector{Symbol}, transform::Bool=false)
Convert (unlist) sets of logical and/or stochastic node values to vectors.
Returns vectors of concatenated node values.
m
: model containing nodes to be unlisted or relisted.block
: sampling block of nodes to be listed (default: all blocks).nodekeys
: node(s) to be listed.transform
: whether to apply a link transformation in the conversion.
MCPhylo.relist
— Functionrelist(m::Model, x::AbstractArray{T}, block::Integer=0,
transform::Bool=false) where {T<:Real}
relist(m::Model, x::AbstractArray{T}, block::Integer=0,
transform::Bool=false) where {T<:GeneralNode}
relist(m::Model, x::AbstractArray{T},
nodekeys::Vector{Symbol}, transform::Bool=false) where {T<:Any}
relist(m::Model, x::N, nodekeys::Vector{Symbol}, transform::Bool=false) where N<:GeneralNode
Reverse of unlist; ie. Converts vectors to sets of logical and/or stochastic node values. Same inputs and return values as unlist.
MCPhylo.relist!
— Functionrelist!(m::Model, x::AbstractArray{T}, block::Integer=0,
transform::Bool=false) where {T<:Any}
relist!(m::Model, x::AbstractArray{T}, nodekey::Symbol,
transform::Bool=false) where {T<:Real}
Reverse of unlist; ie. Converts vectors to sets of logical and/or stochastic node values. Same inputs as unlist.
Returns m
, with values copied to the nodes.
Missing docstring for MCPhylo.update!
. Check Documenter's build log for details.
StatsBase.sample!
— Functionsample!(m::Model, block::Integer=0)
Generate one MCMC sample of values for a specified model.
Returns the model updated with the MCMC sample and, in the case of block=0
, the iter
field incremented by 1.
m
: model specification.block
: block for which to sample values (default: all blocks).
sample!(v::HMCVariate, logfgrad::Function)
Draw one sample from a target distribution using the HMC sampler. Parameters are assumed to be continuous and unconstrained.
Returns v
updated with simulated values and associated tuning parameters.
sample!(v::NUTSVariate, logfgrad::Function; adapt::Bool=false)
Draw one sample from a target distribution using the NUTS sampler. Parameters are assumed to be continuous and unconstrained.
Returns v
updated with simulated values and associated tuning parameters.
sample!(v::RWMVariate, logf::Function, moves::Array{Symbol})
Propose a new tree by randomly performing a move from the ones specified in moves
.
Returns v
updated with simulated values and associated tuning parameters.
sample!(v::RWMVariate, logf::Function)
Draw one sample from a target distribution using the RWM sampler. Parameters are assumed to be continuous and unconstrained.
Returns v
updated with simulated values and associated tuning parameters.
sample!(v::SliceSimplexVariate, logf::Function)
Draw one sample from a target distribution using the SliceSimplex sampler. Parameters are assumed to be continuous and constrained to a simplex.
Returns v
updated with simulated values and associated tuning parameters.
MCPhylo.ABC_sample
— FunctionDo the ABC sampling. This version uses threads.
MCPhylo.Sampler
— TypeSampler(params::Vector{Symbol}, f::Function, tune::Any=Dict())
Construct a Sampler
object that defines a sampling function for a block of stochastic nodes.
Returns a Sampler{typeof(tune)}
type object.
params
: node(s) being block-updated by the sampler.f
: function for theeval
field of the constructed sampler and whose arguments are the other model nodes upon which the sampler depends, typed argumentmodel::Model
that contains all model nodes, and/or typed argumentblock::Integer
that is an index identifying the corresponding sampling function in a vector of all samplers for the associated model. Through the arguments, all model nodes and fields can be accessed in the body of the function. The function may return an updated sample for the nodes identified in itsparams
field. Such a return value can be a structure of the same type as the node if the block consists of only one node, or a dictionary of node structures with keys equal to the block node symbols if one or more. Alternatively, a value ofnothing
may be returned. Return values that are notnothing
will be used to automatically update the node values and propagate them to dependent nodes. No automatic updating will be done ifnothing
is returned.tune
: tuning parameters needed by the sampling function.
Base.getindex
— FunctionBase.getindex(c::Chains, window, names, chains)
Subset MCMC sampler output. The syntax c[i, j, k]
is converted to getindex(c, i, j, k)
.
Subsetted sampler output stored in the same type of object as that supplied in the call.
c
: sampler output to subset.window
: indices of the formstart:stop
orstart:thin:stop
can be used to subset iterations, wherestart
andstop
define a range for the subset andthin
will apply additional thinning to existing sampler output.names
: indices for subsetting of parameters that can be specified as strings, integers, or booleans identifying parameters to be kept.ModelChains
may additionally be indexed by model node symbols.chains
: indices for chains can be integers or booleans.
A value of :
can be specified for any of the dimensions to indicate no subsetting.
Base.setindex!
— FunctionBase.setindex!(c::AbstractChains, value, iters, names, chains)
Store MCMC sampler output at a given index. The syntax c[i, j, k] = value
is converted to setindex!(c, value, i, j, k)
.
Returns an object of the same type as c with the sampler output stored in the specified indices.
c
: object within which to store sampler output.value
: sampler output.iters
: iterations can be indexed as astart:stop
orstart:thin:stop
range, a single numeric index, or a vector of indices; and are taken to be relative to the index range store in thec.range
field.names
: indices for subsetting of parameters can be specified as strings, integers, or booleans.chains
: indices for chains can be integers or booleans.
A value of :
can be specified for any of the dimensions to indicate no subsetting.
Base.cat
— FunctionBase.cat(c1::AbstractChains, args::AbstractChains...; dims::Integer)
Concatenate input MCMC chains along a specified dimension. For dimensions other than the specified one, all input chains must have the same sizes, which will also be the sizes of the output chain. The size of the output chain along the specified dimension will be the sum of the sizes of the input chains in that dimension. vcat concatenates vertically along dimension 1, and has the alternative syntax [chain1; chain2; ...]. hcat concatenates horizontally along dimension 2, and has the alternative syntax [chain1 chain2 ...].
Returns a Chains
object containing the concatenated input.
dim
: dimension (1, 2, or 3) along which to concatenate the input chains.c1
,args...
: Chains to concatenate.
Base.keys
— MethodBase.keys(c::AbstractChains)
Returns names of parameter elements.
c
: Chain to return names of.
Base.show
— MethodBase.show(io::IO, c::AbstractChains)
Prints header and values of Chain.
io
: IO stream on which to print.AbstractChains
: Chain to print.
Base.size
— FunctionBase.size(c::AbstractChains)
Returns Tuple containing last iteration of MCMC sampler output and dimensions of Chain dimensions of c.value.
c
: Chain object of interest.
Base.size(c::AbstractChains, ind)
Returns last iteration of MCMC sampler output, or dimension derived from C, according to value of ind.
c
: Chain object of interest.ind
: index of tuple to return; 1 returns last iteration of MCMC sampler output, 2 and 3 return dimensions of c.value.