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
|
#include <xmath.h>
Public Member Functions | |
TMom () | |
TMom (const TMom &Mom) | |
TMom (const TFltV &_ValV) | |
TMom (TSIn &SIn) | |
void | Save (TSOut &SOut) const |
TMom & | operator= (const TMom &Mom) |
bool | operator== (const TMom &Mom) const |
bool | operator< (const TMom &Mom) const |
void | Def () |
bool | IsDef () const |
void | Add (const TFlt &Val, const TFlt &Wgt=1) |
double | GetWgt () const |
int | GetVals () const |
TFlt | GetVal (const int &ValN) const |
bool | IsUsable () const |
double | GetMn () const |
double | GetMx () const |
double | GetExtent () const |
double | GetMean () const |
double | GetVari () const |
double | GetSDev () const |
double | GetSErr () const |
double | GetMedian () const |
double | GetQuart1 () const |
double | GetQuart3 () const |
double | GetDecile (const int &DecileN) const |
double | GetPercentile (const int &PercentileN) const |
double | GetByNm (const TStr &MomNm) const |
TStr | GetStrByNm (const TStr &MomNm, char *FmtStr=NULL) const |
TStr | GetStr (const char &SepCh=' ', const char &DelimCh=':', const bool &DecileP=true, const bool &PercentileP=true, const TStr &FmtStr="%g") const |
TStr | GetValVStr (const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true) const |
Static Public Member Functions | |
static PMom | New () |
static void | NewV (TMomV &MomV, const int &Moms) |
static void | NewVV (TVVec< PMom > &MomVV, const int &XMoms, const int &YMoms) |
static PMom | New (const TFltV &ValV) |
static PMom | Load (TSIn &SIn) |
static void | DefV (TMomV &MomV) |
static void | DefVV (TVVec< PMom > &MomVV) |
static bool | IsUsableV (const TMomV &MomV) |
static bool | IsUsableVV (const TVVec< PMom > &MomVV) |
static TStr | GetNmVStr (const TStr &VarPfx, const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true) |
Private Attributes | |
TCRef | CRef |
TBool | DefP |
TFltPrV | ValWgtV |
TFlt | SumW |
TFlt | ValSumW |
TInt | Vals |
TBool | UsableP |
TFlt | UnusableVal |
TFlt | Mn |
TFlt | Mx |
TFlt | Mean |
TFlt | Vari |
TFlt | SDev |
TFlt | SErr |
TFlt | Median |
TFlt | Quart1 |
TFlt | Quart3 |
TFltV | DecileV |
TFltV | PercentileV |
Friends | |
class | TPt< TMom > |
TMom::TMom | ( | ) | [inline] |
TMom::TMom | ( | const TMom & | Mom | ) | [inline] |
Definition at line 151 of file xmath.h.
: DefP(Mom.DefP), ValWgtV(Mom.ValWgtV), SumW(Mom.SumW), ValSumW(Mom.ValSumW), Vals(Mom.Vals), UsableP(Mom.UsableP), UnusableVal(Mom.UnusableVal), Mn(Mom.Mn), Mx(Mom.Mx), Mean(Mom.Mean), Vari(Mom.Vari), SDev(Mom.SDev), SErr(Mom.SErr), Median(Mom.Median), Quart1(Mom.Quart1), Quart3(Mom.Quart3), DecileV(Mom.DecileV), PercentileV(Mom.PercentileV){}
TMom::TMom | ( | const TFltV & | _ValV | ) |
TMom::TMom | ( | TSIn & | SIn | ) | [inline] |
void TMom::Def | ( | ) |
Definition at line 339 of file xmath.cpp.
{ IAssert(!DefP); DefP=true; UsableP=(SumW>0)&&(ValWgtV.Len()>0); if (UsableP){ // Mn, Mx Mn=ValWgtV[0].Val1; Mx=ValWgtV[0].Val1; // Mean, Variance (Mn, Mx), Standard-Error Mean=ValSumW/SumW; Vari=0; if (ValWgtV.Len()>1){ for (int ValN=0; ValN<ValWgtV.Len(); ValN++){ const double Val=ValWgtV[ValN].Val1; Vari+=ValWgtV[ValN].Val2*TMath::Sqr(Val-Mean); if (Val<Mn){Mn=Val;} if (Val>Mx){Mx=Val;} } Vari=Vari/SumW; SErr=sqrt(Vari/(ValWgtV.Len()*(ValWgtV.Len()-1))); } // Standard-Deviation SDev=sqrt(double(Vari)); // Median ValWgtV.Sort(); double CurSumW = 0; for (int ValN=0; ValN<ValWgtV.Len(); ValN++){ CurSumW += ValWgtV[ValN].Val2; if (CurSumW > 0.5*SumW) { Median = ValWgtV[ValN].Val1; break; } else if (CurSumW == 0.5*SumW) { Median = 0.5 * (ValWgtV[ValN].Val1+ValWgtV[ValN+1].Val1); break; } } // Quartile-1 and Quartile-3 Quart1=Quart3=TFlt::Mn; CurSumW = 0; for (int ValN=0; ValN<ValWgtV.Len(); ValN++){ CurSumW += ValWgtV[ValN].Val2; if (Quart1==TFlt::Mn) { if (CurSumW > 0.25*SumW) { Quart1 = ValWgtV[ValN].Val1; } //else if (CurSumW == 0.25*SumW) { Quart1 = 0.5 * (ValWgtV[ValN].Val1+ValWgtV[ValN+1].Val1); } } if (Quart3==TFlt::Mn) { if (CurSumW > 0.75*SumW) { Quart3 = ValWgtV[ValN].Val1; } //else if (CurSumW == 0.75*SumW) { Quart3 = 0.5 * (ValWgtV[ValN].Val1+ValWgtV[ValN+1].Val1); } } } // Deciles & Percentiles CurSumW = 0; int DecileN = 1, PercentileN = 1; DecileV.Gen(11); PercentileV.Gen(101); DecileV[0]=Mn; DecileV[10]=Mx; PercentileV[0]=Mn; PercentileV[100]=Mx; for (int ValN=0; ValN<ValWgtV.Len(); ValN++){ CurSumW += ValWgtV[ValN].Val2; if (CurSumW > SumW*DecileN*0.1) { DecileV[DecileN] = ValWgtV[ValN].Val1; DecileN++; } if (CurSumW > SumW*PercentileN*0.01) { PercentileV[PercentileN] = ValWgtV[ValN].Val1; PercentileN++; } } } ValWgtV.Clr(); }
static void TMom::DefV | ( | TMomV & | MomV | ) | [inline, static] |
static void TMom::DefVV | ( | TVVec< PMom > & | MomVV | ) | [inline, static] |
double TMom::GetByNm | ( | const TStr & | MomNm | ) | const |
Definition at line 404 of file xmath.cpp.
{ if (MomNm=="Mean"){return GetMean();} else if (MomNm=="Vari"){return GetVari();} else if (MomNm=="SDev"){return GetSDev();} else if (MomNm=="SErr"){return GetSErr();} else if (MomNm=="Median"){return GetMedian();} else if (MomNm=="Quart1"){return GetQuart1();} else if (MomNm=="Quart3"){return GetQuart3();} else if (MomNm=="Decile0"){return GetDecile(0);} else if (MomNm=="Decile1"){return GetDecile(1);} else if (MomNm=="Decile2"){return GetDecile(2);} else if (MomNm=="Decile3"){return GetDecile(3);} else if (MomNm=="Decile4"){return GetDecile(4);} else if (MomNm=="Decile5"){return GetDecile(5);} else if (MomNm=="Decile6"){return GetDecile(6);} else if (MomNm=="Decile7"){return GetDecile(7);} else if (MomNm=="Decile8"){return GetDecile(8);} else if (MomNm=="Decile9"){return GetDecile(9);} else if (MomNm=="Decile10"){return GetDecile(10);} else {Fail; return 0;} }
double TMom::GetDecile | ( | const int & | DecileN | ) | const [inline] |
double TMom::GetExtent | ( | ) | const [inline] |
double TMom::GetMean | ( | ) | const [inline] |
double TMom::GetMedian | ( | ) | const [inline] |
double TMom::GetMn | ( | ) | const [inline] |
double TMom::GetMx | ( | ) | const [inline] |
TStr TMom::GetNmVStr | ( | const TStr & | VarPfx, |
const char & | SepCh = '\t' , |
||
const bool & | DecileP = true , |
||
const bool & | PercentileP = true |
||
) | [static] |
Definition at line 475 of file xmath.cpp.
{ TChA ChA; ChA+=VarPfx; ChA+="Vals"; ChA+=SepCh; ChA+=VarPfx; ChA+="Min"; ChA+=SepCh; ChA+=VarPfx; ChA+="Max"; ChA+=SepCh; ChA+=VarPfx; ChA+="Mean"; ChA+=SepCh; //ChA+=VarPfx; ChA+="Vari"; ChA+=SepCh; ChA+=VarPfx; ChA+="SDev"; ChA+=SepCh; //ChA+=VarPfx; ChA+="SErr"; ChA+=SepCh; ChA+=VarPfx; ChA+="Quart1"; ChA+=SepCh; ChA+=VarPfx; ChA+="Median"; ChA+=SepCh; ChA+=VarPfx; ChA+="Quart3"; if (DecileP){ ChA+=SepCh; for (int DecileN=0; DecileN<=10; DecileN++){ ChA+=VarPfx; ChA+="Dec"; ChA+=TInt::GetStr(DecileN); if (DecileN<10){ChA+=SepCh;} } } if (PercentileP){ ChA+=SepCh; for (int PercentileN=0; PercentileN<=100; PercentileN++){ ChA+=VarPfx; ChA+="Per"; ChA+=TInt::GetStr(PercentileN); if (PercentileN<100){ChA+=SepCh;} } } return ChA; }
double TMom::GetPercentile | ( | const int & | PercentileN | ) | const [inline] |
double TMom::GetQuart1 | ( | ) | const [inline] |
double TMom::GetQuart3 | ( | ) | const [inline] |
double TMom::GetSDev | ( | ) | const [inline] |
double TMom::GetSErr | ( | ) | const [inline] |
TStr TMom::GetStr | ( | const char & | SepCh = ' ' , |
const char & | DelimCh = ':' , |
||
const bool & | DecileP = true , |
||
const bool & | PercentileP = true , |
||
const TStr & | FmtStr = "%g" |
||
) | const |
Definition at line 438 of file xmath.cpp.
{ TChA ChA; if (IsUsable()){ ChA+="["; ChA+=SepCh; ChA+="Vals"; ChA+=DelimCh; ChA+=TInt::GetStr(GetVals()); ChA+=SepCh; ChA+="Min"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetMn(), FmtStr.CStr()); ChA+=SepCh; ChA+="Max"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetMx(), FmtStr.CStr()); ChA+=SepCh; ChA+="Mean"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetMean(), FmtStr.CStr()); ChA+=SepCh; //ChA+="Vari"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetVari(), FmtStr.CStr()); ChA+=SepCh; ChA+="SDev"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetSDev(), FmtStr.CStr()); ChA+=SepCh; //ChA+="SErr"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetSErr(), FmtStr.CStr()); ChA+=SepCh; ChA+="Quart1"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetQuart1(), FmtStr.CStr()); ChA+=SepCh; ChA+="Median"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetMedian(), FmtStr.CStr()); ChA+=SepCh; ChA+="Quart3"; ChA+=DelimCh; ChA+=TFlt::GetStr(GetQuart3(), FmtStr.CStr()); ChA+=SepCh; if (DecileP){ for (int DecileN=0; DecileN<=10; DecileN++){ ChA+="Dec"; ChA+=TInt::GetStr(DecileN); ChA+=DelimCh; ChA+=TFlt::GetStr(GetDecile(DecileN), FmtStr.CStr()); ChA+=SepCh; } } if (PercentileP){ for (int PercentileN=0; PercentileN<=100; PercentileN++){ ChA+="Per"; ChA+=TInt::GetStr(PercentileN); ChA+=DelimCh; ChA+=TFlt::GetStr(GetPercentile(PercentileN), FmtStr.CStr()); ChA+=SepCh; } } ChA+="]"; } else { ChA="[Unusable]"; } return ChA; }
TStr TMom::GetStrByNm | ( | const TStr & | MomNm, |
char * | FmtStr = NULL |
||
) | const |
Definition at line 426 of file xmath.cpp.
{ if (IsUsable()){ if (FmtStr==NULL){ return TFlt::GetStr(GetByNm(MomNm)); } else { return TFlt::GetStr(GetByNm(MomNm), FmtStr); } } else { return "X"; } }
TFlt TMom::GetVal | ( | const int & | ValN | ) | const [inline] |
int TMom::GetVals | ( | ) | const [inline] |
TStr TMom::GetValVStr | ( | const char & | SepCh = '\t' , |
const bool & | DecileP = true , |
||
const bool & | PercentileP = true |
||
) | const |
Definition at line 505 of file xmath.cpp.
{ TChA ChA; if (IsUsable()){ ChA+=TInt::GetStr(GetVals()); ChA+=SepCh; ChA+=TFlt::GetStr(GetMn()); ChA+=SepCh; ChA+=TFlt::GetStr(GetMx()); ChA+=SepCh; ChA+=TFlt::GetStr(GetMean()); ChA+=SepCh; //ChA+=TFlt::GetStr(GetVari()); ChA+=SepCh; ChA+=TFlt::GetStr(GetSDev()); ChA+=SepCh; //ChA+=TFlt::GetStr(GetSErr()); ChA+=SepCh; ChA+=TFlt::GetStr(GetQuart1()); ChA+=SepCh; ChA+=TFlt::GetStr(GetMedian()); ChA+=SepCh; ChA+=TFlt::GetStr(GetQuart3()); ChA+=SepCh; if (DecileP){ for (int DecileN=0; DecileN<=10; DecileN++){ ChA+=TFlt::GetStr(GetDecile(DecileN)); ChA+=SepCh; } } if (PercentileP){ for (int PercentileN=0; PercentileN<=100; PercentileN++){ ChA+=TFlt::GetStr(GetPercentile(PercentileN)); ChA+=SepCh; } } } else { int Vals=8; if (DecileP){Vals+=11;} if (PercentileP){Vals+=101;} for (int ValN=0; ValN<Vals; ValN++){ ChA="[Unusable]"; if (ValN<Vals-1){ChA+=SepCh;} } } return ChA; }
double TMom::GetVari | ( | ) | const [inline] |
double TMom::GetWgt | ( | ) | const [inline] |
bool TMom::IsDef | ( | ) | const [inline] |
bool TMom::IsUsable | ( | ) | const [inline] |
static bool TMom::IsUsableV | ( | const TMomV & | MomV | ) | [inline, static] |
static bool TMom::IsUsableVV | ( | const TVVec< PMom > & | MomVV | ) | [inline, static] |
static PMom TMom::Load | ( | TSIn & | SIn | ) | [inline, static] |
static void TMom::NewV | ( | TMomV & | MomV, |
const int & | Moms | ||
) | [inline, static] |
static void TMom::NewVV | ( | TVVec< PMom > & | MomVV, |
const int & | XMoms, | ||
const int & | YMoms | ||
) | [inline, static] |
bool TMom::operator< | ( | const TMom & | Mom | ) | const [inline] |
Definition at line 190 of file xmath.h.
{ Assert(!DefP); DefP=Mom.DefP; ValWgtV=Mom.ValWgtV; SumW=Mom.SumW; ValSumW=Mom.ValSumW; Vals=Mom.Vals; UsableP=Mom.UsableP; UnusableVal=Mom.UnusableVal; Mn=Mom.Mn; Mx=Mom.Mx; Mean=Mom.Mean; Vari=Mom.Vari; SDev=Mom.SDev; SErr=Mom.SErr; Median=Mom.Median; Quart1=Mom.Quart1; Quart3=Mom.Quart3; DecileV=Mom.DecileV; PercentileV=Mom.PercentileV; return *this;}
bool TMom::operator== | ( | const TMom & | Mom | ) | const [inline] |
void TMom::Save | ( | TSOut & | SOut | ) | const [inline] |
Definition at line 180 of file xmath.h.
{ DefP.Save(SOut); ValWgtV.Save(SOut); SumW.Save(SOut); ValSumW.Save(SOut); Vals.Save(SOut); UsableP.Save(SOut); UnusableVal.Save(SOut); Mn.Save(SOut); Mx.Save(SOut); Mean.Save(SOut); Vari.Save(SOut); SDev.Save(SOut); SErr.Save(SOut); Median.Save(SOut); Quart1.Save(SOut); Quart3.Save(SOut); DecileV.Save(SOut); PercentileV.Save(SOut);}
TCRef TMom::CRef [private] |
TFltV TMom::DecileV [private] |
TBool TMom::DefP [private] |
TFlt TMom::Mean [private] |
TFlt TMom::Median [private] |
TFltV TMom::PercentileV [private] |
TFlt TMom::Quart1 [private] |
TFlt TMom::Quart3 [private] |
TFlt TMom::SDev [private] |
TFlt TMom::SErr [private] |
TFlt TMom::SumW [private] |
TFlt TMom::UnusableVal [private] |
TBool TMom::UsableP [private] |
TInt TMom::Vals [private] |
TFlt TMom::ValSumW [private] |
TFltPrV TMom::ValWgtV [private] |
TFlt TMom::Vari [private] |