| Crates.io | amari-measure |
| lib.rs | amari-measure |
| version | 0.17.0 |
| created_at | 2025-11-21 22:57:46.514165+00 |
| updated_at | 2026-01-11 22:41:05.220548+00 |
| description | Measure-theoretic foundations for geometric algebra - integration, probability measures, and analysis on multivector spaces |
| homepage | https://github.com/justinelliottcobb/Amari |
| repository | https://github.com/justinelliottcobb/Amari |
| max_upload_size | |
| id | 1944438 |
| size | 403,389 |
Measure-theoretic foundations for geometric algebra - integration, probability measures, and analysis on multivector spaces.
amari-measure provides measure theory, integration, and probability theory for multivector spaces in Clifford algebras. The crate bridges abstract measure theory with practical computation, featuring automatic differentiation, numerical integration, and type-safe convergence theorems.
Add to your Cargo.toml:
[dependencies]
amari-measure = "0.12"
[dependencies]
# Default features
amari-measure = "0.12"
# With serialization
amari-measure = { version = "0.12", features = ["serde"] }
# With formal verification (Creusot)
amari-measure = { version = "0.12", features = ["formal-verification"] }
use amari_measure::parametric::families;
// Create a Gaussian density family
let gaussian = families::gaussian();
// Evaluate density and gradient at x=1.5, params=[μ=1.0, σ=2.0]
let (value, gradient) = gaussian.evaluate_with_gradient(1.5, &[1.0, 2.0]).unwrap();
// Compute Fisher information matrix from data
let data = vec![1.2, 1.5, 1.8];
let fisher = gaussian.fisher_information(&data, &[1.0, 2.0]).unwrap();
use amari_measure::{monte_carlo_integrate, simpson_integrate};
// Monte Carlo integration of f(x) = x² over [0, 1]
let mc_result = monte_carlo_integrate(&|x| x * x, 0.0, 1.0, 10000).unwrap();
// Result ≈ 1/3
// Simpson's rule (higher accuracy)
let simpson_result = simpson_integrate(&|x| x * x, 0.0, 1.0, 100).unwrap();
use amari_measure::multivector_measure::GradeDecomposedMeasure;
use amari_core::Multivector;
// Create a 3D geometric measure (signature (3,0,0))
let measure = GradeDecomposedMeasure::<3, 0, 0>::new();
// Set from a multivector
let mv = Multivector::<3, 0, 0>::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]);
let measure = GradeDecomposedMeasure::<3, 0, 0>::from_multivector(&mv);
A σ-algebra on a set X is a collection of subsets closed under:
use amari_measure::{BorelSigma, LebesgueSigma};
// Borel σ-algebra on ℝ (generated by open sets)
let borel = BorelSigma::<f64>::new();
// Lebesgue σ-algebra (completes Borel)
let lebesgue = LebesgueSigma::<f64>::new();
A measure μ is a function from a σ-algebra to [0, ∞] satisfying:
use amari_measure::{LebesgueMeasure, DiracMeasure, CountingMeasure};
// Lebesgue measure (length, area, volume)
let lebesgue = LebesgueMeasure::new();
// Dirac measure at point x₀
let dirac = DiracMeasure::at(3.14);
// Counting measure
let counting = CountingMeasure::new();
For absolutely continuous ν << μ, the Radon-Nikodym derivative dν/dμ exists:
use amari_measure::radon_nikodym_dual::DualRadonNikodym;
// Define a Gaussian density as Radon-Nikodym derivative
let rn = DualRadonNikodym::new(|x: f64, theta: f64| {
let diff = x - theta;
(-0.5 * diff * diff).exp()
});
// Compute score function: ∂/∂θ log p(x|θ)
let score = rn.score(1.0, 0.0).unwrap();
// Compute Fisher information from data
let data = vec![-1.0, 0.0, 1.0];
let fisher = rn.fisher_information(&data, 0.0).unwrap();
Statistical manifolds with Fisher information as the metric:
use amari_measure::fisher_measure::FisherMeasure;
use amari_measure::parametric::families;
// Create Fisher measure from Gaussian density
let gaussian = families::gaussian();
let fisher_measure = FisherMeasure::from_density(gaussian);
// Compute volume element at parameter point (for Jeffreys prior)
let params = vec![0.0, 1.0]; // μ=0, σ=1
let data = vec![-1.0, 0.0, 1.0];
let volume = fisher_measure.volume_element(¶ms, &data).unwrap();
For extreme value statistics using max-plus algebra:
use amari_measure::tropical_measure::{MaxPlusMeasure, tropical_supremum_integrate};
// Create max-plus measure for finding suprema
let max_measure: MaxPlusMeasure = MaxPlusMeasure::new();
// Find supremum via tropical integration
let f = |x: f64| x * x;
let sample_points = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let supremum = tropical_supremum_integrate(&f, &(), &sample_points).unwrap();
// supremum.value() == 25.0 (at x=5)
Compile-time verification of theorem preconditions:
use amari_measure::type_safe_convergence::{
FunctionSequence, MonotoneIncreasing, NonNegative,
apply_monotone_convergence_theorem
};
// Create a monotone increasing, non-negative sequence
let seq: FunctionSequence<f64, (MonotoneIncreasing, NonNegative)> =
FunctionSequence::from_monotone_nonnegative_closures(vec![
|x: f64| x,
|x: f64| x + 1.0,
|x: f64| x + 2.0,
]);
// Apply MCT - compiles because types are correct
let result = apply_monotone_convergence_theorem(&seq).unwrap();
// Would NOT compile with wrong property type:
// let wrong_seq: FunctionSequence<f64, NonNegative> = ...
// apply_monotone_convergence_theorem(&wrong_seq); // ❌ compile error
| Module | Description |
|---|---|
sigma_algebra |
σ-algebra implementations |
measure |
Basic measure types |
geometric_measure |
Multivector-valued measures |
multivector_measure |
Grade-decomposed measures |
integration |
Lebesgue integration |
density |
Densities and Radon-Nikodym |
radon_nikodym_dual |
Autodiff for Radon-Nikodym |
parametric |
Parametric density families |
fisher_measure |
Fisher-Riemannian geometry |
tropical_measure |
Max-plus extreme value measures |
numerical_integration |
Monte Carlo, Simpson, etc. |
type_safe_convergence |
Phantom type convergence theorems |
signed_measure |
Signed and complex measures |
product |
Product measures and Fubini's theorem |
convergence |
Convergence theorem implementations |
pushforward |
Pushforward and pullback of measures |
use amari_measure::parametric::families;
use amari_measure::fisher_measure::FisherMeasure;
// 1. Define parametric density family
let gaussian = families::gaussian();
// 2. Collect data
let data = vec![0.9, 1.1, 1.2, 0.8, 1.0];
// 3. Compute Fisher information (for Cramér-Rao bound)
let params = vec![1.0, 0.5]; // μ=1.0, σ=0.5
let fisher_info = gaussian.fisher_information(&data, ¶ms).unwrap();
// 4. Create Fisher measure for geometric inference
let fisher_measure = FisherMeasure::from_density(gaussian);
// 5. Compute volume element (for Jeffreys prior)
let volume = fisher_measure.volume_element(¶ms, &data).unwrap();
The crate uses phantom types for compile-time verification:
use amari_measure::phantom::{Finite, SigmaFinite, Signed, Unsigned};
// Type parameters encode measure properties
// Compiler prevents invalid operations
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
This crate is part of the Amari mathematical computing library.