Hipparchus

repository·develop·Indexed 41 days ago

https://github.com/hipparchus-math/hipparchus

A lightweight, self-contained Java library providing advanced mathematics and statistics components. It includes specialized modules for core math, clustering (KMeans++, DBSCAN), FFT, curve fitting, geometry, ODE solvers, optimization, and statistics. Version 4.0.3 provides tools for root-finding of univariate functions and data partitioning via the Clusterable interface.

Tokens
41.9K
Snippets
84
Records
158
Agent score
51%

What's inside Hipparchus

  1. Overview of Hipparchus Core features

    develop

    The hipparchus-core module serves as the foundational component of the Hipparchus mathematics library. All other Hipparchus modules depend on this core module. It provides a wide range of mathematical primitives and utilities, including:

    • Analysis: Numerical analysis tools.
    • Complex numbers: Support for complex arithmetic.
    • Probability distributions: Statistical distributions and functions.
    • Exceptions management: Specialized mathematical exception handling.
    • Fractions: Rational number arithmetic.
    • Linear algebra: Matrix and vector operations.
    • Pseudo-random numbers generators: Various algorithms for generating random sequences.
    • Special functions: Implementation of common mathematical special functions.
    • Utilities: General purpose mathematical helper functions.
  2. Overview of Hipparchus capabilities

    develop

    Hipparchus is a library of lightweight, self-contained math and statistics utilities designed to solve common programming problems. Key capabilities include:

    • Statistics: Computing means, variances, and other summary statistics; performing statistical significance tests.
    • Regression & Curve Fitting: Linear regression, curve fitting, interpolation, and least-squares parametric modeling.
    • Numerical Analysis: Root-finding (solving equations with real-valued functions), solving systems of linear equations, and solving Ordinary Differential Equations (ODEs).
    • Optimization: Minimizing multi-dimensional functions.
    • Filtering: Kalman filtering (linear and non-linear).
    • Random Number Generation: Advanced generation with specific distributions and ranges, and generating datasets that mimic input files.
    • Special Functions: Factorials, binomial coefficients, and special functions like gamma and beta functions.
  3. Overview of the Optimization package structure

    develop

    The optimization package provides algorithms to minimize or maximize objective functions (also called cost functions). The package is organized into sub-packages based on the type of function and the algorithm used:

    • univariate: Handles univariate scalar functions.
    • linear: Handles multivariate vector linear functions with linear constraints (e.g., Simplex algorithm).
    • direct: Handles multivariate scalar functions using direct search methods (methods that do not require or approximate derivatives).
    • general: Handles multivariate scalar or vector functions using derivatives (e.g., Gauss-Newton, Levenberg-Marquardt).
    • fitting: Handles curve fitting using univariate real functions.

    Note: Least squares optimizers have been moved to a dedicated least-squares sub-package.

  4. Choose a transform method for signal analysis

    develop

    The org.hipparchus.transform package provides several transformers for signal analysis. All transformers support both direct and inverse transforms. Choose a transformer based on your required output type:

    • FastFourierTransformer: Use this when you need complex-valued results.
    • FastCosineTransformer: Use this when you need real-valued results (Discrete Cosine Transform).
    • FastSineTransformer: Use this when you need real-valued results (Discrete Sine Transform).
    • FastHadamardTransformer: Use this when you need real-valued results (Hadamard Transform).
  5. Explore Hipparchus Fitting implementations

    develop

    The Hipparchus fitting module provides tools for fitting mathematical models to data. It primarily supports two categories of fitting algorithms:

    • Curve fitting: Standard implementations for fitting various function types to datasets.
    • RANSAC fitting: Robust estimation techniques using the Random Sample Consensus (RANSAC) algorithm, useful for datasets containing outliers.
  6. Explore the Hipparchus User Guide modules

    develop

    The Hipparchus User Guide provides structured documentation for various mathematical domains. You can navigate to specific modules based on your requirements:

    • Statistics: Descriptive statistics, frequency distributions, regression (simple and multiple), rank transformations, covariance, correlation, and statistical tests.
    • Random Data Generation: Random numbers, vectors, strings, permutations, combinations, sampling, and PRNG (Pseudo-Random Number Generator) pluggability.
    • Linear Algebra: Real matrices, real vectors, solving linear systems, eigenvalue/eigenvector/singular value decomposition, and non-real fields (complex, fractions).
    • Numerical Analysis: Root-finding, interpolation, integration, polynomials, differentiation, and error handling.
    • Special Functions: Erf, Gamma, and Beta functions.
    • Complex Analysis: Complex numbers, transcendental functions, and formatting/parsing.
    • Probability Distributions: Distribution framework and user-defined distributions.
    • Geometry: Euclidean spaces, n-Sphere, Binary Space Partitioning, and regions.
    • Optimization: Univariate functions, linear programming, and direct/general methods.
    • Fitting: Least squares (including LeastSquaresBuilder and LeastSquaresFactory), model functions, and parameter validation.
    • Ordinary Differential Equations (ODE): Continuous output, discrete event handling, integrators, and derivatives.
    • Clustering: Clustering algorithms and distance measures.
    • Utilities: Double array utilities, int/double hash maps, continued fractions, and common math functions (binomial coefficients, factorials, etc.).
  7. Understand the Descriptive Statistics API hierarchy

    develop

    The descriptive statistics package in org.hipparchus.stat.descriptive is organized around two main interfaces depending on whether data needs to be stored in memory:

    1. UnivariateStatistic: The top-level interface. It provides evaluate(double[] values) methods to compute statistics directly from an array of data.
    2. StorelessUnivariateStatistic: An extension of UnivariateStatistic for streaming data. It adds increment(double value) to allow updating statistics one value at a time. These implementations use bounded storage (counters, sums, etc.) and do not require keeping the full dataset in memory.

    Statistics are categorized into subpackages like moment, rank, and summary. For convenience, instead of using individual statistic classes, you should generally use aggregate classes like DescriptiveStatistics or StreamingStatistics.

  8. Find roots of univariate functions

    develop

    Hipparchus provides several solvers to find roots (values where $f(x) = 0$) for different types of functions.

    Solver Types

    • UnivariateSolver: For general univariate real-valued functions (UnivariateFunction).
    • UnivariateDifferentiableSolver: For differentiable univariate real-valued functions (UnivariateDifferentiableFunction).
    • PolynomialSolver: For polynomial functions (PolynomialFunction).

    Algorithm Selection Guide

    NameFunction TypeConvergenceNeeds BracketingNotes
    BisectionSolverUnivariateLinear (Guaranteed)YesSlow but extremely robust; use as a fallback.
    BrentSolverUnivariateSuper-linear (Guaranteed)YesFast and robust; uses Brent-Dekker algorithm.
    BracketingNthOrderBrentSolverUnivariateVariable order (Guaranteed)YesRecommended for most users. Supports side selection and higher-order interpolation.
    IllinoisSolverUnivariateSuper-linear (Guaranteed)YesVariation of Regula Falsi to prevent stuck endpoints.
    PegasusSolverUnivariateSuper-linear (Guaranteed)YesVariation of Regula Falsi; often faster than Illinois and good for side selection.
    NewtonRaphsonSolverDifferentiableQuadratic (Non-guaranteed)NoRequires derivatives.
    SecantSolverUnivariateSuper-linear (Non-guaranteed)YesDoes not bracket; may be faster than Brent on well-behaved functions.
    LaguerreSolverPolynomialCubic/LinearYesSpecifically for polynomials.
    MullerSolverUnivariateQuadraticYesTwo versions available: one using bracketing and one using modulus.
    // Example: Using the recommended BracketingNthOrderBrentSolver
    UnivariateFunction function = ...; 
    final double relativeAccuracy = 1.0e-12;
    final double absoluteAccuracy = 1.0e-8;
    final int    maxOrder         = 5;
    UnivariateSolver solver = new BracketingNthOrderBrentSolver(relativeAccuracy, absoluteAccuracy, maxOrder);
    double c = solver.solve(100, function, 1.0, 5.0, AllowedSolution.LEFT_SIDE);