boltzmannbrain alternatives and similar packages
Based on the "Math" category.
Alternatively, view boltzmannbrain alternatives based on common mentions on social networks and blogs.

vector
An efficient implementation of Intindexed arrays (both mutable and immutable), with a powerful loop optimisation framework . 
statistics
A fast, high quality library for computing with statistics in Haskell. 
what4
Symbolic formula representation and solver interaction library 
HerbiePlugin
GHC plugin that improves Haskell code's numerical stability 
hermit
Haskell Equational Reasoning ModeltoImplementation Tunnel 
computationalalgebra
GeneralPurpose Computer Algebra System as an EDSL in Haskell 
mwcrandom
A very fast Haskell library for generating high quality pseudorandom numbers. 
dimensional
Dimensional library variant built on Data Kinds, Closed Type Families, TypeNats (GHC 7.8+). 
matrix
A Haskell native implementation of matrices and their operations. 
numhask
A haskell numeric prelude, providing a clean structure for numbers and operations that combine them. 
vectorspace
Vector & affine spaces, linear maps, and derivatives 
cf
"Exact" real arithmetic for Haskell using continued fractions (Not formally proven correct) 
bayesstack
Framework for Gibbs sampling of probabilistic models 
poly
Fast polynomial arithmetic in Haskell (dense and sparse, univariate and multivariate, usual and Laurent) 
optimization
Some numerical optimization methods implemented in Haskell 
safedecimal
Safe and very efficient arithmetic operations on fixed decimal point numbers 
equationalreasoning
Agdastyle equational reasoning in Haskell 
sbvPlugin
Formally prove properties of Haskell programs using SBV/SMT. 
bedandbreakfast
Matrix operations in 100% pure Haskell 
simplesmt
A simple way to interact with an SMT solver process. 
eigen
Haskel binding for Eigen library. Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms. 
polynomial
Haskell library for manipulating and evaluating polynomials 
lambdacalculator
An introduction to the Lambda Calculus 
diagramssolve
Miscellaneous solver code for diagrams (lowdegree polynomials, tridiagonal matrices) 
vectorbinaryinstances
Instances for the Haskell Binary class, for the types defined in the popular vector package. 
vectorthunbox
Deriver for unboxed vectors using Template Haskell
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of boltzmannbrain or a related project?
README
Boltzmann Brain
Boltzmann Brain is a Haskell library and standalone application meant for random generation of combinatorial structures. Using an easy and intuitive contextfree text input representing a combinatorial specification of rational or algebraic objects, Boltzmann Brain allows its users to:
 sample random structures following the given input specification;
 visualize sampled objects using the GraphViz graph visualization software, and finally
 compile a selfcontained, dedicated analytic sampler for optimal sampling efficiency.
Remarkably, using Boltzmann Brain it is possible to control the outcome distribution of generated objects and, in particular, skew it to one needs. You provide the target distribution, we handle the sampling process for you!
If you can specify it, you can sample it!
Citing Boltzmann Brain
If you use Boltzmann Brain or its components for published work, we encourage you to cite the accompanying paper:
Maciej Bendkowski, Olivier Bodini, Sergey Dovgal
Polynomial tuning of multiparametric combinatorial samplers
Overview
Boltzmann Brain (bb for short) is an opensource analytic sampler compiler. Given a textual representation of the combinatorial system, bb constructs a dedicated analytic sampler. The sampler itself is a selfcontained, and reusable Haskell module which, by construction, is guaranteed to sample random objects following the given, feasible target distribution. Using stateoftheart optimization techniques, bb compiles an efficient sampler implementation which can be further modified, incorporated in other software or used as a standalone module.
The input specification format mimics that of Haskell algebraic data types where in addition each type constructor may be annotated with an additional weight parameter. For instance:
 Motzkin trees
MotzkinTree = Leaf
 Unary MotzkinTree (2)
 Binary MotzkinTree MotzkinTree.
In the above example, a MotzkinTree
data type is defined. It contains three
constructors:
 a constant
Leaf
of weight one (default value if not annotated); a unary
Unary
constructor of weight two, and  a binary contructor
Binary
of default weight one.
 a unary
The definition ends with an obligatory dot.
Each definition constitutes an algebraic data type where each inhabitant has an intrinsic size, defined as the sum of all its building constructor weights.
Given a system of (possibly) mutually recursive types, Boltzmann Brain automatically detects the specification kind (either rational or algebraic) and constructs a singular, rejectionbased analytic sampler able to sample uniformly random, conditioned on size, inhabitants of the system types. Though the exact size of the outcome is a random variable, the outcome sampler allows to control the desired lower and upper bounds of the generated objects.
Sampler tuning
Boltzmann Brain supports a target frequency calibration using convex optimisation techniques. These are implemented as a Python library Paganini built using cvxpy. Boltzmann Brain communicates with Paganini through a tiny executable called medulla (see the medulla subdirectory). Consider the following example of a specification defining Motzkin trees with some arbitrary size notion:
 Motzkin trees
