SNAP Library, User Reference  2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
xmath.h File Reference

Go to the source code of this file.

Classes

class  TMath
class  TSpecFunc
class  TStatTest
class  THist

Typedefs

typedef TVVec< PMom > TMomVV
typedef THash< TInt, PMom > TIntMomH
typedef THash< TInt, TMomV > TIntMomVH
typedef THash< TInt, TMomVVTIntMomVVH

Functions

 TMom ()
 TMom (const TMom &Mom)
static PMom New ()
static void NewV (TMomV &MomV, const int &Moms)
static void NewVV (TVVec< PMom > &MomVV, const int &XMoms, const int &YMoms)
 TMom (const TFltV &_ValV)
static PMom New (const TFltV &ValV)
 TMom (TSIn &SIn)
static PMom Load (TSIn &SIn)
void Save (TSOut &SOut) const
TMomoperator= (const TMom &Mom)
bool operator== (const TMom &Mom) const
bool operator< (const TMom &Mom) const
void Def ()
static void DefV (TMomV &MomV)
static void DefVV (TVVec< PMom > &MomVV)
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
static bool IsUsableV (const TMomV &MomV)
static bool IsUsableVV (const TVVec< PMom > &MomVV)
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
static TStr GetNmVStr (const TStr &VarPfx, const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true)
TStr GetValVStr (const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true) const
 TCorr ()
 TCorr (const TFltV &ValV1, const TFltV &ValV2)
static PCorr New (const TFltV &ValV1, const TFltV &ValV2)
 TCorr (TSIn &)
TCorroperator= (const TCorr &)
double GetCorrCf () const
double GetCorrCfPrb () const
TStr GetStr () const
 TComb ()
 TComb (const int &_Items, const int &_Order)
static PComb New (const int &Items, const int &Order)
 ~TComb ()
 TComb (TSIn &)
TComboperator= (const TComb &)
bool GetNext ()
TIntVGetItemV ()
int GetCombN () const
int GetCombs () const
void Wr ()
void GetXV (const int RecN, TFltV &VarV) const
double GetY (const int RecN) const
double GetSig (const int RecN) const
void NR_covsrt (TFltVV &CovarVV, const int &Vars, const TIntV &ia, const int &mfit)
void NR_gaussj (TFltVV &a, const int &n, TFltVV &b, const int &m)
void NR_lfit ()
 TLinReg ()
static PLinReg New (const TFltVV &XVV, const TFltV &YV, const TFltV &SigV=TFltV())
 ~TLinReg ()
 TLinReg (TSIn &)
