Git Product home page Git Product logo

histogram's Introduction

Gem Version

histogram

Generates histograms similar to R's hist and numpy's histogram functions. Inspired somewhat by Richard Cottons's matlab implementation and the wikipedia histogram article.

NOTE

versions <= 0.1.0 had a stupid bug in the Freedman-Diaconis method for finding bins. So, if you weren't specifying your own number of bins or bin sizes, then you may not have been getting the optimal bin size by default.

Typical usage:

require 'histogram/array'  # enables Array#histogram

data = [0,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,5,5,9,9,10]
# by default, uses Scott's method to calculate optimal number of bins
# and the bin values are midpoints between the bin edges 
(bins, freqs) = data.histogram 
# equivalent to:  data.histogram(:scott, :bin_boundary => :avg)  

Multiple types of binning behavior:

# :scott, :fd, :sturges, or :middle  
data.histogram(:fd)  # use Freedman-Diaconis method to calc num bins
data.histogram(:middle) # (median value between the three methods)
(bins, freqs) = data.histogram(20)                         # use 20 bins
(bins, freqs) = data.histogram([-3,-1,4,5,6])              # custom bins

(bins, freqs) = data.histogram(10, :min => 2, :max => 12)  # 10 bins with set min and max

# bins are midpoints, but can be set as minima
(bins, freqs) = data.histogram([-3,-1,4,5,6], :bin_boundary => :min) # custom bins with :min

# can also set the bin_width (which interpolates between the min and max of the set)
(bins, freqs) = data.histogram(:bin_width => 0.5)

Multiple Datasets:

Sometimes, we want to create histograms where the bins are calculated based on all the data sets. That way, the resulting frequencies will all line up:

# returns [bins, freq1, freq2 ...]
(bins, *freqs) = set1.histogram(30, :other_sets => [[3,3,4,4,5], [-1,0,0,3,3,6]])

Histograms with weights/fractions:

# histogramming with weights
data.histogram(20, :weights => [3,3,8,8,9,9,3,3,3,3])

Works with NArray objects

require 'histogram/narray'    # enables NArray#histogram
# if the calling object is an NArray, the output is two NArrays:
(bins, freqs) = NArray.float(20).random!(3).histogram(20)
# bins and freqs are both NArray.float objects

Installation

gem install histogram

See Also

aggregate, rserve-client, rsruby

histogram's People

Watchers

 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.