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
TMAGAffMtx Class Reference

#include <mag.h>

Collaboration diagram for TMAGAffMtx:

List of all members.

Public Member Functions

 TMAGAffMtx ()
 TMAGAffMtx (const int &Dim)
 TMAGAffMtx (const TFltV &SeedMatrix)
 TMAGAffMtx (const TMAGAffMtx &Kronecker)
TMAGAffMtxoperator= (const TMAGAffMtx &Kronecker)
bool operator== (const TMAGAffMtx &Kronecker) const
int GetPrimHashCd () const
int GetSecHashCd () const
int GetDim () const
int Len () const
bool Empty () const
bool IsProbMtx () const
TFltVGetMtx ()
const TFltVGetMtx () const
void SetMtx (const TFltV &ParamV)
void SetRndMtx (TRnd &Rnd, const int &PrmMtxDim=2, const double &MinProb=0.0)
void PutAllMtx (const double &Val)
void GenMtx (const int &Dim)
void SetEpsMtx (const double &Eps1, const double &Eps0, const int &Eps1Val=1, const int &Eps0Val=0)
void AddRndNoise (TRnd &Rnd, const double &SDev)
TStr GetMtxStr () const
const double & At (const int &Row, const int &Col) const
double & At (const int &Row, const int &Col)
const double & At (const int &ValN) const
double & At (const int &ValN)
double GetMtxSum () const
double GetRowSum (const int &RowId) const
double GetColSum (const int &ColId) const
double Normalize ()
void GetLLMtx (TMAGAffMtx &LLMtx)
void GetProbMtx (TMAGAffMtx &ProbMtx)
void Swap (TMAGAffMtx &Mtx)
void Dump (const TStr &MtxNm=TStr(), const bool &Sort=false) const

Static Public Member Functions

static double GetAvgAbsErr (const TMAGAffMtx &Mtx1, const TMAGAffMtx &Mtx2)
static double GetAvgFroErr (const TMAGAffMtx &Mtx1, const TMAGAffMtx &Mtx2)
static TMAGAffMtx GetMtx (TStr MatlabMtxStr)
static TMAGAffMtx GetRndMtx (TRnd &Rnd, const int &Dim=2, const double &MinProb=0.0)

Private Attributes

TInt MtxDim
TFltV SeedMtx

Static Private Attributes

static const double NInf = -DBL_MAX

Detailed Description

Definition at line 10 of file mag.h.


Constructor & Destructor Documentation

TMAGAffMtx::TMAGAffMtx ( ) [inline]

Definition at line 16 of file mag.h.

: MtxDim(-1), SeedMtx() { }
TMAGAffMtx::TMAGAffMtx ( const int &  Dim) [inline]

Definition at line 17 of file mag.h.

: MtxDim(Dim), SeedMtx(Dim*Dim) { }
TMAGAffMtx::TMAGAffMtx ( const TFltV SeedMatrix)

Definition at line 14 of file mag.cpp.

References IAssert, TVec< TVal, TSizeTy >::Len(), MtxDim, and SeedMtx.

                                              : SeedMtx(SeedMatrix) {
  MtxDim = (int) sqrt((double)SeedMatrix.Len());
  IAssert(MtxDim*MtxDim == SeedMtx.Len());
}

Here is the call graph for this function:

TMAGAffMtx::TMAGAffMtx ( const TMAGAffMtx Kronecker) [inline]

Definition at line 19 of file mag.h.

: MtxDim(Kronecker.MtxDim), SeedMtx(Kronecker.SeedMtx) { }

Member Function Documentation

void TMAGAffMtx::AddRndNoise ( TRnd Rnd,
const double &  SDev 
)

Definition at line 52 of file mag.cpp.

References At(), Dump(), TRnd::GetNrmDev(), and Len().

                                                          {
  Dump("before");
  double NewVal;
  int c =0;
  for (int i = 0; i < Len(); i++) {
    for(c = 0; ((NewVal = At(i)*Rnd.GetNrmDev(1, SDev, 0.8, 1.2)) < 0.01 || NewVal>0.99) && c <1000; c++) { }
    if (c < 999) { At(i) = NewVal; } else { printf("XXXXX\n"); }
  }
  Dump("after");
}

Here is the call graph for this function:

double& TMAGAffMtx::At ( const int &  Row,
const int &  Col 
) [inline]

Definition at line 42 of file mag.h.

References MtxDim, and SeedMtx.

