SNAP Library 2.0, User Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
THist Class Reference

#include <xmath.h>

List of all members.

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 454 of file xmath.h.


Constructor & Destructor Documentation

THist::THist ( ) [inline]

Definition at line 462 of file xmath.h.

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

Definition at line 463 of file xmath.h.

                                                                         :
      MnVal(_MnVal), MxVal(_MxVal), BucketV(Buckets),
          BucketSize(1.01 * double(MxVal - MnVal) / double(Buckets)) { }

Member Function Documentation

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

Definition at line 1270 of file xmath.cpp.

                                                      {
        // get bucket number
    const int BucketN = int(floor((Val - MnVal) / BucketSize));
        if (OnlyInP) { 
                // value should be inside
                EAssert(MnVal <= Val && Val <= MxVal);
                BucketV[BucketN]++;
        } else {
                // value does not need to be inside
                if (BucketN < 0) {
                        BucketV[0]++;
                } else if (BucketN < BucketV.Len()) {
                        BucketV[BucketN]++;
                } else {
                        BucketV.Last()++;
                }
        }
        // for computing percentage
        Vals++;
}
double THist::GetBucketMn ( const int &  BucketN) const [inline]

Definition at line 471 of file xmath.h.

{ return MnVal + BucketN * BucketSize; }
double THist::GetBucketMx ( const int &  BucketN) const [inline]

Definition at line 472 of file xmath.h.

{ return MnVal + (BucketN + 1) * BucketSize; }
int THist::GetBuckets ( ) const [inline]

Definition at line 470 of file xmath.h.

{ return BucketV.Len(); }
int THist::GetBucketVal ( const int &  BucketN) const [inline]

Definition at line 473 of file xmath.h.

{ return BucketV[BucketN]; }
double THist::GetBucketValPerc ( const int &  BucketN) const [inline]

Definition at line 474 of file xmath.h.

                                                          { 
                return (Vals > 0) ? (double(BucketV[BucketN]) / double(Vals)) : 0.0; }
int THist::GetVals ( ) const [inline]

Definition at line 469 of file xmath.h.

{ return Vals; }
void THist::SaveStat ( const TStr ValNm,
TSOut FOut 
) const

Definition at line 1291 of file xmath.cpp.

                                                         {
    FOut.PutStrLn("#" + ValNm + ": " + Vals.GetStr());
    const int Buckets = BucketV.Len() - 1;
    for (int BucketN = 0; BucketN < Buckets; BucketN++) {
        FOut.PutStrLn(TStr::Fmt("%d-%d\t%d", BucketSize*BucketN,
            BucketSize*(BucketN+1), BucketV[BucketN]()));
    }
    if (BucketV.Last() > 0) {
        FOut.PutStrLn(TStr::Fmt("%d-\t%d", BucketSize*Buckets, BucketV.Last()()));
    }

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

Definition at line 478 of file xmath.h.

                                                           {
        TFOut FOut(FNm); SaveStat(ValNm, FOut); }

Member Data Documentation

Definition at line 459 of file xmath.h.

TIntV THist::BucketV [private]

Definition at line 458 of file xmath.h.

TFlt THist::MnVal [private]

Definition at line 456 of file xmath.h.

TFlt THist::MxVal [private]

Definition at line 457 of file xmath.h.

TInt THist::Vals [private]

Definition at line 460 of file xmath.h.


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