AtomisticQoIs
Documentation for AtomisticQoIs.
AtomisticQoIs.AtomisticQoIsAtomisticQoIs.AutocorrelationQoIAtomisticQoIs.CircularDomainAtomisticQoIs.DivergenceAtomisticQoIs.GaussQuadratureAtomisticQoIs.GibbsIntegratorAtomisticQoIs.GibbsQoIAtomisticQoIs.GreenKuboQoIAtomisticQoIs.HMCAtomisticQoIs.HittingDomainAtomisticQoIs.HittingTimeQoIAtomisticQoIs.ISMCAtomisticQoIs.ISMCMCAtomisticQoIs.ISMixSamplesAtomisticQoIs.ISSamplesAtomisticQoIs.IntervalDomainAtomisticQoIs.MALAAtomisticQoIs.MCMCAtomisticQoIs.MCPathsAtomisticQoIs.MCSamplesAtomisticQoIs.MonteCarloAtomisticQoIs.NUTSAtomisticQoIs.PathIntegratorAtomisticQoIs.QoIAtomisticQoIs.RectangularDomainAtomisticQoIs.EffSampleSizeAtomisticQoIs.EffSampleSizeAtomisticQoIs.ISWeightDiagnosticAtomisticQoIs.ISWeightVarianceAtomisticQoIs.MCSEAtomisticQoIs.MCSEbmAtomisticQoIs.MCSEobmAtomisticQoIs.assign_paramAtomisticQoIs.compute_grad_qoiAtomisticQoIs.compute_metricsAtomisticQoIs.expectation_is_stableAtomisticQoIs.gaussquadAtomisticQoIs.gaussquad_2DAtomisticQoIs.hasapproxnormconstAtomisticQoIs.hasupdfAtomisticQoIs.hits_domainAtomisticQoIs.sampleAtomisticQoIs.sampleAtomisticQoIs.sample
AtomisticQoIs.AtomisticQoIs — ModuleAtomisticQoIs
Author: Joanna Zou <jjzou@mit.edu> Version: 0.1.0 Year: 2024 Notes: A Julia library for computing expectation-valued quantities of interest (QoIs) from molecular dynamics simulation.
AtomisticQoIs.AutocorrelationQoI — Type@kwdef mutable struct AutocorrelationQoI <: QoI
Defines quantities for computing two-point invariant statistics, in particular: mean and variance of the autocorrelation of the function H over the Gibbs measure p with lag t, e. g. Ep[H(xt)H(x0)] and Varp[H(xt)H(x0)]
Arguments
H :: Function: function to evaluate autocorrelationlag :: Real: autocorrelation lags :: Function: score (drift) function
AtomisticQoIs.CircularDomain — Typestruct CircularDomain <: HittingDomain
Defines circular domain for N-D state space.
Arguments
center :: Vector: coordinate of center point (N-D vector)radius :: Real: circle radius
AtomisticQoIs.Divergence — TypeDivergence
A struct of abstract type Divergence contains properties needed to compute a divergence metric between measures of the stochastic process.AtomisticQoIs.GaussQuadrature — Typestruct GaussQuadrature <: QuadIntegrator
Contains parameters for 1D or 2D Gauss quadrature integration.
Arguments
ξ :: Union{Vector{<:Real}, Vector{<:Vector}}: quadrature pointsw :: Union{Vector{<:Real}, Vector{<:Vector}}: quadrature weightsd :: Real: dimension
AtomisticQoIs.GibbsIntegrator — TypeGibbsIntegrator
A struct of abstract type GibbsIntegrator computes the expectation of a function h(x, θ) with respect to the invariant measure p(x, θ).AtomisticQoIs.GibbsQoI — Type@kwdef mutable struct GibbsQoI <: QoI
Defines quantities for computing one-point invariant statistics, in particular: mean and variance of the observable function h over the Gibbs measure p, e. g. Ep[h(θ)] and Varp[h(θ)]
Arguments
h :: Function: function to evaluate expectation, receiving inputs (x,θ)p :: Gibbs: Gibbs (invariant) distribution with θ == nothing (undefined parameters)∇h :: Union{Function, Nothing} = nothing: gradient of h (if nothing, gradient is computed using ForwardDiff)
AtomisticQoIs.GreenKuboQoI — Type@kwdef mutable struct GreenKuboQoI <: QoI
Defines quantities for computing a Green Kubo integral, in particular: the integrated autocorrelation function up to time lag t, e. g. ∫₀ᵗ E_p[H(xs)H(x0)] ds
# ArgumentsH :: Function: function to evaluate autocorrelationlag :: Real: autocorrelation lags :: Function: score (drift) function
AtomisticQoIs.HMC — Typestruct HMC <: Sampler
Defines the struct with parameters of the Hamiltonian Monte Carlo algorithm for sampling.
Arguments
L :: Int: time length of integrating Hamiltonian's equationsϵ :: Real: step size
AtomisticQoIs.HittingDomain — TypeHittingDomain
Abstract type defining domain in state space for computing the first hitting time
AtomisticQoIs.HittingTimeQoI — Type@kwdef mutable struct HittingTimeQoI <: QoI
Defines quantities for computing statistics of the first hitting time, in particular: mean and variance of the first hitting time τ over the transient path measure P up to time τ, e. g. EP[τ(θ)] and VarP[τ(θ)]
Arguments
x0 :: Union{Real, Vector{<:Real}}: initial state of the stochastic processD :: HittingDomain: hitting domains :: Function: score (drift) function of the stochastic process
AtomisticQoIs.ISMC — Typestruct ISMC <: ISIntegrator
Contains parameters for Importance Sampling (IS) integration using MC samples from a biasing distribution. This method is implemented when the biasing distribution g can be analytically sampled using rand().
Arguments
g :: Distribution: biasing distributionn :: Int: number of samples
AtomisticQoIs.ISMCMC — Typestruct ISMCMC <: ISIntegrator
Contains parameters for Importance Sampling (IS) integration using MCMC samples from a biasing distribution. This method is implemented when the biasing distribution g cannot be analytically sampled.
Arguments
g :: Distribution: biasing distributionn :: Int: number of samplessampler :: Sampler: type of sampler (seeSampler)ρ0 :: Distribution: prior distribution of the state
AtomisticQoIs.ISMixSamples — Typestruct ISMixSamples <: ISIntegrator
Contains parameters for Importance Sampling (IS) integration using samples from a mixture biasing distribution. The mixture weights are computed based on a kernel distance metric of the parameter with respect to parameters of the mixture component distributions. This method is implemented with the user providing samples from each component mixture distribution.
Arguments
g :: MixtureModel: mixture biasing distributionn :: Int: number of samplesknl :: Kernel: kernel function to compute mixture weightsxsamp :: Vector: Vector of sample sets from each component distributionnormint :: GibbsIntegrator: Integrator for the approximating the normalizing constant of each component distribution
AtomisticQoIs.ISSamples — Typestruct ISSamples <: ISIntegrator
Contains pre-defined Monte Carlo samples from the biasing distribution to evaluate in integration. This method is implemented with the user providing samples from the biasing distribution.
Arguments
g :: Distribution: biasing distributionxsamp :: Vector: fixed set of samplesnormint :: Union{GibbsIntegrator, Nothing}: integrator for computing normalizing constant of biasing distribution (required for mixture models)
AtomisticQoIs.IntervalDomain — Typestruct IntervalDomain <: HittingDomain
Defines bounds of the interval domain for 1D state space.
Arguments
bounds :: Vector{<:Real}: lower and upper bounds [ll, ul]
AtomisticQoIs.MALA — Typestruct MALA <: Sampler
Defines the struct with parameters of the Metropolis-Adjusted Langevin Algorithm (MALA) for sampling.
Arguments
L :: Int: time length between evaluating accept/reject criterionϵ :: Real: step size
AtomisticQoIs.MCMC — Typestruct MCMC <: MCIntegrator
Contains parameters for Monte Carlo (MC) integration using MCMC samples. This method is implemented when the distribution cannot be analytically sampled.
Arguments
n :: Int: number of samplessampler :: Sampler: type of sampler (seeSampler)ρ0 :: Union{Distribution, Real, Vector{<:Real}}: initial state or prior distribution of the state
AtomisticQoIs.MCPaths — Typestruct MCPaths <: PathIntegrator
Contains parameters for generating path realizations to compute Monte Carlo averages over path measures.
Arguments
M :: Int: number of pathsn :: Int: max number of samples per pathsampler :: Sampler: type of sampler (seeSampler)ρ0 :: Union{Distribution, Real, Vector{<:Real}}: initial state or prior distribution of the state
AtomisticQoIs.MCSamples — Typestruct MCSamples <: MCIntegrator
Contains pre-defined Monte Carlo samples to evaluate in integration. This method is implemented with the user providing samples from the distribution.
Arguments
xsamp :: Vector: fixed set of samples
AtomisticQoIs.MonteCarlo — Typestruct MonteCarlo <: MCIntegrator
Contains parameters for Monte Carlo (MC) integration using MC samples. This method may only be implemented when the distribution can be analytically sampled using rand().
Arguments
n :: Int: number of samples
AtomisticQoIs.NUTS — Typestruct NUTS <: Sampler
Defines the struct with parameters of the No-U-Turn-Sampler algorithm for sampling.
Arguments
ϵ :: Union{<:Real, Nothing}: step size
AtomisticQoIs.PathIntegrator — TypePathIntegrator
A struct of abstract type PathIntegrator computes the expectation of a functional h with respect to the path measure P.AtomisticQoIs.QoI — TypeQoI
Abstract type defining observable quantities of interest (QoI) from a stochastic system.AtomisticQoIs.RectangularDomain — Typestruct RectangularDomain <: HittingDomain
Defines rectangular domain for N-D state space.
Arguments
bounds :: Vector: 2-dim. vector of uniform lower and upper bounds, or N-dim. vector of lower and upper bounds in each dimensiondim :: Real: dimension of state space (N)
AtomisticQoIs.EffSampleSize — Methodfunction EffSampleSize(q::GibbsQoI, xsamp::Vector)
Computes the effective sample size of a set of nMC samples from an MCMC chain.
Arguments
q :: GibbsQoI: Gibbs QoI structxsamp :: Vector: nMC-vector of x-samples
Outputs
ESS :: Float64: effective sample size (where 1 < ESS < nMC)
AtomisticQoIs.EffSampleSize — Methodfunction EffSampleSize(hsamp::Vector)
Computes the effective sample size of a set of nMC samples from an MCMC chain.
Arguments
hsamp :: Vector: nMC-vector of d-dimensional function evaluation h
Outputs
ESS :: Float64: effective sample size (where 1 < ESS < nMC)
AtomisticQoIs.ISWeightDiagnostic — Methodfunction ISWeightDiagnostic(wsamp::Vector)
Returns a diagnostic value for importance sampling weights using an unnormalized biasing distribution. The importance sampling estimate is reliable when the diagnostic is less than 5.
Arguments
wsamp :: Vector: nMC-vector of 1-dim. weights
Outputs
diagnostic :: Float64: diagnostic value (want < 5)
AtomisticQoIs.ISWeightVariance — Methodfunction ISWeightVariance(wsamp::Vector)
Returns the variance of importance sampling weights.
Arguments
wsamp :: Vector: nMC-vector of weights
Outputs
var(wsamp) :: Float64: variance of weights
AtomisticQoIs.MCSE — Methodfunction MCSE(q::GibbsQoI, xsamp::Vector)
Estimates the Monte Carlo standard error (se = std(h(x))/√n) using an empirical estimate of standard deviation.
Arguments
q :: GibbsQoI: Gibbs QoI structxsamp :: Vector: vector of samples
Outputs
se :: Float64: Monte Carlo standard error
AtomisticQoIs.MCSEbm — Methodfunction MCSEbm(q::GibbsQoI, xsamp::Vector)
Estimates the Monte Carlo standard error (se = std(h(x))/√n) using the batch means (BM) method.
Arguments
q :: GibbsQoI: Gibbs QoI structxsamp :: Vector: vector of samples
Outputs
se :: Float64: Monte Carlo standard error
AtomisticQoIs.MCSEobm — Methodfunction MCSEbm(q::GibbsQoI, xsamp::Vector)
Estimates the Monte Carlo standard error (se = std(h(x))/√n) using the overlapping batch means (OBM) method.
Arguments
q :: GibbsQoI: Gibbs QoI structxsamp :: Vector: vector of samples
Outputs
se :: Float64: Monte Carlo standard error
AtomisticQoIs.assign_param — Methodfunction assign_param(qoi::GibbsQoI, θ::Vector)
Helper function modifying a GibbsQoI for a specific value of the parameter θ
AtomisticQoIs.compute_grad_qoi — Methodfunction computegradqoi(θ::Union{Real, Vector{<:Real}}, qoi::GibbsQoI, integrator::GibbsIntegrator; gradh::Union{Function, Nothing}=nothing)
Computes the gradient of the QoI with respect to the parameters θ, e. g. ∇θ E_p[h(θ)].
Arguments
θ :: Union{Real, Vector{<:Real}}: parameters to evaluate expectationqoi :: QoI: QoI object containing summand h and Gibbs measure pintegrator :: GibbsIntegrator: struct specifying method of integrationgradh :: Union{Function, Nothing}: gradient of qoi.h; if nothing, compute with ForwardDiff
Outputs
res :: NamedTuple: contains output quantities (seecompute_qoifor more info)
AtomisticQoIs.compute_metrics — Methodfunction compute_metrics(θ::Vector, h::Vector, w::Vector)
Computes importance sampling diagnostic metrics, including variance of IS weights ("wvar"), ESS of IS weights ("wESS"), and diagnostic measure ("wdiag").
Arguments
θ :: Vector: vector of parametersh :: Vector: evaluations of summand function h(x) at samplesw :: Vector: evaluations of importance sampling weights at samples
Outputs
metrics :: Dict{String, Vector}: dictionary of importance sampling diagnostics
AtomisticQoIs.expectation_is_stable — Methodfunction expectationisstable(xsamp::Vector, ϕ::Function, f::Gibbs, g::Distribution; normint=nothing)
Helper function for computing stable importance sampling weights (using log formulation).
AtomisticQoIs.gaussquad — Methodfunction gaussquad(nquad::Integer, gaussbasis::Function, args...; limits::Vector=[-1,1])
Computes 1D Gauss quadrature points with a change of domain to limits=[ll, ul].
Arguments
nquad::Integer: number of quadrature pointsgaussbasis::Function: polynomial basis function from FastGaussQuadrature (gausslegendre, gaussjacobi, etc.)args...: additional arguments for the gaussbasis() functionlimits::Vector: defines lower and upper limits for rescaling
Outputs
ξ :: Vector{<:Real}: quadrature points ranging [ll, ul]w :: Vector{<:Real}: quadrature weights
AtomisticQoIs.gaussquad_2D — Methodfunction gaussquad_2D(nquad::Integer, gaussbasis::Function, args...; limits::Vector=[-1,1])
Computes 2D (symmetric) Gauss quadrature points with a change of domain to limits=[ll, ul].
Arguments
nquad::Integer: number of quadrature pointsgaussbasis::Function: polynomial basis function from FastGaussQuadrature (gausslegendre, gaussjacobi, etc.)args...: additional arguments for the gaussbasis() functionlimits::Vector: defines lower and upper limits for rescaling
Outputs
ξ :: Vector{<:Real}: quadrature points ranging [ll, ul]w :: Vector{<:Real}: quadrature weights
AtomisticQoIs.hasapproxnormconst — Methodfunction hasapproxnormconst(d::Distribution)
Returns 'true' if distribution d requires an approximation of its normalizing constant.
Arguments
d :: Distribution: distribution to check
Outputs
flag :: Bool: true or false
AtomisticQoIs.hasupdf — Methodfunction hasupdf(d::Distribution)
Returns 'true' if distribution d has an unnormalized pdf function (updf(), logupdf()).
Arguments
d :: Distribution: distribution to check
Outputs
flag :: Bool: true or false
AtomisticQoIs.hits_domain — Methodfunction hits_domain(x::Union{Real, Vector{<:Real}, D::HittingDomain)
Returns bool of whether the point x falls within the hitting domain.
Arguments
x::Union{Real, Vector{<:Real}: current state in the simulation trajectoryD::HittingDomain: hitting time domain
AtomisticQoIs.sample — Methodfunction sample(lπ::Function, gradlπ::Function, sampler::NUTS, n::Int64, x0::Real)
Draw samples from target distribution π(x) using the No-U-Turn Sampler (NUTS) for scalar-valued support (x::Real).
Arguments
lπ :: Function: log likelihood of target πgradlπ :: Function: gradient of log likelihood of πsampler :: HMC: Sampler struct specifying sampling algorithmn :: Int64: number of samplesx0 :: Real: initial state
Outputs
samples :: Vector: vector of samples from π
AtomisticQoIs.sample — Methodfunction sample(lπ::Function, gradlπ::Function, sampler::NUTS, n::Int64, x0::Vector{<:Real})
Draw samples from target distribution π(x) using the No-U-Turn Sampler (NUTS) from the AdvancedHMC package. Assumes multi-dimensional support (x::Vector).
Arguments
lπ :: Function: log likelihood of target πgradlπ :: Function: gradient of log likelihood of πsampler :: HMC: Sampler struct specifying sampling algorithmn :: Int64: number of samplesx0 :: Vector{<:Real}: initial state
Outputs
samples::Vector{Vector}: vector of samples from π
AtomisticQoIs.sample — Methodfunction sample(lπ::Function, gradlπ::Function, sampler::Union{HMC,MALA}, n::Int64, x0::Real)
Draw samples from target distribution π(x) for scalar-valued support (x::Real).
Arguments
lπ :: Function: log likelihood of target πgradlπ :: Function: gradient of log likelihood of πsampler :: Union{HMC,MALA}: Sampler struct specifying sampling algorithmn :: Int64: number of samplesx0 :: Real: initial state
Outputs
samples :: Vector: vector of samples from π