Tomographer
v5.4
Tomographer C++ Framework Documentation
|
Stores a histogram. More...
#include <tomographer/histogram.h>
Public Types | |
typedef Scalar_ | Scalar |
The scalar type of the "X"-axis of the histogram (usually double ) | |
typedef CountType_ | CountType |
The type that serves to count how many hits in each bin. | |
typedef HistogramParams< Scalar_ > | Params |
The type for specifying parameters of this histogram (limits, number of bins) | |
Public Member Functions | |
template<typename Params2 = Params> | |
Histogram (Params2 p=Params2()) | |
Constructor: stores the parameters and initializes the histogram to zero counts everywhere. | |
Histogram (Scalar min_, Scalar max_, Eigen::Index num_bins) | |
Constructor: stores the parameters and initializes the histogram to zero counts everywhere. | |
Histogram (Histogram &&x) | |
Constructor: move another histogram type. | |
Histogram (const Histogram &x) | |
Constructor: copy another histogram type. | |
void | reset () |
Resets the histogram to zero counts everywhere (including the off-chart counts) | |
template<typename EigenType > | |
void | load (const Eigen::DenseBase< EigenType > &x, CountType off_chart_=0) |
Load data for the histogram. Uses current histogram parameters, just sets the bin counts. More... | |
template<typename EigenType > | |
void | add (const Eigen::ArrayBase< EigenType > &x, CountType off_chart_=0) |
Add data to the histogram. More... | |
template<typename OtherScalar , typename OtherCountType > | |
void | add (const Histogram< OtherScalar, OtherCountType > &x) |
Add data to the histogram. More... | |
Eigen::Index | numBins () const |
Shorthand for params.num_bins | |
CountType | count (Eigen::Index i) const |
Shorthand for bins(i) | |
bool | isWithinBounds (Scalar value) const |
Shorthand for Params::isWithinBounds() | |
Eigen::Index | binIndex (Scalar value) const |
Shorthand for Params::binIndex() | |
Scalar | binLowerValue (Eigen::Index index) const |
Shorthand for Params::binLowerValue() | |
Scalar | binCenterValue (Eigen::Index index) const |
Shorthand for Params::binCenterValue() | |
Scalar | binUpperValue (Eigen::Index index) const |
Shorthand for Params::binUpperValue() | |
Scalar | binResolution () const |
Shorthand for Params::binResolution() | |
Eigen::Index | record (Scalar value) |
Record a new value in the histogram. More... | |
Eigen::Index | record (Scalar value, CountType weight) |
Record a new value in the histogram, with a certain weight. More... | |
template<typename NewCountType = decltype(Scalar(1) + CountType(1))> | |
NewCountType | normalization () const |
Calculate the total weight stored in this histogram. More... | |
template<typename NewCountType = Scalar> | |
Histogram< Scalar, NewCountType > | normalized () const |
Get a normalized version of this histogram. More... | |
CountType | totalCounts () const |
Return the total number of histogram counts (no normalization) More... | |
template<typename NewCountType = Scalar> | |
Histogram< Scalar, NewCountType > | normalizedCounts () const |
Get a version of this histogram, normalized by total counts. More... | |
std::string | prettyPrint (int max_width=0) const |
Pretty-print the histogram and return it as a string with horizontal bars. More... | |
Static Public Member Functions | |
template<typename HistogramType , ENABLED_IF( HistogramType::HasErrorBars==0|| HistogramType::HasErrorBars==1) > | |
static Histogram | copy (const HistogramType &other) |
explicitly copy another histogram type | |
Public Attributes | |
Params | params |
Parameters of this histogram (range and # of bins) | |
Eigen::Array< CountType, Eigen::Dynamic, 1 > | bins |
The counts for each bin. | |
CountType | off_chart |
The number of points that fell outside of the given range. | |
Static Public Attributes | |
static constexpr bool | HasErrorBars = false |
This histogram type does not provide error bars. | |
Stores a histogram.
Splits the range of values \([\text{min},\text{max}]\) into num_bins
number of bins, and keeps counts of how many samples fell in which bin.
Does not store any form of error bars.
Definition at line 230 of file histogram.h.
|
inline |
Add data to the histogram.
x | is an Eigen Vector or 1-D Array from which to load data to add to the histogram counts. It must be (dense) Eigen::ArrayBase-derived type, have one column and exactly numBins() rows. |
off_chart_ | if provided, add this amount to the off_chart counts. |
Definition at line 344 of file histogram.h.
|
inline |
Add data to the histogram.
Adds the values contained in the other histogram x to the current histogram. This also updates the off_chart counts.
Definition at line 364 of file histogram.h.
|
inline |
Load data for the histogram. Uses current histogram parameters, just sets the bin counts.
x | is an Eigen Vector or 1-D Array from which to load the data. It must be dense, have one column and exactly numBins() rows. |
off_chart_ | if provided, then set the off_chart count to this number. Otherwise, reset the off_chart counts to zero. |
Definition at line 327 of file histogram.h.
|
inline |
Calculate the total weight stored in this histogram.
Calculates the relevant normalization factor by which the bin counts (and possibly error bars) should be divided in order to get a proper normalized probability density on the real line.
This function calculates
\[ \mathit{normalization} ~=~ \texttt{off_chart} ~+~ \texttt{binResolution()} \times \sum_i \texttt{bins[}i\texttt{]} \]
Definition at line 475 of file histogram.h.
|
inline |
Get a normalized version of this histogram.
This function divides the bins and the off chart counts by the appropriate normalization() and stores these values into a new returned histogram.
See also normalizedCounts().
Definition at line 490 of file histogram.h.
|
inline |
Get a version of this histogram, normalized by total counts.
This function divides the bins and the off chart counts by the total number of counts (including off-chart). This function ignores the normalization() and thus any scale given by the x-axis. Use this normalization if you would like each individual bin to represent the average number of points which fall into that bin.
If on the other hand you would like each bin to represent the probability density of falling into that bin, you should use normalized() instead.
Definition at line 523 of file histogram.h.
|
inline |
Pretty-print the histogram and return it as a string with horizontal bars.
max_width | is the maximum line width the display should fit in. |
Definition at line 535 of file histogram.h.
|
inline |
Record a new value in the histogram.
This adds one to the bin corresponding to the given value.
If the value is out of the histogram range, then off_chart is incremented by one.
Returns the index of the bin in which the value was added, or -1 if off-chart.
Definition at line 426 of file histogram.h.
|
inline |
Record a new value in the histogram, with a certain weight.
This adds weight to the histogram bin corresponding to the given value.
If the value is out of the histogram range, then off_chart is incremented by weight.
Returns the index of the bin in which the value was added, or -1 if off-chart.
Definition at line 447 of file histogram.h.
|
inline |
Return the total number of histogram counts (no normalization)
This returns the sum of all bin contents, plus the off_chart counts. This does not account for the normalization and completely ignores the x-axis scaling.
This is literally just bins.sum() + off_chart
.
Definition at line 506 of file histogram.h.