KMath Documentation

repository·main·Indexed 20 days ago

https://github.com/sciprogcentre/kmath

A modular, multiplatform mathematics library for Kotlin providing high-level abstractions for algebras, ND-structures, linear algebra, and statistics. It includes specialized modules such as kmath-ast for expression parsing and compilation to JVM bytecode or JavaScript, kmath-complex for hypercomplex number systems, kmath-functions for interpolation and integration, and kmath-for-real for Numpy-like operations on Double numbers. It also provides integrations with external libraries like EJML and Apache Commons Math.

Tokens
15.9K
Snippets
59
Records
94
Agent score
71%

What's inside KMath

  1. Overview of kmath-ejml components

    main

    The kmath-ejml module provides linear algebra implementations backed by the EJML library. It is organized into the following functional areas:

    • Point implementations: Provided by ejml-vector.
    • Matrix implementation: Provided by ejml-matrix.
    • LinearSpace implementations: Provided by ejml-linear-space.
  2. Overview of kmath-for-real module

    main

    The kmath-for-real module provides specialized KMath APIs optimized for Double numbers. It is designed to offer Numpy-like operations for real-valued mathematical structures. Key features include:

    • DoubleVector: Provides Numpy-like operations for Buffers and Points.
    • DoubleMatrix: Provides Numpy-like operations for 2D real structures.
    • Grids: Includes uniform grid generators for mathematical modeling.
  3. Overview of KMath-Benchmarks module

    main
    The kmath-benchmarks module contains performance benchmarks for various KMath components and integrations. It utilizes the JMH (Java Microbenchmark Harness) to measure the throughput (thrpt mode) of different mathematical operations, buffer implementations, and external library integrations (such as EJML, Multik, Ojalgo, and Viktor).
  4. Overview of kmath-kotlingrad integration

    main

    The kmath-kotlingrad module provides integration between KMath and Kotlin∇, a library for automatic differentiation. It primarily offers:

    • MST-based Differentiable Expressions: Using differentiable-mst-expression to bridge Kotlin∇'s expression trees with KMath's differentiable structures.
    • Scalar Adapters: Using scalars-adapters to handle conversions between Kotlin∇'s SFun type and KMath's MST (Mathematical Syntax Tree) representations.
  5. Overview of kmath-core components

    main

    The kmath-core module provides the fundamental building blocks for mathematical operations in KMath. Its main components include:

    • Algebras: Algebraic structures such as rings, spaces, and fields.
    • ND Structures: Many-dimensional structures (StructureND) and operations performed on them.
    • Linear Algebra: Basic operations (sums, products, etc.) backed by the Space API.
    • Buffers: One-dimensional data structures.
    • Expressions: A system for writing mathematical expressions once and applying them across different contexts.
    • Domains: Mathematical domains.
    • Autodiff: Automatic differentiation capabilities.
    • Parallel Linear Algebra: Parallel implementations for LinearAlgebra operations.
  6. Overview of kmath-tensors capabilities

    main

    The kmath-tensors module provides common linear algebra operations on tensors. It is organized into several functional areas:

    • Tensor Algebra: Basic linear algebra operations such as addition (plus) and dot products.
    • Tensor Algebra with Broadcasting: Basic operations implemented using broadcasting support.
    • Linear Algebra Operations: Advanced mathematical operations including LU decomposition, SVD (Singular Value Decomposition), and other complex decompositions.
  7. Overview of KMath

    main

    KMath (pronounced key-math) is a modular Kotlin Mathematics library designed for Kotlin Multiplatform (JVM, JS, Native, and Wasm). Unlike NumPy, which is monolithic, KMath provides a lightweight core and specialized modules for different mathematical needs. It focuses on providing flexible APIs for mathematical abstractions and bindings for optimized platform libraries.

    Key design principles:

    • Modular Architecture: Use only the modules you need.
    • Generic Core: The core API is designed to be generic. For specialized performance (e.g., working specifically with Double), use specialization modules like kmath-for-real.
    • Multiplatform: Most interfaces are declared in common source sets, allowing code to run across various targets.
  8. Explore kmath-functions capabilities

    main

    The kmath-functions module provides tools for mathematical functions and interpolation. Key features include:

    • Piecewise functions: Defined in the piecewise package.
    • Polynomial functions: Defined in the polynomials package.
    • Linear interpolation: XY interpolator available via LinearInterpolator.
    • Spline interpolation: Cubic spline XY interpolator available via SplineInterpolator.
    • Integration: Support for univariate and multivariate quadratures.
  9. Understand the KMath license and third-party code

    main

    Most code in the KMath repository is licensed under the Apache 2 license and is copyrighted by the KMath contributors.

    However, certain modules incorporate third-party code derived from other projects. While these components are also provided under the Apache 2 license, they originate from different sources (such as Apache Commons Math, Apache Commons RNG, or Numky). If you are performing a legal audit or compliance check, note that these specific files have distinct origins.

  10. Explore KMath documentation topics

    main

    KMath documentation is organized into several key functional areas. Depending on your mathematical requirements, you can refer to the following guides:

    • Algebra: Learn about context-based operations on various primitives and mathematical structures.
    • NDStructures: Documentation for N-dimensional structures.
    • Linear algebra: Covers matrices, operations, and solving linear equations. Note that this currently supports a basic API with multiple library back-ends but is planned to move to a separate module.
    • Histograms: Guidance on multidimensional histogram calculation and operations.
    • Expressions: Documentation regarding mathematical expressions.
    • Statistics: Instructions for performing statistical functions on data stored in Buffers.
    • Commons math integration: Information on how to integrate with Apache Commons Math.
  11. Use complex and quaternion number systems in kmath-complex

    main

    The kmath-complex module provides support for hypercomplex number systems, specifically:

    • Complex numbers: Operations involving complex number types.
    • Quaternions: Support for quaternions and their composition.

    Refer to the complex and quaternion packages within the module for specific API implementations.