TLinRegoperator= (const TLinReg &)
int GetRecs () const
int GetVars () const
double GetCf (const int &VarN) const
double GetCfUncer (const int &VarN) const
double GetCovar (const int &VarN1, const int &VarN2) const
double GetChiSq () const
static double LinInterp (const double &x1, const double &y1, const double &x2, const double &y2, const double &AtX) _CMPWARN
static double NR_SIGN (double a, double b)
static double NR_FMAX (double maxarg1, double maxarg2)
static int NR_IMIN (int iminarg1, int iminarg2)
static double NR_pythag (double a, double b)
static void NR_svdcmp (TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
void NR_svbksb (TFltVV &u, TFltV &w, TFltVV &v, int m, int n, TFltV &b, TFltV &x)
void NR_svdvar (TFltVV &v, int ma, TFltV &w, TFltVV &cvm)
void NR_svdfit ()
 TSvd ()
 ~TSvd ()
 TSvd (TSIn &)
TSvdoperator= (const TSvd &)
void GetCfV (TFltV &_CfV)
void GetCfUncerV (TFltV &CfUncerV)
static void Svd (const TFltVV &InMtx, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
static void Svd1Based (const TFltVV &InMtx1, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)

Variables

ClassTPV(TMom, PMom, TMomV)
private 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
ClassTP(TCorr, PCorr) private
double 
CorrCf
double CorrCfPrb
double FisherZ
ClassTP(TComb, PComb) public int Order
int CombN
TIntV ItemV
ClassTP(TLinReg, PLinReg)
public TFltV 
YV
TFltV SigV
int Recs
int Vars
TFltVV CovarVV
TFltV CfV
double ChiSq

Typedef Documentation

typedef THash<TInt, PMom> TIntMomH

Definition at line 259 of file xmath.h.

typedef THash<TInt, TMomV> TIntMomVH

Definition at line 260 of file xmath.h.

Definition at line 261 of file xmath.h.

typedef TVVec<PMom> TMomVV

Definition at line 257 of file xmath.h.


Function Documentation

void Add ( const TFlt Val,
const TFlt Wgt = 1 
)

Definition at line 214 of file xmath.h.

                                              {Assert(!DefP);
    ValWgtV.Add(TFltPr(Val, Wgt)); SumW+=Wgt; ValSumW+=Wgt*Val; Vals++;}
void Def ( )
static void DefV ( TMomV &  MomV) [static]

Definition at line 205 of file xmath.h.

                               {
    for (int MomN=0; MomN<MomV.Len(); MomN++){MomV[MomN]->Def();}}
static void DefVV ( TVVec< PMom > &  MomVV) [static]

Definition at line 207 of file xmath.h.

                                       {
    for (int XMomN=0; XMomN<MomVV.GetXDim(); XMomN++){
      for (int YMomN=0; YMomN<MomVV.GetYDim(); YMomN++){
        MomVV.At(XMomN, YMomN)->Def();}}}
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 GetCf ( const int &  VarN) const

Definition at line 373 of file xmath.h.

{return CfV[VarN+1];}
double GetCfUncer ( const int &  VarN) const

Definition at line 374 of file xmath.h.

                                           {
    return sqrt(double(CovarVV.At(VarN+1, VarN+1)));}
void TSvd::GetCfUncerV ( TFltV CfUncerV)

Definition at line 1213 of file xmath.cpp.

                                     {
  CfUncerV.Gen(Vars);
  for (int VarN=0; VarN<Vars; VarN++){
    CfUncerV[VarN]=GetCfUncer(VarN);
  }
}
void TSvd::GetCfV ( TFltV _CfV)

Definition at line 1209 of file xmath.cpp.

                            {
  _CfV=CfV; _CfV.Del(0);
}
double GetChiSq ( ) const

Definition at line 379 of file xmath.h.

{return ChiSq;}
int GetCombN ( ) const

Definition at line 334 of file xmath.h.

{return CombN;}
int TComb::GetCombs ( ) const

Definition at line 748 of file xmath.cpp.

                          {
  int LCombs=1; int HCombs=1;
  for (int OrderN=0; OrderN<Order; OrderN++){
    LCombs*=OrderN+1; HCombs*=Items-OrderN;}
  int Combs=HCombs/LCombs;
  return Combs;
}
double GetCorrCf ( ) const

Definition at line 282 of file xmath.h.

{return CorrCf;}
double GetCorrCfPrb ( ) const

Definition at line 283 of file xmath.h.

{return CorrCfPrb;}
double GetCovar ( const int &  VarN1,
const int &  VarN2 
) const

Definition at line 376 of file xmath.h.

                                                            {
    return CovarVV.At(VarN1+1, VarN2+1);}
double GetDecile ( const int &  DecileN) const

Definition at line 244 of file xmath.h.

                                             {
    Assert(DefP&&UsableP); return DecileV[DecileN];}
double GetExtent ( ) const

Definition at line 236 of file xmath.h.

{Assert(DefP&&UsableP); return Mx-Mn;}

Definition at line 333 of file xmath.h.

{return ItemV;}
double GetMean ( ) const

Definition at line 237 of file xmath.h.

{Assert(DefP&&UsableP); return Mean;}
double GetMedian ( ) const

Definition at line 241 of file xmath.h.

{Assert(DefP&&UsableP); return Median;}
double GetMn ( ) const

Definition at line 234 of file xmath.h.

{Assert(DefP&&UsableP); return Mn;}
double GetMx ( ) const

Definition at line 235 of file xmath.h.

{Assert(DefP&&UsableP); return Mx;}
bool TComb::GetNext ( )

Definition at line 724 of file xmath.cpp.

                   {
  if (ItemV.Len()==0){
    ItemV.Gen(Order, Order);
    for (int OrderN=0; OrderN<Order; OrderN++){
      ItemV[OrderN]=OrderN;}
    return true;
  } else {
    if (ItemV.Last()==Items-1){
      int OrderN=Order-1;
      while ((OrderN>=0)&&(ItemV[OrderN]==Items-(Order-OrderN-1)-1)){OrderN--;}
      if (OrderN<0){
        return false;
      } else {
        ItemV[OrderN]++;
        for (int SubOrderN=OrderN+1; SubOrderN<Order; SubOrderN++){
          ItemV[SubOrderN]=ItemV[SubOrderN-1]+1;}
        CombN++; return true;
      }
    } else {
      ItemV.Last()++; CombN++; return true;
    }
  }
}
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 GetPercentile ( const int &  PercentileN) const

Definition at line 246 of file xmath.h.

                                                     {
    Assert(DefP&&UsableP); return PercentileV[PercentileN];}
double GetQuart1 ( ) const

Definition at line 242 of file xmath.h.

{Assert(DefP&&UsableP); return Quart1;}
double GetQuart3 ( ) const

Definition at line 243 of file xmath.h.

{Assert(DefP&&UsableP); return Quart3;}
int GetRecs ( ) const

Definition at line 370 of file xmath.h.

{return Recs;}
double GetSDev ( ) const

Definition at line 239 of file xmath.h.

{Assert(DefP&&UsableP); return SDev;}
double GetSErr ( ) const

Definition at line 240 of file xmath.h.

{Assert(DefP&&UsableP); return SErr;}
double GetSig ( const int  RecN) const

Definition at line 355 of file xmath.h.

{return SigV[RecN-1];}
TStr GetStr ( const char &  SepCh = ' ',
const char &  DelimCh = ':',
const bool &  DecileP = true,
const bool &  PercentileP = true,
const TStr FmtStr = "%g" 
) const
TStr GetStr ( ) const

Definition at line 201 of file html.h.

{return Str;}
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 GetVal ( const int &  ValN) const

Definition at line 218 of file xmath.h.

{IAssert(!IsDef()); return ValWgtV[ValN].Val1;}
int GetVals ( ) const

Definition at line 217 of file xmath.h.

{return Vals;}
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 GetVari ( ) const

Definition at line 238 of file xmath.h.

{Assert(DefP&&UsableP); return Vari;}
int GetVars ( ) const

Definition at line 371 of file xmath.h.

{return Vars;}
double GetWgt ( ) const

Definition at line 216 of file xmath.h.

{return SumW;}
void GetXV ( const int  RecN,
TFltV VarV 
) const

Definition at line 350 of file xmath.h.

                                                {
    VarV.Gen(Vars+1);
    for (int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.At(RecN-1, VarN);}
  }
double GetY ( const int  RecN) const

Definition at line 354 of file xmath.h.

{return YV[RecN-1];}
bool IsDef ( ) const

Definition at line 211 of file xmath.h.

{return DefP;}
bool IsUsable ( ) const

Definition at line 222 of file xmath.h.

{Assert(DefP); return UsableP;}
static bool IsUsableV ( const TMomV &  MomV) [static]

Definition at line 223 of file xmath.h.

                                          {
    for (int MomN=0; MomN<MomV.Len(); MomN++){
      if (!MomV[MomN]->IsUsable()){return false;}}
    return true;}
static bool IsUsableVV ( const TVVec< PMom > &  MomVV) [static]

Definition at line 227 of file xmath.h.

                                                  {
    for (int XMomN=0; XMomN<MomVV.GetXDim(); XMomN++){
      for (int YMomN=0; YMomN<MomVV.GetYDim(); YMomN++){
        if (!MomVV.At(XMomN, YMomN)->IsUsable()){return false;}}}
    return true;}
static double LinInterp ( const double &  x1,
const double &  y1,
const double &  x2,
const double &  y2,
const double &  AtX 
) [static]

Definition at line 381 of file xmath.h.

                                                                  {
    if (x1 == x2) return (y1+y2)/2.0;
    const double k = (y2 - y1) / (x2 - x1);
    return k*(AtX - x1) + y1;
  }
static PSvd Load ( TSIn SIn) [static]

Definition at line 177 of file xmath.h.

{return new TMom(SIn);}
static PMom New ( ) [static]

Definition at line 157 of file xmath.h.

{return PMom(new TMom());}
static PMom New ( const TFltV ValV) [static]

Definition at line 166 of file xmath.h.

                                    {
    return PMom(new TMom(ValV));}
static PCorr New ( const TFltV ValV1,
const TFltV ValV2 
) [static]

Definition at line 274 of file xmath.h.

                                                          {
    return PCorr(new TCorr(ValV1, ValV2));}
static PComb New ( const int &  Items,
const int &  Order 
) [static]

Definition at line 323 of file xmath.h.

                                                      {
    return PComb(new TComb(Items, Order));}
static PSvd New ( const TFltVV XVV,
const TFltV YV,
const TFltV SigV = TFltV() 
) [static]
static void NewV ( TMomV &  MomV,
const int &  Moms 
) [static]

Definition at line 158 of file xmath.h.

                                                {
    MomV.Gen(Moms); for (int MomN=0; MomN<Moms; MomN++){MomV[MomN]=New();}}
static void NewVV ( TVVec< PMom > &  MomVV,
const int &  XMoms,
const int &  YMoms 
) [static]

Definition at line 160 of file xmath.h.

                                                                           {
    MomVV.Gen(XMoms, YMoms);
    for (int XMomN=0; XMomN<XMoms; XMomN++){
      for (int YMomN=0; YMomN<YMoms; YMomN++){
        MomVV.At(XMomN, YMomN)=New();}}}
void TLinReg::NR_covsrt ( TFltVV CovarVV,
const int &  Vars,
const TIntV ia,
const int &  mfit 
)

Definition at line 789 of file xmath.cpp.

                                                                    {
  for (int i=mfit+1; i<=Vars; i++){
    for (int j=1; j<=i; j++){
      CovarVV.At(i, j)=0; CovarVV.At(j, i)=0.0;}
  }
  int k=mfit;
  for (int j=Vars; j>=1; j--){
    if (ia[j]!=0){
      for (int i=1; i<=Vars; i++){Swap(CovarVV.At(i, k), CovarVV.At(i, j));}
      {for (int i=1; i<=Vars; i++){Swap(CovarVV.At(k, i), CovarVV.At(j, i));}}
      k--;
    }
  }
}
static double NR_FMAX ( double  maxarg1,
double  maxarg2 
) [static]

Definition at line 409 of file xmath.h.

                                                       {
    return maxarg1 > maxarg2 ? maxarg1 : maxarg2;}
void TLinReg::NR_gaussj ( TFltVV a,
const int &  n,
TFltVV b,
const int &  m 
)

Definition at line 805 of file xmath.cpp.

                                                                       {
  int i, icol, irow=0, j, k, l, ll;
  double big, dum, pivinv;

  TIntV indxc(n+1);
  TIntV indxr(n+1);
  TIntV ipiv(n+1);
  for (j=1; j<=n; j++){ipiv[j]=0;}
  for (i=1; i<=n; i++){
    big=0.0;
    for (j=1; j<=n; j++){
      if (ipiv[j]!=1){
        for (k=1; k<=n; k++){
          if (ipiv[k]==0){
            if (fabs(double(a.At(j, k))) >= big){
              big=fabs(double(a.At(j, k)));
              irow=j;
              icol=k;
            }
          } else
          if (ipiv[k]>1){
            TExcept::Throw("Singular Matrix(1) in Gauss");}
        }
      }
    }
    ipiv[icol]++;
    if (irow != icol){
      for (l=1; l<=n; l++){Swap(a.At(irow, l), a.At(icol, l));}
      for (l=1; l<=m; l++){Swap(b.At(irow, l), b.At(icol, l));}
    }
    indxr[i]=irow;
    indxc[i]=icol;
    if (a.At(icol, icol)==0.0){
      TExcept::Throw("Singular Matrix(1) in Gauss");}
    pivinv=1.0/a.At(icol, icol);
    a.At(icol, icol)=1.0;
    for (l=1; l<=n; l++){a.At(icol, l)=a.At(icol, l)*pivinv;}
    for (l=1; l<=m; l++){b.At(icol, l)=b.At(icol, l)*pivinv;}
    for (ll=1; ll<=n; ll++){
      if (ll != icol){
        dum=a.At(ll, icol);
        a.At(ll, icol)=0.0;
        for (l=1;l<=n;l++){a.At(ll, l)-=a.At(icol, l)*dum;}
        for (l=1;l<=m;l++){b.At(ll, l)-=b.At(icol, l)*dum;}
      }
    }
  }
  for (l=n; l>=1; l--){
    if (indxr[l]!=indxc[l]){
      for (k=1; k<=n; k++){
        Swap(a.At(k, indxr[l]), a.At(k, indxc[l]));}
    }
  }
}
static int NR_IMIN ( int  iminarg1,
int  iminarg2 
) [static]

Definition at line 411 of file xmath.h.

                                                {
    return iminarg1 < iminarg2 ? iminarg1 : iminarg2;}
void TLinReg::NR_lfit ( )

Definition at line 860 of file xmath.cpp.

                     {
  int i,j,k,l,m,mfit=0;
  double ym,wt,sum,sig2i;

  TIntV ia(Vars+1); for (i=1; i<=Vars; i++){ia[i]=1;}
  TFltVV beta(Vars+1, 1+1);
  TFltV afunc(Vars+1);
  for (j=1;j<=Vars;j++){
    if (ia[j]!=0){mfit++;}}
  if (mfit==0){TExcept::Throw("No parameters to be fitted in LFit");}
  for (j=1; j<=mfit; j++){
    for (k=1; k<=mfit; k++){CovarVV.At(j, k)=0.0;}
    beta.At(j, 1)=0.0;
  }
  for (i=1; i<=Recs; i++){
    GetXV(i, afunc); // funcs(XVV[i],afunc,Vars);
    ym=GetY(i);
    if (mfit<Vars){
      for (j=1;j<=Vars;j++){
        if (ia[j]==0){ym-=CfV[j]*afunc[j];}}
    }
    sig2i=1.0/TMath::Sqr(GetSig(i));
    for (j=0, l=1; l<=Vars; l++){
      if (ia[l]!=0){
        wt=afunc[l]*sig2i;
        for (j++, k=0, m=1; m<=l; m++){
          if (ia[m]!=0){CovarVV.At(j, ++k)+=wt*afunc[m];}
        }
        beta.At(j, 1)+=ym*wt;
      }
    }
  }
  for (j=2; j<=mfit; j++){
    for (k=1; k<j; k++){CovarVV.At(k, j)=CovarVV.At(j, k);}
  }
  NR_gaussj(CovarVV, mfit, beta, 1);
  for (j=0, l=1; l<=Vars; l++){
    if (ia[l]!=0){CfV[l]=beta.At(++j, 1);}
  }
  ChiSq=0.0;
  for (i=1; i<=Recs; i++){
    GetXV(i, afunc); // funcs(XVV[i],afunc,Vars);
    for (sum=0.0, j=1; j<=Vars; j++){sum+=CfV[j]*afunc[j];}
    ChiSq+=TMath::Sqr((GetY(i)-sum)/GetSig(i));
  }
  NR_covsrt(CovarVV, Vars, ia, mfit);
}
double TSvd::NR_pythag ( double  a,
double  b 
) [static]

Definition at line 948 of file xmath.cpp.

                                        {
  double absa,absb;
  absa=fabs(a);
  absb=fabs(b);
  if (absa > absb){
    return absa*sqrt(1.0+TMath::Sqr(absb/absa));
  } else {
    return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+TMath::Sqr(absa/absb)));
  }
}
static double NR_SIGN ( double  a,
double  b 
) [static]

Definition at line 408 of file xmath.h.

{return b >= 0.0 ? fabs(a) : -fabs(a);}
void TSvd::NR_svbksb ( TFltVV u,
TFltV w,
TFltVV v,
int  m,
int  n,
TFltV b,
TFltV x 
)

Definition at line 1136 of file xmath.cpp.

                                                                  {
  int jj,j,i;
  double s;

  TFltV tmp(n+1);
  for (j=1;j<=n;j++) {
    s=0.0;
    if (w[j]) {
      for (i=1;i<=m;i++) s += u.At(i,j)*b[i];
      s /= w[j];
    }
    tmp[j]=s;
  }
  for (j=1;j<=n;j++) {
    s=0.0;
    for (jj=1;jj<=n;jj++) s += v.At(j,jj)*tmp[jj];
    x[j]=s;
  }
}
void TSvd::NR_svdcmp ( TFltVV a,
int  m,
int  n,
TFltV w,
TFltVV v 
) [static]

Definition at line 959 of file xmath.cpp.

                                                                {
  int flag,i,its,j,jj,k,l=0,nm;
  double anorm,c,f,g,h,s,scale,x,y,z;

  TFltV rv1(n+1);
  g=scale=anorm=0.0;
  for (i=1;i<=n;i++) {
    l=i+1;
    rv1[i]=scale*g;
    g=s=scale=0.0;
    if (i <= m) {
      for (k=i;k<=m;k++) scale += fabs(double(a.At(k,i)));
      if (scale) {
        for (k=i;k<=m;k++) {
          a.At(k,i) /= scale;
          s += a.At(k,i)*a.At(k,i);
        }
        f=a.At(i,i);
        g = -NR_SIGN(sqrt(s),f);
        h=f*g-s;
        a.At(i,i)=f-g;
        for (j=l;j<=n;j++) {
          for (s=0.0,k=i;k<=m;k++) s += a.At(k,i)*a(k,j);
          f=s/h;
          for (k=i;k<=m;k++) a.At(k,j) += f*a.At(k,i);
        }
        for (k=i;k<=m;k++) a.At(k,i) *= scale;
      }
    }
    w[i]=scale *g;
    g=s=scale=0.0;
    if (i <= m && i != n) {
      for (k=l;k<=n;k++) scale += fabs(double(a.At(i,k)));
      if (scale) {
        for (k=l;k<=n;k++) {
          a.At(i,k) /= scale;
          s += a.At(i,k)*a.At(i,k);
        }
        f=a.At(i,l);
        g = -NR_SIGN(sqrt(s),f);
        h=f*g-s;
        a.At(i,l)=f-g;
        for (k=l;k<=n;k++) rv1[k]=a.At(i,k)/h;
        for (j=l;j<=m;j++) {
          for (s=0.0,k=l;k<=n;k++) s += a.At(j,k)*a.At(i,k);
          for (k=l;k<=n;k++) a.At(j,k) += s*rv1[k];
        }
        for (k=l;k<=n;k++) a.At(i,k) *= scale;
      }
    }
    anorm=NR_FMAX(anorm,(fabs(double(w[i]))+fabs(double(rv1[i]))));
  }
  for (i=n;i>=1;i--) {
    if (i < n) {
      if (g) {
        for (j=l;j<=n;j++)
          v.At(j,i)=(a.At(i,j)/a.At(i,l))/g;
        for (j=l;j<=n;j++) {
          for (s=0.0,k=l;k<=n;k++) s += a.At(i,k)*v.At(k,j);
          for (k=l;k<=n;k++) v.At(k,j) += s*v.At(k,i);
        }
      }
      for (j=l;j<=n;j++) v.At(i,j)=v.At(j,i)=0.0;
    }
    v.At(i,i)=1.0;
    g=rv1[i];
    l=i;
  }
  for (i=NR_IMIN(m,n);i>=1;i--) {
    l=i+1;
    g=w[i];
    for (j=l;j<=n;j++) a.At(i,j)=0.0;
    if (g) {
      g=1.0/g;
      for (j=l;j<=n;j++) {
        for (s=0.0,k=l;k<=m;k++) s += a.At(k,i)*a.At(k,j);
        f=(s/a.At(i,i))*g;
        for (k=i;k<=m;k++) a.At(k,j) += f*a.At(k,i);
      }
      for (j=i;j<=m;j++) a.At(j,i) *= g;
    } else for (j=i;j<=m;j++) a.At(j,i)=0.0;
    a.At(i,i)++;
  }
  for (k=n;k>=1;k--) {
    for (its=1;its<=30;its++) {
      flag=1;
      for (l=k;l>=1;l--) {
        nm=l-1;
        if ((double)(fabs(double(rv1[l])+anorm)) == anorm) {
          flag=0;
          break;
        }
        if ((double)(fabs(double(w[nm]))+anorm) == anorm) break;
      }
      if (flag) {
        c=0.0;
        s=1.0;
        for (i=l;i<=k;i++) {
          f=s*rv1[i];
          rv1[i]=c*rv1[i];
          if ((double)(fabs(f)+anorm) == anorm) break;
          g=w[i];
          h=NR_pythag(f,g);
          w[i]=h;
          h=1.0/h;
          c=g*h;
          s = -f*h;
          for (j=1;j<=m;j++) {
            y=a.At(j,nm);
            z=a.At(j,i);
            a.At(j,nm)=y*c+z*s;
            a.At(j,i)=z*c-y*s;
          }
        }
      }
      z=w[k];
      if (l == k) {
        if (z < 0.0) {
          w[k] = -z;
          for (j=1;j<=n;j++) v.At(j,k) = -v.At(j,k);
        }
        break;
      }
      if (its==30){
        TExcept::Throw("no convergence in 30 svdcmp iterations");}
      x=w[l];
      nm=k-1;
      y=w[nm];
      g=rv1[nm];
      h=rv1[k];
      f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
      g=NR_pythag(f,1.0);
      f=((x-z)*(x+z)+h*((y/(f+NR_SIGN(g,f)))-h))/x;
      c=s=1.0;
      for (j=l;j<=nm;j++) {
        i=j+1;
        g=rv1[i];
        y=w[i];
        h=s*g;
        g=c*g;
        z=NR_pythag(f,h);
        rv1[j]=z;
        c=f/z;
        s=h/z;
        f=x*c+g*s;
        g = g*c-x*s;
        h=y*s;
        y *= c;
        for (jj=1;jj<=n;jj++) {
          x=v.At(jj,j);
          z=v.At(jj,i);
          v.At(jj,j)=x*c+z*s;
          v.At(jj,i)=z*c-x*s;
        }
        z=NR_pythag(f,h);
        w[j]=z;
        if (z) {
          z=1.0/z;
          c=f*z;
          s=h*z;
        }
        f=c*g+s*y;
        x=c*y-s*g;
        for (jj=1;jj<=m;jj++) {
          y=a.At(jj,j);
          z=a.At(jj,i);
          a.At(jj,j)=y*c+z*s;
          a.At(jj,i)=z*c-y*s;
        }
      }
      rv1[l]=0.0;
      rv1[k]=f;
      w[k]=x;
    }
  }
}
void TSvd::NR_svdfit ( )

