Parallel library for approximate inference on discrete Bayesian networks

baylib C++ library

c++ CI build GPU build License

Baylib is a parallel inference library for discrete Bayesian networks supporting approximate inference algorithms both in CPU and GPU.

Main features

Here's a list of the main requested features:

  • Copy-On-Write semantics for the graph data structure, including the conditional probability table (CPT) of each node
  • parallel implementation of the algorithms either using C++17 threads or GPU computing with boost compute
  • template-based classes for probability format
  • input compatibility with the XDSL format provided by the SMILE library
  • cmake-based deployment

Currently supported algorithms

  • Gibbs Sampling - C++11 threads
  • Likelihood Weighting - C++11 threads
  • Logic Sampling - GPGPU with boost compute
  • Rejection Sampling - C++11 threads
  • Adaptive importance sampling - C++11 threads, GPGPU with boost compute
algorithm evidence deterministic nodes multi-threading GPGPU
gibbs sampling *
likelihood weighting
logic sampling
rejection sampling
adaptive importance sampling

*It's a very well-known limitation of the Gibbs sampling approach

Dependencies

  • cmake >= 2.8
  • boost >= 1.65
  • libtbb
  • ocl-icd-opencl
  • mesa-opencl-icd

Under Linux, you can install the required dependencies using the provided script install_dependencies.sh as follows

 cd scripts/
 chmod u+x install_dependencies.sh
./install_dependencies.sh

Install baylib

Using the cmake FetchContent directives you can directly setup baylib as follows

include(FetchContent)

FetchContent_Declare(
        baylib
        GIT_REPOSITORY https://github.com/mspronesti/baylib.git
)

FetchContent_MakeAvailable(baylib)
# create your executable 
# and whatever you need for
# your project ...
target_link_libraries(<your_executable> baylib)

Alternatively under Linux or MacOS, you can run the provided script install.sh as follows

cd scripts/
chmod u+x install.sh
sudo ./install.sh