{ return SeedMtx[MtxDim*Row+Col].Val; }
const double& TMAGAffMtx::At ( const int &  ValN) const [inline]

Definition at line 43 of file mag.h.

References SeedMtx.

{ return SeedMtx[ValN].Val; }
double& TMAGAffMtx::At ( const int &  ValN) [inline]

Definition at line 44 of file mag.h.

References SeedMtx.

{ return SeedMtx[ValN].Val; }
void TMAGAffMtx::Dump ( const TStr MtxNm = TStr(),
const bool &  Sort = false 
) const

Definition at line 128 of file mag.cpp.

References TStr::CStr(), TStr::Empty(), GetDim(), TVec< TVal, TSizeTy >::Len(), SeedMtx, and TVec< TVal, TSizeTy >::Sort().

Referenced by AddRndNoise().

                                                               {
  /*printf("%s: %d x %d\n", MtxNm.Empty()?"Mtx":MtxNm.CStr(), GetDim(), GetDim());
  for (int r = 0; r < GetDim(); r++) {
    for (int c = 0; c < GetDim(); c++) { printf("  %8.2g", At(r, c)); }
    printf("\n");
  }*/
  if (! MtxNm.Empty()) printf("%s\n", MtxNm.CStr());
  double Sum=0.0;
  TFltV ValV = SeedMtx;
  if (Sort) { ValV.Sort(false); }
  for (int i = 0; i < ValV.Len(); i++) {
    printf("  %10.4g", ValV[i]());
    Sum += ValV[i];
    if ((i+1) % GetDim() == 0) { printf("\n"); }
  }
  printf(" (sum:%.4f)\n", Sum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool TMAGAffMtx::Empty ( ) const [inline]

Definition at line 28 of file mag.h.

References TVec< TVal, TSizeTy >::Empty(), and SeedMtx.

{ return SeedMtx.Empty(); }

Here is the call graph for this function:

void TMAGAffMtx::GenMtx ( const int &  Dim) [inline]

Definition at line 36 of file mag.h.

References TVec< TVal, TSizeTy >::Gen(), MtxDim, and SeedMtx.

Referenced by GetLLMtx(), and GetProbMtx().

{ MtxDim=Dim;  SeedMtx.Gen(Dim*Dim); }

Here is the call graph for this function:

Here is the caller graph for this function:

double TMAGAffMtx::GetAvgAbsErr ( const TMAGAffMtx Mtx1,
const TMAGAffMtx Mtx2 
) [static]

Definition at line 147 of file mag.cpp.

References GetMtx(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().

                                                                              {
  TFltV P1 = Mtx1.GetMtx();
  TFltV P2 = Mtx2.GetMtx();
  IAssert(P1.Len() == P2.Len());
  P1.Sort();  P2.Sort();
  double delta = 0.0;
  for (int i = 0; i < P1.Len(); i++) {
    delta += fabs(P1[i] - P2[i]);
  }
  return delta/P1.Len();
}

Here is the call graph for this function:

double TMAGAffMtx::GetAvgFroErr ( const TMAGAffMtx Mtx1,
const TMAGAffMtx Mtx2 
) [static]

Definition at line 160 of file mag.cpp.

References GetMtx(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().

                                                                              {
  TFltV P1 = Mtx1.GetMtx();
  TFltV P2 = Mtx2.GetMtx();
  IAssert(P1.Len() == P2.Len());
  P1.Sort();  P2.Sort();
  double delta = 0.0;
  for (int i = 0; i < P1.Len(); i++) {
    delta += pow(P1[i] - P2[i], 2);
  }
  return sqrt(delta/P1.Len());
}

Here is the call graph for this function:

double TMAGAffMtx::GetColSum ( const int &  ColId) const

Definition at line 109 of file mag.cpp.

References At(), and GetDim().

                                                   {
  double Sum = 0;
  for (int r = 0; r < GetDim(); r++) {
    Sum += At(r, ColId); }
  return Sum;
}

Here is the call graph for this function:

int TMAGAffMtx::GetDim ( ) const [inline]

Definition at line 26 of file mag.h.

References MtxDim.

Referenced by Dump(), GetColSum(), GetMtxStr(), and GetRowSum().

{ return MtxDim; }

Here is the caller graph for this function:

void TMAGAffMtx::GetLLMtx ( TMAGAffMtx LLMtx)

Definition at line 74 of file mag.cpp.

References At(), GenMtx(), Len(), MtxDim, and NInf.

Referenced by TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::UpdateApxPhiMI(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().

                                           {
  LLMtx.GenMtx(MtxDim);
  for (int i = 0; i < Len(); i++) {
    if (At(i) != 0.0) { LLMtx.At(i) = log(At(i)); }
    else { LLMtx.At(i) = NInf; }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

TFltV& TMAGAffMtx::GetMtx ( ) [inline]

Definition at line 31 of file mag.h.

References SeedMtx.

Referenced by GetAvgAbsErr(), GetAvgFroErr(), and TMAGParam< TNodeAttr >::LoadTxt().

{ return SeedMtx; }

Here is the caller graph for this function:

const TFltV& TMAGAffMtx::GetMtx ( ) const [inline]

Definition at line 32 of file mag.h.

References SeedMtx.

{ return SeedMtx; }
TMAGAffMtx TMAGAffMtx::GetMtx ( TStr  MatlabMtxStr) [static]

Definition at line 173 of file mag.cpp.

References At(), TStr::ChangeChAll(), TVec< TVal, TSizeTy >::Empty(), IAssert, TVec< TVal, TSizeTy >::Len(), and TStr::SplitOnAllCh().

                                               {
  TStrV RowStrV, ColStrV;
  MatlabMtxStr.ChangeChAll(',', ' ');
  MatlabMtxStr.SplitOnAllCh(';', RowStrV);  IAssert(! RowStrV.Empty());
  RowStrV[0].SplitOnWs(ColStrV);    IAssert(! ColStrV.Empty());
  const int Rows = RowStrV.Len();
  const int Cols = ColStrV.Len();
  IAssert(Rows == Cols);
  TMAGAffMtx Mtx(Rows);
  for (int r = 0; r < Rows; r++) {
    RowStrV[r].SplitOnWs(ColStrV);
    IAssert(ColStrV.Len() == Cols);
    for (int c = 0; c < Cols; c++) {
      Mtx.At(r, c) = (double) ColStrV[c].GetFlt(); }
  }
  return Mtx;
}

Here is the call graph for this function:

Definition at line 63 of file mag.cpp.

References At(), TStr::Fmt(), GetDim(), and Len().

Referenced by TMAGFitBern::UpdateAffMtx().

                                 {
  TChA ChA("[");
  for (int i = 0; i < Len(); i++) {
    ChA += TStr::Fmt("%g", At(i));
    if ((i+1)%GetDim()==0 && (i+1<Len())) { ChA += "; "; }
    else if (i+1<Len()) { ChA += " "; }
  }
  ChA += "]";
  return TStr(ChA);
}

Here is the call graph for this function:

Here is the caller graph for this function:

double TMAGAffMtx::GetMtxSum ( ) const

Definition at line 95 of file mag.cpp.

References At(), and Len().

Referenced by Normalize().

                                   {
  double Sum = 0;
  for (int i = 0; i < Len(); i++) {
    Sum += At(i); }
  return Sum;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int TMAGAffMtx::GetPrimHashCd ( ) const [inline]

Definition at line 22 of file mag.h.

References TVec< TVal, TSizeTy >::GetPrimHashCd(), and SeedMtx.

{ return SeedMtx.GetPrimHashCd(); }

Here is the call graph for this function:

void TMAGAffMtx::GetProbMtx ( TMAGAffMtx ProbMtx)

Definition at line 82 of file mag.cpp.

References At(), GenMtx(), Len(), MtxDim, and NInf.

                                               {
  ProbMtx.GenMtx(MtxDim);
  for (int i = 0; i < Len(); i++) {
    if (At(i) != NInf) { ProbMtx.At(i) = exp(At(i)); }
    else { ProbMtx.At(i) = 0.0; }
  }
}

Here is the call graph for this function:

TMAGAffMtx TMAGAffMtx::GetRndMtx ( TRnd Rnd,
const int &  Dim = 2,
const double &  MinProb = 0.0 
) [static]

Definition at line 191 of file mag.cpp.

References SetRndMtx().

                                                                                 {
  TMAGAffMtx Mtx;
  Mtx.SetRndMtx(Rnd, Dim, MinProb);
  return Mtx;
}

Here is the call graph for this function:

double TMAGAffMtx::GetRowSum ( const int &  RowId) const

Definition at line 102 of file mag.cpp.

References At(), and GetDim().

                                                   {
  double Sum = 0;
  for (int c = 0; c < GetDim(); c++) {
    Sum += At(RowId, c); }
  return Sum;
}

Here is the call graph for this function:

int TMAGAffMtx::GetSecHashCd ( ) const [inline]

Definition at line 23 of file mag.h.

References TVec< TVal, TSizeTy >::GetSecHashCd(), and SeedMtx.

{ return SeedMtx.GetSecHashCd(); }

Here is the call graph for this function:

bool TMAGAffMtx::IsProbMtx ( ) const

Definition at line 27 of file mag.cpp.

References At(), and Len().

                                 {
  for (int i = 0; i < Len(); i++) {
    if (At(i) < 0.0 || At(i) > 1.0) return false;
  }
  return true;
}

Here is the call graph for this function:

int TMAGAffMtx::Len ( ) const [inline]

Definition at line 27 of file mag.h.

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

Referenced by AddRndNoise(), GetLLMtx(), GetMtxStr(), GetMtxSum(), GetProbMtx(), IsProbMtx(), Normalize(), SetEpsMtx(), TMAGFitBern::UpdateApxPhiMI(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().

{ return SeedMtx.Len(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 116 of file mag.cpp.

References At(), GetMtxSum(), and Len().

                             {
        double Sum = GetMtxSum();
        if(Sum == 0) {
                return 0;
        }

        for(int i = 0; i < Len(); i++) {
                At(i) = At(i) / Sum;
        }
        return Sum;
}

Here is the call graph for this function:

TMAGAffMtx & TMAGAffMtx::operator= ( const TMAGAffMtx Kronecker)

Definition at line 19 of file mag.cpp.

References MtxDim, and SeedMtx.

                                                               {
  if (this != &Kronecker){
    MtxDim=Kronecker.MtxDim;
    SeedMtx=Kronecker.SeedMtx;
  }
  return *this;
}
bool TMAGAffMtx::operator== ( const TMAGAffMtx Kronecker) const [inline]

Definition at line 21 of file mag.h.

References SeedMtx.

{ return SeedMtx==Kronecker.SeedMtx; }
void TMAGAffMtx::PutAllMtx ( const double &  Val) [inline]

Definition at line 35 of file mag.h.

References TVec< TVal, TSizeTy >::PutAll(), and SeedMtx.

{ SeedMtx.PutAll(Val); }

Here is the call graph for this function:

void TMAGAffMtx::SetEpsMtx ( const double &  Eps1,
const double &  Eps0,
const int &  Eps1Val = 1,
const int &  Eps0Val = 0 
)

Definition at line 44 of file mag.cpp.

References At(), and Len().

                                                                                                         {
  for (int i = 0; i < Len(); i++) {
    double& Val = At(i);
    if (Val == Eps1Val) Val = double(Eps1);
    else if (Val == Eps0Val) Val = double(Eps0);
  }
}

Here is the call graph for this function:

void TMAGAffMtx::SetMtx ( const TFltV ParamV) [inline]

Definition at line 33 of file mag.h.

References SeedMtx.

{ SeedMtx = ParamV; }
void TMAGAffMtx::SetRndMtx ( TRnd Rnd,
const int &  PrmMtxDim = 2,
const double &  MinProb = 0.0 
)

Definition at line 34 of file mag.cpp.

References TVec< TVal, TSizeTy >::Gen(), TRnd::GetUniDev(), TVec< TVal, TSizeTy >::Len(), MtxDim, and SeedMtx.

Referenced by GetRndMtx().

                                                                                 {
  MtxDim = PrmMtxDim;
  SeedMtx.Gen(MtxDim*MtxDim);
  for (int p = 0; p < SeedMtx.Len(); p++) {
    do {
      SeedMtx[p] = Rnd.GetUniDev();
    } while (SeedMtx[p] < MinProb);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TMAGAffMtx::Swap ( TMAGAffMtx Mtx)

Definition at line 90 of file mag.cpp.

References MtxDim, SeedMtx, and TVec< TVal, TSizeTy >::Swap().

                                     {
  ::Swap(MtxDim, Mtx.MtxDim);
  SeedMtx.Swap(Mtx.SeedMtx);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 13 of file mag.h.

Referenced by At(), GenMtx(), GetDim(), GetLLMtx(), GetProbMtx(), operator=(), SetRndMtx(), Swap(), and TMAGAffMtx().

const double TMAGAffMtx::NInf = -DBL_MAX [static, private]

Definition at line 11 of file mag.h.

Referenced by GetLLMtx(), and GetProbMtx().


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