histogram

package module
Version: v0.0.0-...-506edba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2015 License: MIT Imports: 2 Imported by: 2

README

histogram

Build Status GoDoc

Simple Histogram library, with support for interpolation and percentile calculation.

The Histogram stores a count of the number of occurrences for each value. This count can later be used to interpolate expected counts for unknown values, and to calculate the percentile position of a value (number of equal or smaller values). The percentile calculation also does implicit interpolation if needed.

Sample usage

 h := NewHistogram()
 for _ , v := range values {
     h.Add(v)
 }
 p := GetPercentile(x)

Full documentation: http://godoc.org/github.com/dripolles/histogram

Documentation

Overview

Package histogram provides a simple histogram library, with support for interpolation and percentile calculation.

The Histogram stores a count of the number of occurrences for each value. This count can later be used to interpolate expected counts for unknown values, and to calculate the percentile position of a value (number of equal or smaller values). The percentile calculation also does implicit interpolation if needed.

Sample usage

h := NewHistogram()
for _ , v := range values {
    h.Add(v)
}
p := GetPercentile(x)

Index

Constants

This section is empty.

Variables

View Source
var ErrExtrapolation = errors.New("Extrapolation of histogram values not supported")

This library does not support extrapolation of histogram values outside the range of known values. An ErrExtrapolation is used if such extrapolation is attempted.

Functions

This section is empty.

Types

type Histogram

type Histogram struct {
	// contains filtered or unexported fields
}

Histogram holds the values and can perform interpolation and percentile calculation.

func NewHistogram

func NewHistogram() *Histogram

NewHistogram creates new empty Histogram.

func (*Histogram) Add

func (h *Histogram) Add(v int)

Add inserts a value into the Histogram.

func (*Histogram) AddCount

func (h *Histogram) AddCount(v, count int)

func (*Histogram) Get

func (h *Histogram) Get(v int) (float64, error)

Get returns the frequency for value v.

func (*Histogram) GetAtPercentile

func (h *Histogram) GetAtPercentile(p float64) int

GetAtPercentile gets the value at percentile p

func (*Histogram) GetInterpolated

func (h *Histogram) GetInterpolated(v int) (float64, error)

GetInterpolated returns the frequency for value v. Automatically performs interpolation if needed.

func (*Histogram) GetPercentile

func (h *Histogram) GetPercentile(v int) float64

GetPercentile returns the percentile position for value v. Automatically performs interpolation if needed.

func (*Histogram) Len

func (h *Histogram) Len() int

Len returns the number of non unique values inserted in the Histogram.

func (*Histogram) Update

func (h *Histogram) Update(h2 *Histogram)

Update adds all the values from h2 to h

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL