Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
elementa::math::stats::Histogram::BinDef Class Reference

Definition of the support (bins) of a histogram. More...

Description

Definition of the support (bins) of a histogram.

The definition consists of a vector of increasing values that define the left boundaries of the bins (to be considered open intervals), plus the rightmost boundary (also open), plus possible infinite bins at the left and right of the finite bins. If the finite bins is empty, the definition is considered to cover from -inf to +inf in a single bin.

Definition at line 62 of file histograms.h.

#include "histograms.h"

Inheritance diagram for elementa::math::stats::Histogram::BinDef:
Collaboration diagram for elementa::math::stats::Histogram::BinDef:

Static Public Member Functions

static size_t eq_freq_nbins (size_t ndata)
 Return a reasonable number of bins for a sample with NDATA data. More...
 

Public Member Functions

 BinDef (void)
 Default constructor: one bin from -inf to +inf.
More...
 
 BinDef (double leftmost, double binwidth_or_rightmost, size_t numbins, bool iswidthorright=true, bool addleftinf=false, bool addrightinf=false)
 Constructor for periodic bins. More...
 
 BinDef (long leftcenter, long rightcenter, bool addleftinf=false, bool addrightinf=false)
 Constructor for bins that cover discrete supports. More...
 
size_t numbins (void) const noexcept
 Return the total number of bins, including infinite ones. More...
 
bool entireReals (void) const noexcept
 Return TRUE if there is only one bin covering from -inf to +inf. More...
 
void binBounds (size_t ind, double &left, double &right) const
 Fill LEFT and RIGHT with the boundaries of the IND-th bin. More...
 
bool whichBin (double v, size_t &ind) const noexcept
 Fill IND with the index of the bin where V lies.
 
std::string to_string (void) const
 Return an informative text with the summary of the bin definition.
 

Constructor & Destructor Documentation

◆ BinDef() [1/3]

elementa::math::stats::Histogram::BinDef::BinDef ( void  )
inline

Default constructor: one bin from -inf to +inf.

Definition at line 77 of file histograms.h.

◆ BinDef() [2/3]

elementa::math::stats::Histogram::BinDef::BinDef ( double  leftmost,
double  binwidth_or_rightmost,
size_t  numbins,
bool  iswidthorright = true,
bool  addleftinf = false,
bool  addrightinf = false 
)

Constructor for periodic bins.

Parameters
leftmostis the finite (not included) left boundary of the first bin.
binwidth_or_rightmostis, if iswidthorright == TRUE, the width of all bins (it cannot be infinity or 0.0), and, if iswidthorright == FALSE the rightmost boundary of the finite bins.
numbinsis the number of finite bins (it cannot be 0).
addleftinfis TRUE for adding a bin from -inf to the leftmost.
addrightinfis TRUE for adding a bin from the rightmost to +inf.

◆ BinDef() [3/3]

elementa::math::stats::Histogram::BinDef::BinDef ( long  leftcenter,
long  rightcenter,
bool  addleftinf = false,
bool  addrightinf = false 
)

Constructor for bins that cover discrete supports.

Parameters
leftcenteris the position of the first integral value that must be a the center of a bin and separated from the two adjacent integral values.
rightcenteris the center of the rightmost bin.
addleftinfis TRUE for adding a bin from -inf to the leftmost boundary.

Member Function Documentation

◆ eq_freq_nbins()

static size_t elementa::math::stats::Histogram::BinDef::eq_freq_nbins ( size_t  ndata)
inlinestatic

Return a reasonable number of bins for a sample with NDATA data.

This is calculated for dividing the histogram into close-to-equal- frequency bins, according to "Goodness-of-fit-techniques" (Ralph B. D'Agostino and Michael A. Stephens -eds-, 1986), p. 70.

Definition at line 70 of file histograms.h.

◆ numbins()

size_t elementa::math::stats::Histogram::BinDef::numbins ( void  ) const
inlinenoexcept

Return the total number of bins, including infinite ones.

Definition at line 105 of file histograms.h.

Referenced by elementa::math::stats::Histogram::Histogram().

◆ entireReals()

bool elementa::math::stats::Histogram::BinDef::entireReals ( void  ) const
inlinenoexcept

Return TRUE if there is only one bin covering from -inf to +inf.

This is necessary since there are definitions with 1 bin that is finite and does not cover the real line.

Definition at line 110 of file histograms.h.

Referenced by elementa::math::stats::Histogram::Histogram().

◆ binBounds()

void elementa::math::stats::Histogram::BinDef::binBounds ( size_t  ind,
double &  left,
double &  right 
) const

Fill LEFT and RIGHT with the boundaries of the IND-th bin.

Take into account infinite bins. IND must go from 0 to numbins()-1. Throw if IND is out of range.


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