SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
THist Class Reference

#include <xmath.h>

Public Member Functions

 THist ()
 
 THist (const double &_MnVal, const double &_MxVal, const int &Buckets)
 
void Add (const double &Val, const bool &OnlyInP)
 
int GetVals () const
 
int GetBuckets () const
 
double GetBucketMn (const int &BucketN) const
 
double GetBucketMx (const int &BucketN) const
 
int GetBucketVal (const int &BucketN) const
 
double GetBucketValPerc (const int &BucketN) const
 
void SaveStat (const TStr &ValNm, TSOut &FOut) const
 
void SaveTxt (const TStr &ValNm, const TStr &FNm) const
 

Private Attributes

TFlt MnVal
 
TFlt MxVal
 
TIntV BucketV
 
TFlt BucketSize
 
TInt Vals
 

Detailed Description

Definition at line 456 of file xmath.h.

Constructor & Destructor Documentation

THist::THist ( )
inline

Definition at line 464 of file xmath.h.

464 { }
THist::THist ( const double &  _MnVal,
const double &  _MxVal,
const int &  Buckets 
)
inline

Definition at line 465 of file xmath.h.

465  :
466  MnVal(_MnVal), MxVal(_MxVal), BucketV(Buckets) {
467  BucketSize = (MxVal == MnVal) ? 1.0 : (1.01 * double(MxVal - MnVal) / double(Buckets)); }
TFlt MxVal
Definition: xmath.h:459
TIntV BucketV
Definition: xmath.h:460
TFlt BucketSize
Definition: xmath.h:461
TFlt MnVal
Definition: xmath.h:458

Member Function Documentation

void THist::Add ( const double &  Val,
const bool &  OnlyInP 
)

Definition at line 1281 of file xmath.cpp.

1281  {
1282  // get bucket number
1283  const int BucketN = int(floor((Val - MnVal) / BucketSize));
1284  if (OnlyInP) {
1285  // value should be inside
1286  EAssert(MnVal <= Val && Val <= MxVal);
1287  BucketV[BucketN]++;
1288  } else {
1289  // value does not need to be inside
1290  if (BucketN < 0) {
1291  BucketV[0]++;
1292  } else if (BucketN < BucketV.Len()) {
1293  BucketV[BucketN]++;
1294  } else {
1295  BucketV.Last()++;
1296  }
1297  }
1298  // for computing percentage
1299  Vals++;
1300 }
TFlt MxVal
Definition: xmath.h:459
TInt Vals
Definition: xmath.h:462
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:551
#define EAssert(Cond)
Definition: bd.h:280
TIntV BucketV
Definition: xmath.h:460
TFlt BucketSize
Definition: xmath.h:461
TFlt MnVal
Definition: xmath.h:458
double THist::GetBucketMn ( const int &  BucketN) const
inline

Definition at line 473 of file xmath.h.

473 { return MnVal + BucketN * BucketSize; }
TFlt BucketSize
Definition: xmath.h:461
TFlt MnVal
Definition: xmath.h:458
double THist::GetBucketMx ( const int &  BucketN) const
inline

Definition at line 474 of file xmath.h.

474 { return MnVal + (BucketN + 1) * BucketSize; }
TFlt BucketSize
Definition: xmath.h:461
TFlt MnVal
Definition: xmath.h:458
int THist::GetBuckets ( ) const
inline

Definition at line 472 of file xmath.h.

472 { return BucketV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TIntV BucketV
Definition: xmath.h:460
int THist::GetBucketVal ( const int &  BucketN) const
inline

Definition at line 475 of file xmath.h.

475 { return BucketV[BucketN]; }
TIntV BucketV
Definition: xmath.h:460
double THist::GetBucketValPerc ( const int &  BucketN) const
inline

Definition at line 476 of file xmath.h.

476  {
477  return (Vals > 0) ? (double(BucketV[BucketN]) / double(Vals)) : 0.0; }
TInt Vals
Definition: xmath.h:462
TIntV BucketV
Definition: xmath.h:460
int THist::GetVals ( ) const
inline

Definition at line 471 of file xmath.h.

471 { return Vals; }
TInt Vals
Definition: xmath.h:462
void THist::SaveStat ( const TStr ValNm,
TSOut FOut 
) const

Definition at line 1302 of file xmath.cpp.

1302  {
1303  FOut.PutStrLn("#" + ValNm + ": " + Vals.GetStr());
1304  const int Buckets = BucketV.Len() - 1;
1305  for (int BucketN = 0; BucketN < Buckets; BucketN++) {
1306  FOut.PutStrLn(TStr::Fmt("%d-%d\t%d", BucketSize*BucketN,
1307  BucketSize*(BucketN+1), BucketV[BucketN]()));
1308  }
1309  if (BucketV.Last() > 0) {
1310  FOut.PutStrLn(TStr::Fmt("%d-\t%d", BucketSize*Buckets, BucketV.Last()()));
1311  }
1312 
1313 }
TStr GetStr() const
Definition: dt.h:1107
TInt Vals
Definition: xmath.h:462
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:551
TIntV BucketV
Definition: xmath.h:460
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TFlt BucketSize
Definition: xmath.h:461
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
Definition: fl.h:161
void THist::SaveTxt ( const TStr ValNm,
const TStr FNm 
) const
inline

Definition at line 480 of file xmath.h.

480  {
481  TFOut FOut(FNm); SaveStat(ValNm, FOut); }
Definition: fl.h:319
void SaveStat(const TStr &ValNm, TSOut &FOut) const
Definition: xmath.cpp:1302

Member Data Documentation

TFlt THist::BucketSize
private

Definition at line 461 of file xmath.h.

TIntV THist::BucketV
private

Definition at line 460 of file xmath.h.

TFlt THist::MnVal
private

Definition at line 458 of file xmath.h.

TFlt THist::MxVal
private

Definition at line 459 of file xmath.h.

TInt THist::Vals
private

Definition at line 462 of file xmath.h.


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