another option for the script is running the following commands (assuming you're in the root of the project):

mkdir build
cd build
cmake ..
make
sudo make install

You can now include baylib in your projects.

In the latter two cases, make sure your CMakeLists.txt looks like this

find_package(baylib)
# create your executable 
# and whatever you need for
# your project ...
target_link_libraries(<your_executable> baylib)

Usage

Baylib allows performing approximate inference on Bayesian Networks loaded from xdsl files or created by hand (either using named nodes or numeric identifiers).

Have a look at examples for more.

External references

Owner
Massimiliano Pronesti
The impossible happened -Valgrind
Massimiliano Pronesti
Comments
  • terminate called after throwing an instance of 'std::future_error'   what():  std::future_error: No associated state

    terminate called after throwing an instance of 'std::future_error' what(): std::future_error: No associated state

    compute_network_marginal_probabilities produces the following crash:

    terminate called after throwing an instance of 'std::future_error'
      what():  std::future_error: No associated state
    

    The issue can be reproduced assigning element 0 and 1 to results while running on the ventureBN.xdsl network. One of the two future<shared_ptr<bcvec>> is empty despite cnmp running correctly.

  • condition should be pruned and reasserted before discarding it

    condition should be pruned and reasserted before discarding it

    Let X be a random variable of the Bayesian network. Let P be the set of parents of X. Let Y be a random variable not included in P. From basic notions of conditional probability, P( X | P U Y) = P( X | P) therefore, if a condition contains couples node-state not being actual dependencies of X, I suggest pruning the condition before discarding it (the current assertion discards it once a non-parent is detected)

  • Convert CPT from file to algorithm format

    Convert CPT from file to algorithm format

    The logic_sampling algorithm requires a specific format for the CPT: image in the image we can see an example taken from https://repo.bayesfusion.com/bayesbox.html, the CPT must be represented as a contiguous vector, the order in which the probabilities must be reported is by column, e.g. the set of related probabilities must be contiguous, the order in which the parents is presented is very important as it will be used to interpret the CPT vector. From the image presented the derived CPT vector is: {0.8, 0.2, 0.8, 0.2, 0.8, 0.2, 0.05, 0.095} with the parents passed as: {Increased_serum_calcium, Brain_Tumor}

  • GPU memory limitations might be problematic

    GPU memory limitations might be problematic

    Our logic sampling implementation is limited mainly by how much memory we can use on the GPU, a possible problem could arise when trying to use more memory than the device has available, the solution is to simply rerun the algorithm in separate instances and accumulate the results.

  • fix: fixed typedefs in vectorized algorithms

    fix: fixed typedefs in vectorized algorithms

    • fixed typedef in adaptive_importance_sampling.hpp and logic_sampling.hpp
    • added example_gpu_inference.cpp
    • removed duplicate files
    • removed useless import from condition_factory.hpp
    • added more installation infos to README.md
  • Consider migrating to boost::labeled_graph

    Consider migrating to boost::labeled_graph

    boost::labeled_graph offers an easy and friendly infrastructure to better use labels on templated bayesian network.

    typedef adjacency_list<
            listS,
            vecS,
            bidirectionalS,
            Vertex
    > Graph;
    
    typedef labeled_graph <Graph, Label> LabeledGraph;
    
  • add documentation (Doxygen)

    add documentation (Doxygen)

    First install flex and bison

    sudo apt install flex
    sudo apt install bison
    

    then clone the official repository

    git clone https://github.com/doxygen/doxygen.git
    cd doxygen
    

    build

    mkdir build
    cd build
    cmake -G "Unix Makefiles" ..
    make
    

    and force a clean install of doxygen

    sudo make install
    

    Create a doc directory in the root of this project and run the following command to have a template of a doxygen configuration file

    doxygen -g doxy-config
    

    edit doxy-config with your favorite text editor (e.g. vi) to specify the value of the INPUT variable. For instance

    INPUT                  = ../baylib \
                             ../baylib/graph \
                             ../baylib/inference \
                             ../baylib/network \
                             ../baylib/parser  \
                             ../baylib/probability \
                             ../baylib/tools \
                             ../baylib/tools/cow \
                             ../baylib/tools/gpu \
                             ../baylib/tools/random 
    

    Eventually, run

    doxygen doxy-config
    

    to produce the documentation both in html and latex format.

  • Consider using TBB to further parallelize std algorithms

    Consider using TBB to further parallelize std algorithms

    To properly use TBB, install it with

    sudo apt install libtbb-dev
    

    (don't forget to add the above line to scripts/install_dependencies.sh). Then add the following lines to baylib/CMakeLists.txt

    find_package(TBB REQUIRED)
    ...
    set(BAYLIB_REQUIRED_LIBS
         ...
         tbb
    )
    
  • `add_variable` must check if another node has an identical cpt

    `add_variable` must check if another node has an identical cpt

    When adding a new variable, the add_variable method must check whether another node already has an identical cpt. If it the case, it must be assigned through copy-on-wright facilities

  • Parser is no longer compatible with bayesian_network

    Parser is no longer compatible with bayesian_network

    2 options:

    • adapt previous parser to the new bn representation
    • provide a constructor for bayesian_network receiving a file to perform this task

    Don't forget to add tests.

  • OpenCL algorithms very rarely cause segfault

    OpenCL algorithms very rarely cause segfault

    Very rarely opencl algorithms that use boost compute cause a segfault, I wasn't able to track down the leading cause as it happens with a very low probability and I didn't manage to reproduce it for now. A minimal reproducible example is needed.

  • Segmentation fault (core dumped) on python binding of inference algorithms

    Segmentation fault (core dumped) on python binding of inference algorithms

    I suspect I'm not using properly the following two macros:

    • PYBIND11_OVERLOAD
    • PYBIND11_OVERLOAD_PURE

    I followed the official doc , yet it's not working

BayesOpt: A toolbox for bayesian optimization, experimental design and stochastic bandits.

BayesOpt: A Bayesian optimization library BayesOpt is an efficient implementation of the Bayesian optimization methodology for nonlinear optimization,

Jun 2, 2022
Header-only C++/python library for fast approximate nearest neighbors

Hnswlib - fast approximate nearest neighbor search Header-only C++ HNSW implementation with python bindings. NEWS: Hnswlib is now 0.5.2. Bugfixes - th

Jun 19, 2022
Assignment skeleton for course on Discrete Differential Geometry (15-458/858)

ddg-exercises This repo contains C++ skeleton code for course assignments from Discrete Differential Geometry (15-458/858). For the JavaScript version

May 24, 2022
ADOP: Approximate Differentiable One-Pixel Point Rendering
ADOP: Approximate Differentiable One-Pixel Point Rendering

ADOP: Approximate Differentiable One-Pixel Point Rendering

Jun 16, 2022
A lightweight C library for artificial neural networks

Getting Started # acquire source code and compile git clone https://github.com/attractivechaos/kann cd kann; make # learn unsigned addition (30000 sam

Jun 10, 2022
A header-only C++ library for deep neural networks

MiniDNN MiniDNN is a C++ library that implements a number of popular deep neural network (DNN) models. It has a mini codebase but is fully functional

Jun 22, 2022
A library for creating Artificial Neural Networks, for use in Machine Learning and Deep Learning algorithms.
A library for creating Artificial Neural Networks, for use in Machine Learning and Deep Learning algorithms.

iNeural A library for creating Artificial Neural Networks, for use in Machine Learning and Deep Learning algorithms. What is a Neural Network? Work on

Apr 5, 2022
Edge ML Library - High-performance Compute Library for On-device Machine Learning Inference
 Edge ML Library - High-performance Compute Library for On-device Machine Learning Inference

Edge ML Library (EMLL) offers optimized basic routines like general matrix multiplications (GEMM) and quantizations, to speed up machine learning (ML) inference on ARM-based devices. EMLL supports fp32, fp16 and int8 data types. EMLL accelerates on-device NMT, ASR and OCR engines of Youdao, Inc.

Jun 17, 2022
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Tensors and Dynamic neural networks in Python with strong GPU acceleration

PyTorch is a Python package that provides two high-level features: Tensor computation (like NumPy) with strong GPU acceleration Deep neural networks b

Jun 23, 2022
Convolutional Neural Networks
Convolutional Neural Networks

Darknet Darknet is an open source neural network framework written in C and CUDA. It is fast, easy to install, and supports CPU and GPU computation. D

Jun 23, 2022
Low dependency(C++11 STL only), good portability, header-only, deep neural networks for embedded
Low dependency(C++11 STL only), good portability, header-only, deep neural networks for embedded

LKYDeepNN LKYDeepNN 可訓練的深度類神經網路 (Deep Neural Network) 函式庫。 輕量,核心部份只依賴 C++11 標準函式庫,低相依性、好移植,方便在嵌入式系統上使用。 Class diagram 附有訓練視覺化 demo 程式 訓練視覺化程式以 OpenCV

Apr 27, 2022
Tiny CUDA Neural Networks
 Tiny CUDA Neural Networks

This is a small, self-contained framework for training and querying neural networks. Most notably, it contains a lightning fast "fully fused" multi-layer perceptron as well as support for various advanced input encodings, losses, and optimizers.

Jun 22, 2022
Raspberry Pi guitar pedal using neural networks to emulate real amps and pedals.
Raspberry Pi guitar pedal using neural networks to emulate real amps and pedals.

NeuralPi NeuralPi is a guitar pedal using neural networks to emulate real amps and pedals on a Raspberry Pi 4. The NeuralPi software is a VST3 plugin

Jun 16, 2022
An Efficient Implementation of Analytic Mesh Algorithm for 3D Iso-surface Extraction from Neural Networks
An Efficient Implementation of Analytic Mesh Algorithm for 3D Iso-surface Extraction from Neural Networks

AnalyticMesh Analytic Marching is an exact meshing solution from neural networks. Compared to standard methods, it completely avoids geometric and top

May 21, 2022
An Efficient Implementation of Analytic Mesh Algorithm for 3D Iso-surface Extraction from Neural Networks
An Efficient Implementation of Analytic Mesh Algorithm for 3D Iso-surface Extraction from Neural Networks

AnalyticMesh Analytic Marching is an exact meshing solution from neural networks. Compared to standard methods, it completely avoids geometric and top

May 21, 2022
InsNet Runs Instance-dependent Neural Networks with Padding-free Dynamic Batching.

InsNet documentation InsNet (documentation) is a powerful neural network library aiming at building instance-dependent computation graphs. It is desig

Jun 9, 2022
Grouped Feedback Delay Networks for Coupled Room Modeling
Grouped Feedback Delay Networks for Coupled Room Modeling

Grouped Feedback Delay Networks Reverb Plugin GFDNs connect multiple spaces with different T60 characteristics and a parameterized mixing matrix to co

Jun 23, 2022
TS-9 guitar pedal clone using neural networks.
TS-9 guitar pedal clone using neural networks.

TS-M1N3 TS-M1N3 is a guitar plugin clone of the TS-9 Tubescreamer overdrive pedal. Machine learning was used to train a model of both the drive and to

Apr 17, 2022
A Tool for Verifying Neural Networks using SMT-Based Model Checking

Project Title QNNVerifier Description A Tool for Verifying Neural Networks using SMT-Based Model Checking. Using Frama-C and ESBMC as the backends. Yo

Dec 11, 2021