math

Documentation and code examples are available at https://asaparov.org/docs/math. The repository is located at https://github.com/asaparov/math.

This repository contains a handful of data structures and algorithms for common mathematical operations in scientific computing.

Dependencies

To use the code, simply download the files into a folder named "math". Add this folder to the include path for the compiler, for example by using the -I flag.

This library depends on core and the data structures and procedures follow the same paradigm as core. Otherwise, there are no dependencies on external libraries. The code makes use of C++11 and is regularly tested with gcc 11 but I have previously compiled it with gcc 4.8, clang 4.0, and Microsoft Visual C++ 14.0 (2015). The code is intended to be platform-independent, so please create an issue if there are any compilation bugs.

OverviewThis library contains the following files:
  • distributions.h contains structures that represent various probability distributions, such as the Dirichlet (both symmetric and general), categorical (implemented using a dense array or sparsely using a hash_map), discrete uniform, and sequence distributions. This file contains functions for computing the probabilities and log probabilities of events according to these distributions, as well as generating samples from them.

  • features.h contains structures for representing feature vectors, which are commonly used in machine learning.

  • multiset.h contains multiset data structures, which are structures that count the number of occurrences of distinct elements in a set.

  • log.h contains functions to perform arithmetic in log space, while avoiding loss of floating-point precision.