I have noticed, it++ lacks histogram functionality in stat.h. I have got a template class implementing histogram computations. Please let me know if you are intersted in integrating it into the library.
/*!
\file
\brief Class for Histogram computation
\author Andy Panov
$Revision: $
$Date: $
*/
ifndef __histogram_h
define __histogram_h
include "base/matfunc.h"
include "base/vec.h"
namespace itpp{
//! \addtogroup statistics
//!@{
/*! \brief A class for the histogram computation*/template<classT>classHistogram{public://!Constructorconstructshistogramwith100binsbydefaultspanningvaluesfrom0to99Histogram(Tfrom=0,Tto=99,intn_bins=100);//!Virtualdestructorvirtual~Histogram(){};//!Histogramupdatevoidupdate(Tvalue);//!Binsreset,soaccumulationcanberestartedvoidreset(){trials_cnt=0;bins.zeros();};//!Accesstosinglebinintget_bin(intix)const{returnbins[ix];};//!Accesstohistogramasavectorivecget_bins()const{ivecret=bins;returnret;};//!AccesstobincentersVec<T>get_bin_vals()const{Vec<T>ret=center_vals;returnret;};Tget_bin_val(intix)const{returncenter_vals[ix];};//!ExperimentalProbabilityDensityFunction(PDF)computationvecget_pdf()const;//!ExperimentalCumulativeDensityFunction(CDF)computationvecget_cdf()const;//!Currentnumberofbinsintbins_num()const{returnnum_bins;};private://!Numberofprocessedsamplesinttrials_cnt;//!Numberofbinsintnum_bins;//!StepbetweenbinsTstep;//!LowboundariesofhistogrambinsVec<T>low_vals;//!UpperboundariesofhistogrambinsVec<T>hi_vals;//!BincentersVec<T>center_vals;//!Binsstorageivecbins;};template<classT>inlineHistogram<T>::Histogram(Tfrom,Tto,intn_bins):num_bins(n_bins),low_vals(n_bins),hi_vals(n_bins),center_vals(n_bins),bins(n_bins),trials_cnt(0){step=(to-from)/(num_bins-1);center_vals=linspace(from,to,num_bins);low_vals=center_vals-step/2;hi_vals=center_vals+step/2;reset();}////Histogrammethods.Inliningisusedtospeedthingsup.//template<classT>inlinevoidHistogram<T>::update(Tvalue){//searchforthecorrespondingbin//usingdichotomyapproachintstart=0;intend=num_bins-1;inttest=(start+end)/2;;while(start<end){if(value<low_vals[test])end=test-1;elseif(value>=hi_vals[test])start=test+1;elsebreak;test=(start+end)/2;};bins[test]+=1;trials_cnt++;}template<classT>inlinevecHistogram<T>::get_pdf()const{vecpdf(num_bins);for(intj=0;j<num_bins;j++)pdf[j]=static_cast<double>(bins[j])/trials_cnt;returnpdf;}template<classT>inlinevecHistogram<T>::get_cdf()const{ivectmp=cumsum(bins);veccdf(num_bins);for(intj=0;j<num_bins;j++)cdf[j]=static_cast<double>(tmp[j])/trials_cnt;returncdf;}
}
endif //#ifndef __histogram_h
Best regards.
Andy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for your contribution. Of couse, we are open to include new functions and classes to the IT++ library. But first we need to check out if everything new fits IT++ and works as expected.
To help us, could you please post a patch or a new file to the Feature Requests tracker, so your contribution will not get lost in the forum threads.
Thanks in advance!
BR,
/ediap
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi ediap,
I have noticed, it++ lacks histogram functionality in stat.h. I have got a template class implementing histogram computations. Please let me know if you are intersted in integrating it into the library.
/*!
\file
\brief Class for Histogram computation
\author Andy Panov
$Revision: $
$Date: $
*/
ifndef __histogram_h
define __histogram_h
include "base/matfunc.h"
include "base/vec.h"
namespace itpp{
//! \addtogroup statistics
//!@{
}
endif //#ifndef __histogram_h
Best regards.
Andy.
Hi Adam
I gonna put the source to the Feature Requests tracker tomorrow.
Best Regards.
Andy.
Hi Andy,
Thanks for your contribution. Of couse, we are open to include new functions and classes to the IT++ library. But first we need to check out if everything new fits IT++ and works as expected.
To help us, could you please post a patch or a new file to the Feature Requests tracker, so your contribution will not get lost in the forum threads.
Thanks in advance!
BR,
/ediap