-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcascinf.h
131 lines (121 loc) · 3.5 KB
/
cascinf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef snap_cascinf_h
#define snap_cascinf_h
#include "snap/Snap.h"
// Hit info (timestamp, candidate parent) about a node in a cascade
class THitInfo
{
public:
TInt NId, Parent;
TFlt Tm;
public:
THitInfo(const int &NodeId = -1, const double &HitTime = 0) : NId(NodeId), Parent(-1), Tm(HitTime) {}
THitInfo(TSIn &SIn) : NId(SIn), Parent(SIn), Tm(SIn) {}
void Save(TSOut &SOut) const
{
NId.Save(SOut);
Parent.Save(SOut);
Tm.Save(SOut);
}
bool operator<(const THitInfo &Hit) const
{
return Tm < Hit.Tm;
}
};
// Cascade
class TCascade
{
public:
THash<TInt, THitInfo> NIdHitH;
TFlt CurProb, Alpha;
double Eps;
public:
TCascade() : NIdHitH(), CurProb(0), Alpha(1.0), Eps(1e-64) {}
TCascade(const double &alpha) : NIdHitH(), CurProb(0), Eps(1e-64) { Alpha = alpha; }
TCascade(const double &alpha, const double &eps) : NIdHitH(), CurProb(0)
{
Alpha = alpha;
Eps = eps;
}
TCascade(TSIn &SIn) : NIdHitH(SIn), CurProb(SIn), Alpha(SIn) {}
void Save(TSOut &SOut) const
{
NIdHitH.Save(SOut);
CurProb.Save(SOut);
Alpha.Save(SOut);
}
void Clr()
{
NIdHitH.Clr();
CurProb = 0;
Alpha = 1.0;
}
int Len() const { return NIdHitH.Len(); }
int GetNode(const int &i) const { return NIdHitH.GetKey(i); }
int GetParent(const int NId) const { return NIdHitH.GetDat(NId).Parent; }
double GetAlpha() const { return Alpha; }
double GetTm(const int &NId) const { return NIdHitH.GetDat(NId).Tm; }
void Add(const int &NId, const double &HitTm) { NIdHitH.AddDat(NId, THitInfo(NId, HitTm)); }
void Del(const int &NId) { NIdHitH.DelKey(NId); }
bool IsNode(const int &NId) const { return NIdHitH.IsKey(NId); }
void Sort() { NIdHitH.SortByDat(false); }
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);
};
// Node info (name and number of cascades)
class TNodeInfo
{
public:
TStr Name;
TInt Vol;
public:
TNodeInfo() {}
TNodeInfo(const TStr &NodeNm, const int &Volume) : Name(NodeNm), Vol(Volume) {}
TNodeInfo(TSIn &SIn) : Name(SIn), Vol(SIn) {}
void Save(TSOut &SOut) const
{
Name.Save(SOut);
Vol.Save(SOut);
}
};
// Edge info (name and number of cascades)
class TEdgeInfo
{
public:
TInt Vol;
TFlt MarginalGain, MarginalBound, MedianTimeDiff, AverageTimeDiff; // we can skip MarginalBound for efficiency if not explicitly required
public:
TEdgeInfo() {}
TEdgeInfo(const int &v,
const double &mg,
const double &mb,
const double &mt,
const double &at) : Vol(v), MarginalGain(mg), MarginalBound(mb), MedianTimeDiff(mt), AverageTimeDiff(at) {}
TEdgeInfo(const int &v,
const double &mg,
const double &mt,
const double &at) : Vol(v), MarginalGain(mg), MarginalBound(0), MedianTimeDiff(mt), AverageTimeDiff(at) {}
TEdgeInfo(TSIn &SIn) : Vol(SIn), MarginalGain(SIn), MarginalBound(SIn), MedianTimeDiff(SIn), AverageTimeDiff(SIn) {}
void Save(TSOut &SOut) const
{
Vol.Save(SOut);
SOut.Save(MarginalGain);
SOut.Save(MarginalBound);
SOut.Save(MedianTimeDiff);
SOut.Save(AverageTimeDiff);
} //
};
class Edge
{
public:
int start;
int end;
double value;
Edge(){};
friend bool operator<(const Edge &e1, const Edge &e2);
friend bool operator>(const Edge &e1, const Edge &e2);
friend bool operator>=(const Edge &e1, const Edge &e2);
friend bool operator<=(const Edge &e1, const Edge &e2);
};
#endif