A knowledge base of data science and machine learning tools and algorithms written in Haskell that either already exist or we would like to exist.
Note: some libraries are mentioned more than once, because they provide functionality that covers a few areas, however for clarity the links and project descriptions are only given at their first occurrence.
- Chart : A library for generating 2D Charts and Plots, with backends provided by Cairo (http://hackage.haskell.org/package/Chart-cairo) and Diagrams (http://hackage.haskell.org/package/Chart-diagrams). Documentation: https://github.com/timbod7/haskell-chart/wiki.
- plotlyhs : This is a library for generating JSON value to use with the Plotly.js library. The interface directly reflects the structure of the Plotly.js library and is therefore quite low-level. Lenses are used throughout to set Maybe fields in records to provide both data and configuration options. This library does not attempt to communicate with the Plotly API in any other way. All generated plots can be hosted on stand-alone web pages.
- plots :
Diagrams-based plotting library.
- hvega : Create Vega-Lite visualizations in Haskell, targeting version 3 of the vega-lite specification. This library follows closely the naming conventions of vega-lite, and offers an extensive tutorial.
- knit : knit-haskell is a beginning attempt at bringing some of the benefits of Rmarkdown to Haskell. Various helper functions are provided to simplify common operations, making it especially straightforward to build an HTML document from bits of markdown, latex and Lucid or Blaze html. Support is also included for including
- pandoc-pyplot : A Pandoc filter to include figures generated from Python code blocks. Keep the document and Python code in the same location. Output from Matplotlib is captured and included as a figure.
- inliterate :
inliterateis a GHC preprocessor which transforms a markdown document into a Haskell program, which, when run, prints to stdout the input document in HTML format. Certain code blocks with special annotations can be treated in particular ways: as Haskell code that must be included in the generating program (at the top level or in a do block) and as code that must be evaluated with the results inserted into the HTML document. For an example document, see https://github.com/diffusionkinetics/open/blob/master/plotlyhs/gendoc/GenDocInlit.hs which compiles into https://glutamate.github.io/plotlyhs/.
- Frames : User-friendly, type safe, runtime efficient tooling for working with tabular data deserialized from comma-separated values (CSV) files. The type of each row of data is inferred from data, which can then be streamed from disk, or worked with in memory. Also see the comprehensive tutorial
- Frames-map-reduce : This library contains some useful functions for using the map-reduce-folds package with Frames (containers of data rows) from the Frames package. Included, in Frames.MapReduce, are helpers for filtering Frames, splitting records into key and data columns and reattaching key columns after reducing. Also included, in the Frames.Folds module, are some helpful functions for building folds of Frames from folds over each column, specified either individually or via a constraint on all the columns being folded over.
- analyze :
pandas-like dataframe operations for tabular data with CSV interface. Currently maintained within the scope of the DataHaskell
- bookkeeper : A new take on datatypes and records using
OverloadedLabels(which is available since GHC 8). It bears some similarities to Nikita Volkov’s
recordlibrary, but requires no Template Haskell.
- colonnade : The colonnade package provides a way to talk about columnar encodings and decodings of data. This package provides very general types and does not provide a way for the end-user to actually apply the columnar encodings they build to data. Most users will also want to one a companion packages that provides (1) a content type and (2) functions for feeding data into a columnar encoding:
- lucid-colonnade for lucid html tables
- blaze-colonnade for blaze html tables
- reflex-dom-colonnade for reactive reflex-dom tables
- yesod-colonnade for yesod widgets
- siphon for encoding and decoding CSVs
Streaming / Folds
- map-reduce-folds : map-reduce-folds is an attempt to find a good balance between simplicity, performance, and flexibility for simple map/reduce style operations on a foldable container f of some type x (e.g., [x]). The goal of the package is to provide an efficient fold for the computation via the types in the foldl package. Folds can be composed Applicatively, which makes it simple to do many such operations on the same data and loop over it only once.
- vector : An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework.
- contiguous : This package provides a typeclass Contiguous that offers a unified interface to working with Array, SmallArray, PrimArray, and UnliftedArray.
- accelerate : Data.Array.Accelerate defines an embedded array language for computations for high-performance computing in Haskell. Computations on multi-dimensional, regular arrays are expressed in the form of parameterised collective operations, such as maps, reductions, and permutations. These computations may then be online compiled and executed on a range of architectures.
- repa : Repa provides high performance, regular, multi-dimensional, shape polymorphic parallel arrays. All numeric data is stored unboxed.
- massiv : Repa-style high-performance multi-dimentional arrays with nested parallelism and stencil computation capabilities.
- arrayfire : Haskell bindings to the ArrayFire general-purpose GPU library
- vinyl : Extensible records for Haskell with lenses. It has minimal dependencies and
Framesis based on it.
- labels : Declare and access tuple fields with labels. An approach to anonymous records.
- superrecord Supercharged anonymous records. Introductory blogpost, with case study using ReaderT.
- algebraic-graphs :
alga) is a library for algebraic construction and manipulation of graphs in Haskell. See this paper for the motivation behind the library, the underlying theory and implementation details. The top-level module
Algebra.Graphdefines the core data type
Graph, which is a deep embedding of four graph construction primitives
connect. To represent non-empty graphs, see
Algebra.Graph.NonEmpty. More conventional graph representations can be found in
Algebra.Graph.Relation. The type classes defined in
Algebra.Graph.HigherKinded.Classcan be used for polymorphic graph construction and manipulation. Also see
Algebra.Graph.Foldthat defines the Boehm-Berarducci encoding of algebraic graphs and provides additional flexibility for polymorphic graph manipulation.
- fgl : An inductive representation of manipulating graph data structures. Original website can be found at http://web.engr.oregonstate.edu/~erwig/fgl/haskell.
- graphite : Represent, analyze and visualize graphs & networks. A beginner friendly tutorial can be found at https://haskell-graphite.readthedocs.io/en/latest/.
- tree-traversals : The tree-traversals package defines in-order, pre-order, post-order, level-order, and reversed level-order traversals for tree-like types, and it also provides newtype wrappers for the various traversals so they may be used with
- KdTree : A simple library for k-d trees in Haskell. It enables searching through collections of points in O(log N) average time, using the nearestNeighbor function.
- beam Homepage : Beam is a highly-general library for accessing any kind of database with Haskell. It supports several backends. beam-postgres and beam-sqlite are included in the main beam repository. Others are hosted and maintained independently, such as beam-mysql and beam-firebird. The documentation here shows examples in all known backends. Beam is highly extensible and other backends can be shipped independently without requiring any changes in the core libraries.For information on creating additional SQL backends, see the manual section for more.
- selda : Selda is a Haskell library for interacting with SQL-based relational databases inspired by LINQ and Opaleye.
- relational-record Homepage : Haskell Relational Record (HRR) is a query generator based on typed relational algebra and correspondence between SQL value lists and Haskell record types, which provide programming interfaces to Relational DataBase Managemsnt Systems (RDBMS).
Numerical linear algebra
- hmatrix : Bindings to BLAS/LAPACK. Linear solvers, matrix decompositions, and more.
- dense-linear-algebra : A collection of linear-algebra related modules, extracted from the
statisticslibrary. Matrices and vectors are internally represented with unboxed
vectors, and the algorithms rely on in-place mutation for high efficiency. Currently maintained within the scope of the DataHaskell
- sparse-linear-algebra : Native library for sparse algebraic computation. Linear solvers, matrix decompositions and related tools; functional but not optimized for efficiency yet.
- linearEqSolver : Solve linear systems of equations over integers and rationals, using an SMT solver.
Generation of random data
- mwc-probability : A simple probability distribution type, where distributions are characterized by sampling functions. Simple and idiomatic interface based on Applicative and Monad instances.
- random-fu : Random number generation based on modeling random variables in two complementary ways: first, by the parameters of standard mathematical distributions and, second, by an abstract type (RVar) which can be composed and manipulated monadically and sampled in either monadic or “pure” styles. The primary purpose of this library is to support defining and sampling a wide variety of high quality random variables. Quality is prioritized over speed, but performance is an important goal too. Very flexible, providing both a concrete (‘Distribution’) and and abstract but composable (‘RVar’) view of random variables.
- pcg-random : Haskell bindings to the PCG random number generator http://www.pcg-random.org. The api is very similar to
mwc-randombut the pcg generator appears to be slightly faster. There is also a pure interface via the
- statistics : This library provides a number of common functions and types useful in statistics. We focus on high performance, numerical robustness, and use of good algorithms. Where possible, we provide references to the statistical literature.
The library’s facilities can be divided into four broad categories:
- Working with widely used discrete and continuous probability distributions. (There are dozens of exotic distributions in use; we focus on the most common.)
- Computing with sample data: quantile estimation, kernel density estimation, histograms, bootstrap methods, significance testing, and regression and autocorrelation analysis.
- Random variate generation under several different distributions.
- Common statistical tests for significant differences between samples.
- foldl-statistics : A reimplementation of the Statistics.Sample module using the foldl package. The intention of this package is to allow these algorithms to be used on a much broader set of data input types, including lists and streaming libraries such as conduit and pipes, and any other type which is Foldable. All statistics in this package can be computed with no more than two passes over the data - once to compute the mean and once to compute any statistics which require the mean.
- tdigest : A new data structure for accurate on-line accumulation of rank-based statistics such as quantiles and trimmed means.
- histogram-fill : A convenient way to create and fill histograms. It supports fixed- and variable-size bins, missing data and 2D binning.
- uncertain : Provides tools to manipulate numbers with inherent experimental/measurement uncertainty, and propagates them through functions.
- measurable : Construct measures from samples, mass/density functions, or even sampling functions. Construct image measures by fmap-ing measurable functions over them, or create new measures from existing ones by measure convolution and friends provided by a simple Num instance enabled by an Applicative instance. Create measures from graphs of other measures using the Monad instance and do-notation. Query measures by integrating meaurable functions against them. Extract moments, cumulative density functions, or probabilities. Caveat: while fun to play with, and rewarding to see how measures fit together, measure operations as nested integrals are exponentially complex. Don’t expect them to scale very far!
- Markov Chain Monte Carlo
- declarative : A simple combinator language for Markov transition operators that are useful in MCMC.
- flat-mcmc : flat-mcmc uses an ensemble sampler that is invariant to affine transformations of space. It wanders a target probability distribution’s parameter space as if it had been “flattened” or “unstretched” in some sense, allowing many particles to explore it locally and in parallel. In general this sampler is useful when you want decent performance without dealing with any tuning parameters or local proposal distributions.
- Dynamical systems
- Automatic differentiation
- ad : Automatic differentiation to arbitrary order, applicable to data provided in any Traversable container.
- backprop : Automatic heterogeneous back-propagation. Write your functions to compute your result, and the library will automatically generate functions to compute your gradient. Differs from
adby offering full heterogeneity – each intermediate step and the resulting value can have different types. Mostly intended for usage with gradient descent and other numeric optimization techniques. Introductory blogpost here.
- Linear programming
- Convex optimization
Discrete/Fast Fourier Transform
Machine Learning frameworks
- probably-baysig : This library contains definitions and functions for probabilistic and statistical inference.
- Math.Probably.Sampler defines the sampling function monad
- Math.Probably.PDF defines some common parametric log-probability density functions
- Math.Probably.FoldingStats defines statistics as folds that can be composed and calculated independently of the container of the underlying data.
- Strategy.* implements various transition operators for Markov Chain Monte Carlo, including Metropolis-Hastings, Hamiltonian Monte Carlo, NUTS, and continuous/discrete slice samplers.
- Math.Probably.MCMC implements functions and combinators for running Markov chains and interleaving transition operators.
- mltool : Haskell Machine Learning Toolkit includes various methods of supervised learning: linear regression, logistic regression, SVN, neural networks, etc. as well as some methods of unsupervised methods: K-Means and PCA.
- NestedSampling : The code here is a fairly straightforward translation of the tutorial nested sampling code from Skilling and Sivia. The original code can be found at http://www.inference.phy.cam.ac.uk/bayesys/sivia/ along with documentation at http://www.inference.phy.cam.ac.uk/bayesys/. An example program called lighthouse.hs is included.
- NestedSampling-hs : This is a Haskell implementation of the classic Nested Sampling algorithm introduced by John Skilling. You can use it for Bayesian inference, statistical mechanics, and optimisation applications, and it comes with a few example programs.
Probabilistic programming languages
- monad-bayes : A library for probabilistic programming in Haskell using probability monads. The emphasis is on composition of inference algorithms implemented in terms of monad transformers. The code is still experimental, but will be released on Hackage as soon as it reaches relative stability. User’s guide will appear soon. In the meantime see the models folder that contains several examples.
- hakaru : Hakaru is a simply-typed probabilistic programming language, designed for easy specification of probabilistic models and inference algorithms. Hakaru enables the design of modular probabilistic inference programs by providing:
- A language for representing probabilistic distributions, queries, and inferences
- Methods for transforming probabilistic information, such as conditional probability and probabilistic inference, using computer algebra
- deanie :
deanieis an embedded probabilistic programming language. It can be used to denote, sample from, and perform inference on probabilistic programs.
- Kalman filtering
- estimator : The goal of this library is to simplify implementation and use of state-space estimation algorithms, such as Kalman Filters. The interface for constructing models is isolated as much as possible from the specifics of a given algorithm, so swapping out a Kalman Filter for a Bayesian Particle Filter should involve a minimum of effort. This implementation is designed to support symbolic types, such as from sbv or ivory. As a result you can generate code in another language, such as C, from a model written using this package; or run static analyses on your model.
- kalman : Linear, extended and unscented Kalman filters are provided, along with their corresponding smoothers. Furthermore, a particle filter and smoother is provided.
- Hidden Markov models
- hmm-hmatrix : Hidden Markov Models implemented using HMatrix data types and operations. http://en.wikipedia.org/wiki/Hidden_Markov_Model
It supports any kind of emission distribution, where discrete and multivariate Gaussian distributions are implemented as examples.
It currently implements:
- generation of samples of emission sequences,
- computation of the likelihood of an observed sequence of emissions,
- construction of most likely state sequence that produces an observed sequence of emissions,
- supervised and unsupervised training of the model by Baum-Welch algorithm.
- learning-hmm : This library provides functions for the maximum likelihood estimation of discrete hidden Markov models. At present, only Baum-Welch and Viterbi algorithms are implemented for the plain HMM and the input-output HMM.
- Linear discriminant analysis
- Support Vector Machines
- svm-simple : A set of simplified bindings to libsvm suite of support vector machines. This package provides tools for classification, one-class classification and support vector regression.
- Decision trees
- hinduce-classifier-decisiontree : A very simple decision tree construction algorithm; an implementation of
hinduce-classifier’s Classifier class.
- HaskellGBM : Haskell wrapper around LightGBM, the distributed library for gradient-boosted decision tree algorithms. The emphasis is on using Haskell types (in particular the
refinedlibrary) to help ensure that the hyperparameter settings chosen by the user are coherent and in-bounds at all times.
- hinduce-classifier-decisiontree : A very simple decision tree construction algorithm; an implementation of
- Gaussian processes
- neural : The goal of neural is to provide a modular and flexible neural network library written in native Haskell.
- composability via arrow-like instances and pipes,
- automatic differentiation for automatic gradient descent/ backpropagation training (using Edward Kmett’s fabulous ad library). The idea is to be able to easily define new components and wire them up in flexible, possibly complicated ways (convolutional deep networks etc.). Four examples are included as proof of concept:
- A simple neural network that approximates the sine function on [0,2 pi].
- Another simple neural network that approximates the sqrt function on [0,4].
- A slightly more complicated neural network that solves the famous Iris flower problem.
- A first (still simple) neural network for recognizing handwritten digits from the equally famous MNIST database. The library is still very much experimental at this point.
- backprop-learn : Combinators and types for easily building trainable neural networks using the ‘backprop’ library.
- grenade : Grenade is a composable, dependently typed, practical, and fast recurrent neural network library for precise specifications and complex deep neural networks in Haskell. Grenade provides an API for composing layers of a neural network into a sequence parallel graph in a type safe manner; running networks with reverse automatic differentiation to calculate their gradients; and applying gradient decent for learning. Documentation and examples are available on github https://github.com/HuwCampbell/grenade.
- hasktorch : Hasktorch is a library for tensors and neural networks in Haskell. It is an independent open source community project which leverages the core C libraries shared by Torch and PyTorch. This library leverages cabal new-build and backpack. Note that this project is in early development and should only be used by contributing developers. Expect substantial changes to the library API as it evolves.
- tensorflow : Haskell bindings for Tensorflow.
- Recurrent Neural Networks
- Convolutional Neural Networks
- LSTM (Long Short-Term Memory)
- Convolutional Neural Networks
Generative Neural Networks
- References : Neural Networks, Types, and Functional Programming
- Gaussian Naive Bayes
- Multinomial Naive Bayes
- Bernoulli Naive Bayes
- Nearest Neighbors
- Linear Regression
- Gaussian processes
- Kalman filtering
- reinforce :
reinforceexports an openai-gym-like typeclass, MonadEnv, with both an interface to gym-http-api, as well as haskell-native environments which provide a substantial speed-up to the http-server interface.
- gym-http-api : This library provides a REST client to the gym open-source library. gym-http-api itself provides a python-based REST server to the gym open-source library, allowing development in languages other than python. Note that the openai/gym-http-api is a monorepo of all language-clients. This hackage library tracks stites/gym-http-api which is the actively-maintained haskell fork.
- Neural Network Q-Learning
- kmeans : A simple implementation of the standard k-means clustering algorithm.
- clustering : Methods included in this library: Agglomerative hierarchical clustering: Complete linkage O(n^2), Single linkage O(n^2), Average linkage O(n^2), Weighted linkage O(n^2), Ward’s linkage O(n^2). KMeans clustering.
- Self-Organising Maps (SOM)
- Hierarchical (H)SOMs
- Affinity propagation
- Spectral Clustering
- Hierarchical clustering
- Principal Component Analysis (PCA)
- Kernel PCA
- Incremental PCA
- Truncated SVD*
- Independent Component Analysis (ICA)
- t-SNE (t-distributed stochastic neighbor embedding)
Machine Learning Misc.
- sibe : A simple, experimental machine learning library. Contains implementations of
- Multi-class Naive Bayes classification
- Word2Vec word embedding
- Principal component analysis (PCA)
- aima-haskell : Algorithms from Artificial Intelligence: A Modern Approach by Russell and Norvig.
- Natural Language Processing (NLP)
- chatter : chatter is a collection of simple Natural Language Processing algorithms, which also comes with models for POS tagging and Phrasal Chunking that have been trained on the Brown corpus (POS only) and the Conll2000 corpus (POS and Chunking).
- Part of speech tagging with Averaged Perceptrons. Based on the Python implementation by Matthew Honnibal: (http://honnibal.wordpress.com/2013/09/11/a-good-part-of-speechpos-tagger-in-about-200-lines-of-python/) See NLP.POS for the details of part-of-speech tagging with chatter.
- Phrasal Chunking (also with an Averaged Perceptron) to identify arbitrary chunks based on training data.
- Document similarity; A cosine-based similarity measure, and TF-IDF calculations, are available in the NLP.Similarity.VectorSim module.
- Information Extraction patterns via (http://www.haskell.org/haskellwiki/Parsec/) Parsec
- snowball : The Snowball FFI binding library is used to compute the stems of words in natural languages. Compared to the older stemmer package, this one:
- Correctly handles unicode without relying on the system locale
- Takes greater care to avoid memory leaks and to be thread safe
- Uses Text rather than String
- chatter : chatter is a collection of simple Natural Language Processing algorithms, which also comes with models for POS tagging and Phrasal Chunking that have been trained on the Brown corpus (POS only) and the Conll2000 corpus (POS and Chunking). Chatter supports:
- datasets : Classical machine learning and statistics datasets from the UCI Machine Learning Repository and other sources.
The datasets package defines two different kinds of datasets:
- Small data sets which are directly (or indirectly with file-embed) embedded in the package as pure values and do not require network or IO to download the data set. This includes Iris, Anscombe and OldFaithful
- Other data sets which need to be fetched over the network and are cached in a local temporary directory.
Currently maintained within the scope of the DataHaskell
- mnist-idx : Read and write data in the IDX format used in e.g. the MINST database.
- HaskellR (https://tweag.github.io/HaskellR/)
- inline-r : Seamlessly call R from Haskell and vice versa. No FFI required. Efficiently mix Haskell and R code in the same source file using quasiquotation. R code is designed to be evaluated using an instance of the R interpreter embedded in the binary, with no marshalling costs and hence little to no overhead when communicating values back to Haskell.
- H : An interactive prompt for exploring and graphing data sets. This is a thin wrapper around GHCi, with the full power of an R prompt, and the full power of Haskell prompt: you can enter expressions of either language, providing you with plotting and distributed computing facilities out-of-the-box.
Data science frameworks
Apache Spark bindings
sparkle : A library for writing resilient analytics applications in Haskell that scale to thousands of nodes, using Spark and the rest of the Apache ecosystem under the hood. See the blog post for details.
distributed-dataset : A distributed data processing framework in pure Haskell. Inspired by Apache Spark.
Control.Distributed.Datasetprovides a type which lets you express transformations on a distributed multiset. Its API is highly inspired by Apache Spark. It uses pluggable ShuffleStore’s for storing intermediate compuation results. See ‘distributed-dataset-aws’ for an implementation using S3.
Control.Distributed.Forkcontains a fork function which lets you run arbitrary IO actions on remote machines; leveraging StaticPointers language extension and distributed-closure library. This module is useful when your task is embarrassingly parallel: It uses pluggable Backends for spawning executors. See ‘distributed-dataset-aws’ for an implementation using AWS Lambda .
- A specification to describe data pipelines in a language-agnostic manner, and a communication protocol to submit these pipelines to Spark.
- A serving library, called krapsh-server, that implements this specification on top of Spark. It is written in Scala and is loaded as a standard Spark package.
- A client written in Haskell that sends pipelines to Spark for execution. In addition, this client serves as an experimental platform for whole-program optimization and verification, as well as compiler-enforced type checking.
If you know a library that has to do with Data Science, please consider adding it, if the category it belongs to doesn’t exist, suggest a category for it.
Add sections related to data science and not only Machine Learning such as Data Mining, Distributed Processing, etc