19 for (
int n = 0; n <
Len(); n++) {
21 const double DstTm =
GetTm(DstNId);
23 double MxProb = log(
Eps);
25 for (
int e = 0; e < NI.
GetInDeg(); e++) {
28 const double Prob = log(
TransProb(SrcNId, DstNId));
29 if (MxProb < Prob) { MxProb = Prob; BestParent = SrcNId; }
42 for (
int i = 0; i <
Len(); i++) {
66 if (Line==
"") {
break; }
70 printf(
"All nodes read!\n");
72 printf(
"All cascades read!\n");
81 if (Line==
"") {
break; }
101 for (
int i = 0; i < NIdV.
Len(); i+=2) {
104 NId = NIdV[i].GetInt();
105 Tm = NIdV[i+1].GetFlt();
114 const double& std_waiting_time,
const double& std_beta) {
116 double GlobalTime;
int StartNId;
122 while (C.
Len() < 2) {
129 InfectedNIdH.
AddDat(StartNId) = GlobalTime;
134 const int& NId = InfectedNIdH.
BegI().
GetKey();
138 if (GlobalTime >= window)
142 C.
Add(NId, GlobalTime);
146 for (
int e = 0; e < NI.
GetOutDeg(); e++) {
158 if (InfectedBy.
IsKey(NId) && InfectedBy.
GetDat(NId).
Val == DstNId)
182 if (std_waiting_time > 0)
185 double t1 = GlobalTime + sigmaT;
187 if (InfectedNIdH.
IsKey(DstNId)) {
188 double t2 = InfectedNIdH.
GetDat(DstNId);
189 if (t2 > t1 && t2 != window) {
190 InfectedNIdH.
GetDat(DstNId) = t1;
191 InfectedBy.
GetDat(DstNId) = NId;
194 InfectedNIdH.
AddDat(DstNId) = t1;
195 InfectedBy.
AddDat(DstNId) = NId;
200 InfectedNIdH.
GetDat(NId) = window;
208 TIntPr Edge(EI.GetDat().Val, EI.GetKey().Val);
210 if (!EdgesUsed.
IsKey(Edge)) EdgesUsed.
AddDat(Edge) = 0;
212 EdgesUsed.
GetDat(Edge) += 1;
225 for (
int c = 0; c <
CascV.
Len(); c++) {
226 for (
int i = 0; i <
CascV[c].
Len(); i++) {
237 for (
int c = 0; c < Cascs.
Len(); c++) {
238 for (
int i=0; i <
CascV[Cascs[c]].
Len(); i++) {
239 if (
CascV[Cascs[c]].GetNode(i)==NI.GetId())
242 if (
CascV[Cascs[c]].GetTm(
CascV[Cascs[c]].GetNode(i)) <
CascV[Cascs[c]].GetTm(NI.GetId()) ) {
258 if (EdgeN1==-1 && EdgeN2==-1) {
259 for (
int c = 0; c <
CascV.
Len(); c++) {
260 P +=
CascV[c].UpdateProb(EdgeN1, EdgeN2,
false); }
266 for (
int c = 0; c < CascsEdge.
Len(); c++) {
267 P += (
CascV[CascsEdge[c]].UpdateProb(EdgeN1, EdgeN2,
false) -
CascV[CascsEdge[c]].CurProb); }
277 int BestGainIndex = -1;
286 EdgeGainCopyToSortV.
Sort(
false);
291 for (
int i=0, ii=0, j=0; ii < EdgeGainCopyToSortV.
Len(); j++) {
292 if ( (i+EdgeGainCopyToSortV.
Len() <
EdgeGainV.Len()) && (EdgeGainCopyToSortV[ii].Val1 <
EdgeGainV[i+EdgeGainCopyToSortV.
Len()].Val1) ) {
304 for (
int e = 0; e <
EdgeGainV.Len(); e++) {
310 if (BestGain < EProb) {
335 for (
int i=EdgeZero.
Len()-1; i>=0; i--) {
336 if (EdgeZero[i] > BestGainIndex)
342 if (EdgeZero.
Len() > 2) { attempts -= (EdgeZero.
Len()-1); }
344 msort = (attempts > 1);
352 printf(
"Edges exhausted!\n");
361 for (
int e=0; e <
EdgeGainV.Len(); e++) {
365 if (EProb > CurProb) Bounds.
Add(EProb - CurProb); }
369 for (
int i=0; i<
Graph->
GetEdges() && i<Bounds.
Len(); i++) Bound += Bounds[i];
380 for (
int k = 0; k < MxEdges &&
EdgeGainV.Len() > 0; k++) {
382 if (BestE ==
TIntPr(-1, -1))
386 double precision = 0, recall = 0;
405 for (
int c = 0; c < CascsEdge.
Len(); c++) {
406 CascV[CascsEdge[c]].UpdateProb(BestE.
Val1, BestE.
Val2,
true);
411 Vol = 0; AverageTimeDiff = 0;
412 for (
int i=0; i<
CascV.
Len(); i++) {
415 AverageTimeDiff += TimeDiffs[TimeDiffs.
Len()-1]; }
417 AverageTimeDiff /= Vol;
418 if (TimeDiffs.
Len() > 0)
427 TimeDiffs[(
int)(TimeDiffs.
Len()/2)],
441 FILE *F = fopen(OutFNm.
CStr(),
"wt");
442 fprintf(F,
"*Vertices %d\r\n", NIdSet.
Len());
445 fprintf(F,
"%d \"%s\" ic Blue x_fact %f y_fact %f\r\n", NI.GetKey().Val,
446 I.
Name.
CStr(), TMath::Mx<double>(log((
double)I.
Vol)-5,1), TMath::Mx<double>(log((
double)I.
Vol)-5,1));
448 fprintf(F,
"*Arcs\r\n");
450 fprintf(F,
"%d %d 1\r\n", EI.GetSrcNId(), EI.GetDstNId());
457 FILE *F = fopen(OutFNm.
CStr(),
"wt");
459 fprintf(F,
"%d,%d\r\n", NI.GetKey().Val, NI.GetKey().Val);
465 fprintf(F,
"%d,%d\r\n", EI.GetSrcNId(), EI.GetDstNId());
471 FILE *F = fopen(OutFNm.
CStr(),
"wt");
473 fprintf(F,
"src dst vol marginal_gain median_timediff average_timediff\n");
476 fprintf(F,
"%s/%s/%d/%f/%f/%f\n",
491 if (Objective.
Len()==0) { Objective.
Add(EI.GetDat().MarginalGain);
493 Objective.
Add(Objective[Objective.
Len()-1]+EI.
GetDat().MarginalGain);
515 if (EI.GetSrcNId() != EI.GetDstNId()) {
540 FOut.
PutStr(
TStr::Fmt(
",%d,%f", NI.GetDat().NId.Val, NI.GetDat().Tm.Val));
542 FOut.
PutStr(
TStr::Fmt(
"%d,%f", NI.GetDat().NId.Val, NI.GetDat().Tm.Val));
static const T & Mn(const T &LVal, const T &RVal)
void AddNodeNm(const int &NId, const TNodeInfo &Info)
TPair< TInt, TInt > TIntPr
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
void SavePng(const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr())
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
static double GetMx(const double &Flt1, const double &Flt2)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
double GetProb(const PNGraph &G)
void LoadCascadesTxt(TSIn &SIn, const int &Model, const double &alpha)
int GetEdges() const
Returns the number of edges in the graph.
int GetParent(const int NId) const
TSizeTy Len() const
Returns the number of elements in the vector.
double TransProb(const int &NId1, const int &NId2) const
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
double GetRayleigh(const double &Sigma)
int GetNodes() const
Returns the number of nodes in the graph.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
void SavePlaneTextNet(const TStr &OutFNm)
THash< TInt, THitInfo > NIdHitH
const TDat & GetDat(const TKey &Key) const
void SaveObjInfo(const TStr &OutFNm)
double UpdateProb(const int &N1, const int &N2, const bool &UpdateProb=false)
THash< TInt, TNodeInfo > NodeNmH
const TKey & GetKey() const
THash< TIntPr, TIntV > CascPerEdge
void SaveEdgeInfo(const TStr &OutFNm)
double GetTm(const int &NId) const
TVec< TPair< TFlt, TIntPr > > EdgeGainV
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
void GreedyOpt(const int &MxEdges)
const TDat & GetDat() const
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Edge iterator. Only forward iteration (operator++) is supported.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph.
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the graph.
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
void SaveCascades(const TStr &OutFNm)
void SavePajek(const TStr &OutFNm)
THash< TIntPr, TEdgeInfo > EdgeInfoH
TNodeInfo GetNodeInfo(const int &NId) const
void GenCascade(TCascade &C, const int &TModel, const double &window, TIntPrIntH &EdgesUsed, const double &delta, const double &std_waiting_time=0, const double &std_beta=0)
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
void AddCasc(const TStr &CascStr, const int &Model=0, const double &alpha=1.0)
int GetOutDeg() const
Returns out-degree of the current node.
static TStr Fmt(const char *FmtStr,...)
void Add(const int &NId, const double &HitTm)
int PutStr(const char *CStr)
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
Node iterator. Only forward iteration (operator++) is supported.
double GetAllCascProb(const int &EdgeN1, const int &EdgeN2)
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
void LoadGroundTruthTxt(TSIn &SIn)
int GetNode(const int &i) const
int GetInDeg() const
Returns in-degree of the current node.
bool IsKey(const TKey &Key) const
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
TDat & AddDat(const TKey &Key)
double GetBound(const TIntPr &Edge, double &CurProb)
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
bool IsNode(const int &NId) const
double GetPowerDev(const double &AlphaSlope)
void SaveGroundTruth(const TStr &OutFNm)
bool GetNextLn(TStr &LnStr)
void SortByDat(const bool &Asc=true)
TIntPr GetBestEdge(double &CurProb, double &LastGain, bool &msort, int &attempts)