SNAP Library 2.1, User Reference  2013-09-25 10:47:25
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
TCascade Class Reference

#include <cascdynetinf.h>

List of all members.

Public Member Functions

 TCascade ()
 TCascade (const int &model)
 TCascade (const int &cid, const int &model)
 TCascade (TSIn &SIn)
void Save (TSOut &SOut) const
void Clr ()
int GetId ()
int Len () const
int LenBeforeT (const double &T)
int LenAfterT (const double &T)
int GetNode (const int &i) const
THash< TInt, THitInfo >::TIter BegI () const
THash< TInt, THitInfo >::TIter EndI () const
int GetModel () const
double GetTm (const int &NId) const
double GetMaxTm () const
double GetMinTm () const
void Add (const int &NId, const double &HitTm)
void Del (const int &NId)
bool IsNode (const int &NId) const
void Sort ()
bool operator< (const TCascade &Cascade) const
 TCascade ()
 TCascade (const double &alpha)
 TCascade (const double &alpha, const int &model)
 TCascade (const double &alpha, const double &eps)
 TCascade (const double &alpha, const int &model, const double &eps)
 TCascade (TSIn &SIn)
void Save (TSOut &SOut) const
void Clr ()
int Len () const
int GetNode (const int &i) const
int GetParent (const int NId) const
double GetAlpha () const
double GetTm (const int &NId) const
void Add (const int &NId, const double &HitTm)
void Del (const int &NId)
bool IsNode (const int &NId) const
void Sort ()
double TransProb (const int &NId1, const int &NId2) const
double GetProb (const PNGraph &G)
void InitProb ()
double UpdateProb (const int &N1, const int &N2, const bool &UpdateProb=false)

Public Attributes

TInt CId
THash< TInt, THitInfoNIdHitH
TInt Model
TFlt CurProb
TFlt Alpha
TFlt Eps

Detailed Description

Definition at line 84 of file cascdynetinf.h.


Constructor & Destructor Documentation

TCascade::TCascade ( ) [inline]

Definition at line 90 of file cascdynetinf.h.

: CId(0), NIdHitH(), Model(0) { }
TCascade::TCascade ( const int &  model) [inline]

Definition at line 91 of file cascdynetinf.h.

: NIdHitH() { Model = model; }
TCascade::TCascade ( const int &  cid,
const int &  model 
) [inline]

Definition at line 92 of file cascdynetinf.h.

: NIdHitH() { CId = cid; Model = model; }
TCascade::TCascade ( TSIn SIn) [inline]

Definition at line 93 of file cascdynetinf.h.

: CId(SIn), NIdHitH(SIn), Model(SIn) { }
TCascade::TCascade ( ) [inline]

Definition at line 26 of file cascnetinf.h.

: NIdHitH(), CurProb(0), Alpha(1.0), Eps(1e-64), Model(0) { }
TCascade::TCascade ( const double &  alpha) [inline]

Definition at line 27 of file cascnetinf.h.

: NIdHitH(), CurProb(0), Alpha(alpha), Eps(1e-64), Model(0) { }
TCascade::TCascade ( const double &  alpha,
const int &  model 
) [inline]

Definition at line 28 of file cascnetinf.h.

: NIdHitH(), CurProb(0), Alpha(alpha), Eps(1e-64), Model(model) { }
TCascade::TCascade ( const double &  alpha,
const double &  eps 
) [inline]

Definition at line 29 of file cascnetinf.h.

: NIdHitH(), CurProb(0), Alpha(alpha), Eps(eps), Model(0) { }
TCascade::TCascade ( const double &  alpha,
const int &  model,
const double &  eps 
) [inline]

Definition at line 30 of file cascnetinf.h.

: NIdHitH(), CurProb(0), Alpha(alpha), Eps(eps), Model(model) { }
TCascade::TCascade ( TSIn SIn) [inline]

Definition at line 31 of file cascnetinf.h.

: NIdHitH(SIn), CurProb(SIn), Alpha(SIn) { }

Member Function Documentation

void TCascade::Add ( const int &  NId,
const double &  HitTm 
) [inline]

