GithubHelp home page GithubHelp logo

llersch / cpp_random_distributions Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 6.0 14 KB

Additional C++11 Random Distributions

License: MIT License

C++ 100.00%
random zipfs-law cpp cpp11 zipf zipfian-distribution skew-factors self-similar

cpp_random_distributions's Introduction

C++ Random Distributions

This repository provides header-only classes with additional statistical distributions to be used by C++11 random generators.

Example:

#include <random>
#include "selfsimilar_int_distribution.h"

int main() {
    std::default_random_engine generator;
    selfsimilar_int_distribution<int> distribution(1, 10, 0.2);
    int i = distribution(generator);
}

Most formulas are taken from: "Quickly Generating Billion-Record Synthetic Databases", Jim Gray et al, SIGMOD 1994".

Self-Similar

The self-similar distribution has a skew factor h represented by a double in the range (0.0,1.0). For a domain of size N, the distribution of probability is such that the first (N*h) elements are generated (1-h) of the times. In other words, for a domain of 25 elements and skew of 0.2, the first 5 elements (20% of 25) will be generated 80% (1-0.2) of the times.

This distribution also has the property that the skew is the same within any region of the domain. Therefore, the first element (20% of 20% of 25) will be generated 64% (80% of 80%) of the times.

In the plots below we generate random integers in the range [1,25] (X axis) and plot the percentage of times they were generated (Y axis) with different skew factors.

Zipfian

The Zipfian distribution is a power law distribution. It has a parameter h indicating the skew factor (higher means more skew). Since the Zipfian distribution is based on the zeta distribution, it requires calculating the zeta value upon initialization. Calculating the zeta value can be unpractical for very large domains, therefore the user has the option of passing a pre-calculated zeta value to the distribution.

In the plots below we generate random integers in the range [1,25] (X axis) and plot the percentage of times they were generated (Y axis) with different skew factors. Note that the Zipfian distribution is less skewed than the self-similar one, as the percentages on the Y axis are lower.

cpp_random_distributions's People

Contributors

llersch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.