Definition at line 1174 of file xmath.cpp.

                    {
  int j,i;
  double wmax,tmp,thresh,sum;
  double TOL=1.0e-5;

  TFltVV u(Recs+1, Vars+1);
  TFltVV v(Vars+1, Vars+1);
  TFltV w(Vars+1);
  TFltV b(Recs+1);
  TFltV afunc(Vars+1);
  for (i=1;i<=Recs;i++) {
    GetXV(i, afunc); // (*funcs)(x[i],afunc,Vars);
    tmp=1.0/GetSig(i);
    for (j=1;j<=Vars;j++){u.At(i,j)=afunc[j]*tmp;}
    b[i]=GetY(i)*tmp;
  }
  NR_svdcmp(u,Recs,Vars,w,v);
  wmax=0.0;
  for (j=1;j<=Vars;j++){
    if (w[j] > wmax){wmax=w[j];}}
  thresh=TOL*wmax;
  for (j=1;j<=Vars;j++){
    if (double(w[j])<thresh){w[j]=0.0;}}
  NR_svbksb(u,w,v,Recs,Vars,b,CfV);
  ChiSq=0.0;
  for (i=1;i<=Recs;i++) {
    GetXV(i, afunc); // (*funcs)(x[i],afunc,Vars);
    for (sum=0.0,j=1;j<=Vars;j++){sum += CfV[j]*afunc[j];}
    ChiSq += (tmp=(GetY(i)-sum)/GetSig(i),tmp*tmp);
  }
  // covariance matrix calculation
  CovarVV.Gen(Vars+1, Vars+1);
  NR_svdvar(v, Vars, w, CovarVV);
}
void TSvd::NR_svdvar ( TFltVV v,
int  ma,
TFltV w,
TFltVV cvm 
)

Definition at line 1157 of file xmath.cpp.

                                                            {
  int k,j,i;
  double sum;

  TFltV wti(ma+1);
  for (i=1;i<=ma;i++) {
    wti[i]=0.0;
    if (w[i]) wti[i]=1.0/(w[i]*w[i]);
  }
  for (i=1;i<=ma;i++) {
    for (j=1;j<=i;j++) {
      for (sum=0.0,k=1;k<=ma;k++) sum += v.At(i,k)*v.At(j,k)*wti[k];
      cvm.At(j,i)=cvm.At(i,j)=sum;
    }
  }
}
bool operator< ( const TMom Mom) const

Definition at line 200 of file xmath.h.

                                        {
    return Vals<Mom.Vals;}
TMom& operator= ( const TMom Mom)

Definition at line 188 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;}
TCorr& operator= ( const TCorr )

Definition at line 280 of file xmath.h.

{Fail; return *this;}
TComb& operator= ( const TComb )

Definition at line 330 of file xmath.h.

{Fail; return *this;}
TLinReg& operator= ( const TLinReg )

Definition at line 368 of file xmath.h.

{Fail; return *this;}
TSvd& operator= ( const TSvd )

Definition at line 428 of file xmath.h.

{Fail; return *this;}
bool operator== ( const TMom Mom) const

