本文整理汇总了C++中TRnd类的典型用法代码示例。如果您正苦于以下问题:C++ TRnd类的具体用法?C++ TRnd怎么用?C++ TRnd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TRnd类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main() {
TLSHash LSH(7, 7, DIM, TLSHash::EUCLIDEAN);
LSH.Init();
TRnd Gen;
Gen.Randomize();
TVec<TFltV> DataV;
for (int i=0; i<1000000; i++) {
TFltV Datum;
for (int j=0; j<3; j++) {
Datum.Add(Gen.GetUniDev()*2100);
}
DataV.Add(Datum);
}
LSH.AddV(DataV);
TVec<TPair<TFltV, TFltV> > NeighborsV = LSH.GetAllCandidatePairs();
printf("Number of Candidates: %d\n", NeighborsV.Len());
NeighborsV = LSH.GetAllNearPairs();
printf("Number of Close Pairs: %d\n", NeighborsV.Len());
for (int i=0; i<NeighborsV.Len(); i++) {
outputPoint(NeighborsV[i].GetVal1());
printf(" ");
outputPoint(NeighborsV[i].GetVal2());
printf("\n");
}
return 0;
}
开发者ID:BestSean2016,项目名称:snap,代码行数:30,代码来源:lshtest.cpp
示例2: GenSmallWorld
/// Generates a small-world graph using the Watts-Strogatz model.
/// We assume a circle where each node creates links to NodeOutDeg other nodes.
/// This way at the end each node is connected to 2*NodeOutDeg other nodes.
/// See: Collective dynamics of 'small-world' networks. Watts and Strogatz.
/// URL: http://research.yahoo.com/files/w_s_NATURE_0.pdf
PUNGraph GenSmallWorld(const int& Nodes, const int& NodeOutDeg, const double& RewireProb, TRnd& Rnd) {
THashSet<TIntPr> EdgeSet(Nodes*NodeOutDeg);
IAssertR(Nodes > NodeOutDeg, TStr::Fmt("Insufficient nodes for out degree, %d!", NodeOutDeg));
for (int node = 0; node < Nodes; node++) {
const int src = node;
for (int edge = 1; edge <= NodeOutDeg; edge++) {
int dst = (node+edge) % Nodes; // edge to next neighbor
if (Rnd.GetUniDev() < RewireProb) { // random edge
dst = Rnd.GetUniDevInt(Nodes);
while (dst == src || EdgeSet.IsKey(TIntPr(src, dst))) {
dst = Rnd.GetUniDevInt(Nodes); }
}
EdgeSet.AddKey(TIntPr(src, dst));
}
}
PUNGraph GraphPt = TUNGraph::New();
TUNGraph& Graph = *GraphPt;
Graph.Reserve(Nodes, EdgeSet.Len());
int node;
for (node = 0; node < Nodes; node++) {
IAssert(Graph.AddNode(node) == node);
}
for (int edge = 0; edge < EdgeSet.Len(); edge++) {
Graph.AddEdge(EdgeSet[edge].Val1, EdgeSet[edge].Val2);
}
Graph.Defrag();
return GraphPt;
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:34,代码来源:ggen.cpp
示例3: GenRndBipart
PBPGraph GenRndBipart(const int& LeftNodes, const int& RightNodes, const int& Edges, TRnd& Rnd) {
PBPGraph G = TBPGraph::New();
for (int i = 0; i < LeftNodes; i++) { G->AddNode(i, true); }
for (int i = 0; i < RightNodes; i++) { G->AddNode(LeftNodes+i, false); }
IAssertR(Edges <= LeftNodes*RightNodes, "Too many edges in the bipartite graph!");
for (int edges = 0; edges < Edges; ) {
const int LNId = Rnd.GetUniDevInt(LeftNodes);
const int RNId = LeftNodes + Rnd.GetUniDevInt(RightNodes);
if (G->AddEdge(LNId, RNId) != -2) { edges++; } // is new edge
}
return G;
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:12,代码来源:ggen.cpp
示例4: RndConnectInsideCommunity
void TAGM::RndConnectInsideCommunity(PUNGraph& Graph, const TIntV& CmtyV, const double& Prob, TRnd& Rnd){
int CNodes = CmtyV.Len();
int CEdges = Rnd.GetBinomialDev(Prob,CNodes*(CNodes-1)/2);
THashSet<TIntPr> NewEdgeSet(CEdges);
for (int edge = 0; edge < CEdges; ) {
int SrcNId = CmtyV[Rnd.GetUniDevInt(CNodes)];
int DstNId = CmtyV[Rnd.GetUniDevInt(CNodes)];
if(SrcNId>DstNId){Swap(SrcNId,DstNId);}
if (SrcNId != DstNId && !NewEdgeSet.IsKey(TIntPr(SrcNId,DstNId))) { // is new edge
NewEdgeSet.AddKey(TIntPr(SrcNId,DstNId));
Graph->AddEdge(SrcNId,DstNId);
edge++;
}
}
}
开发者ID:Networks-Learning,项目名称:infopath,代码行数:15,代码来源:agm.cpp
示例5: GetRndNId
int TBPGraph::GetRndNId(TRnd& Rnd) {
const int NNodes = GetNodes();
if (Rnd.GetUniDevInt(NNodes) < GetLNodes()) {
return GetRndLNId(Rnd); }
else {
return GetRndRNId(Rnd); }
}
开发者ID:arbenson,项目名称:snap,代码行数:7,代码来源:graph.cpp
示例6: choose_seeds
THash<TInt, TInt> * choose_seeds (const PUNGraph g, const int num, const int * infection_state, const int infect) {
THash<TInt, TInt> choices;
THash<TInt, TUNGraph::TNode> nodes;
THash<TInt, TInt> * output = new THash<TInt, TInt> ();
TInt weight = 0;
TInt num_total = 0;
for (TUNGraph::TNodeI n = g->BegNI(); n != g->EndNI(); n++) {
//cout << "nodeID: " << n.GetId() << ",\tStatus: " << infection_state[n.GetId () - 1] << endl;
if (infection_state[n.GetId () - 1] != infect) {
weight += n.GetDeg ();
choices.AddDat (num_total, weight);
nodes.AddDat (num_total, n.GetId());
num_total++;
}
}
// TRnd random ((int) time(NULL));
// TRnd random (0);
TInt num_chosen = 0;
while (num_chosen < num) {
TInt choice = my_random.GetUniDevInt (weight);
TUNGraph::TNode node_choice = nodes[find (choice, choices, 0, num_total-1)];
if (!output->IsKey(node_choice.GetId())) {
num_chosen++;
// cout << node_choice.GetId () << "\n";
output->AddDat(node_choice.GetId (), 1);
}
}
return output;
}
开发者ID:pbd6595,项目名称:pbd6595_F2013_project,代码行数:30,代码来源:statnet.cpp
示例7: test
bool test(PGraph &graph, bool followOut, bool followIn) {
printf("\n================================\nFollowOut: %d, FollowIn: %d\n", followOut, followIn);
int iters = 10;
for (int k = 0; k < iters; k++) {
TRnd rnd = TRnd((int)time(0));
int start = graph->GetRndNId(rnd);
rnd.PutSeed(0);
// int target = graph->GetRndNId(rnd);
// printf("Start node: %d, target node: %d\n", start, target);
int target = -1;
printf("Start node: %d\n", start);
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
/* Hybrid */
TBreathFS<PGraph> bfs_hybrid(graph, true);
int maxDist_hybrid = bfs_hybrid.DoBfsHybrid(start, followOut, followIn, target);
gettimeofday(&tv2, NULL);
double time_hybrid = timeInSeconds(tv1, tv2);
/* Original */
gettimeofday(&tv1, NULL);
TBreathFS<PGraph> bfs(graph, true);
int maxDist = bfs.DoBfs(start, followOut, followIn, target);
gettimeofday(&tv2, NULL);
double time = timeInSeconds(tv1, tv2);
/* Check results */
if (maxDist_hybrid != maxDist) {
printf("MaxDist incorrect.\n");
return false;
}
if (target == -1) {
if (!checkResults<PGraph>(bfs_hybrid, bfs)) {
printf("NIdDistH values incorrect!\n");
return false;
}
}
printf("Execution times: Original: %.2f, Hybrid: %.2f\n", time, time_hybrid);
}
return true;
}
开发者ID:IsmaelAli,项目名称:snap,代码行数:47,代码来源:test.cpp
示例8: InitPosEmb
//Initialize positive embeddings
void InitPosEmb(TIntV& Vocab, int& Dimensions, TRnd& Rnd, TVVec<TFlt, int64>& SynPos) {
SynPos = TVVec<TFlt, int64>(Vocab.Len(),Dimensions);
for (int64 i = 0; i < SynPos.GetXDim(); i++) {
for (int j = 0; j < SynPos.GetYDim(); j++) {
SynPos(i,j) =(Rnd.GetUniDev()-0.5)/Dimensions;
}
}
}
开发者ID:jsw883,项目名称:snap,代码行数:9,代码来源:word2vec.cpp
示例9: Init
void TLSHash::Init() {
TRnd Gen;
Gen.Randomize();
for (int i=0; i<Bands*Rows; i++) {
if (Type == JACCARD) {
HashFuncV.Add(TPt<HashFunc>(new JaccardHash(Gen, Dim)));
} else if (Type == COSINE) {
HashFuncV.Add(TPt<HashFunc>(new CosineHash(Gen, Dim)));
} else {
HashFuncV.Add(TPt<HashFunc>(new EuclideanHash(Gen, Dim)));
}
}
for (int i=0; i<Bands; i++) {
SigBucketVHV.Add(THash<TInt, TIntV> (ExpectedSz, true));
}
}
开发者ID:EDzhangjianyu,项目名称:snap,代码行数:18,代码来源:lsh.cpp
示例10: GenPLSeq
///Generate sequence from Power law
void TAGMUtil::GenPLSeq(TIntV& SzSeq, const int& SeqLen, const double& Alpha, TRnd& Rnd, const int& Min, const int& Max) {
SzSeq.Gen(SeqLen, 0);
while (SzSeq.Len() < SeqLen) {
int Sz = (int) TMath::Round(Rnd.GetPowerDev(Alpha));
if (Sz >= Min && Sz <= Max) {
SzSeq.Add(Sz);
}
}
}
开发者ID:RoyZhengGao,项目名称:CommunityEvaluation,代码行数:10,代码来源:agm.cpp
示例11: GenCopyModel
/// Generates a random scale-free network using the Copying Model.
/// The generating process operates as follows: Node u is added to a graph, it
/// selects a random node v, and with prob Beta it links to v, with 1-Beta
/// links u links to neighbor of v. The power-law degree exponent is -1/(1-Beta).
/// See: Stochastic models for the web graph.
/// Kumar, Raghavan, Rajagopalan, Sivakumar, Tomkins, Upfal.
/// URL: http://snap.stanford.edu/class/cs224w-readings/kumar00stochastic.pdf
PNGraph GenCopyModel(const int& Nodes, const double& Beta, TRnd& Rnd) {
PNGraph GraphPt = TNGraph::New();
TNGraph& Graph = *GraphPt;
Graph.Reserve(Nodes, Nodes);
const int startNId = Graph.AddNode();
Graph.AddEdge(startNId, startNId);
for (int n = 1; n < Nodes; n++) {
const int rnd = Graph.GetRndNId();
const int NId = Graph.AddNode();
if (Rnd.GetUniDev() < Beta) {
Graph.AddEdge(NId, rnd); }
else {
const TNGraph::TNodeI NI = Graph.GetNI(rnd);
const int rnd2 = Rnd.GetUniDevInt(NI.GetOutDeg());
Graph.AddEdge(NId, NI.GetOutNId(rnd2));
}
}
return GraphPt;
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:26,代码来源:ggen.cpp
示例12: GetSphereDev
/// Sample random point from the surface of a Dim-dimensional unit sphere.
void GetSphereDev(const int& Dim, TRnd& Rnd, TFltV& ValV) {
if (ValV.Len() != Dim) { ValV.Gen(Dim); }
double Length = 0.0;
for (int i = 0; i < Dim; i++) {
ValV[i] = Rnd.GetNrmDev();
Length += TMath::Sqr(ValV[i]); }
Length = 1.0 / sqrt(Length);
for (int i = 0; i < Dim; i++) {
ValV[i] *= Length;
}
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:12,代码来源:ggen.cpp
示例13: GenConfModel
/// Generates a random undirect graph with a given degree sequence DegSeqV.
/// Configuration model operates as follows. For each node N, of degree
/// DeqSeqV[N] we create DeqSeqV[N] spokes (half-edges). We then pick two
/// spokes at random, and connect the spokes endpoints. We continue this
/// process until no spokes are left. Generally this generates a multigraph
/// (i.e., spokes out of same nodes can be chosen multiple times).We ignore
/// (discard) self-loops and multiple edges. Thus, the generated graph will
/// only approximate follow the given degree sequence. The method is very fast!
PUNGraph GenConfModel(const TIntV& DegSeqV, TRnd& Rnd) {
const int Nodes = DegSeqV.Len();
PUNGraph GraphPt = TUNGraph::New();
TUNGraph& Graph = *GraphPt;
Graph.Reserve(Nodes, -1);
TIntV NIdDegV(DegSeqV.Len(), 0);
int DegSum=0, edges=0;
for (int node = 0; node < Nodes; node++) {
Graph.AddNode(node);
for (int d = 0; d < DegSeqV[node]; d++) { NIdDegV.Add(node); }
DegSum += DegSeqV[node];
}
NIdDegV.Shuffle(Rnd);
TIntPrSet EdgeH(DegSum/2); // set of all edges, is faster than graph edge lookup
if (DegSum % 2 != 0) {
printf("Seg seq is odd [%d]: ", DegSeqV.Len());
for (int d = 0; d < TMath::Mn(100, DegSeqV.Len()); d++) { printf(" %d", (int)DegSeqV[d]); }
printf("\n");
}
int u=0, v=0;
for (int c = 0; NIdDegV.Len() > 1; c++) {
u = Rnd.GetUniDevInt(NIdDegV.Len());
while ((v = Rnd.GetUniDevInt(NIdDegV.Len())) == u) { }
if (u > v) { Swap(u, v); }
const int E1 = NIdDegV[u];
const int E2 = NIdDegV[v];
if (v == NIdDegV.Len()-1) { NIdDegV.DelLast(); }
else { NIdDegV[v] = NIdDegV.Last(); NIdDegV.DelLast(); }
if (u == NIdDegV.Len()-1) { NIdDegV.DelLast(); }
else { NIdDegV[u] = NIdDegV.Last(); NIdDegV.DelLast(); }
if (E1 == E2 || EdgeH.IsKey(TIntPr(E1, E2))) { continue; }
EdgeH.AddKey(TIntPr(E1, E2));
Graph.AddEdge(E1, E2);
edges++;
if (c % (DegSum/100+1) == 0) { printf("\r configuration model: iter %d: edges: %d, left: %d", c, edges, NIdDegV.Len()/2); }
}
printf("\n");
return GraphPt;
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:47,代码来源:ggen.cpp
示例14: GenRndGnm
PGraph GenRndGnm(const int& Nodes, const int& Edges, const bool& IsDir, TRnd& Rnd) {
PGraph GraphPt = PGraph::New();
typename PGraph::TObj& Graph = *GraphPt;
Graph.Reserve(Nodes, Edges);
for (int node = 0; node < Nodes; node++) {
IAssert(Graph.AddNode(node) == node);
}
for (int edge = 0; edge < Edges; ) {
const int SrcNId = Rnd.GetUniDevInt(Nodes);
const int DstNId = Rnd.GetUniDevInt(Nodes);
if (SrcNId != DstNId && Graph.AddEdge(SrcNId, DstNId) != -2) {
if (! IsDir) { Graph.AddEdge(DstNId, SrcNId); }
edge++;
}
}
return GraphPt;
}
开发者ID:nikhilkhadke,项目名称:snapr,代码行数:17,代码来源:demo-topology-benchmark.cpp
示例15: GenGeoPrefAttach
/// Generates a random scale-free graph using the Geometric Preferential
/// Attachment model by Flexman, Frieze and Vera.
/// See: A geometric preferential attachment model of networks by Flexman,
/// Frieze and Vera. WAW 2004.
/// URL: http://math.cmu.edu/~af1p/Texfiles/GeoWeb.pdf
PUNGraph GenGeoPrefAttach(const int& Nodes, const int& OutDeg, const double& Beta, TRnd& Rnd) {
PUNGraph G = TUNGraph::New(Nodes, Nodes*OutDeg);
TFltTrV PointV(Nodes, 0);
TFltV ValV;
// points on a sphere of radius 1/(2*pi)
const double Rad = 0.5 * TMath::Pi;
for (int i = 0; i < Nodes; i++) {
TSnapDetail::GetSphereDev(3, Rnd, ValV);
PointV.Add(TFltTr(Rad*ValV[0], Rad*ValV[1], Rad*ValV[2]));
}
const double R2 = TMath::Sqr(log((double) Nodes) / (pow((double) Nodes, 0.5-Beta)));
TIntV DegV, NIdV;
int SumDeg;
for (int t = 0; t < Nodes; t++) {
const int pid = t;
const TFltTr& P1 = PointV[pid];
// add node
if (! G->IsNode(pid)) { G->AddNode(pid); }
// find neighborhood
DegV.Clr(false); NIdV.Clr(false); SumDeg=0;
for (int p = 0; p < t; p++) {
const TFltTr& P2 = PointV[p];
if (TMath::Sqr(P1.Val1-P2.Val1)+TMath::Sqr(P1.Val2-P2.Val2)+TMath::Sqr(P1.Val3-P2.Val3) < R2) {
NIdV.Add(p);
DegV.Add(G->GetNI(p).GetDeg()+1);
SumDeg += DegV.Last();
}
}
// add edges
for (int m = 0; m < OutDeg; m++) {
const int rnd = Rnd.GetUniDevInt(SumDeg);
int sum = 0, dst = -1;
for (int s = 0; s < DegV.Len(); s++) {
sum += DegV[s];
if (rnd < sum) { dst=s; break; }
}
if (dst != -1) {
G->AddEdge(pid, NIdV[dst]);
SumDeg -= DegV[dst];
NIdV.Del(dst); DegV.Del(dst);
}
}
}
return G;
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:50,代码来源:ggen.cpp
示例16: choose
THash <TInt, TInt> * choose (const TInt & population_size, const TInt & sample_size) {
THash <TInt, TInt> * hits = new THash <TInt, TInt> ();
//TRnd random ((int)time(NULL));
//TRnd random (0);
TInt min = TMath::Mn<TInt> (population_size, sample_size);
for (int i = 0; i < min; i++) {
TInt chosen = my_random.GetUniDevInt (population_size - i);
if (hits->IsKey (chosen)) {
hits->AddDat((*hits)(chosen), population_size - i - 1);
}
hits->AddDat(chosen, population_size - i - 1);
}
return hits;
}
开发者ID:pbd6595,项目名称:pbd6595_F2013_project,代码行数:18,代码来源:statnet.cpp
示例17: RewireCmtyNID
/// rewire bipartite community affiliation graphs
void TAGMUtil::RewireCmtyNID(THash<TInt,TIntV >& CmtyVH, TRnd& Rnd) {
THash<TInt,TIntV > NewCmtyVH(CmtyVH.Len());
TIntV NDegV;
TIntV CDegV;
for (int i = 0; i < CmtyVH.Len(); i++) {
int CID = CmtyVH.GetKey(i);
for (int j = 0; j < CmtyVH[i].Len(); j++) {
int NID = CmtyVH[i][j];
NDegV.Add(NID);
CDegV.Add(CID);
}
}
TIntPrSet CNIDSet(CDegV.Len());
int c=0;
while (c++ < 15 && CDegV.Len() > 1) {
for (int i = 0; i < CDegV.Len(); i++) {
int u = Rnd.GetUniDevInt(CDegV.Len());
int v = Rnd.GetUniDevInt(NDegV.Len());
if (CNIDSet.IsKey(TIntPr(CDegV[u], NDegV[v]))) {
continue;
}
CNIDSet.AddKey(TIntPr(CDegV[u], NDegV[v]));
if (u == CDegV.Len() - 1) {
CDegV.DelLast();
} else {
CDegV[u] = CDegV.Last();
CDegV.DelLast();
}
if ( v == NDegV.Len() - 1) {
NDegV.DelLast();
} else {
NDegV[v] = NDegV.Last();
NDegV.DelLast();
}
}
}
for (int i = 0; i < CNIDSet.Len(); i++) {
TIntPr CNIDPr = CNIDSet[i];
IAssert(CmtyVH.IsKey(CNIDPr.Val1));
NewCmtyVH.AddDat(CNIDPr.Val1);
NewCmtyVH.GetDat(CNIDPr.Val1).Add(CNIDPr.Val2);
}
CmtyVH = NewCmtyVH;
}
开发者ID:RoyZhengGao,项目名称:CommunityEvaluation,代码行数:45,代码来源:agm.cpp
示例18: GenRndPowerLaw
/// Generates a random scale-free graph with power-law degree distribution with
/// exponent PowerExp. The method uses either the Configuration model (fast but
/// the result is approximate) or the Edge Rewiring method (slow but exact).
PUNGraph GenRndPowerLaw(const int& Nodes, const double& PowerExp, const bool& ConfModel, TRnd& Rnd) {
TIntV DegSeqV;
uint DegSum=0;
for (int n = 0; n < Nodes; n++) {
const int Val = (int) TMath::Round(Rnd.GetPowerDev(PowerExp));
if (! (Val >= 1 && Val < Nodes/2)) { n--; continue; } // skip nodes with too large degree
DegSeqV.Add(Val);
DegSum += Val;
}
printf("%d nodes, %u edges\n", Nodes, DegSum);
if (DegSum % 2 == 1) { DegSeqV[0] += 1; }
if (ConfModel) {
// use configuration model -- fast but does not exactly obey the degree sequence
return GenConfModel(DegSeqV, Rnd);
} else {
PUNGraph G = TSnap::GenDegSeq(DegSeqV, Rnd);
return TSnap::GenRewire(G, 10, Rnd);
}
}
开发者ID:DumexVN,项目名称:RandomAggLargeWithSnap,代码行数:22,代码来源:ggen.cpp
示例19: Shuffle
void TTransCorpus::Shuffle(const PTransCorpus& InFirstTransCorpus,
const PTransCorpus& InSecondTransCorpus, TRnd& Rnd, const double& SwapProb,
PTransCorpus& OutFirstTransCorpus, PTransCorpus& OutSecondTransCorpus) {
// prepare new corpuses
OutFirstTransCorpus = TTransCorpus::New();
OutSecondTransCorpus = TTransCorpus::New();
// swap sentences
TIntV FirstSentIdV, SecondSentIdV;
InFirstTransCorpus->GetSentIdV(FirstSentIdV);
InSecondTransCorpus->GetSentIdV(SecondSentIdV);
for (int SentIdN = 0; SentIdN < FirstSentIdV.Len(); SentIdN++) {
// get sentence id
const int SentId = FirstSentIdV[SentIdN];
// check if id same in both cases
IAssert(SecondSentIdV[SentIdN] == SentId);
// read sentences
TStr OrgStr1 = InFirstTransCorpus->GetOrgStr(SentId);
TStr OrgStr2 = InSecondTransCorpus->GetOrgStr(SentId);
IAssert(OrgStr1 == OrgStr2 );
TStr RefTransStr1 = InFirstTransCorpus->GetRefTransStrV(SentId)[0];
TStr RefTransStr2 = InSecondTransCorpus->GetRefTransStrV(SentId)[0];
IAssert(RefTransStr1 == RefTransStr2);
TStr FirstTransStr = InFirstTransCorpus->GetTransStr(SentId);
TStr SecondTransStr = InSecondTransCorpus->GetTransStr(SentId);
// swap sentences
if (Rnd.GetUniDev() < SwapProb) {
// we swap
OutFirstTransCorpus->AddSentence(SentId, OrgStr1, SecondTransStr, RefTransStr1);
OutSecondTransCorpus->AddSentence(SentId, OrgStr1, FirstTransStr, RefTransStr1);
} else {
// no swap
OutFirstTransCorpus->AddSentence(SentId, OrgStr1, FirstTransStr, RefTransStr1);
OutSecondTransCorpus->AddSentence(SentId, OrgStr1, SecondTransStr, RefTransStr1);
}
}
}
开发者ID:AlertProject,项目名称:Text-processing-bundle,代码行数:37,代码来源:biling.cpp
示例20: ConnectCmtyVV
///Generate bipartite community affiliation from given power law coefficients for membership distribution and community size distribution.
void TAGMUtil::ConnectCmtyVV(TVec<TIntV>& CmtyVV, const TIntPrV& CIDSzPrV, const TIntPrV& NIDMemPrV, TRnd& Rnd) {
const int Nodes = NIDMemPrV.Len(), Coms = CIDSzPrV.Len();
TIntV NDegV,CDegV;
TIntPrSet CNIDSet;
TIntSet HitNodes(Nodes);
THash<TInt,TIntV> CmtyVH;
for (int i = 0; i < CIDSzPrV.Len(); i++) {
for (int j = 0; j < CIDSzPrV[i].Val2; j++) {
CDegV.Add(CIDSzPrV[i].Val1);
}
}
for (int i = 0; i < NIDMemPrV.Len(); i++) {
for (int j = 0; j < NIDMemPrV[i].Val2; j++) {
NDegV.Add(NIDMemPrV[i].Val1);
}
}
while (CDegV.Len() < (int) (1.2 * Nodes)) {
CDegV.Add(CIDSzPrV[Rnd.GetUniDevInt(Coms)].Val1);
}
while (NDegV.Len() < CDegV.Len()) {
NDegV.Add(NIDMemPrV[Rnd.GetUniDevInt(Nodes)].Val1);
}
printf("Total Mem: %d, Total Sz: %d\n",NDegV.Len(), CDegV.Len());
int c=0;
while (c++ < 15 && CDegV.Len() > 1) {
for (int i = 0; i < CDegV.Len(); i++) {
int u = Rnd.GetUniDevInt(CDegV.Len());
int v = Rnd.GetUniDevInt(NDegV.Len());
if (CNIDSet.IsKey(TIntPr(CDegV[u], NDegV[v]))) {
continue;
}
CNIDSet.AddKey(TIntPr(CDegV[u], NDegV[v]));
HitNodes.AddKey(NDegV[v]);
if (u == CDegV.Len() - 1) {
CDegV.DelLast();
}
else {
CDegV[u] = CDegV.Last();
CDegV.DelLast();
}
if (v == NDegV.Len() - 1) {
NDegV.DelLast();
}
else {
NDegV[v] = NDegV.Last();
NDegV.DelLast();
}
}
}
//make sure that every node belongs to at least one community
for (int i = 0; i < Nodes; i++) {
int NID = NIDMemPrV[i].Val1;
if (! HitNodes.IsKey(NID)) {
CNIDSet.AddKey(TIntPr(CIDSzPrV[Rnd.GetUniDevInt(Coms)].Val1, NID));
HitNodes.AddKey(NID);
}
}
IAssert(HitNodes.Len() == Nodes);
for (int i = 0; i < CNIDSet.Len(); i++) {
TIntPr CNIDPr = CNIDSet[i];
CmtyVH.AddDat(CNIDPr.Val1);
CmtyVH.GetDat(CNIDPr.Val1).Add(CNIDPr.Val2);
}
CmtyVH.GetDatV(CmtyVV);
}
开发者ID:RoyZhengGao,项目名称:CommunityEvaluation,代码行数:66,代码来源:agm.cpp
注:本文中的TRnd类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论