Git Product home page Git Product logo

cxx-distr's Introduction

Efficient discrete random distribution for C++

Test Status C++11 Boost License

Header-only library providing cxx::discrete_distribution class for C++11 and later. The class uses array-based sum tree to allow efficient sampling and updates of discrete events, making it suitable for dynamic simulations like Kinetic Monte Carlo and Gillespie algorithm.

Usage

Download discrete_distribution.hpp and include in your program. The library is single header-only and has zero dependency.

#include <discrete_distribution.hpp>

int main()
{
    // Distribution of four events (0, 1, 2 or 3) with given weights.
    cxx::discrete_distribution<int> distr = {1.2, 3.4, 5.6, 7.8};
    std::mt19937_64 random;

    // 0, 1, 2 or 3 is chosen.
    int choice = distr(random);

    // Change the weight of the event 1 to zero.
    distr.update(1, 0.0);

    // Now event 1 will not be chosen because it has zero weight.
    choice = distr(random);
}

Testing

To run unit tests:

git clone https://github.com/snsinfu/cxx-distr.git
cd cxx-distr/test
make

Also you can test example program:

cd cxx-distr/example
make -C gillespie
make -C random_network

Project Status

Basic features are done.

License

Boost Software License, Version 1.0.

cxx-distr's People

Contributors

snsinfu avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

cxx-distr's Issues

Vector like APIs?

Related to #3. If we add size(), indexing and iteration, the discrete_distribution class becomes to look much like std::vector. I'm tempted to add vector-like functions like push_back() and resize(). It is normal to incrementally add reactions in the setup phase of a Gillespie simulation, so the vector-like functions will be actually useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.