A library for working with phylogenetic and population genetic data.
v0.27.0
Histogram Class Reference

#include <genesis/utils/math/histogram.hpp>

Detailed Description

Histogram class for accumulating and summarizing data.

Many details of the implementation are taken from the GNU Scientific Library: https://www.gnu.org/software/gsl/manual/html_node/Histograms.html See there for some more information.

The structure of the kept data is as follows:

   [ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[4] )
---|---------|---------|---------|---------|---------|---  x
 r[0]      r[1]      r[2]      r[3]      r[4]      r[5]

The number of bins needs to be determined at construction. The number of ranges is always one more than the number of bins.

Definition at line 68 of file histogram.hpp.

Public Member Functions

 Histogram ()=default
 
 Histogram (const std::vector< double > &ranges)
 
 Histogram (Histogram &&)=default
 
 Histogram (Histogram const &)=default
 
 Histogram (size_t num_bins)
 
 Histogram (size_t num_bins, double range_min, double range_max)
 
 ~Histogram ()=default
 
long accumulate (double x, double weight)
 
void accumulate_bin (size_t bin, double weight)
 
double & at (size_t bin_num)
 
double at (size_t bin_num) const
 
iterator begin ()
 
const_iterator begin () const
 
double bin_midpoint (size_t bin_num) const
 
std::pair< double, double > bin_range (size_t bin_num) const
 
double bin_width (size_t bin_num) const
 
size_t bins () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
bool check_range (double x) const
 
void clear ()
 
iterator end ()
 
const_iterator end () const
 
long find_bin (double x) const
 
long increment (double x)
 
void increment_bin (size_t bin)
 
Histogramoperator= (Histogram &&)=default
 
Histogramoperator= (Histogram const &)=default
 
bool operator== (Histogram const &rhs)
 
double & operator[] (size_t bin_num)
 
double operator[] (size_t bin_num) const
 
OutOfRangeBehaviour out_of_range_behaviour () const
 
void out_of_range_behaviour (OutOfRangeBehaviour v)
 
double range_max () const
 
double range_min () const
 
void set_ranges (const std::vector< double > &ranges)
 
void set_uniform_ranges (const double min, const double max)
 

Public Types

typedef std::vector< double >::const_iterator const_iterator
 
typedef std::vector< double >::iterator iterator
 
enum  OutOfRangeBehaviour { kSqueeze, kIgnore, kThrow }
 

Friends

bool equal_ranges (Histogram const &lhs, Histogram const &rhs)
 
void swap (Histogram &lhs, Histogram &rhs)
 

Constructor & Destructor Documentation

◆ Histogram() [1/6]

Histogram ( )
default

◆ Histogram() [2/6]

Histogram ( size_t  num_bins)
explicit

Definition at line 64 of file histogram.cpp.

◆ Histogram() [3/6]

Histogram ( size_t  num_bins,
double  range_min,
double  range_max 
)

Definition at line 72 of file histogram.cpp.

◆ Histogram() [4/6]

Histogram ( const std::vector< double > &  ranges)
explicit

Definition at line 88 of file histogram.cpp.

◆ ~Histogram()

~Histogram ( )
default

◆ Histogram() [5/6]

Histogram ( Histogram const &  )
default

◆ Histogram() [6/6]

Histogram ( Histogram &&  )
default

Member Function Documentation

◆ accumulate()

long accumulate ( double  x,
double  weight 
)

Definition at line 320 of file histogram.cpp.

◆ accumulate_bin()

void accumulate_bin ( size_t  bin,
double  weight 
)

Definition at line 354 of file histogram.cpp.

◆ at() [1/2]

double & at ( size_t  bin_num)

Definition at line 180 of file histogram.cpp.

◆ at() [2/2]

double at ( size_t  bin_num) const

Definition at line 188 of file histogram.cpp.

◆ begin() [1/2]

Definition at line 210 of file histogram.cpp.

◆ begin() [2/2]

const_iterator begin ( ) const

◆ bin_midpoint()

double bin_midpoint ( size_t  bin_num) const

Definition at line 254 of file histogram.cpp.

◆ bin_range()

std::pair< double, double > bin_range ( size_t  bin_num) const

Definition at line 249 of file histogram.cpp.

◆ bin_width()

double bin_width ( size_t  bin_num) const

Definition at line 259 of file histogram.cpp.

◆ bins()

size_t bins ( ) const

Definition at line 244 of file histogram.cpp.

◆ cbegin()

Histogram::const_iterator cbegin ( ) const

Definition at line 230 of file histogram.cpp.

◆ cend()

Histogram::const_iterator cend ( ) const

Definition at line 235 of file histogram.cpp.

◆ check_range()

bool check_range ( double  x) const

Definition at line 306 of file histogram.cpp.

◆ clear()

void clear ( )

Definition at line 150 of file histogram.cpp.

◆ end() [1/2]

Definition at line 215 of file histogram.cpp.

◆ end() [2/2]

const_iterator end ( ) const

◆ find_bin()

long find_bin ( double  x) const

Definition at line 264 of file histogram.cpp.

◆ increment()

long increment ( double  x)

Definition at line 315 of file histogram.cpp.

◆ increment_bin()

void increment_bin ( size_t  bin)

Definition at line 349 of file histogram.cpp.

◆ operator=() [1/2]

Histogram& operator= ( Histogram &&  )
default

◆ operator=() [2/2]

Histogram& operator= ( Histogram const &  )
default

◆ operator==()

bool operator== ( Histogram const &  rhs)

Definition at line 171 of file histogram.cpp.

◆ operator[]() [1/2]

double & operator[] ( size_t  bin_num)

Definition at line 196 of file histogram.cpp.

◆ operator[]() [2/2]

double operator[] ( size_t  bin_num) const

Definition at line 201 of file histogram.cpp.

◆ out_of_range_behaviour() [1/2]

Histogram::OutOfRangeBehaviour out_of_range_behaviour ( ) const

Definition at line 157 of file histogram.cpp.

◆ out_of_range_behaviour() [2/2]

void out_of_range_behaviour ( OutOfRangeBehaviour  v)

Definition at line 162 of file histogram.cpp.

◆ range_max()

double range_max ( ) const

Definition at line 301 of file histogram.cpp.

◆ range_min()

double range_min ( ) const

Definition at line 296 of file histogram.cpp.

◆ set_ranges()

void set_ranges ( const std::vector< double > &  ranges)

Definition at line 107 of file histogram.cpp.

◆ set_uniform_ranges()

void set_uniform_ranges ( const double  min,
const double  max 
)

Definition at line 120 of file histogram.cpp.

Friends And Related Function Documentation

◆ equal_ranges

bool equal_ranges ( Histogram const &  lhs,
Histogram const &  rhs 
)
friend

Definition at line 55 of file histogram.cpp.

◆ swap

void swap ( Histogram lhs,
Histogram rhs 
)
friend

Definition at line 47 of file histogram.cpp.

Member Typedef Documentation

◆ const_iterator

typedef std::vector<double>::const_iterator const_iterator

Definition at line 83 of file histogram.hpp.

◆ iterator

typedef std::vector<double>::iterator iterator

Definition at line 82 of file histogram.hpp.

Member Enumeration Documentation

◆ OutOfRangeBehaviour

enum OutOfRangeBehaviour
strong
Enumerator
kSqueeze 
kIgnore 
kThrow 

Definition at line 76 of file histogram.hpp.


The documentation for this class was generated from the following files: