SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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>

Collaboration diagram for THist:

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.

References BucketSize, MnVal, and MxVal.

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.

References BucketSize, BucketV, EAssert, TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::Len(), MnVal, MxVal, and Vals.

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:575
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
#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

Here is the call graph for this function:

double THist::GetBucketMn ( const int &  BucketN) const
inline

Definition at line 473 of file xmath.h.

References BucketSize, and MnVal.

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.

References BucketSize, and MnVal.

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.

References BucketV, and TVec< TVal, TSizeTy >::Len().

472 { return BucketV.Len(); }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TIntV BucketV
Definition: xmath.h:460

Here is the call graph for this function:

int THist::GetBucketVal ( const int &  BucketN) const
inline

Definition at line 475 of file xmath.h.

References BucketV.

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.

References BucketV, and Vals.

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.

References Vals.

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.

References BucketSize, BucketV, TStr::Fmt(), TInt::GetStr(), TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::Len(), TSOut::PutStrLn(), and Vals.

Referenced by SaveTxt().

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:1197
TInt Vals
Definition: xmath.h:462
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:579
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

Here is the call graph for this function:

Here is the caller graph for this function:

void THist::SaveTxt ( const TStr ValNm,
const TStr FNm 
) const
inline

Definition at line 480 of file xmath.h.

References SaveStat().

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

Here is the call graph for this function:

Member Data Documentation

TFlt THist::BucketSize
private

Definition at line 461 of file xmath.h.

Referenced by Add(), GetBucketMn(), GetBucketMx(), SaveStat(), and THist().

TIntV THist::BucketV
private

Definition at line 460 of file xmath.h.

Referenced by Add(), GetBuckets(), GetBucketVal(), GetBucketValPerc(), and SaveStat().

TFlt THist::MnVal
private

Definition at line 458 of file xmath.h.

Referenced by Add(), GetBucketMn(), GetBucketMx(), and THist().

TFlt THist::MxVal
private

Definition at line 459 of file xmath.h.

Referenced by Add(), and THist().

TInt THist::Vals
private

Definition at line 462 of file xmath.h.

Referenced by Add(), GetBucketValPerc(), GetVals(), and SaveStat().


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