⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histogram.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
字号:
// file: $isip/class/stat/Histogram/Histogram.h// version: $Id: Histogram.h,v 1.2 2001/12/26 22:32:50 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_HISTOGRAM#define ISIP_HISTOGRAM// isip include files//#ifndef ISIP_VECTOR_BYTE#include <VectorByte.h>#endif#ifndef ISIP_VECTOR_DOUBLE#include <VectorDouble.h>#endif#ifndef ISIP_VECTOR_FLOAT#include <VectorFloat.h>#endif#ifndef ISIP_VECTOR_LLONG#include <VectorLlong.h>#endif#ifndef ISIP_VECTOR_LONG#include <VectorLong.h>#endif#ifndef ISIP_VECTOR_SHORT#include <VectorShort.h>#endif#ifndef ISIP_VECTOR_ULLONG#include <VectorUllong.h>#endif#ifndef ISIP_VECTOR_ULONG#include <VectorUlong.h>#endif#ifndef ISIP_VECTOR_USHORT#include <VectorUshort.h>#endif#ifndef ISIP_NAME_MAP#include <NameMap.h>#endif#ifndef ISIP_MEMORY_MANAGER#include <MemoryManager.h>#endif// Histogram: a class for storing, computing, and updating histograms of data.// the Histogram class works under two binning modes:////  CENTERS: bins are represented by their bin centers. values are assigned//            to the bin whose center is closest.////  EDGES: bins are represented by their bin edges. values will be assigned//         to bin 'k' if edge(k) <= value < edge(k+1). the last bin counts//         only those values that exactly match the last bin. values outside//         of the edge boundaries are not counted. the edges must increase//         monotonically with their index.//// Histogram(Vector Y): bins the elements of Y into DEF_NUM_BINS equally spaced//     containers on the range of min(Y), max(Y)// Histogram(Vector Y, long M): bins the elements of Y into M bins// Histogram(Vector Y, Vector X): bins the elements of Y into bins according//     to the bin boundaries specified in X. These boundaries are interpreted//     depending on the binning mode.//class Histogram {  //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //  static const String CLASS_NAME;    //----------------------------------------  //  // i/o related constants  //  //----------------------------------------      static const String DEF_PARAM;  static const String PARAM_MODE;  static const String PARAM_BINS;  static const String PARAM_COUNTS;      //----------------------------------------  //  // other important constants  //  //----------------------------------------  // a static name map  //  static const NameMap MODE_MAP;  //----------------------------------------  //  // default values and arguments  //  //----------------------------------------    static const long DEF_MIN = 0;  static const long DEF_MAX = 1;  static const long DEF_NUM_BINS = 10;    enum BIN_MODE {CENTERS = 0, EDGES, DEF_MODE = CENTERS};  //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 60500;  static const long ERR_BINS = 60501;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:  // bin mode  //  BIN_MODE mode_d;    // bins and counts  //  VectorDouble bins_d;  VectorDouble counts_d;  // a static debug level  //  static Integral::DEBUG debug_level_d;    // a static memory manager  //  static MemoryManager mgr_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:      // method: name  //  static const String& name() {    return CLASS_NAME;  }  // other static methods  //  static boolean diagnose(Integral::DEBUG debug_level);    // method: setDebug  //  static boolean setDebug(Integral::DEBUG debug_level) {    debug_level_d = debug_level;    return true;  }    // other debug methods  //  boolean debug(const unichar* msg) const;  // method: destructor  //  ~Histogram() {}    // method: default constructor  //  Histogram(BIN_MODE mode = DEF_MODE) {    mode_d = mode;  }  // method: copy constructor  //  Histogram(const Histogram& arg) {    assign(arg);  }    // method: assign  //  boolean assign(const Histogram& arg) {    mode_d = arg.mode_d;    bins_d = arg.bins_d;    counts_d = arg.counts_d;    return true;  }  // method: operator=  //  Histogram& operator= (const Histogram& arg) {    assign(arg);    return *this;  }  // method: sofSize  //  long sofSize() const;    // other i/o methods  //  boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;  boolean readData(Sof& sof, const String& pname = DEF_PARAM,                   long size = SofParser::FULL_OBJECT,                   boolean param = true,                   boolean nested = false);  boolean writeData(Sof& sof, const String& name = DEF_PARAM) const;  // method: eq  //  boolean eq(const Histogram& arg) const {    return((mode_d == arg.mode_d) &&	   bins_d.eq(arg.bins_d) &&	   counts_d.eq(arg.counts_d));  }  // memory management methods  //  // method: new  //  static void* operator new(size_t size) {    return mgr_d.get();  }  // method: new[]  //  static void* operator new[](size_t size) {    return mgr_d.getBlock(size);  }  // method: delete  //  static void operator delete(void* ptr) {    mgr_d.release(ptr);  }  // method: delete[]  //  static void operator delete[](void* ptr) {    mgr_d.releaseBlock(ptr);  }    // method: setGrowSize  //   static boolean setGrowSize(long grow_size) {    return mgr_d.setGrow(grow_size);  }  // method: clear  //  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  set methods  //  //---------------------------------------------------------------------------  // method: setMode  //  if the mode is changed then the counts and bins are reset  //  boolean setMode(BIN_MODE mode) {    mode_d = mode;    bins_d.clear();    counts_d.clear();    return true;  }    // methods to manually initialize the bins  //  in all cases, the counts vector is reset to all zeros.  //  Any data type can be used to set the bins (float, double, long, etc.)  //  template <class TVector>  boolean setBins(const TVector& bins);  template <class T1, class T2>  boolean setBins(T1 min = DEF_MIN, T2 max = DEF_MAX,		  long num_bins = DEF_NUM_BINS);    // methods to manually initialize the counts  //  in all cases, the length of the input vectors must be the same as the  //  current length of the bins vector  //  template <class TVector>  boolean setCounts(const TVector& counts);    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  get methods  //  //---------------------------------------------------------------------------   // method: getMode  //  BIN_MODE getMode() {    return mode_d;  }    // method: getBins  //  boolean getBins(VectorDouble& bins) {    return bins.assign(bins_d);  }    // method: getCounts  //  template <class TVector>  boolean getCounts(TVector& counts) {    return counts.assign(counts_d);  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  histogram computation methods. all methods operate on any numerical  //  input type  //  //---------------------------------------------------------------------------  // methods to compute a histogram  //  compute(Vector values): 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)]  //  compute(Vector value, long num_bins): bins the elements of 'values' into  //     num_bins equally spaced bins  //  compute(Vector values, Vector bins): bins the elements of 'values' into  //     bins according to the bin boundaries specified in 'bins'. These  //     boundaries are interpreted depending on mode_d  //  template <class TVector>  boolean compute(const TVector& values);  template <class TVector>  boolean compute(const TVector& values, long num_bins);  template <class TVector>  boolean compute(const TVector& values, const TVector& bins);  // methods to update the histogram counts  //  this method adds to the binned counts rather than overwriting them  //  template <class TVector>  boolean update(const TVector& values);    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  histogram normalization methods  //  //---------------------------------------------------------------------------  // probability distribution methods  //  boolean pdf(VectorDouble& pdf) const;  boolean cdf(VectorDouble& cdf) const;  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  display methods  //  //---------------------------------------------------------------------------  // pretty-printing methods  //  boolean prettyPrint() const;    //---------------------------------------------------------------------------  //  // private methods  //  //---------------------------------------------------------------------------private:  };// end of include file// #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -