loghist

package
v3.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package loghist provides integer histograms with exponentially growing bucket sizes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Left  int
	Right int
	Count int
}

Bucket describes a bucket in the histogram for values [left, right] containing Count many values.

type Hist

type Hist struct {
	Overflow  int // Number of added values > Max
	Underflow int // Number of added values < 0
	// contains filtered or unexported fields
}

Hist is a histogram of non-negative integer values whose bin size increases exponentially and covers the intervall [0,Max]. The bins are grouped into blocks of 1<<bist equal-sized bins. The first block has a bin size of 1; in each consecutive block the bin size is doubled. The resolution of the histogram is 1/(1<<bits).

func New

func New(bits uint, max int) *Hist

New returns a new Hist capable of storing values from 0 to (at least) max with a resolution of bits. N will be 1<<bits.

func (*Hist) Add

func (h *Hist) Add(v int)

Add counts the value v. Values below 0 or larger than h.Max are not stored in the histogram but counted in Underflow and Overflow.

func (*Hist) Average

func (h *Hist) Average() int

Average returns an approximation to the average of all non-over/underflowing values added to h.

func (*Hist) Data

func (h *Hist) Data() []Bucket

Data returns all non-empty buckets of h.

func (*Hist) MustAdd

func (h *Hist) MustAdd(v int)

MustAdd works like Add but will panic if v under- or overflows the allowed range of [0,h.Max].

func (Hist) Parameters

func (h Hist) Parameters() (bits int, max int)

Parameters returns the number of bits resolution of the histogram and the maximum value which can be stored without overflowing.

func (*Hist) Quantiles

func (h *Hist) Quantiles(p []float64) []int

Quantiles returns an approximation to the sample quantiles for the given probabilities p which must be a sorted list of increasing float64s from the intervall [0,1]. Quantiles ignores overflowing and underflowing values in h and can compute only an approximation if the bin sizes become large: The approximation will overestimate the real sample quantile.

func (*Hist) String

func (h *Hist) String() string

String prints the histogram as a sequence of bucket ranges, count per bucket and two graphical representations: The '#' show the raw count while the '*' show counts scaled by bucket width.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL