Giter VIP home page Giter VIP logo

llh's Introduction

LLH

What's a logarithmic-linear histogram?

Histograms have been widely used to estimate the probability distribution of a continuous variable. Choosing the bin size is difficult: using a logarithmic progression gives a wide range, but at a cost to resolution (particularly in the upper part of the range). Histograms using a linear progression require a large amount of space to compensate for their decreased range.

The logarithmic-linear histogram is a compromise between the two, and provides improved resolution while maintaining a wide range and a reduced space requirement. It does this by using a two-level binning scheme. The top-level bins (which are called buckets) are sized logarithmically (base 2). Each bucket also has a set of second-level bins (which are called slots) -- 16 per bucket -- which are sized linearly within the bin.

Usage

The entire implementation is contained in the header file llh.h; there's no library to link against.

Create a new LLH by initializing it with the provided static initializer, or by just allocating some cleared memory for it:

llh_t histogram1 = LLH_INIT;
llh_t* histogram2 = calloc(1, sizeof(llh_t));

To record an event in a histogram, call llh_record:

llh_record((llh_t*)histogram, (uint64_t)value);

To get data back out of a histogram, you have three choices, depending on the degree of aggregation desired -- total over the entire histogram, total for one bucket, or the value in a specific slot.

(uint64_t)llh_population_get((llh_t*)histogram);
(uint64_t)llh_population_get((llh_t*)histogram, bucket);
(uint64_t)llh_population_get((llh_t*)histogram, bucket, slot);

Finally, you can use the provided accessor to get the number of overflows:

(uint32_t)llh_overflows_get((llh_t*)histogram);

Tests

To run the provided unit tests, use the provided Makefile:

make clean && make && bin/llh_test

Implementation notes

Incrementing histogram values is done by means of an atomic increment. If your platform does not support the INCL instruction, you'll need to compile with the LLH_UNSAFE_INCREMENT flag set.

llh's People

Contributors

gp avatar

Watchers

 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.