diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 7144e1521..bc20630a0 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-19T11:05:54","documenter_version":"1.8.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-19T11:09:41","documenter_version":"1.8.0"}} \ No newline at end of file diff --git a/dev/api/Inference/index.html b/dev/api/Inference/index.html index d11f03cec..8db4c9ac5 100644 --- a/dev/api/Inference/index.html +++ b/dev/api/Inference/index.html @@ -1,463 +1,5 @@ -Inference · Turing - - - - - -

API: Turing.Inference

Turing.Inference.ESSType
ESS

Elliptical slice sampling algorithm.

Examples

julia> @model function gdemo(x)
+Inference · Turing

API: Turing.Inference

Turing.Inference.ESSType
ESS

Elliptical slice sampling algorithm.

Examples

julia> @model function gdemo(x)
            m ~ Normal()
            x ~ Normal(m, 0.5)
        end
@@ -469,14 +11,14 @@
 │ Row │ parameters │ mean     │
 │     │ Symbol     │ Float64  │
 ├─────┼────────────┼──────────┤
-│ 1   │ m          │ 0.824853 │
source
Turing.Inference.EmceeType
Emcee(n_walkers::Int, stretch_length=2.0)

Affine-invariant ensemble sampling algorithm.

Reference

Foreman-Mackey, D., Hogg, D. W., Lang, D., & Goodman, J. (2013). emcee: The MCMC Hammer. Publications of the Astronomical Society of the Pacific, 125 (925), 306. https://doi.org/10.1086/670067

source
Turing.Inference.ExternalSamplerType
ExternalSampler{S<:AbstractSampler,AD<:ADTypes.AbstractADType,Unconstrained}

Represents a sampler that is not an implementation of InferenceAlgorithm.

The Unconstrained type-parameter is to indicate whether the sampler requires unconstrained space.

Fields

  • sampler::AbstractMCMC.AbstractSampler: the sampler to wrap

  • adtype::ADTypes.AbstractADType: the automatic differentiation (AD) backend to use

source
Turing.Inference.GibbsType
Gibbs

A type representing a Gibbs sampler.

Fields

  • varnames::Any: varnames representing variables for each sampler

  • samplers::Any: samplers for each entry in varnames

source
Turing.Inference.GibbsContextType
GibbsContext{VNs}(global_varinfo, context)

A context used in the implementation of the Turing.jl Gibbs sampler.

There will be one GibbsContext for each iteration of a component sampler.

VNs is a a tuple of symbols for VarNames that the current component sampler is sampling. For those VarNames, GibbsContext will just pass tilde_assume calls to its child context. For other variables, their values will be fixed to the values they have in global_varinfo.

The naive implementation of GibbsContext would simply have a field target_varnames that would be a collection of VarNames that the current component sampler is sampling. The reason we instead have a Tuple type parameter listing Symbols is to allow is_target_varname to benefit from compile time constant propagation. This is important for type stability of tilde_assume.

Fields

  • global_varinfo: a Ref to the global AbstractVarInfo object that holds values for all variables, both those fixed and those being sampled. We use a Ref because this field may need to be updated if new variables are introduced.
  • context: the child context that tilde calls will eventually be passed onto.
source
Turing.Inference.HMCType
HMC(ϵ::Float64, n_leapfrog::Int; adtype::ADTypes.AbstractADType = AutoForwardDiff())

Hamiltonian Monte Carlo sampler with static trajectory.

Arguments

  • ϵ: The leapfrog step size to use.
  • n_leapfrog: The number of leapfrog steps to use.
  • adtype: The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.

Usage

HMC(0.05, 10)

Tips

If you are receiving gradient errors when using HMC, try reducing the leapfrog step size ϵ, e.g.

# Original step size
+│ 1   │ m          │ 0.824853 │
source
Turing.Inference.EmceeType
Emcee(n_walkers::Int, stretch_length=2.0)

Affine-invariant ensemble sampling algorithm.

Reference

Foreman-Mackey, D., Hogg, D. W., Lang, D., & Goodman, J. (2013). emcee: The MCMC Hammer. Publications of the Astronomical Society of the Pacific, 125 (925), 306. https://doi.org/10.1086/670067

source
Turing.Inference.ExternalSamplerType
ExternalSampler{S<:AbstractSampler,AD<:ADTypes.AbstractADType,Unconstrained}

Represents a sampler that is not an implementation of InferenceAlgorithm.

The Unconstrained type-parameter is to indicate whether the sampler requires unconstrained space.

Fields

  • sampler::AbstractMCMC.AbstractSampler: the sampler to wrap

  • adtype::ADTypes.AbstractADType: the automatic differentiation (AD) backend to use

source
Turing.Inference.GibbsType
Gibbs

A type representing a Gibbs sampler.

Fields

  • varnames::Any: varnames representing variables for each sampler

  • samplers::Any: samplers for each entry in varnames

source
Turing.Inference.GibbsContextType
GibbsContext{VNs}(global_varinfo, context)

A context used in the implementation of the Turing.jl Gibbs sampler.

There will be one GibbsContext for each iteration of a component sampler.

VNs is a a tuple of symbols for VarNames that the current component sampler is sampling. For those VarNames, GibbsContext will just pass tilde_assume calls to its child context. For other variables, their values will be fixed to the values they have in global_varinfo.

The naive implementation of GibbsContext would simply have a field target_varnames that would be a collection of VarNames that the current component sampler is sampling. The reason we instead have a Tuple type parameter listing Symbols is to allow is_target_varname to benefit from compile time constant propagation. This is important for type stability of tilde_assume.

Fields

  • global_varinfo: a Ref to the global AbstractVarInfo object that holds values for all variables, both those fixed and those being sampled. We use a Ref because this field may need to be updated if new variables are introduced.
  • context: the child context that tilde calls will eventually be passed onto.
source
Turing.Inference.HMCType
HMC(ϵ::Float64, n_leapfrog::Int; adtype::ADTypes.AbstractADType = AutoForwardDiff())

Hamiltonian Monte Carlo sampler with static trajectory.

Arguments

  • ϵ: The leapfrog step size to use.
  • n_leapfrog: The number of leapfrog steps to use.
  • adtype: The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.

Usage

HMC(0.05, 10)

Tips

If you are receiving gradient errors when using HMC, try reducing the leapfrog step size ϵ, e.g.

# Original step size
 sample(gdemo([1.5, 2]), HMC(0.1, 10), 1000)
 
 # Reduced step size
-sample(gdemo([1.5, 2]), HMC(0.01, 10), 1000)
source
Turing.Inference.HMCDAType
HMCDA(
     n_adapts::Int, δ::Float64, λ::Float64; ϵ::Float64 = 0.0;
     adtype::ADTypes.AbstractADType = AutoForwardDiff(),
-)

Hamiltonian Monte Carlo sampler with Dual Averaging algorithm.

Usage

HMCDA(200, 0.65, 0.3)