Definition at line 39 of file cascnetinf.h.

{ NIdHitH.AddDat(NId, THitInfo(NId, HitTm)); }
void TCascade::Add ( const int &  NId,
const double &  HitTm 
) [inline]

Definition at line 107 of file cascdynetinf.h.

{ NIdHitH.AddDat(NId, THitInfo(NId, HitTm)); }
THash<TInt, THitInfo>::TIter TCascade::BegI ( ) const [inline]

Definition at line 101 of file cascdynetinf.h.

{ return NIdHitH.BegI(); }
void TCascade::Clr ( ) [inline]

Definition at line 33 of file cascnetinf.h.

{ NIdHitH.Clr(); CurProb = 0; Alpha = 1.0; }
void TCascade::Clr ( ) [inline]

Definition at line 95 of file cascdynetinf.h.

{ NIdHitH.Clr(); }
void TCascade::Del ( const int &  NId) [inline]

Definition at line 40 of file cascnetinf.h.

{ NIdHitH.DelKey(NId); }
void TCascade::Del ( const int &  NId) [inline]

Definition at line 108 of file cascdynetinf.h.

{ NIdHitH.DelKey(NId); }
THash<TInt, THitInfo>::TIter TCascade::EndI ( ) const [inline]

Definition at line 102 of file cascdynetinf.h.

{ return NIdHitH.EndI(); }
double TCascade::GetAlpha ( ) const [inline]

Definition at line 37 of file cascnetinf.h.

{ return Alpha; }
int TCascade::GetId ( ) [inline]

Definition at line 96 of file cascdynetinf.h.

{ return CId; }
double TCascade::GetMaxTm ( ) const [inline]

Definition at line 105 of file cascdynetinf.h.

{ return NIdHitH[NIdHitH.Len()-1].Tm; } // we assume the cascade is sorted
double TCascade::GetMinTm ( ) const [inline]

Definition at line 106 of file cascdynetinf.h.

{ return NIdHitH[0].Tm; } // we assume the cascade is sorted
int TCascade::GetModel ( ) const [inline]

Definition at line 103 of file cascdynetinf.h.

{ return Model; }
int TCascade::GetNode ( const int &  i) const [inline]

Definition at line 35 of file cascnetinf.h.

{ return NIdHitH.GetKey(i); }
int TCascade::GetNode ( const int &  i) const [inline]

Definition at line 100 of file cascdynetinf.h.

{ return NIdHitH.GetKey(i); }
int TCascade::GetParent ( const int  NId) const [inline]

Definition at line 36 of file cascnetinf.h.

{ return NIdHitH.GetDat(NId).Parent; }
double TCascade::GetProb ( const PNGraph G)

Definition at line 17 of file cascnetinf.cpp.

                                         {
    double P = 0;
    for (int n = 0; n < Len(); n++) {
      const int DstNId = GetNode(n);
      const double DstTm = GetTm(DstNId);
      TNGraph::TNodeI NI = G->GetNI(DstNId);
      double MxProb = log(Eps);
      int BestParent = -1;
      for (int e = 0; e < NI.GetInDeg(); e++) {
        const int SrcNId = NI.GetInNId(e);
        if (IsNode(SrcNId) && GetTm(SrcNId) < DstTm) {
          const double Prob = log(TransProb(SrcNId, DstNId));
          if (MxProb < Prob) { MxProb = Prob;  BestParent = SrcNId; }
        }
      }
      NIdHitH.GetDat(DstNId).Parent = BestParent;
      P += MxProb;
    }

    return P;
}
double TCascade::GetTm ( const int &  NId) const [inline]

Definition at line 38 of file cascnetinf.h.

{ return NIdHitH.GetDat(NId).Tm; }
double TCascade::GetTm ( const int &  NId) const [inline]

Definition at line 104 of file cascdynetinf.h.

{ return NIdHitH.GetDat(NId).Tm; }

