Crate ruvector_math

Crate ruvector_math 

Source
Expand description

§RuVector Math

Advanced mathematics for next-generation vector search and AI governance, featuring:

§Core Modules

  • Optimal Transport: Wasserstein distances, Sinkhorn algorithm, Sliced Wasserstein
  • Information Geometry: Fisher Information, Natural Gradient, K-FAC
  • Product Manifolds: Mixed-curvature spaces (Euclidean × Hyperbolic × Spherical)
  • Spherical Geometry: Geodesics on the n-sphere for cyclical patterns

§Theoretical CS Modules (New)

  • Tropical Algebra: Max-plus semiring for piecewise linear analysis and routing
  • Tensor Networks: TT/Tucker/CP decomposition for memory compression
  • Spectral Methods: Chebyshev polynomials for graph diffusion without eigendecomposition
  • Persistent Homology: TDA for topological drift detection and coherence monitoring
  • Polynomial Optimization: SOS certificates for provable bounds on attention policies

§Design Principles

  1. Pure Rust: No BLAS/LAPACK dependencies for full WASM compatibility
  2. SIMD-Ready: Hot paths optimized for auto-vectorization
  3. Numerically Stable: Log-domain arithmetic, clamping, and stable softmax
  4. Modular: Each component usable independently
  5. Mincut as Spine: All modules designed to integrate with mincut governance

§Architecture: Mincut as Unifying Signal

┌─────────────────────────────────────────────────────────────┐
│                    Mincut Governance                         │
│  (Structural tension meter for attention graphs)            │
└───────────────────────┬─────────────────────────────────────┘
                        │
    ┌───────────────────┼───────────────────┐
    ▼                   ▼                   ▼
┌─────────┐       ┌───────────┐       ┌───────────┐
│ Tensor  │       │ Spectral  │       │   TDA     │
│ Networks│       │ Methods   │       │ Homology  │
│ (TT)    │       │(Chebyshev)│       │           │
└─────────┘       └───────────┘       └───────────┘
Compress          Smooth within       Monitor drift
representations   partitions          over time

    ┌───────────────────┼───────────────────┐
    ▼                   ▼                   ▼
┌─────────┐       ┌───────────┐       ┌───────────┐
│Tropical │       │    SOS    │       │ Optimal   │
│ Algebra │       │ Certs     │       │ Transport │
└─────────┘       └───────────┘       └───────────┘
Plan safe         Certify policy      Measure
routing paths     constraints         distributional
                                      distances

§Quick Start

use ruvector_math::optimal_transport::{SlicedWasserstein, SinkhornSolver, OptimalTransport};
use ruvector_math::information_geometry::FisherInformation;
use ruvector_math::product_manifold::ProductManifold;

// Sliced Wasserstein distance between point clouds
let sw = SlicedWasserstein::new(100).with_seed(42);
let points_a = vec![vec![0.0, 0.0], vec![1.0, 0.0]];
let points_b = vec![vec![0.5, 0.5], vec![1.5, 0.5]];
let dist = sw.distance(&points_a, &points_b);
assert!(dist > 0.0);

// Sinkhorn optimal transport
let solver = SinkhornSolver::new(0.1, 100);
let cost_matrix = vec![vec![0.0, 1.0], vec![1.0, 0.0]];
let weights_a = vec![0.5, 0.5];
let weights_b = vec![0.5, 0.5];
let result = solver.solve(&cost_matrix, &weights_a, &weights_b).unwrap();
assert!(result.converged);

// Product manifold operations (Euclidean only for simplicity)
let manifold = ProductManifold::new(2, 0, 0);
let point_a = vec![0.0, 0.0];
let point_b = vec![3.0, 4.0];
let dist = manifold.distance(&point_a, &point_b).unwrap();
assert!((dist - 5.0).abs() < 1e-10);

Re-exports§

pub use error::MathError;
pub use error::Result;
pub use optimal_transport::SlicedWasserstein;
pub use optimal_transport::SinkhornSolver;
pub use optimal_transport::GromovWasserstein;
pub use optimal_transport::TransportPlan;
pub use optimal_transport::WassersteinConfig;
pub use information_geometry::FisherInformation;
pub use information_geometry::NaturalGradient;
pub use information_geometry::KFACApproximation;
pub use spherical::SphericalSpace;
pub use spherical::SphericalConfig;
pub use product_manifold::ProductManifold;
pub use product_manifold::ProductManifoldConfig;
pub use product_manifold::CurvatureType;
pub use tropical::Tropical;
pub use tropical::TropicalSemiring;
pub use tropical::TropicalPolynomial;
pub use tropical::TropicalMatrix;
pub use tropical::LinearRegionCounter;
pub use tropical::TropicalNeuralAnalysis;
pub use tensor_networks::DenseTensor;
pub use tensor_networks::TensorTrain;
pub use tensor_networks::TensorTrainConfig;
pub use tensor_networks::TuckerDecomposition;
pub use tensor_networks::TuckerConfig;
pub use tensor_networks::CPDecomposition;
pub use tensor_networks::CPConfig;
pub use tensor_networks::TensorNetwork;
pub use tensor_networks::TensorNode;
pub use spectral::ChebyshevPolynomial;
pub use spectral::ChebyshevExpansion;
pub use spectral::SpectralFilter;
pub use spectral::GraphFilter;
pub use spectral::FilterType;
pub use spectral::SpectralWaveletTransform;
pub use spectral::GraphWavelet;
pub use spectral::SpectralClustering;
pub use spectral::ScaledLaplacian;
pub use homology::PersistenceDiagram;
pub use homology::PersistentHomology;
pub use homology::BirthDeathPair;
pub use homology::Simplex;
pub use homology::SimplicialComplex;
pub use homology::Filtration;
pub use homology::VietorisRips;
pub use homology::BottleneckDistance;
pub use homology::WassersteinDistance as HomologyWasserstein;
pub use optimization::Polynomial;
pub use optimization::Monomial;
pub use optimization::Term;
pub use optimization::SOSDecomposition;
pub use optimization::SOSResult;
pub use optimization::NonnegativityCertificate;
pub use optimization::BoundsCertificate;

Modules§

error
Error types for ruvector-math
homology
Persistent Homology and Topological Data Analysis
information_geometry
Information Geometry
optimal_transport
Optimal Transport Algorithms
optimization
Polynomial Optimization and Sum-of-Squares
prelude
Prelude module for convenient imports
product_manifold
Product Manifolds: Mixed-Curvature Geometry
spectral
Spectral Methods for Graph Analysis
spherical
Spherical Geometry
tensor_networks
Tensor Networks
tropical
Tropical Algebra (Max-Plus Semiring)
utils
Utility functions for numerical operations