Definition at line 198 of file xmath.h.

                                         {
    return Vals==Mom.Vals;}
void Save ( TSOut SOut) const

Definition at line 178 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);}
void TSvd::Svd ( const TFltVV InMtx,
TFltVV LSingV,
TFltV SingValV,
TFltVV RSingV 
) [static]

Definition at line 1221 of file xmath.cpp.

                                                                                   {
  //LSingV = InMtx;
  LSingV.Gen(InMtx.GetYDim()+1, InMtx.GetYDim()+1);
  // create 1 based adjacency matrix
  for (int x = 0; x < InMtx.GetXDim(); x++) {
    for (int y = 0; y < InMtx.GetYDim(); y++) {
      LSingV.At(x+1, y+1) = InMtx.At(x, y);
    }
  }
  RSingV.Gen(InMtx.GetYDim()+1, InMtx.GetYDim()+1);
  SingValV.Gen(InMtx.GetYDim()+1);
  TSvd::NR_svdcmp(LSingV, InMtx.GetXDim(), InMtx.GetYDim(), SingValV, RSingV);
  // 0-th singular value/vector is full of zeros, delete it
  SingValV.Del(0);
  LSingV.DelX(0); LSingV.DelY(0);
  RSingV.DelX(0); RSingV.DelY(0);
}
void TSvd::Svd1Based ( const TFltVV InMtx1,
TFltVV LSingV,
TFltV SingValV,
TFltVV RSingV 
) [static]