MotzkinTree = Leaf
 Unary MotzkinTree (2) [0.3]
 Binary MotzkinTree MotzkinTree (2).
Here, the Unary
construct is given weight 2 and a target frequency of
0.3. In consequence, the system is to be tuned such that the Unary
node contributes, on average, 30% of the total size of constructed Motzkin
trees. It is hence possible to distort the natural frequency of each
constructor in the given system.
Note however, such an additional nontrivial tuning procedure causes a not insignificant change in the underlying probability model. In extreme cases, such as for instance requiring 80% of internal nodes in plane binary trees, the constructed sampler might be virtually ineffective due to the sparsity of tuned structures.
Please tune with caution!
Basic usage
For standard help/usage hints type bb h
(or paganini h
). For more advanced options, Boltzmann Brain provides its own annotation system (see example below):
 Motzkin trees
@module Sampler
@precision 1.0e12
@maxiter 30
@withIO y
@withLists y
@withShow y
M = Leaf
 Unary M [0.3]
 Binary M M.
The @module
annotation controls the name of the generated Haskell module (it
defaults to Sampler
if not explicitly given). Next two annotations
@precision
and @maxiter
are parameters passed to Paganini and control the
quality of the tuning procedure. If not provided, some reasonable default values are
assumed (depending on the detected system type). The last three parameters
control some additional parameters used while generating the sampler code.
Specifically, whether to generate addtional IO
(input/output) generators, whether to generate
list samplers for each type in the system, and finally whether to include
deriving Show
clauses for each type in the system. By default, @withIO
and
@withShow
are enabled (to disable them, set them to n
or no
); @withLists
is by default disabled if not stated otherwise in the input specification.
Using annotations it is also possible to control the sampling parameters of Boltzmann Brain . Consider the following example:
 Random sampling of Motzkin trees
 Parameters for "tuning"
@precision 1.0e12
@maxiter 30
 Sampling parameters
@lowerBound 100
@upperBound 10000
@generate M
M = Leaf
 Unary M [0.3]
 Binary M M.
