### Install recommended ecosystem packages Source: https://github.com/bat/bat.jl/blob/main/docs/src/installation.md Installs common statistics, plotting, and I/O packages recommended for use with BAT.jl. ```julia julia> using Pkg julia> pkg"add BAT ArraysOfArrays Distributions ElasticArrays IntervalSets Parameters Plots StatsBase Tables TypedTables" ``` -------------------------------- ### Install BAT.jl via Pkg Source: https://github.com/bat/bat.jl/blob/main/README.md Use the Julia package manager to add the BAT package to your environment. ```julia julia> using Pkg julia> pkg"add BAT" ``` -------------------------------- ### Install development version of BAT.jl Source: https://github.com/bat/bat.jl/blob/main/docs/src/installation.md Installs the latest code from the main branch instead of the stable release. ```julia julia> pkg"add BAT#main" ``` -------------------------------- ### Install optional algorithm packages Source: https://github.com/bat/bat.jl/blob/main/docs/src/installation.md Installs additional packages required for specific BAT algorithms and advanced functionality. ```julia julia> pkg"add AutoDiffOperators AdvancedHMC Cuba Folds HDF5 NestedSamplers Optim" ``` -------------------------------- ### Install IJulia kernel Source: https://github.com/bat/bat.jl/blob/main/docs/src/installation.md Commands to install the IJulia kernel for Jupyter, including platform-specific configurations for existing Jupyter installations. ```julia pkg"add IJulia" ``` ```julia ENV["JUPYTER"] = "$(homedir())/opt/anaconda3/bin/jupyter"; pkg"add IJulia" ``` ```julia ENV["JUPYTER"] = "DRIVE:/path/to/your/anaconda/.../jupyter.exe"; pkg"add IJulia" ``` -------------------------------- ### Generate documentation locally Source: https://github.com/bat/bat.jl/blob/main/docs/src/developing.md Commands to navigate to the documentation directory and execute the build script. ```shell cd docs julia make.jl ``` -------------------------------- ### Configure DocTestSetup Source: https://github.com/bat/bat.jl/blob/main/docs/src/stable_api.md Sets up the environment for doctests by importing the BAT module. ```julia DocTestSetup = quote using BAT end ``` -------------------------------- ### Find Mode using Optim.jl Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Requires the Optim package. Demonstrates NelderMead and LBFGS optimization algorithms. ```julia using Optim bat_findmode(target, OptimAlg(optalg = Optim.NelderMead())) import ForwardDiff set_batcontext(ad = ForwardDiff) bat_findmode(target, OptimAlg(optalg = Optim.LBFGS())) ``` -------------------------------- ### Find Mode using OptimizationBase.jl Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Requires an implementation package like OptimizationOptimJL. ```julia using OptimizationOptimJL alg = OptimizationAlg(; optalg = OptimizationOptimJL.ParticleSwarm(n_particles=10), maxiters=200, kwargs=(f_calls_limit=50,) ) bat_findmode(target, alg) ``` -------------------------------- ### Perform HDF5 File I/O Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses BATHDF5IO to write and read samples to/from HDF5 files. ```julia import HDF5 bat_write("results.h5", smpls) # ... later ... smpls = bat_read("results.h5").result ``` -------------------------------- ### Perform Integration with Cuba Algorithms Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Integration methods requiring the Cuba package. Includes Vegas, Suave, Cuhre, and Divonne. ```julia import Cuba bat_integrate(target, VEGASIntegration()) ``` ```julia import Cuba bat_integrate(target, SuaveIntegration()) ``` ```julia import Cuba bat_integrate(target, CuhreIntegration()) ``` ```julia import Cuba bat_integrate(target, DivonneIntegration()) ``` -------------------------------- ### Render License File in Julia Source: https://github.com/bat/bat.jl/blob/main/docs/src/license.md Uses the Markdown package to parse and display the contents of the LICENSE.md file located in the project root. ```julia using Markdown Markdown.parse_file(joinpath(@__DIR__, "..", "..", "LICENSE.md")) ``` -------------------------------- ### Locate Julia binary directory Source: https://github.com/bat/bat.jl/blob/main/docs/src/installation.md Run this command in a Julia session to find the path for adding to your system PATH. ```julia Sys.BINDIR ``` -------------------------------- ### Perform JLD2 File I/O Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses FileIO and JLD2 for saving and loading complex Julia data structures. ```julia using FileIO import JLD2 FileIO.save("results.jld2", Dict("smpls" => smpls)) # ... later ... smpls = FileIO.load("results.jld2", "smpls") ``` -------------------------------- ### Perform Sobol Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses the SobolSampler for quasi-random sampling. ```julia bat_sample(target, SobolSampler(nsamples=10^5)) ``` -------------------------------- ### plot(samples::DensitySampleVector, vsel::Union{NTuple{2, Integer}, NTuple{2, Union{Symbol, Expr}}}; ...) Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md Generates a 2D plot for the specified parameters from a DensitySampleVector. ```APIDOC ## plot(samples, vsel) ### Description Creates a 2D visualization of samples from a DensitySampleVector for two selected parameters. ### Parameters - **samples** (DensitySampleVector) - Required - The samples to be plotted. - **vsel** (Union{NTuple{2, Integer}, NTuple{2, Union{Symbol, Expr}}}) - Required - Indices or names of the two parameters to be plotted. ### Keyword Arguments - **seriestype** (Symbol) - Optional - Plot style (e.g., :smallest_intervals, :smallest_intervals_contour, :histogram, :scatter). - **bins** (Union{Integer, NTuple{2, Integer}, NTuple{2, AbstractRange}}) - Optional - Number of histogram bins or bin edges. - **intervals** (Array{<:Real, 1}) - Optional - Probability levels for smallest intervals. - **mean** (Union{Dict, Bool}) - Optional - Indicate mean value. - **std** (Union{Bool}) - Optional - Indicate standard deviation as errorbars. - **globalmode** (Union{Dict, Bool}) - Optional - Indicate global mode. - **marginalmode** (Union{Dict, Bool}) - Optional - Indicate marginal mode. - **smoothing** (Real) - Optional - Gaussian kernel standard deviation for contour smoothing. - **filter** (Bool) - Optional - Whether to drop low weight samples before plotting. ``` -------------------------------- ### List of Experimental BAT.jl APIs Source: https://github.com/bat/bat.jl/blob/main/docs/src/experimental_api.md A collection of experimental functions, types, and modules available in the current version of BAT.jl. ```julia ```@docs ARPWeighting bat_compare bat_integrated_autocorr_len bat_marginalmode BAT.auto_renormalize BAT.batsampleable BAT.BinnedModeEstimator BAT.DistributionTransform BAT.enable_error_log BAT.error_log BAT.EvalException BAT.ext_default BAT.get_adselector BAT.get_valid_adselector BAT.PackageExtension BAT.pkgext BAT.set_rng batmeasure BridgeSampling EllipsoidalNestedSampling GridSampler HierarchicalDistribution PriorImportanceSampler ReactiveNestedSampling SobolSampler truncate_batmeasure ValueAndThreshold BAT.MCMCChainState BAT.MCMCChainStateInfo BAT.MCMCIterator BAT.MCMCProposal BAT.MCMCProposalState BAT.MCMCProposalTunerState BAT.MCMCState BAT.MCMCTempering BAT.MCMCTransformTunerState BAT.PolarShellDistribution BAT.SimpleMCMCProposalState BAT.TemperingState ``` ``` -------------------------------- ### Perform Reactive Nested Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Experimental feature requiring the UltraNest package. ```julia import UltraNest bat_sample(target, ReactiveNestedSampling()) ``` -------------------------------- ### Perform Integration via Bridge Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Experimental integration method using BridgeSampling on an evaluated measure. ```julia bat_integrate(EvaluatedMeasure(target, smpls), BridgeSampling()) ``` -------------------------------- ### Plot 1D Density Samples in Julia Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md Use the plot function with a DensitySampleVector and parameter selector to visualize 1D distributions. ```julia plot( samples::DensitySampleVector, vsel::Union{Integer, Symbol, Expr}; intervals = BAT.default_credibilities, bins = 200, colors = BAT.default_colors, interval_labels = [], mean = false, std = false, globalmode = false, marginalmode = true, filter = false, closed = :left ) ``` -------------------------------- ### Define Documentation Contents Source: https://github.com/bat/bat.jl/blob/main/docs/src/index.md Configuration block for the Documenter.jl package to define the structure of the documentation pages. ```julia @contents Pages = [ # "basics.md", "installation.md", "tutorial.md", # "faq.md", # "examples.md", # "algorithms.md", # "benchmarks.md", # "publications.md", "api.md", "developing.md", "license.md", ] Depth = 1 ``` -------------------------------- ### Perform Grid Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses the GridSampler with a specified points-per-axis (ppa) parameter. ```julia bat_sample(target, GridSampler(ppa=100)) ``` -------------------------------- ### Perform Prior Importance Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses the PriorImportanceSampler for importance sampling based on the prior. ```julia bat_sample(target, PriorImportanceSampler(nsamples=10^5)) ``` -------------------------------- ### plot(samples::DensitySampleVector) Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md Generates a grid plot with 1D marginalized distributions on the diagonal and 2D marginalized distributions in the off-diagonal triangles. ```APIDOC ## plot(samples::DensitySampleVector) ### Description Plot a grid with the 1D marginalized distributions on the diagonal and all combinations of the 2D marginalized distributions in the lower and upper triangle. ### Parameters - **samples** (DensitySampleVector) - Required - Samples to be plotted. - **vsel** (Any) - Optional - Indices or parameter names of the parameters to be plotted. Default: collect(1:5). - **bins** (Union{Integer, Tuple{Union{Integer, AbstractRange}}, NamedTuple}) - Optional - Number of bins or bin edges. Default: 200. - **mean** (Bool) - Optional - Indicate mean value in all plots. Default: false. - **std** (Bool) - Optional - Indicate the standard deviation of the mean in all plots. Default: false. - **globalmode** (Bool) - Optional - Indicate global mode in all plots. Default: false. - **marginalmode** (Bool) - Optional - Indicate local mode(s) in all plots. Default: false. - **diagonal** (Dict) - Optional - Dictionary containing seriestypes and plot options for 1D distributions. - **upper** (Dict) - Optional - Dictionary containing seriestypes and plot options for 2D distributions in the upper triangle. - **lower** (Dict) - Optional - Dictionary containing seriestypes and plot options for 2D distributions in the lower triangle. - **vsel_label** (Array) - Optional - Parameter labels as strings or LatexStrings. ``` -------------------------------- ### Perform Hamiltonian Monte Carlo Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Requires the AdvancedHMC package. Uses HamiltonianMC as the proposal mechanism. ```julia import AdvancedHMC, ForwardDiff set_batcontext(ad = ForwardDiff) bat_sample(target, TransformedMCMC(proposal = HamiltonianMC())) ``` -------------------------------- ### Find Mode using Maximum Sample Estimator Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses MaxDensitySearch to find the mode from existing samples. ```julia bat_findmode(smpls, MaxDensitySearch()) ``` -------------------------------- ### Perform Metropolis-Hastings Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses TransformedMCMC with a RandomWalk proposal for sampling. ```julia bat_sample(target, TransformedMCMC(proposal = RandomWalk(), nsteps = 10^5, nchains = 4)) ``` -------------------------------- ### Perform IID Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Uses the IIDSampling algorithm to sample from the target prior. ```julia bat_sample(target.prior, IIDSampling(nsamples=10^5)) ``` -------------------------------- ### plot(samples::DensitySampleVector, vsel::Union{Integer, Symbol, Expr}) Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md Generates a 1D plot for a specific parameter from a DensitySampleVector. Supports various seriestypes and statistical overlays. ```APIDOC ## plot(samples::DensitySampleVector, vsel::Union{Integer, Symbol, Expr}) ### Description Creates a 1D plot for a parameter selected from a DensitySampleVector. Users can customize the plot style, intervals, and statistical indicators. ### Parameters #### Positional Arguments - **samples** (DensitySampleVector) - Required - The samples to be plotted. - **vsel** (Union{Integer, Symbol, Expr}) - Required - The index or name of the parameter to be plotted. #### Keyword Arguments - **seriestype** (Symbol) - Optional - Plot style: :smallest_intervals (default), :central_intervals, :histogram, or :stephist. - **bins** (Union{Integer, AbstractRange}) - Optional - Number of histogram bins or bin edges (default: 200). - **intervals** (Array{<:Real, 1}) - Optional - Probabilities for intervals (default: [0.683, 0.955, 0.997]). - **colors** (Array{Symbol, 1}) - Optional - Colors for interval regions. - **mean** (Union{Dict, Bool}) - Optional - Indicates mean value; can be a boolean or a Dict for styling. - **std** (Union{Dict, Bool}) - Optional - Indicates standard deviation; can be a boolean or a Dict for styling. - **globalmode** (Union{Dict, Bool}) - Optional - Indicates global mode; can be a boolean or a Dict for styling. - **marginalmode** (Union{Dict, Bool}) - Optional - Indicates marginal mode; can be a boolean or a Dict for styling. - **filter** (Bool) - Optional - If true, applies low-weight sample filtering. - **closed** (Symbol) - Optional - Histogram bin closure (default: :left). ``` -------------------------------- ### Define likelihood using DensityInterface Source: https://github.com/bat/bat.jl/blob/main/NEWS.md Use the DensityInterface API to define likelihoods, replacing the deprecated LogDVal approach. ```julia likelihood = let data = mydata logfuncdensity(function(v) log_likelihood_value = ... return log_likelihood_value end) end ``` ```julia struct MyLikeLihood{D} data::D end @inline DensityInterface.DensityKind(::MyLikeLihood) = IsDensity() function DensityInterface.logdensityof(likelihood::MyLikeLihood, v) log_likelihood_value = ... return log_likelihood_value end likelihood = MyLikeLihood(mydata) ``` -------------------------------- ### Perform Ellipsoidal Nested Sampling Source: https://github.com/bat/bat.jl/blob/main/docs/src/list_of_algorithms.md Experimental feature requiring the NestedSamplers package. ```julia import NestedSamplers bat_sample(target, EllipsoidalNestedSampling()) ``` -------------------------------- ### Plot 1D and 2D marginalized distributions Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md Use this function to generate a grid of marginalized distribution plots from a DensitySampleVector. Customize the output using keyword arguments for binning, statistical indicators, and styling dictionaries. ```julia plot( samples::DensitySampleVector; vsel=collect(1:5), bins = 200, mean=false, std=false, globalmode=false, marginalmode=false, diagonal = Dict(), upper = Dict(), lower = Dict(), vsel_label = [] ) ``` -------------------------------- ### Cite BAT.jl in BibTeX Source: https://github.com/bat/bat.jl/blob/main/docs/src/index.md BibTeX entry for referencing the BAT.jl publication in academic work. ```bibtex @article{Schulz:2021BAT, author = {Schulz, Oliver and Beaujean, Frederik and Caldwell, Allen and Grunwald, Cornelius and Hafych, Vasyl and Kr{"o}ninger, Kevin and Cagnina, Salvatore La and R{"o}hrig, Lars and Shtembari, Lolian}, journal = {SN Computer Science}, title = {BAT.jl: A Julia-Based Tool for Bayesian Inference}, year = {2021}, issn = {2661-8907}, month = {Apr}, number = {3}, pages = {210}, volume = {2}, day = {12}, doi = {10.1007/s42979-021-00626-4}, url = {https://doi.org/10.1007/s42979-021-00626-4}, } ``` -------------------------------- ### 2D Plot Function Signature Source: https://github.com/bat/bat.jl/blob/main/docs/src/plotting.md The primary function signature for generating 2D plots from sample data. ```julia plot( samples::DensitySampleVector, vsel::Union{NTuple{2, Integer}, NTuple{2, Union{Symbol, Expr}}}; intervals = BAT.default_credibilities, interval_labels = [], colors = BAT.default_colors, bins = 200, mean = false, std = false, globalmode = false, marginalmode = true, smoothing = 0, diagonal = Dict(), upper = Dict(), right = Dict(), filter = false, closed = :left ) ``` -------------------------------- ### Deprecated LogDVal usage Source: https://github.com/bat/bat.jl/blob/main/NEWS.md This pattern is deprecated and should no longer be used for defining likelihoods. ```julia likelihood = let data = mydata function(v) log_likelihood_value = ... return LogDVal(log_likelihood_value) end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.