Arguments

  • n_adapts: Numbers of samples to use for adaptation.
  • δ: Target acceptance rate. 65% is often recommended.
  • λ: Target leapfrog length.
  • ϵ: Initial step size; 0 means automatically search by Turing.
  • adtype: The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.

Reference

For more information, please view the following paper (arXiv link):

Hoffman, Matthew D., and Andrew Gelman. "The No-U-turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo." Journal of Machine Learning Research 15, no. 1 (2014): 1593-1623.

source
Turing.Inference.ISType
IS()

Importance sampling algorithm.

Usage:

IS()

Example:

# Define a simple Normal model with unknown mean and variance.
+)

Hamiltonian Monte Carlo sampler with Dual Averaging algorithm.

Usage

HMCDA(200, 0.65, 0.3)

Arguments

  • n_adapts: Numbers of samples to use for adaptation.
  • δ: Target acceptance rate. 65% is often recommended.
  • λ: Target leapfrog length.
  • ϵ: Initial step size; 0 means automatically search by Turing.
  • adtype: The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.

Reference

For more information, please view the following paper (arXiv link):

Hoffman, Matthew D., and Andrew Gelman. "The No-U-turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo." Journal of Machine Learning Research 15, no. 1 (2014): 1593-1623.

source
Turing.Inference.ISType
IS()

Importance sampling algorithm.

Usage:

IS()

Example:

# Define a simple Normal model with unknown mean and variance.
 @model function gdemo(x)
     s² ~ InverseGamma(2,3)
     m ~ Normal(0,sqrt.(s))
@@ -485,7 +27,7 @@
     return s², m
 end
 
-sample(gdemo([1.5, 2]), IS(), 1000)
source
Turing.Inference.MHMethod
MH(space...)

Construct a Metropolis-Hastings algorithm.

The arguments space can be

  • Blank (i.e. MH()), in which case MH defaults to using the prior for each parameter as the proposal distribution.
  • An iterable of pairs or tuples mapping a Symbol to a AdvancedMH.Proposal, Distribution, or Function that generates returns a conditional proposal distribution.
  • A covariance matrix to use as for mean-zero multivariate normal proposals.

Examples

The default MH will draw proposal samples from the prior distribution using AdvancedMH.StaticProposal.

@model function gdemo(x, y)
+sample(gdemo([1.5, 2]), IS(), 1000)
source
Turing.Inference.MHMethod
MH(space...)

Construct a Metropolis-Hastings algorithm.

The arguments space can be

  • Blank (i.e. MH()), in which case MH defaults to using the prior for each parameter as the proposal distribution.
  • An iterable of pairs or tuples mapping a Symbol to a AdvancedMH.Proposal, Distribution, or Function that generates returns a conditional proposal distribution.
  • A covariance matrix to use as for mean-zero multivariate normal proposals.

Examples

The default MH will draw proposal samples from the prior distribution using AdvancedMH.StaticProposal.

@model function gdemo(x, y)
     s² ~ InverseGamma(2,3)
     m ~ Normal(0, sqrt(s²))
     x ~ Normal(m, sqrt(s²))
@@ -533,22 +75,22 @@
     ),
     1_000
 )