Definition at line 40 of file cascnetinf.cpp.

                        {
    CurProb = log(Eps) * Len();
    for (int i = 0; i < Len(); i++) {
      NIdHitH[i].Parent = -1; }
}
bool TCascade::IsNode ( const int &  NId) const [inline]

Definition at line 41 of file cascnetinf.h.

{ return NIdHitH.IsKey(NId); }
bool TCascade::IsNode ( const int &  NId) const [inline]

Definition at line 109 of file cascdynetinf.h.

{ return NIdHitH.IsKey(NId); }
int TCascade::Len ( ) const [inline]

Definition at line 34 of file cascnetinf.h.

{ return NIdHitH.Len(); }
int TCascade::Len ( ) const [inline]

Definition at line 97 of file cascdynetinf.h.

{ return NIdHitH.Len(); }
int TCascade::LenAfterT ( const double &  T) [inline]

Definition at line 99 of file cascdynetinf.h.

{ int len = 0; while (len < NIdHitH.Len() && NIdHitH[NIdHitH.Len()-1-len].Tm >= T) { len++; } return len; }
int TCascade::LenBeforeT ( const double &  T) [inline]

Definition at line 98 of file cascdynetinf.h.

{ int len = 0; while (len < NIdHitH.Len() && NIdHitH[len].Tm <= T) { len++; } return len; }
bool TCascade::operator< ( const TCascade Cascade) const [inline]

Definition at line 111 of file cascdynetinf.h.

                                                  {
      return Len() < Cascade.Len(); }
void TCascade::Save ( TSOut SOut) const [inline]

Definition at line 32 of file cascnetinf.h.

{ NIdHitH.Save(SOut); CurProb.Save(SOut); Alpha.Save(SOut); }
void TCascade::Save ( TSOut SOut) const [inline]

Definition at line 94 of file cascdynetinf.h.

{ CId.Save(SOut); NIdHitH.Save(SOut); Model.Save(SOut); }
void TCascade::Sort ( ) [inline]

Definition at line 42 of file cascnetinf.h.

{ NIdHitH.SortByDat(true); }
void TCascade::Sort ( ) [inline]

Definition at line 110 of file cascdynetinf.h.

{ NIdHitH.SortByDat(true); }
double TCascade::TransProb ( const int &  NId1,
const int &  NId2 
) const

Definition at line 4 of file cascnetinf.cpp.

                                                                 {
  if (!IsNode(NId1) || !IsNode(NId2)) { return Eps.Val; }
  if (GetTm(NId1) >= GetTm(NId2)) { return Eps.Val; }
  if (Model==0)
    return Alpha*exp(-Alpha*(GetTm(NId2)-GetTm(NId1))); // exponential
  else if (Model==1)
    return (Alpha-1)*pow((GetTm(NId2)-GetTm(NId1)), -Alpha); // power-law
  else
    return Alpha*(GetTm(NId2)-GetTm(NId1))*exp(-0.5*Alpha*pow(GetTm(NId2)-GetTm(NId1), 2)); // rayleigh

  return (-1);
}
double TCascade::UpdateProb ( const int &  N1,
const int &  N2,
const bool &  UpdateProb = false 
)

Definition at line 47 of file cascnetinf.cpp.

                                                                                {
    if (!IsNode(N1) || !IsNode(N2)) { return CurProb; }
    if (GetTm(N1) >= GetTm(N2)) { return CurProb; }
    const double P1 = log(TransProb(GetParent(N2), N2));
    const double P2 = log(TransProb(N1, N2)); // N1 influences N2
    if (P1 < P2) {
      if (UpdateProb) { // the edge is there, update the CurProb and best Parent
        CurProb = CurProb - P1 + P2;
        NIdHitH.GetDat(N2).Parent = N1;
      } else {
        return CurProb - P1 + P2; }
    }
    return CurProb;
}

Member Data Documentation

Definition at line 23 of file cascnetinf.h.

Definition at line 86 of file cascdynetinf.h.

Definition at line 23 of file cascnetinf.h.

Definition at line 23 of file cascnetinf.h.

Definition at line 88 of file cascdynetinf.h.

Definition at line 87 of file cascdynetinf.h.


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