In the above example, three more annotations are used. The first two dictate the
admissible size window of the generated structures whereas the third one specifies
the type from which we want to generate. If no bounds are provided, Boltzmann Brain uses
some (small) default ones. If no @generate
annotation is provided, Boltzmann Brain
assumes some default type.
Advanced usage
For parameter tuning, Boltzmann Brain invokes the external medulla script. Usually, Boltzmann Brain automatically calls medulla once tuning is in order. If no special handling is required, it just suffices to have paganini
available in the system; Boltzmann Brain will automatically pass it necessary data and retrieve the tuning data.
However, it needed, a manual tuning workflow is also supported. To tune a combinatorial specification "by hand", you can start with generating a Paganini representation of the system, e.g. using
bb spec i specification.in o specification.out
.
Boltzmann Brain ensures that the input specification is sound and wellfounded. Otherwise, (arguably) userfriendly error messages are provided. Once the Paganini specification is generated, we type
medulla i paganini.pg > bb.param
which runs Paganini and outputs the required tuning data for bb
. You
can alter the default agruments of paganini
scripts such as tuning precision,
optimisation problem solver, maximum number of iterations, and explicitly
specify if the type of the grammar is rational (for rational specifications the optimization problem
might become unbounded).
Finally, we need to tell bb
to use the tuning data typing, e.g.:
bb compile o Sampler.hs t bb.param i specification.in
Installation
Boltzmann Brain consists of two executables, bb
and medulla
. The former one is implemented in Haskell whereas the latter is implemented in Python. Both applications rely on some (few) external libraries to work, such as LAPACK or BLAS. The following sections explain several common installation methods.
We start with the recommended method of compiling Boltzmann Brain from sources. The following section explains the compilation process under Ubuntu 16.04, however, let us note that with little modifications it should also work under other Linux distributions.
Linux (Ubuntu 16.04 or newer)
We start with installing all the required system dependencies:
aptget update
aptget install y cmake curl git libblasdev liblapackdev python3 python3pip
The above script installs BLAS
and LAPACK
as well as python3 and its package manager pip
. Since the target destination of both bb
and medulla
is going to be ~/.local/bin
, before proceeding please make sure that it is included in your PATH
.
Next, we install required python dependencies
pip3 install user upgrade pip
pip3 install user numpy scipy
pip3 install user cvxpy
pip3 install user paganini
Note that the above packages play the central role in the system tuning procedure. Without them, medulla cannot not work properly. Next, we clone the current repository
git clone https://github.com/maciejbendkowski/boltzmannbrain.git
and install medulla
:
cd boltzmannbrain/medulla
python3 setup.py install user prefix=
We can check that medulla is installed by typing
medulla h
If medulla
is available, we should see a help/usage message.
Finally, we have to prepare to install bb
. For that purpose, we are going
to download Haskell's Stack tool chain. Note that stack is able to download and isolate various GHC (Glasgow Haskell Compiler) instances, avoiding the infamous Cabal hell.
To install stack for linux x86_64 type
curl L https://get.haskellstack.org/stable/linuxx86_64.tar.gz  tar xz wildcards stripcomponents=1 C ~/.local/bin '*/stack'
Now, all we need is to go back to the main boltzmannbrain folder and use stack install:
stack setup resolver=lts14.16
stack install happy resolver=lts14.16
stack install
Nix support (linux / macOS)
nix is a package manager that works under linux and macos. Support for installing dependencies and a assembling a development environment for building and running boltzmannbrain is provided by the shell.nix
file in the toplevel directory. To use it, you need to have nixpkgs installed already. Then you can install boltzmannbrain as follows:
git clone https://github.com/maciejbendkowski/boltzmannbrain.git
nixshell # Enters a shell which provides GHC, python, paganini, and installs medulla all in one step.
That's it!
Now you can build bb and then run an example. For instance:
cabal build # compile and build bb
cabal run bb  sample i examples/algebraic/boolean.alg
Caveats:
Nix support was tested under nixos with ghc 8.6.5 and cabalinstall 3. Earlier versions of GHC may be difficult to get working due to changes in package dependencies. As of 20191205 nix support requires a recent version of the nixpkgs repostory (e.g. nixpkgsunstable).
Additional nix derivations are currently (temporarily) needed to support
cvxpy
. After adding them to nixpkgs, you can follow the previously given instructions. Those derivations can be found in https://github.com/teh/nixpkgs/tree/cvxpy. If you mangage nixpkgs by using git, then one way to get cvxpy is to go your nixpkgs directory and enter:
git remote add teh [email protected]:teh/nixpkgs.git
git checkout b cvxpy teh/cvxpy
git rebase nixpkgsunstable
Once support for
cxvpy
is mainstreamed into nixpkgs, step 3 will become unnecessary. Perhaps by 202003, at the latest.If you get nixpkgs updates via nix channels then a custom overlay will be needed (not provided here).
macOS >= 10.12
In the following section we explain how to compile Boltzmann Brain in OSX.
First, you need
python
to be installed (both versions 2 or 3 should be fine). If you don't havepython
installed, you can find it at https://wiki.python.org/moin/BeginnersGuide/Download.Using the dedicated
python
package managerpip
you can install the paganini frameworkpip install paganini
Normally this works, but if some packages are outdated, consider upgrading them.
The Boltzmann Brain package
bb
can be installed with package managerhomebrew
brew tap electrictric/bb brew install boltzmannbrain
If you don't have
homebrew
, you can download the binary file from our releases webpage.
Troubleshooting
On Mac OS
older versions like 10.9
package managers like brew
can only
install stack
from source because the binaries are not maintained.
This takes a long time. In some cases it is faster
to completely update the operating system before attempting to install some of
the prerequisites.
For some versions of
python
, the package managerpip
doesn't come by default.pip
is already installed if you usepython2 >= 2.7.9
orpython3 >= 3.4
. Otherwise see instructions.If some of your packages, for example
numpy
are installed but outdated, the installation process sometimes gives an error. For such packages trypip install upgrade numpy sympy cvxpy
The package manager
pip
should not be used withsudo
. If you don't have the right to write to some specific directory, try addinguser
flag, for examplepip install user paganini
Within
python
, several additional packages should be installed. Normally pip handles the dependencies, so you just need to executepip install paganini
When you launch
medulla
, the program tells you the list of packages that are missing. In order to install the packages, type into the command linepip install six cvxpy numpy sympy
Note that the last two packages come by default with Scientific Computing Tools for Python
The
hmatrix
package inHaskell
requires prominent linear algebra packagesLAPACK
andBLAS
(which are sometimes called "one of the achievements of the human species"). For some systems these packages are already included, but if they are not, you can follow the instructions on the official website.
For more help on installation, please consult also our Travis CI tool chain.
Precompiled binaries
We use Travis CI in order to build bb
for Linux and OSX, both in the
x86_64 architecture. Precompiled binaries of bb
are available at out releases webpage.
Package managers
We offer Hackage. You can install it by typing
stack install boltzmannbrain
References
Boltzmann Brain heavily relies on published work of numerous excellent authors. Below, you can find a short (and definitely inexhaustive) list of papers on the subject:
 P. Flajolet, R. Sedgewick: Analytic Combinatorics
 P. Duchon, P. Flajolet, G. Louchard. G. Schaeffer: Boltzmann Samplers for the random generation of combinatorial structures
 C. Pivoteau, B. Salvy, M. Soria: Algorithms for Combinatorial Systems: WellFounded Systems and Newton Iterations
 O.Bodini, J. Lumbroso, N. Rolin: Analytic samplers and the combinatorial rejection method
*Note that all licence references and agreements mentioned in the boltzmannbrain README section above
are relevant to that project's source code only.