Skip to main content

fugue/
lib.rs

1// Copyright (c) 2025 Alex Nodeland
2// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>
3// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4// This file may not be copied, modified, or distributed except according to those terms.
5
6#![doc = include_str!("../README.md")]
7// Allow large error types for rich error context
8#![allow(clippy::result_large_err)]
9
10pub mod core;
11pub mod error;
12pub mod inference;
13pub mod macros;
14pub mod runtime;
15
16pub use core::address::Address;
17// `addr!` macro is exported at the crate root via #[macro_export]
18pub use core::distribution::{
19    Bernoulli, Beta, Binomial, Categorical, Cauchy, ChiSquared, DiscreteUniform, Distribution,
20    Exponential, Gamma, InverseGamma, Laplace, LogNormal, Normal, Poisson, StudentT, Uniform,
21    Weibull,
22};
23pub use core::model::{
24    factor, guard, observe, pure, sample, sample_bool, sample_f64, sample_i64, sample_u64,
25    sample_usize, sequence_vec, traverse_vec, zip, Model, ModelExt, SampleType,
26};
27pub use runtime::handler::Handler;
28pub use runtime::interpreters::{
29    score_given_trace_reconciled, PriorHandler, ReconcileReport, ReplayHandler, SafeReplayHandler,
30    SafeScoreGivenTrace, ScoreGivenTrace,
31};
32pub use runtime::trace::{Choice, ChoiceValue, Trace};
33
34// Re-export key inference methods
35pub use core::numerical::{log1p_exp, log_sum_exp, normalize_log_probs, safe_ln};
36pub use error::{ErrorCategory, ErrorCode, ErrorContext, FugueError, FugueResult, Validate};
37pub use inference::abc::{
38    abc_rejection, abc_scalar_summary, abc_smc, DistanceFunction, EuclideanDistance,
39};
40pub use inference::diagnostics::{
41    classic_r_hat_f64, extract_bool_values, extract_f64_values, extract_i64_values,
42    extract_u64_values, extract_usize_values, print_diagnostics, r_hat_f64,
43    summarize_f64_parameter, Diagnostics, ParameterSummary,
44};
45pub use inference::hmc::{hmc_chain, HMCConfig, HmcSession, HmcStepInfo, LeapfrogPoint};
46pub use inference::mcmc_utils::{
47    effective_sample_size_mcmc, effective_sample_size_multichain, geweke_diagnostic,
48    DiminishingAdaptation,
49};
50pub use inference::mh::{
51    adaptive_mcmc_chain, adaptive_mcmc_chain_thinned, adaptive_mcmc_chain_with_overrides,
52    adaptive_mcmc_chain_with_overrides_thinned, adaptive_single_site_mh, block_regeneration_mh,
53    SiteProposal,
54};
55pub use inference::smc::{
56    adaptive_smc, adaptive_smc_with_kernel, decode_particle, decode_particles,
57    effective_sample_size, multinomial_resample, normalize_particles, rejuvenate_particles,
58    resample_particles, smc_prior_particles, stratified_resample, systematic_resample,
59    try_decode_particle, CrossoverKernel, NoKernel, Particle, PopulationKernel, ResamplingMethod,
60    SMCConfig, SMCResult,
61};
62pub use inference::validation::{
63    ks_test_distribution, test_conjugate_beta_bernoulli_model, test_conjugate_normal_model,
64    ConjugateBetaBernoulliConfig, ConjugateNormalConfig, ValidationResult,
65};
66pub use inference::vi::{elbo_with_guide, optimize_meanfield_vi, MeanFieldGuide, VariationalParam};