Definition at line 1241 of file xmath.cpp.

                                                                                          {
  LSingV = InMtx1;
  SingValV.Gen(InMtx1.GetYDim());
  RSingV.Gen(InMtx1.GetYDim(), InMtx1.GetYDim());
  TSvd::NR_svdcmp(LSingV, InMtx1.GetXDim()-1, InMtx1.GetYDim()-1, SingValV, RSingV);
  // 0-th singular value/vector is full of zeros, delete it
  SingValV.Del(0);
  LSingV.DelX(0); LSingV.DelY(0);
  RSingV.DelX(0); RSingV.DelY(0);
}
TComb ( )

Definition at line 319 of file xmath.h.

: Items(-1), Order(-1), CombN(-1), ItemV(){}
TComb ( const int &  _Items,
const int &  _Order 
)

Definition at line 320 of file xmath.h.

                                             :
    Items(_Items), Order(_Order), CombN(0), ItemV(){
    IAssert((Order>0)&&(Order<=Items));}
TComb ( TSIn )

Definition at line 326 of file xmath.h.

{Fail;}
TCorr ( )

Definition at line 272 of file xmath.h.

{}
TCorr::TCorr ( const TFltV ValV1,
const TFltV ValV2 
)

Definition at line 543 of file xmath.cpp.

                                                  :
  ValVLen(ValV1.Len()), CorrCf(), CorrCfPrb(), FisherZ(){
  static const double TINY=1.0e-20;
  IAssert(ValV1.Len()==ValV2.Len());

  // calculate the means
  double MeanVal1=0; double MeanVal2=0;
  {for (int ValN=0; ValN<ValVLen; ValN++){
    MeanVal1+=ValV1[ValN]; MeanVal2+=ValV2[ValN];}}
  MeanVal1/=ValVLen; MeanVal2/=ValVLen;

  // calculate correlation coefficient
  double yt, xt;
  double syy=0.0; double sxy=0.0; double sxx=0.0;
  {for (int ValN=0; ValN<ValVLen; ValN++){
    xt=ValV1[ValN]-MeanVal1;
    yt=ValV2[ValN]-MeanVal2;
    sxx+=xt*xt;
    syy+=yt*yt;
    sxy+=xt*yt;
  }}
  if (sxx*syy==0){
    CorrCf=0; //** not in numerical recipes - check why (pojavi se, ko so same nicle)
  } else {
    CorrCf=sxy/sqrt(sxx*syy);
  }
  // calculate correlation coefficient significance level
  double df=ValVLen-2;
  double t=CorrCf*sqrt(df/((1.0-CorrCf+TINY)*(1.0+CorrCf+TINY)));
  CorrCfPrb=TSpecFunc::BetaI(0.5*df,0.5,df/(df+t*t));
  // calculate Fisher's Z transformation
  FisherZ=0.5*log((1.0+(CorrCf)+TINY)/(1.0-(CorrCf)+TINY));
}
TCorr ( TSIn )

