SNAP Library 2.0, Developer 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>

Collaboration diagram for THist:

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.

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

                                                      {
        // 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++;
}

Here is the call graph for this function:

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

Definition at line 471 of file xmath.h.

References BucketSize, and MnVal.

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

Definition at line 472 of file xmath.h.

References BucketSize, and MnVal.

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

Definition at line 470 of file xmath.h.

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

{ return BucketV.Len(); }

Here is the call graph for this function:

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

Definition at line 473 of file xmath.h.

References BucketV.

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

Definition at line 474 of file xmath.h.

References BucketV, and Vals.

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

Definition at line 469 of file xmath.h.

References Vals.

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

Definition at line 1291 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().

                                                         {
    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()()));
    }

}

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

References SaveStat().

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

Here is the call graph for this function:


Member Data Documentation

Definition at line 459 of file xmath.h.

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

TIntV THist::BucketV [private]

Definition at line 458 of file xmath.h.

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

TFlt THist::MnVal [private]

Definition at line 456 of file xmath.h.

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

TFlt THist::MxVal [private]

Definition at line 457 of file xmath.h.

Referenced by Add().

TInt THist::Vals [private]

Definition at line 460 of file xmath.h.

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


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