-mean(chain)
source
Turing.Inference.NUTSType
NUTS(n_adapts::Int, δ::Float64; max_depth::Int=10, Δ_max::Float64=1000.0, init_ϵ::Float64=0.0; adtype::ADTypes.AbstractADType=AutoForwardDiff()

No-U-Turn Sampler (NUTS) sampler.

Usage:

NUTS()            # Use default NUTS configuration.
-NUTS(1000, 0.65)  # Use 1000 adaption steps, and target accept ratio 0.65.

Arguments:

  • n_adapts::Int : The number of samples to use with adaptation.
  • δ::Float64 : Target acceptance rate for dual averaging.
  • max_depth::Int : Maximum doubling tree depth.
  • Δ_max::Float64 : Maximum divergence during doubling tree.
  • init_ϵ::Float64 : Initial step size; 0 means automatically searching using a heuristic procedure.
  • adtype::ADTypes.AbstractADType : The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.
source
Turing.Inference.NUTSType
NUTS(n_adapts::Int, δ::Float64; max_depth::Int=10, Δ_max::Float64=1000.0, init_ϵ::Float64=0.0; adtype::ADTypes.AbstractADType=AutoForwardDiff()

No-U-Turn Sampler (NUTS) sampler.

Usage:

NUTS()            # Use default NUTS configuration.
+NUTS(1000, 0.65)  # Use 1000 adaption steps, and target accept ratio 0.65.

Arguments:

  • n_adapts::Int : The number of samples to use with adaptation.
  • δ::Float64 : Target acceptance rate for dual averaging.
  • max_depth::Int : Maximum doubling tree depth.
  • Δ_max::Float64 : Maximum divergence during doubling tree.
  • init_ϵ::Float64 : Initial step size; 0 means automatically searching using a heuristic procedure.
  • adtype::ADTypes.AbstractADType : The automatic differentiation (AD) backend. If not specified, ForwardDiff is used, with its chunksize automatically determined.
source
Turing.Inference.PGType
PG(n, space...)
 PG(n, [resampler = AdvancedPS.ResampleWithESSThreshold(), space = ()])
-PG(n, [resampler = AdvancedPS.resample_systematic, ]threshold[, space = ()])

Create a Particle Gibbs sampler of type PG with n particles for the variables in space.

If the algorithm for the resampling step is not specified explicitly, systematic resampling is performed if the estimated effective sample size per particle drops below 0.5.

source
Turing.Inference.PGType
struct PG{space, R} <: Turing.Inference.ParticleInference

Particle Gibbs sampler.

Fields

  • nparticles::Int64: Number of particles.

  • resampler::Any: Resampling algorithm.

source
Turing.Inference.RepeatSamplerType
RepeatSampler <: AbstractMCMC.AbstractSampler

A RepeatSampler is a container for a sampler and a number of times to repeat it.

Fields

  • sampler: The sampler to repeat

  • num_repeat: The number of times to repeat the sampler

Examples

repeated_sampler = RepeatSampler(sampler, 10)
-AbstractMCMC.step(rng, model, repeated_sampler) # take 10 steps of `sampler`
source
Turing.Inference.SGHMCType
SGHMC{AD,space}

Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampler.e

Fields

  • learning_rate::Real

  • momentum_decay::Real

  • adtype::Any

Reference

Tianqi Chen, Emily Fox, & Carlos Guestrin (2014). Stochastic Gradient Hamiltonian Monte Carlo. In: Proceedings of the 31st International Conference on Machine Learning (pp. 1683–1691).

source
Turing.Inference.SGHMCMethod
SGHMC(
+PG(n, [resampler = AdvancedPS.resample_systematic, ]threshold[, space = ()])

Create a Particle Gibbs sampler of type PG with n particles for the variables in space.

If the algorithm for the resampling step is not specified explicitly, systematic resampling is performed if the estimated effective sample size per particle drops below 0.5.

source
Turing.Inference.PGType
struct PG{space, R} <: Turing.Inference.ParticleInference

Particle Gibbs sampler.

Fields

  • nparticles::Int64: Number of particles.

  • resampler::Any: Resampling algorithm.

source
Turing.Inference.RepeatSamplerType
RepeatSampler <: AbstractMCMC.AbstractSampler

A RepeatSampler is a container for a sampler and a number of times to repeat it.

Fields

  • sampler: The sampler to repeat

  • num_repeat: The number of times to repeat the sampler

Examples

repeated_sampler = RepeatSampler(sampler, 10)
+AbstractMCMC.step(rng, model, repeated_sampler) # take 10 steps of `sampler`
source
Turing.Inference.SGHMCType
SGHMC{AD,space}

Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampler.e

Fields

  • learning_rate::Real

  • momentum_decay::Real

  • adtype::Any

Reference

Tianqi Chen, Emily Fox, & Carlos Guestrin (2014). Stochastic Gradient Hamiltonian Monte Carlo. In: Proceedings of the 31st International Conference on Machine Learning (pp. 1683–1691).

source
Turing.Inference.SGHMCMethod
SGHMC(
     space::Symbol...;
     learning_rate::Real,
     momentum_decay::Real,
     adtype::ADTypes.AbstractADType = AutoForwardDiff(),
-)

Create a Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampler.

If the automatic differentiation (AD) backend adtype is not provided, ForwardDiff with automatically determined chunksize is used.

Reference

Tianqi Chen, Emily Fox, & Carlos Guestrin (2014). Stochastic Gradient Hamiltonian Monte Carlo. In: Proceedings of the 31st International Conference on Machine Learning (pp. 1683–1691).

source
Turing.Inference.SGLDType
SGLD

Stochastic gradient Langevin dynamics (SGLD) sampler.

Fields

  • stepsize::Any: Step size function.

  • adtype::Any

Reference

Max Welling & Yee Whye Teh (2011). Bayesian Learning via Stochastic Gradient Langevin Dynamics. In: Proceedings of the 28th International Conference on Machine Learning (pp. 681–688).

source
Turing.Inference.SGLDMethod
SGLD(
+)

Create a Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampler.

If the automatic differentiation (AD) backend adtype is not provided, ForwardDiff with automatically determined chunksize is used.

Reference

Tianqi Chen, Emily Fox, & Carlos Guestrin (2014). Stochastic Gradient Hamiltonian Monte Carlo. In: Proceedings of the 31st International Conference on Machine Learning (pp. 1683–1691).

source
Turing.Inference.SGLDType
SGLD

Stochastic gradient Langevin dynamics (SGLD) sampler.

Fields

  • stepsize::Any: Step size function.

  • adtype::Any

Reference

Max Welling & Yee Whye Teh (2011). Bayesian Learning via Stochastic Gradient Langevin Dynamics. In: Proceedings of the 28th International Conference on Machine Learning (pp. 681–688).

source
Turing.Inference.SGLDMethod
SGLD(
     space::Symbol...;
     stepsize = PolynomialStepsize(0.01),
     adtype::ADTypes.AbstractADType = AutoForwardDiff(),
-)

Stochastic gradient Langevin dynamics (SGLD) sampler.

By default, a polynomially decaying stepsize is used.

If the automatic differentiation (AD) backend adtype is not provided, ForwardDiff with automatically determined chunksize is used.

Reference

Max Welling & Yee Whye Teh (2011). Bayesian Learning via Stochastic Gradient Langevin Dynamics. In: Proceedings of the 28th International Conference on Machine Learning (pp. 681–688).

See also: PolynomialStepsize

source
Turing.Inference.SMCType
SMC(space...)
+)

Stochastic gradient Langevin dynamics (SGLD) sampler.

By default, a polynomially decaying stepsize is used.

If the automatic differentiation (AD) backend adtype is not provided, ForwardDiff with automatically determined chunksize is used.

Reference

Max Welling & Yee Whye Teh (2011). Bayesian Learning via Stochastic Gradient Langevin Dynamics. In: Proceedings of the 28th International Conference on Machine Learning (pp. 681–688).

See also: PolynomialStepsize

source
Turing.Inference.SMCType
SMC(space...)
 SMC([resampler = AdvancedPS.ResampleWithESSThreshold(), space = ()])
-SMC([resampler = AdvancedPS.resample_systematic, ]threshold[, space = ()])

Create a sequential Monte Carlo sampler of type SMC for the variables in space.

If the algorithm for the resampling step is not specified explicitly, systematic resampling is performed if the estimated effective sample size per particle drops below 0.5.

source
Turing.Inference.SMCType
struct SMC{space, R} <: Turing.Inference.ParticleInference

Sequential Monte Carlo sampler.

Fields

  • resampler::Any
source
StatsAPI.predictMethod
predict([rng::AbstractRNG,] model::Model, chain::MCMCChains.Chains; include_all=false)

Execute model conditioned on each sample in chain, and return the resulting Chains.

If include_all is false, the returned Chains will contain only those variables sampled/not present in chain.

Details

Internally calls Turing.Inference.transitions_from_chain to obtained the samples and then converts these into a Chains object using AbstractMCMC.bundle_samples.

Example

julia> using Turing; Turing.setprogress!(false);
+SMC([resampler = AdvancedPS.resample_systematic, ]threshold[, space = ()])

Create a sequential Monte Carlo sampler of type SMC for the variables in space.

If the algorithm for the resampling step is not specified explicitly, systematic resampling is performed if the estimated effective sample size per particle drops below 0.5.

source
Turing.Inference.SMCType
struct SMC{space, R} <: Turing.Inference.ParticleInference

Sequential Monte Carlo sampler.

Fields

  • resampler::Any
source
StatsAPI.predictMethod
predict([rng::AbstractRNG,] model::Model, chain::MCMCChains.Chains; include_all=false)

Execute model conditioned on each sample in chain, and return the resulting Chains.

If include_all is false, the returned Chains will contain only those variables sampled/not present in chain.

Details

Internally calls Turing.Inference.transitions_from_chain to obtained the samples and then converts these into a Chains object using AbstractMCMC.bundle_samples.

Example

julia> using Turing; Turing.setprogress!(false);
 [ Info: [Turing]: progress logging is disabled globally
 
 julia> @model function linear_reg(x, y, σ = 0.1)
@@ -596,10 +138,11 @@
         y[1]  20.0342  20.1188  20.2135  20.2588  20.4188
         y[2]  20.1870  20.3178  20.3839  20.4466  20.5895
 
+
 julia> ys_pred = vec(mean(Array(group(predictions, :y)); dims = 1));
 
 julia> sum(abs2, ys_test - ys_pred) ≤ 0.1
-true
source
Turing.Inference.dist_val_tupleMethod
dist_val_tuple(spl::Sampler{<:MH}, vi::VarInfo)

Return two NamedTuples.

The first NamedTuple has symbols as keys and distributions as values. The second NamedTuple has model symbols as keys and their stored values as values.

source
Turing.Inference.externalsamplerMethod
externalsampler(sampler::AbstractSampler; adtype=AutoForwardDiff(), unconstrained=true)

Wrap a sampler so it can be used as an inference algorithm.

Arguments

  • sampler::AbstractSampler: The sampler to wrap.

Keyword Arguments

  • adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(): The automatic differentiation (AD) backend to use.
  • unconstrained::Bool=true: Whether the sampler requires unconstrained space.
source
Turing.Inference.group_varnames_by_symbolMethod
group_varnames_by_symbol(vns)

Group the varnames by their symbol.

Arguments

  • vns: Iterable of VarName.

Returns

  • OrderedDict{Symbol, Vector{VarName}}: A dictionary mapping symbol to a vector of varnames.
source
Turing.Inference.isgibbscomponentMethod
isgibbscomponent(alg::Union{InferenceAlgorithm, AbstractMCMC.AbstractSampler})

Return a boolean indicating whether alg is a valid component for a Gibbs sampler.

Defaults to false if no method has been defined for a particular algorithm type.

source
Turing.Inference.make_conditionalMethod
make_conditional(model, target_variables, varinfo)

Return a new, conditioned model for a component of a Gibbs sampler.

Arguments

  • model::DynamicPPL.Model: The model to condition.
  • target_variables::AbstractVector{<:VarName}: The target variables of the component

sampler. These will not be conditioned.

  • varinfo::DynamicPPL.AbstractVarInfo: Values for all variables in the model. All the

values in varinfo but not in target_variables will be conditioned to the values they have in varinfo.

Returns

  • A new model with the variables not in target_variables conditioned.
  • The GibbsContext object that will be used to condition the variables. This is necessary

because evaluation can mutate its global_varinfo field, which we need to access later.

source
Turing.Inference.match_linking!!Method
match_linking!!(varinfo_local, prev_state_local, model)

Make sure the linked/invlinked status of varinfo_local matches that of the previous state for this sampler. This is relevant when multilple samplers are sampling the same variables, and one might need it to be linked while the other doesn't.

source
Turing.Inference.mh_acceptMethod
mh_accept(logp_current::Real, logp_proposal::Real, log_proposal_ratio::Real)

Decide if a proposal $x'$ with log probability $\log p(x') = logp_proposal$ and log proposal ratio $\log k(x', x) - \log k(x, x') = log_proposal_ratio$ in a Metropolis-Hastings algorithm with Markov kernel $k(x_t, x_{t+1})$ and current state $x$ with log probability $\log p(x) = logp_current$ is accepted by evaluating the Metropolis-Hastings acceptance criterion

\[\log U \leq \log p(x') - \log p(x) + \log k(x', x) - \log k(x, x')\]

for a uniform random number $U \in [0, 1)$.

source
Turing.Inference.setparams_varinfo!!Method
setparams_varinfo!!(model, sampler::Sampler, state, params::AbstractVarInfo)

A lot like AbstractMCMC.setparams!!, but instead of taking a vector of parameters, takes an AbstractVarInfo object. Also takes the sampler as an argument. By default, falls back to AbstractMCMC.setparams!!(model, state, params[:]).

model is typically a DynamicPPL.Model, but can also be e.g. an AbstractMCMC.LogDensityModel.

source
Turing.Inference.dist_val_tupleMethod
dist_val_tuple(spl::Sampler{<:MH}, vi::VarInfo)

Return two NamedTuples.

The first NamedTuple has symbols as keys and distributions as values. The second NamedTuple has model symbols as keys and their stored values as values.

source
Turing.Inference.externalsamplerMethod
externalsampler(sampler::AbstractSampler; adtype=AutoForwardDiff(), unconstrained=true)

Wrap a sampler so it can be used as an inference algorithm.

Arguments

  • sampler::AbstractSampler: The sampler to wrap.

Keyword Arguments

  • adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(): The automatic differentiation (AD) backend to use.
  • unconstrained::Bool=true: Whether the sampler requires unconstrained space.
source
Turing.Inference.group_varnames_by_symbolMethod
group_varnames_by_symbol(vns)

Group the varnames by their symbol.

Arguments

  • vns: Iterable of VarName.

Returns

  • OrderedDict{Symbol, Vector{VarName}}: A dictionary mapping symbol to a vector of varnames.
source
Turing.Inference.isgibbscomponentMethod
isgibbscomponent(alg::Union{InferenceAlgorithm, AbstractMCMC.AbstractSampler})

Return a boolean indicating whether alg is a valid component for a Gibbs sampler.

Defaults to false if no method has been defined for a particular algorithm type.

source
Turing.Inference.make_conditionalMethod
make_conditional(model, target_variables, varinfo)

Return a new, conditioned model for a component of a Gibbs sampler.

Arguments

  • model::DynamicPPL.Model: The model to condition.
  • target_variables::AbstractVector{<:VarName}: The target variables of the component

sampler. These will not be conditioned.

  • varinfo::DynamicPPL.AbstractVarInfo: Values for all variables in the model. All the

values in varinfo but not in target_variables will be conditioned to the values they have in varinfo.

Returns

  • A new model with the variables not in target_variables conditioned.
  • The GibbsContext object that will be used to condition the variables. This is necessary

because evaluation can mutate its global_varinfo field, which we need to access later.

source
Turing.Inference.match_linking!!Method
match_linking!!(varinfo_local, prev_state_local, model)

Make sure the linked/invlinked status of varinfo_local matches that of the previous state for this sampler. This is relevant when multilple samplers are sampling the same variables, and one might need it to be linked while the other doesn't.

source
Turing.Inference.mh_acceptMethod
mh_accept(logp_current::Real, logp_proposal::Real, log_proposal_ratio::Real)

Decide if a proposal $x'$ with log probability $\log p(x') = logp_proposal$ and log proposal ratio $\log k(x', x) - \log k(x, x') = log_proposal_ratio$ in a Metropolis-Hastings algorithm with Markov kernel $k(x_t, x_{t+1})$ and current state $x$ with log probability $\log p(x) = logp_current$ is accepted by evaluating the Metropolis-Hastings acceptance criterion

\[\log U \leq \log p(x') - \log p(x) + \log k(x', x) - \log k(x, x')\]

for a uniform random number $U \in [0, 1)$.

source
Turing.Inference.setparams_varinfo!!Method
setparams_varinfo!!(model, sampler::Sampler, state, params::AbstractVarInfo)

A lot like AbstractMCMC.setparams!!, but instead of taking a vector of parameters, takes an AbstractVarInfo object. Also takes the sampler as an argument. By default, falls back to AbstractMCMC.setparams!!(model, state, params[:]).

model is typically a DynamicPPL.Model, but can also be e.g. an AbstractMCMC.LogDensityModel.

source
Turing.Inference.transitions_from_chainMethod
transitions_from_chain(
     [rng::AbstractRNG,]
     model::Model,
     chain::MCMCChains.Chains;
@@ -625,5 +168,4 @@
 julia> [first(t.θ.x) for t in transitions] # extract samples for `x`
 2-element Array{Array{Float64,1},1}:
  [-2.0844148956440796]
- [-1.704630494695469]
source
- + [-1.704630494695469]
source
diff --git a/dev/api/Optimisation/index.html b/dev/api/Optimisation/index.html index 944d392c7..71b67bc7d 100644 --- a/dev/api/Optimisation/index.html +++ b/dev/api/Optimisation/index.html @@ -1,481 +1,22 @@ -Optimisation · Turing - - - - - -

API: Turing.Optimisation

SciMLBase.OptimizationProblemMethod
OptimizationProblem(log_density::OptimLogDensity, adtype, constraints)

Create an OptimizationProblem for the objective function defined by log_density.

source
Turing.Optimisation.MAPType
MAP <: ModeEstimator

Concrete type for maximum a posteriori estimation. Only used for the Optim.jl interface.

source
Turing.Optimisation.ModeEstimationConstraintsType
ModeEstimationConstraints

A struct that holds constraints for mode estimation problems.

The fields are the same as possible constraints supported by the Optimization.jl: ub and lb specify lower and upper bounds of box constraints. cons is a function that takes the parameters of the model and returns a list of derived quantities, which are then constrained by the lower and upper bounds set by lcons and ucons. We refer to these as generic constraints. Please see the documentation of Optimization.jl for more details.

Any of the fields can be nothing, disabling the corresponding constraints.

source
Turing.Optimisation.ModeEstimatorType
ModeEstimator

An abstract type to mark whether mode estimation is to be done with maximum a posteriori (MAP) or maximum likelihood estimation (MLE). This is only needed for the Optim.jl interface.

source
Turing.Optimisation.ModeResultType
ModeResult{
+Optimisation · Turing

API: Turing.Optimisation

SciMLBase.OptimizationProblemMethod
OptimizationProblem(log_density::OptimLogDensity, adtype, constraints)

Create an OptimizationProblem for the objective function defined by log_density.

source
Turing.Optimisation.MAPType
MAP <: ModeEstimator

Concrete type for maximum a posteriori estimation. Only used for the Optim.jl interface.

source
Turing.Optimisation.ModeEstimationConstraintsType
ModeEstimationConstraints

A struct that holds constraints for mode estimation problems.

The fields are the same as possible constraints supported by the Optimization.jl: ub and lb specify lower and upper bounds of box constraints. cons is a function that takes the parameters of the model and returns a list of derived quantities, which are then constrained by the lower and upper bounds set by lcons and ucons. We refer to these as generic constraints. Please see the documentation of Optimization.jl for more details.

Any of the fields can be nothing, disabling the corresponding constraints.

source
Turing.Optimisation.ModeEstimatorType
ModeEstimator

An abstract type to mark whether mode estimation is to be done with maximum a posteriori (MAP) or maximum likelihood estimation (MLE). This is only needed for the Optim.jl interface.

source
Turing.Optimisation.ModeResultType
ModeResult{
     V<:NamedArrays.NamedArray,
     M<:NamedArrays.NamedArray,
     O<:Optim.MultivariateOptimizationResults,
     S<:NamedArrays.NamedArray
-}

A wrapper struct to store various results from a MAP or MLE estimation.

source
Turing.Optimisation.ModeResultMethod
ModeResult(log_density::OptimLogDensity, solution::SciMLBase.OptimizationSolution)

Create a ModeResult for a given log_density objective and a solution given by solve.

Optimization.solve returns its own result type. This function converts that into the richer format of ModeResult. It also takes care of transforming them back to the original parameter space in case the optimization was done in a transformed space.

source
Turing.Optimisation.OptimLogDensityMethod
(f::OptimLogDensity)(z)
-(f::OptimLogDensity)(z, _)

Evaluate the negative log joint or log likelihood at the array z. Which one is evaluated depends on the context of f.

Any second argument is ignored. The two-argument method only exists to match interface the required by Optimization.jl.

source
Turing.Optimisation.OptimLogDensityMethod
OptimLogDensity(model::DynamicPPL.Model, context::OptimizationContext)

Create a callable OptimLogDensity struct that evaluates a model using the given context.

source
Turing.Optimisation.OptimizationContextType
OptimizationContext{C<:AbstractContext} <: AbstractContext

The OptimizationContext transforms variables to their constrained space, but does not use the density with respect to the transformation. This context is intended to allow an optimizer to sample in R^n freely.

source
Base.getMethod
Base.get(m::ModeResult, var_symbol::Symbol)
-Base.get(m::ModeResult, var_symbols::AbstractVector{Symbol})

Return the values of all the variables with the symbol(s) var_symbol in the mode result m. The return value is a NamedTuple with var_symbols as the key(s). The second argument should be either a Symbol or a vector of Symbols.

source
Turing.Optimisation.ModeResultMethod
ModeResult(log_density::OptimLogDensity, solution::SciMLBase.OptimizationSolution)

Create a ModeResult for a given log_density objective and a solution given by solve.

Optimization.solve returns its own result type. This function converts that into the richer format of ModeResult. It also takes care of transforming them back to the original parameter space in case the optimization was done in a transformed space.

source
Turing.Optimisation.OptimLogDensityMethod
(f::OptimLogDensity)(z)
+(f::OptimLogDensity)(z, _)

Evaluate the negative log joint or log likelihood at the array z. Which one is evaluated depends on the context of f.

Any second argument is ignored. The two-argument method only exists to match interface the required by Optimization.jl.

source
Turing.Optimisation.OptimLogDensityMethod
OptimLogDensity(model::DynamicPPL.Model, context::OptimizationContext)

Create a callable OptimLogDensity struct that evaluates a model using the given context.

source
Turing.Optimisation.OptimizationContextType
OptimizationContext{C<:AbstractContext} <: AbstractContext

The OptimizationContext transforms variables to their constrained space, but does not use the density with respect to the transformation. This context is intended to allow an optimizer to sample in R^n freely.

source
Base.getMethod
Base.get(m::ModeResult, var_symbol::Symbol)
+Base.get(m::ModeResult, var_symbols::AbstractVector{Symbol})

Return the values of all the variables with the symbol(s) var_symbol in the mode result m. The return value is a NamedTuple with var_symbols as the key(s). The second argument should be either a Symbol or a vector of Symbols.

source
Turing.Optimisation.estimate_modeFunction
estimate_mode(
     model::DynamicPPL.Model,
     estimator::ModeEstimator,
     [solver];
     kwargs...
-)

Find the mode of the probability distribution of a model.

Under the hood this function calls Optimization.solve.

Arguments

  • model::DynamicPPL.Model: The model for which to estimate the mode.
  • estimator::ModeEstimator: Can be either MLE() for maximum likelihood estimation or MAP() for maximum a posteriori estimation.
  • solver=nothing. The optimization algorithm to use. Optional. Can be any solver recognised by Optimization.jl. If omitted a default solver is used: LBFGS, or IPNewton if non-box constraints are present.

Keyword arguments

  • initial_params::Union{AbstractVector,Nothing}=nothing: Initial value for the optimization. Optional, unless non-box constraints are specified. If omitted it is generated by either sampling from the prior distribution or uniformly from the box constraints, if any.
  • adtype::AbstractADType=AutoForwardDiff(): The automatic differentiation type to use.
  • Keyword arguments lb, ub, cons, lcons, and ucons define constraints for the optimization problem. Please see ModeEstimationConstraints for more details.
  • Any extra keyword arguments are passed to Optimization.solve.
source
Turing.Optimisation.generate_initial_paramsMethod
generate_initial_params(model::DynamicPPL.Model, initial_params, constraints)

Generate an initial value for the optimization problem.

If initial_params is not nothing, a copy of it is returned. Otherwise initial parameter values are generated either by sampling from the prior (if no constraints are present) or uniformly from the box constraints. If generic constraints are set, an error is thrown.

source
Turing.Optimisation.maximum_a_posterioriMethod
maximum_a_posteriori(
+)

Find the mode of the probability distribution of a model.

Under the hood this function calls Optimization.solve.

Arguments

  • model::DynamicPPL.Model: The model for which to estimate the mode.
  • estimator::ModeEstimator: Can be either MLE() for maximum likelihood estimation or MAP() for maximum a posteriori estimation.
  • solver=nothing. The optimization algorithm to use. Optional. Can be any solver recognised by Optimization.jl. If omitted a default solver is used: LBFGS, or IPNewton if non-box constraints are present.

Keyword arguments

  • initial_params::Union{AbstractVector,Nothing}=nothing: Initial value for the optimization. Optional, unless non-box constraints are specified. If omitted it is generated by either sampling from the prior distribution or uniformly from the box constraints, if any.
  • adtype::AbstractADType=AutoForwardDiff(): The automatic differentiation type to use.
  • Keyword arguments lb, ub, cons, lcons, and ucons define constraints for the optimization problem. Please see ModeEstimationConstraints for more details.
  • Any extra keyword arguments are passed to Optimization.solve.
source
Turing.Optimisation.generate_initial_paramsMethod
generate_initial_params(model::DynamicPPL.Model, initial_params, constraints)

Generate an initial value for the optimization problem.

If initial_params is not nothing, a copy of it is returned. Otherwise initial parameter values are generated either by sampling from the prior (if no constraints are present) or uniformly from the box constraints. If generic constraints are set, an error is thrown.

source
- +)

Find the maximum likelihood estimate of a model.

This is a convenience function that calls estimate_mode with MLE() as the estimator. Please see the documentation of Turing.Optimisation.estimate_mode for more details.

source
diff --git a/dev/api/index.html b/dev/api/index.html index cb068f23b..72f9a637f 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,476 +1,18 @@ -API · Turing - - - - - -

API

Module-wide re-exports

Turing.jl directly re-exports the entire public API of the following packages:

Please see the individual packages for their documentation.

Individual exports and re-exports

All of the following symbols are exported unqualified by Turing, even though the documentation suggests that many of them are qualified. That means, for example, you can just write

using Turing
+API · Turing

API

Module-wide re-exports

Turing.jl directly re-exports the entire public API of the following packages:

Please see the individual packages for their documentation.

Individual exports and re-exports

All of the following symbols are exported unqualified by Turing, even though the documentation suggests that many of them are qualified. That means, for example, you can just write

using Turing
 
 @model function my_model() end
 
 sample(my_model(), Prior(), 100)

instead of

DynamicPPL.@model function my_model() end
 
-sample(my_model(), Turing.Inference.Prior(), 100)

even though Prior() is actually defined in the Turing.Inference module and @model in the DynamicPPL package.

Modelling

Exported symbolDocumentationDescription
@modelDynamicPPL.@modelDefine a probabilistic model
@varnameAbstractPPL.@varnameGenerate a VarName from a Julia expression
to_submodelDynamicPPL.to_submodelDefine a submodel

Inference

Exported symbolDocumentationDescription
sampleStatsBase.sampleSample from a model

Samplers

Exported symbolDocumentationDescription
PriorTuring.Inference.PriorSample from the prior distribution
MHTuring.Inference.MHMetropolis–Hastings
EmceeTuring.Inference.EmceeAffine-invariant ensemble sampler
ESSTuring.Inference.ESSElliptical slice sampling
GibbsTuring.Inference.GibbsGibbs sampling
GibbsConditionalTuring.Inference.GibbsConditionalA "pseudo-sampler" to provide analytical conditionals to Gibbs
HMCTuring.Inference.HMCHamiltonian Monte Carlo
SGLDTuring.Inference.SGLDStochastic gradient Langevin dynamics
SGHMCTuring.Inference.SGHMCStochastic gradient Hamiltonian Monte Carlo
PolynomialStepsizeTuring.Inference.PolynomialStepsizeReturns a function which generates polynomially decaying step sizes
HMCDATuring.Inference.HMCDAHamiltonian Monte Carlo with dual averaging
NUTSTuring.Inference.NUTSNo-U-Turn Sampler
ISTuring.Inference.ISImportance sampling
SMCTuring.Inference.SMCSequential Monte Carlo
PGTuring.Inference.PGParticle Gibbs
CSMCTuring.Inference.CSMCThe same as PG
externalsamplerTuring.Inference.externalsamplerWrap an external sampler for use in Turing

Variational inference

See the variational inference tutorial for a walkthrough on how to use these.

Exported symbolDocumentationDescription
viAdvancedVI.viPerform variational inference
ADVIAdvancedVI.ADVIConstruct an instance of a VI algorithm

Automatic differentiation types

These are used to specify the automatic differentiation backend to use. See the AD guide for more information.

Exported symbolDocumentationDescription
AutoForwardDiffADTypes.AutoForwardDiffForwardDiff.jl backend
AutoReverseDiffADTypes.AutoReverseDiffReverseDiff.jl backend
AutoZygoteADTypes.AutoZygoteZygote.jl backend
AutoMooncakeADTypes.AutoMooncakeMooncake.jl backend

Debugging

Turing.setprogress!Function
setprogress!(progress::Bool)

Enable progress logging in Turing if progress is true, and disable it otherwise.

source

Distributions

These distributions are defined in Turing.jl, but not in Distributions.jl.

Turing.FlatType
Flat()

The flat distribution is the improper distribution of real numbers that has the improper probability density function

\[f(x) = 1.\]

source
Turing.FlatPosType
FlatPos(l::Real)

The positive flat distribution with real-valued parameter l is the improper distribution of real numbers that has the improper probability density function

\[f(x) = \begin{cases} +sample(my_model(), Turing.Inference.Prior(), 100)

even though Prior() is actually defined in the Turing.Inference module and @model in the DynamicPPL package.

Modelling

Exported symbolDocumentationDescription
@modelDynamicPPL.@modelDefine a probabilistic model
@varnameAbstractPPL.@varnameGenerate a VarName from a Julia expression
to_submodelDynamicPPL.to_submodelDefine a submodel

Inference

Exported symbolDocumentationDescription
sampleStatsBase.sampleSample from a model

Samplers

Exported symbolDocumentationDescription
PriorTuring.Inference.PriorSample from the prior distribution
MHTuring.Inference.MHMetropolis–Hastings
EmceeTuring.Inference.EmceeAffine-invariant ensemble sampler
ESSTuring.Inference.ESSElliptical slice sampling
GibbsTuring.Inference.GibbsGibbs sampling
GibbsConditionalTuring.Inference.GibbsConditionalA "pseudo-sampler" to provide analytical conditionals to Gibbs
HMCTuring.Inference.HMCHamiltonian Monte Carlo
SGLDTuring.Inference.SGLDStochastic gradient Langevin dynamics
SGHMCTuring.Inference.SGHMCStochastic gradient Hamiltonian Monte Carlo
PolynomialStepsizeTuring.Inference.PolynomialStepsizeReturns a function which generates polynomially decaying step sizes
HMCDATuring.Inference.HMCDAHamiltonian Monte Carlo with dual averaging
NUTSTuring.Inference.NUTSNo-U-Turn Sampler
ISTuring.Inference.ISImportance sampling
SMCTuring.Inference.SMCSequential Monte Carlo
PGTuring.Inference.PGParticle Gibbs
CSMCTuring.Inference.CSMCThe same as PG
externalsamplerTuring.Inference.externalsamplerWrap an external sampler for use in Turing

Variational inference

See the variational inference tutorial for a walkthrough on how to use these.

Exported symbolDocumentationDescription
viAdvancedVI.viPerform variational inference
ADVIAdvancedVI.ADVIConstruct an instance of a VI algorithm

Automatic differentiation types

These are used to specify the automatic differentiation backend to use. See the AD guide for more information.

Exported symbolDocumentationDescription
AutoForwardDiffADTypes.AutoForwardDiffForwardDiff.jl backend
AutoReverseDiffADTypes.AutoReverseDiffReverseDiff.jl backend
AutoZygoteADTypes.AutoZygoteZygote.jl backend
AutoMooncakeADTypes.AutoMooncakeMooncake.jl backend

Debugging

Turing.setprogress!Function
setprogress!(progress::Bool)

Enable progress logging in Turing if progress is true, and disable it otherwise.

source

Distributions

These distributions are defined in Turing.jl, but not in Distributions.jl.

Turing.FlatType
Flat()

The flat distribution is the improper distribution of real numbers that has the improper probability density function

\[f(x) = 1.\]

source
Turing.FlatPosType
FlatPos(l::Real)

The positive flat distribution with real-valued parameter l is the improper distribution of real numbers that has the improper probability density function

\[f(x) = \begin{cases} 0 & \text{if } x \leq l, \\ 1 & \text{otherwise}. -\end{cases}\]

source
Turing.BinomialLogitType
BinomialLogit(n, logitp)

The Binomial distribution with logit parameterization characterizes the number of successes in a sequence of independent trials.

It has two parameters: n, the number of trials, and logitp, the logit of the probability of success in an individual trial, with the distribution

\[P(X = k) = {n \choose k}{(\text{logistic}(logitp))}^k (1 - \text{logistic}(logitp))^{n-k}, \quad \text{ for } k = 0,1,2, \ldots, n.\]

See also: Binomial

source
Turing.OrderedLogisticType
OrderedLogistic(η, c::AbstractVector)

The ordered logistic distribution with real-valued parameter η and cutpoints c has the probability mass function

\[P(X = k) = \begin{cases} +\end{cases}\]

source
Turing.BinomialLogitType
BinomialLogit(n, logitp)

The Binomial distribution with logit parameterization characterizes the number of successes in a sequence of independent trials.

It has two parameters: n, the number of trials, and logitp, the logit of the probability of success in an individual trial, with the distribution

\[P(X = k) = {n \choose k}{(\text{logistic}(logitp))}^k (1 - \text{logistic}(logitp))^{n-k}, \quad \text{ for } k = 0,1,2, \ldots, n.\]

See also: Binomial

source
Turing.OrderedLogisticType
OrderedLogistic(η, c::AbstractVector)

The ordered logistic distribution with real-valued parameter η and cutpoints c has the probability mass function

\[P(X = k) = \begin{cases} 1 - \text{logistic}(\eta - c_1) & \text{if } k = 1, \\ \text{logistic}(\eta - c_{k-1}) - \text{logistic}(\eta - c_k) & \text{if } 1 < k < K, \\ \text{logistic}(\eta - c_{K-1}) & \text{if } k = K, -\end{cases}\]

where K = length(c) + 1.

source
Turing.LogPoissonType
LogPoisson(logλ)

The Poisson distribution with logarithmic parameterization of the rate parameter describes the number of independent events occurring within a unit time interval, given the average rate of occurrence $\exp(\log\lambda)$.

The distribution has the probability mass function

\[P(X = k) = \frac{e^{k \cdot \log\lambda}}{k!} e^{-e^{\log\lambda}}, \quad \text{ for } k = 0,1,2,\ldots.\]

See also: Poisson

source

BernoulliLogit is part of Distributions.jl since version 0.25.77. If you are using an older version of Distributions where this isn't defined, Turing will export the same distribution.

Distributions.BernoulliLogitType
BernoulliLogit(logitp=0.0)

A Bernoulli distribution that is parameterized by the logit logitp = logit(p) = log(p/(1-p)) of its success rate p.

\[P(X = k) = \begin{cases} +\end{cases}\]

where K = length(c) + 1.

source
Turing.LogPoissonType
LogPoisson(logλ)

The Poisson distribution with logarithmic parameterization of the rate parameter describes the number of independent events occurring within a unit time interval, given the average rate of occurrence $\exp(\log\lambda)$.

The distribution has the probability mass function

\[P(X = k) = \frac{e^{k \cdot \log\lambda}}{k!} e^{-e^{\log\lambda}}, \quad \text{ for } k = 0,1,2,\ldots.\]

See also: Poisson

source

BernoulliLogit is part of Distributions.jl since version 0.25.77. If you are using an older version of Distributions where this isn't defined, Turing will export the same distribution.

Distributions.BernoulliLogitType
BernoulliLogit(logitp=0.0)

A Bernoulli distribution that is parameterized by the logit logitp = logit(p) = log(p/(1-p)) of its success rate p.

\[P(X = k) = \begin{cases} \operatorname{logistic}(-logitp) = \frac{1}{1 + \exp{(logitp)}} & \quad \text{for } k = 0, \\ \operatorname{logistic}(logitp) = \frac{1}{1 + \exp{(-logitp)}} & \quad \text{for } k = 1. \end{cases}\]

External links:

See also Bernoulli

source

Tools to work with distributions

Exported symbolDocumentationDescription
filldistDistributionsAD.filldistCreate a product distribution from a distribution and integers
arraydistDistributionsAD.arraydistCreate a product distribution from an array of distributions
NamedDistDynamicPPL.NamedDistA distribution that carries the name of the variable

Predictions

StatsAPI.predictFunction
predict([rng::AbstractRNG,] model::Model, chain::MCMCChains.Chains; include_all=false)

Execute model conditioned on each sample in chain, and return the resulting Chains.

If include_all is false, the returned Chains will contain only those variables sampled/not present in chain.

Details

Internally calls Turing.Inference.transitions_from_chain to obtained the samples and then converts these into a Chains object using AbstractMCMC.bundle_samples.

Example

julia> using Turing; Turing.setprogress!(false);
@@ -521,8 +63,8 @@
         y[1]  20.0342  20.1188  20.2135  20.2588  20.4188
         y[2]  20.1870  20.3178  20.3839  20.4466  20.5895
 
+
 julia> ys_pred = vec(mean(Array(group(predictions, :y)); dims = 1));
 
 julia> sum(abs2, ys_test - ys_pred) ≤ 0.1
-true
source

Querying model probabilities and quantities

Please see the generated quantities and probability interface guides for more information.

Exported symbolDocumentationDescription
generated_quantitiesDynamicPPL.generated_quantitiesCalculate additional quantities defined in a model
pointwise_loglikelihoodsDynamicPPL.pointwise_loglikelihoodsCompute log likelihoods for each sample in a chain
logpriorDynamicPPL.logpriorCompute log prior probability
logjointDynamicPPL.logjointCompute log joint probability
LogDensityFunctionDynamicPPL.LogDensityFunctionWrap a Turing model to satisfy LogDensityFunctions.jl interface
conditionAbstractPPL.conditionCondition a model on data
deconditionAbstractPPL.deconditionRemove conditioning on data
conditionedDynamicPPL.conditionedReturn the conditioned values of a model
fixDynamicPPL.fixFix the value of a variable
unfixDynamicPPL.unfixUnfix the value of a variable
OrderedDictOrderedCollections.OrderedDictAn ordered dictionary

Extra re-exports from Bijectors

Note that Bijectors itself does not export ordered.

Bijectors.orderedFunction
ordered(d::Distribution)

Return a Distribution whose support are ordered vectors, i.e., vectors with increasingly ordered elements.

Specifically, d is restricted to the subspace of its domain containing only ordered elements.

Warning

rand is implemented using rejection sampling, which can be slow for high-dimensional distributions. In such cases, consider using MCMC methods to sample from the distribution instead.

Warning

The resulting ordered distribution is un-normalized, which can cause issues in some contexts, e.g. in hierarchical models where the parameters of the ordered distribution are themselves sampled. See the notes below for a more detailed discussion.

Notes on ordered being un-normalized

The resulting ordered distribution is un-normalized. This is not a problem if used in a context where the normalizing factor is irrelevant, but if the value of the normalizing factor impacts the resulting computation, the results may be inaccurate.

For example, if the distribution is used in sampling a posterior distribution with MCMC and the parameters of the ordered distribution are themselves sampled, then the normalizing factor would in general be needed for accurate sampling, and ordered should not be used. However, if the parameters are fixed, then since MCMC does not require distributions be normalized, ordered may be used without problems.

A common case is where the distribution being ordered is a joint distribution of n identical univariate distributions. In this case the normalization factor works out to be the constant n!, and ordered can again be used without problems even if the parameters of the univariate distribution are sampled.

source

Point estimates

See the mode estimation tutorial for more information.

Exported symbolDocumentationDescription
maximum_a_posterioriTuring.Optimisation.maximum_a_posterioriFind a MAP estimate for a model
maximum_likelihoodTuring.Optimisation.maximum_likelihoodFind a MLE estimate for a model
MAPTuring.Optimisation.MAPType to use with Optim.jl for MAP estimation
MLETuring.Optimisation.MLEType to use with Optim.jl for MLE estimation
- +truesource

Querying model probabilities and quantities

Please see the generated quantities and probability interface guides for more information.

Exported symbolDocumentationDescription
generated_quantitiesDynamicPPL.generated_quantitiesCalculate additional quantities defined in a model
pointwise_loglikelihoodsDynamicPPL.pointwise_loglikelihoodsCompute log likelihoods for each sample in a chain
logpriorDynamicPPL.logpriorCompute log prior probability
logjointDynamicPPL.logjointCompute log joint probability
LogDensityFunctionDynamicPPL.LogDensityFunctionWrap a Turing model to satisfy LogDensityFunctions.jl interface
conditionAbstractPPL.conditionCondition a model on data
deconditionAbstractPPL.deconditionRemove conditioning on data
conditionedDynamicPPL.conditionedReturn the conditioned values of a model
fixDynamicPPL.fixFix the value of a variable
unfixDynamicPPL.unfixUnfix the value of a variable
OrderedDictOrderedCollections.OrderedDictAn ordered dictionary

Extra re-exports from Bijectors

Note that Bijectors itself does not export ordered.

Bijectors.orderedFunction
ordered(d::Distribution)

Return a Distribution whose support are ordered vectors, i.e., vectors with increasingly ordered elements.

Specifically, d is restricted to the subspace of its domain containing only ordered elements.

Warning

rand is implemented using rejection sampling, which can be slow for high-dimensional distributions. In such cases, consider using MCMC methods to sample from the distribution instead.

Warning

The resulting ordered distribution is un-normalized, which can cause issues in some contexts, e.g. in hierarchical models where the parameters of the ordered distribution are themselves sampled. See the notes below for a more detailed discussion.

Notes on ordered being un-normalized

The resulting ordered distribution is un-normalized. This is not a problem if used in a context where the normalizing factor is irrelevant, but if the value of the normalizing factor impacts the resulting computation, the results may be inaccurate.

For example, if the distribution is used in sampling a posterior distribution with MCMC and the parameters of the ordered distribution are themselves sampled, then the normalizing factor would in general be needed for accurate sampling, and ordered should not be used. However, if the parameters are fixed, then since MCMC does not require distributions be normalized, ordered may be used without problems.

A common case is where the distribution being ordered is a joint distribution of n identical univariate distributions. In this case the normalization factor works out to be the constant n!, and ordered can again be used without problems even if the parameters of the univariate distribution are sampled.

source

Point estimates

See the mode estimation tutorial for more information.

Exported symbolDocumentationDescription
maximum_a_posterioriTuring.Optimisation.maximum_a_posterioriFind a MAP estimate for a model
maximum_likelihoodTuring.Optimisation.maximum_likelihoodFind a MLE estimate for a model
MAPTuring.Optimisation.MAPType to use with Optim.jl for MAP estimation
MLETuring.Optimisation.MLEType to use with Optim.jl for MLE estimation
diff --git a/dev/index.html b/dev/index.html index 63c92af9a..a5575c522 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,461 +1,2 @@ -Home · Turing - - - - - -

Turing.jl

This site contains the API documentation for the identifiers exported by Turing.jl.

If you are looking for usage examples and guides, please visit https://turinglang.org/docs.

- +Home · Turing

Turing.jl

This site contains the API documentation for the identifiers exported by Turing.jl.

If you are looking for usage examples and guides, please visit https://turinglang.org/docs.

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