Definition at line 276 of file xmath.h.

{Fail;}
TLinReg ( )

Definition at line 360 of file xmath.h.

{}
TLinReg ( TSIn )

Definition at line 364 of file xmath.h.

{Fail;}
TMom ( )

Definition at line 141 of file xmath.h.

        :
    DefP(false), ValWgtV(),
    SumW(), ValSumW(), Vals(),
    UsableP(false), UnusableVal(-1),
    Mn(), Mx(),
    Mean(), Vari(), SDev(), SErr(),
    Median(), Quart1(), Quart3(),
    DecileV(), PercentileV(){}
TMom ( const TMom Mom)

Definition at line 149 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)

Definition at line 326 of file xmath.cpp.

                            :
  //WgtV(_ValV.Len(), 0), ValV(_ValV.Len(), 0),
  ValWgtV(_ValV.Len(), 0),
  SumW(), ValSumW(),
  UsableP(false), UnusableVal(-1),
  Mn(), Mx(),
  Mean(), Vari(), SDev(), SErr(),
  Median(), Quart1(), Quart3(),
  DecileV(), PercentileV(){
  for (int ValN=0; ValN<_ValV.Len(); ValN++){Add(_ValV[ValN], 1);}
  Def();
}
TMom ( TSIn SIn)

Definition at line 168 of file xmath.h.

                 :
    DefP(SIn),
    ValWgtV(SIn),
    SumW(SIn), ValSumW(SIn), Vals(SIn),
    UsableP(SIn), UnusableVal(SIn),
    Mn(SIn), Mx(SIn),
    Mean(SIn), Vari(SIn), SDev(SIn), SErr(SIn),
    Median(SIn), Quart1(SIn), Quart3(SIn),
    DecileV(SIn), PercentileV(SIn){}
TSvd ( )

Definition at line 420 of file xmath.h.

{}
TSvd ( TSIn )

Definition at line 424 of file xmath.h.

{Fail;}
void Wr ( )
~TComb ( )

Definition at line 325 of file xmath.h.

{}
~TLinReg ( )

Definition at line 363 of file xmath.h.

{}
~TSvd ( )

Definition at line 423 of file xmath.h.

{}

Variable Documentation

Definition at line 348 of file xmath.h.

double ChiSq

Definition at line 349 of file xmath.h.

int CombN

Definition at line 316 of file xmath.h.

ClassTP (TCorr, PCorr) private double CorrCf

Definition at line 265 of file xmath.h.

double CorrCfPrb

Definition at line 269 of file xmath.h.

Definition at line 347 of file xmath.h.

Definition at line 138 of file xmath.h.

double FisherZ

Definition at line 270 of file xmath.h.

Definition at line 317 of file xmath.h.

Definition at line 136 of file xmath.h.

Definition at line 137 of file xmath.h.

Definition at line 135 of file xmath.h.

Definition at line 135 of file xmath.h.

ClassTP (TComb, PComb) public int Order

Definition at line 312 of file xmath.h.

Definition at line 139 of file xmath.h.

Definition at line 137 of file xmath.h.

Definition at line 137 of file xmath.h.

int Recs

Definition at line 346 of file xmath.h.

Definition at line 136 of file xmath.h.

Definition at line 136 of file xmath.h.

Definition at line 345 of file xmath.h.

Definition at line 131 of file xmath.h.

Definition at line 134 of file xmath.h.

Definition at line 133 of file xmath.h.

Definition at line 132 of file xmath.h.

Definition at line 131 of file xmath.h.

ClassTPV (TMom, PMom, TMomV) private TFltPrV ValWgtV

Definition at line 127 of file xmath.h.

Definition at line 136 of file xmath.h.

int Vars

Definition at line 346 of file xmath.h.

ClassTP (TSvd, PSvd) public TFltV YV

Definition at line 341 of file xmath.h.