📄 hist_07.cc
字号:
// file: $isip/class/numeric/Histogram/hist_07.cc// version: $Id: hist_07.cc,v 1.1 2001/02/01 16:47:51 hamaker Exp $//// isip include files//#include "Histogram.h"// method: compute//// arguments:// const TVector& values: (input) values to histogram//// return: boolean value indicating status//// this method bins the elements of 'values' into the bins that are already// set. If no bins are set, then it bins the 'values' into DEF_NUM_BINS// equally spaced containers on the range of [min(values), max(values)]//template <class TVector>boolean Histogram::compute(const TVector& values_a) { // see if we are already binned // if (bins_d.length() == 0) { // get the min and max of the data // double min = values_a.min(); double max = values_a.max(); // set the bins // setBins(min, max, DEF_NUM_BINS); } else { // we still need to clear out any old counts // counts_d.assign(0.0); } // update the counts // return update(values_a);}// explicit instantiations//template booleanHistogram::compute<VectorByte>(const VectorByte&);template booleanHistogram::compute<VectorDouble>(const VectorDouble&);template booleanHistogram::compute<VectorFloat>(const VectorFloat&);template booleanHistogram::compute<VectorLlong>(const VectorLlong&);template booleanHistogram::compute<VectorLong>(const VectorLong&);template booleanHistogram::compute<VectorShort>(const VectorShort&);template booleanHistogram::compute<VectorUllong>(const VectorUllong&);template booleanHistogram::compute<VectorUlong>(const VectorUlong&);template booleanHistogram::compute<VectorUshort>(const VectorUshort&);// method: compute//// arguments:// const TVector& values: (input) values to histogram// long num_bins: (input) number of bins to split data into//// return: boolean value indicating status//// this method creates a histogram using num_bins bins on the range// of min(values), max(values)//template <class TVector>boolean Histogram::compute(const TVector& values_a, long num_bins_a) { // get the min and max of the data // double min = values_a.min(); double max = values_a.max(); // set the bins // setBins(min, max, num_bins_a); // update the counts // return update(values_a);}// explicit instantiations//template booleanHistogram::compute<VectorByte>(const VectorByte&, long);template booleanHistogram::compute<VectorDouble>(const VectorDouble&, long);template booleanHistogram::compute<VectorFloat>(const VectorFloat&, long);template booleanHistogram::compute<VectorLlong>(const VectorLlong&, long);template booleanHistogram::compute<VectorLong>(const VectorLong&, long);template booleanHistogram::compute<VectorShort>(const VectorShort&, long);template booleanHistogram::compute<VectorUllong>(const VectorUllong&, long);template booleanHistogram::compute<VectorUlong>(const VectorUlong&, long);template booleanHistogram::compute<VectorUshort>(const VectorUshort&, long);// method: compute//// arguments:// const TVector& values: (input) values to histogram// const TVector& bins: (input) bin endpoints//// return: boolean value indicating status//// this method creates a histogram using the given bin boundaries and// input data//template <class TVector>boolean Histogram::compute(const TVector& values_a, const TVector& bins_a) { // set the bins // setBins(bins_a); // update the counts // return update(values_a);}// explicit instantiations//template booleanHistogram::compute<VectorByte>(const VectorByte&, const VectorByte&);template booleanHistogram::compute<VectorDouble>(const VectorDouble&, const VectorDouble&);template booleanHistogram::compute<VectorFloat>(const VectorFloat&, const VectorFloat&);template booleanHistogram::compute<VectorLlong>(const VectorLlong&, const VectorLlong&);template booleanHistogram::compute<VectorLong>(const VectorLong&, const VectorLong&);template booleanHistogram::compute<VectorShort>(const VectorShort&, const VectorShort&);template booleanHistogram::compute<VectorUllong>(const VectorUllong&, const VectorUllong&);template booleanHistogram::compute<VectorUlong>(const VectorUlong&, const VectorUlong&);template booleanHistogram::compute<VectorUshort>(const VectorUshort&, const VectorUshort&);// method: update//// arguments:// const TVector& values: (input) values to histogram//// return: boolean value indicating status//// this method updates the current histogram counts with the values passed// in//template <class TVector>boolean Histogram::update(const TVector& values_a) { // verify that the bins are set // if ((bins_d.length() == 0) || (counts_d.length() != bins_d.length())) { return Error::handle(name(), L"update", ERR_BINS, __FILE__, __LINE__); } // define local variables // double value = 0; double diffi = 0; double diffip1 = 0; boolean counted = false; // the counting algorithm varies with the bin mode // if (mode_d == CENTERS) { // loop over the input data and accumulate the counts // long data_length = values_a.length(); long last_bin = bins_d.length() - 1; for (long k = 0; k < data_length; k++) { value = (double)values_a(k); diffi = Integral::abs(bins_d(0) - value); diffip1 = 0; counted = false; for (long i = 0; i < last_bin; i++) { // count for bin(i) if abs(bin(i) - value) < abs(bin(i+1) - value) // diffip1 = Integral::abs(bins_d(i+1) - value); if (diffi <= diffip1) { counts_d(i) += 1; counted = true; break; } diffi = diffip1; } // check the last bin // if (!counted) { counts_d(last_bin) += 1; } } } else if (mode_d == EDGES) { // loop over the input data and accumulate the counts // long data_length = values_a.length(); long last_bin = bins_d.length() - 1; for (long k = 0; k < data_length; k++) { double value = (double)values_a(k); for (long i = 0; i < last_bin; i++) { // count for bin(i) if bin(i) <= value < bin(i+1) // if ((value >= bins_d(i)) && (value < bins_d(i+1))) { counts_d(i) += 1; break; } } // check the last bin // if (value == bins_d(last_bin)) { counts_d(last_bin) += 1; } } } // exit gracefully // return true;}// explicit instantiations//template booleanHistogram::update<VectorByte>(const VectorByte&);template booleanHistogram::update<VectorDouble>(const VectorDouble&);template booleanHistogram::update<VectorFloat>(const VectorFloat&);template booleanHistogram::update<VectorLlong>(const VectorLlong&);template booleanHistogram::update<VectorLong>(const VectorLong&);template booleanHistogram::update<VectorShort>(const VectorShort&);template booleanHistogram::update<VectorUllong>(const VectorUllong&);template booleanHistogram::update<VectorUlong>(const VectorUlong&);template booleanHistogram::update<VectorUshort>(const VectorUshort&);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -