SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TKronNoise Class Reference

#include <kronecker.h>

Public Member Functions

 TKronNoise ()
 

Static Public Member Functions

static int RemoveNodeNoise (PNGraph &Graph, const int &NNodes, const bool Random=true)
 !!!!! MYUNGHWAN, CHECK! More...
 
static int RemoveNodeNoise (PNGraph &Graph, const double &Rate, const bool Random=true)
 
static int FlipEdgeNoise (PNGraph &Graph, const int &NEdges, const bool Random=true)
 
static int FlipEdgeNoise (PNGraph &Graph, const double &Rate, const bool Random=true)
 
static int RemoveEdgeNoise (PNGraph &Graph, const int &NEdges)
 
static int RemoveEdgeNoise (PNGraph &Graph, const double &Rate)
 

Detailed Description

Definition at line 251 of file kronecker.h.

Constructor & Destructor Documentation

TKronNoise::TKronNoise ( )
inline

Definition at line 253 of file kronecker.h.

253 {};

Member Function Documentation

int TKronNoise::FlipEdgeNoise ( PNGraph Graph,
const int &  NEdges,
const bool  Random = true 
)
static

Definition at line 2229 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), TNGraph::AddEdge(), TNGraph::BegEI(), TNGraph::DelEdge(), TNGraph::EndEI(), TVec< TVal, TSizeTy >::Gen(), TNGraph::GetEdges(), TNGraph::GetNIdV(), TNGraph::GetNodes(), TRnd::GetUniDevInt(), IAssert, TNGraph::IsEdge(), and TVec< TVal, TSizeTy >::Shuffle().

Referenced by FlipEdgeNoise().

2229  {
2230  IAssert(NEdges > 0 && NEdges < Graph->GetEdges());
2231 
2232  const int Nodes = Graph->GetNodes();
2233  const int Edges = Graph->GetEdges();
2234  int Src, Dst;
2235 
2236  TIntV NIdV, TempV;
2237  TIntPrV ToAdd, ToDel;
2238  Graph->GetNIdV(NIdV);
2239 
2240  ToAdd.Gen(NEdges / 2, 0);
2241  for(int i = 0; i < NEdges / 2; i++) {
2242  Src = NIdV[TKronMtx::Rnd.GetUniDevInt(Nodes)];
2243  Dst = NIdV[TKronMtx::Rnd.GetUniDevInt(Nodes)];
2244  if(Graph->IsEdge(Src, Dst)) { i--; continue; }
2245 
2246  ToAdd.Add(TIntPr(Src, Dst));
2247  }
2248 
2249  ToDel.Gen(Edges, 0);
2250  for(TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
2251  ToDel.Add(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
2252  }
2253  ToDel.Shuffle(TKronMtx::Rnd);
2254 
2255  for(int i = 0; i < NEdges / 2; i++) {
2256  Graph->DelEdge(ToDel[i].Val1, ToDel[i].Val2);
2257  Graph->AddEdge(ToAdd[i].Val1, ToAdd[i].Val2);
2258  }
2259 
2260  return Graph->GetEdges();
2261 }
#define IAssert(Cond)
Definition: bd.h:262
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
static TRnd Rnd
Definition: kronecker.h:14
Edge iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:430
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Definition: ds.h:1335
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronNoise::FlipEdgeNoise ( PNGraph Graph,
const double &  Rate,
const bool  Random = true 
)
static

Definition at line 2263 of file kronecker.cpp.

References FlipEdgeNoise(), TNGraph::GetEdges(), and IAssert.

2263  {
2264  IAssert(Rate > 0 && Rate < 0.5);
2265  return TKronNoise::FlipEdgeNoise(Graph, (int) floor(Rate * double(Graph->GetEdges())), Random);
2266 }
#define IAssert(Cond)
Definition: bd.h:262
static int FlipEdgeNoise(PNGraph &Graph, const int &NEdges, const bool Random=true)
Definition: kronecker.cpp:2229

Here is the call graph for this function:

int TKronNoise::RemoveEdgeNoise ( PNGraph Graph,
const int &  NEdges 
)
static

Definition at line 2268 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), TNGraph::BegEI(), TNGraph::DelEdge(), TNGraph::EndEI(), TVec< TVal, TSizeTy >::Gen(), TNGraph::GetEdges(), IAssert, and TVec< TVal, TSizeTy >::Shuffle().

Referenced by RemoveEdgeNoise().

2268  {
2269  IAssert(NEdges > 0 && NEdges < Graph->GetEdges());
2270 
2271  TIntPrV ToDel;
2272 
2273  ToDel.Gen(Graph->GetEdges(), 0);
2274  for(TNGraph::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
2275  if(EI.GetSrcNId() != EI.GetDstNId()) {
2276  ToDel.Add(TIntPr(EI.GetSrcNId(), EI.GetDstNId()));
2277  }
2278  }
2279  ToDel.Shuffle(TKronMtx::Rnd);
2280 
2281  for(int i = 0; i < NEdges; i++) {
2282  Graph->DelEdge(ToDel[i].Val1, ToDel[i].Val2);
2283  }
2284 
2285  return Graph->GetEdges();
2286 }
#define IAssert(Cond)
Definition: bd.h:262
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
static TRnd Rnd
Definition: kronecker.h:14
Edge iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:430
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Definition: ds.h:1335
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronNoise::RemoveEdgeNoise ( PNGraph Graph,
const double &  Rate 
)
static

Definition at line 2288 of file kronecker.cpp.

References TNGraph::GetEdges(), IAssert, and RemoveEdgeNoise().

2288  {
2289  IAssert(Rate > 0 && Rate < 0.5);
2290  return TKronNoise::RemoveEdgeNoise(Graph, (int) floor(Rate * double(Graph->GetEdges())));
2291 }
#define IAssert(Cond)
Definition: bd.h:262
static int RemoveEdgeNoise(PNGraph &Graph, const int &NEdges)
Definition: kronecker.cpp:2268

Here is the call graph for this function:

int TKronNoise::RemoveNodeNoise ( PNGraph Graph,
const int &  NNodes,
const bool  Random = true 
)
static

!!!!! MYUNGHWAN, CHECK!

Definition at line 2204 of file kronecker.cpp.

References TNGraph::DelNode(), TNGraph::GetNIdV(), TNGraph::GetNodes(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Shuffle().

Referenced by RemoveNodeNoise().

2204  {
2205  IAssert(NNodes > 0 && NNodes < (Graph->GetNodes() / 2));
2206 
2207  int i = 0;
2208  TIntV ShufflePerm;
2209  Graph->GetNIdV(ShufflePerm);
2210  if(Random) {
2211  ShufflePerm.Shuffle(TKronMtx::Rnd);
2212  for(i = 0; i < NNodes; i++) {
2213  Graph->DelNode(int(ShufflePerm[i]));
2214  }
2215  } else {
2216  for(i = 0; i < NNodes; i++) {
2217  Graph->DelNode(int(ShufflePerm[ShufflePerm.Len() - 1 - i]));
2218  }
2219  }
2220 
2221  return Graph->GetNodes();
2222 }
#define IAssert(Cond)
Definition: bd.h:262
static TRnd Rnd
Definition: kronecker.h:14
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
Definition: ds.h:1335

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronNoise::RemoveNodeNoise ( PNGraph Graph,
const double &  Rate,
const bool  Random = true 
)
static

Definition at line 2224 of file kronecker.cpp.

References TNGraph::GetNodes(), IAssert, and RemoveNodeNoise().

2224  {
2225  IAssert(Rate > 0 && Rate < 0.5);
2226  return TKronNoise::RemoveNodeNoise(Graph, (int) floor(Rate * double(Graph->GetNodes())), Random);
2227 }
#define IAssert(Cond)
Definition: bd.h:262
static int RemoveNodeNoise(PNGraph &Graph, const int &NNodes, const bool Random=true)
!!!!! MYUNGHWAN, CHECK!
Definition: kronecker.cpp:2204

Here is the call graph for this function:


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