@@ -56,6 +56,7 @@ private class ClusteringInfo {
56
56
public ArrayList <Long > community_core_stubs_ = new ArrayList <Long >();
57
57
public ArrayList <Float > community_core_probs_ = new ArrayList <Float >();
58
58
public ArrayList <Integer > core_nodes_ = new ArrayList <Integer >();
59
+ public ArrayList <Integer > community_id_ = new ArrayList <Integer >();
59
60
public float sumProbs = 0.0f ;
60
61
public int numCommunities = 0 ;
61
62
@@ -67,17 +68,26 @@ private class ClusteringInfo {
67
68
core_node_expected_external_degree_ .add (0.0 );
68
69
is_core_ .add (false );
69
70
clustering_coefficient_ .add (0.0 );
71
+ community_id_ .add (0 );
70
72
}
71
73
for ( int i = 0 ; i < communities .size (); ++i ) {
72
74
community_core_stubs_ .add (0L );
73
75
community_core_probs_ .add (0.0f );
74
76
}
75
77
78
+ int index = 0 ;
76
79
for ( Community c : communities ) {
77
80
for ( PersonInfo pI : c .core_ ) {
78
81
core_nodes_ .add (pI .index_ );
79
82
is_core_ .set (pI .index_ , true );
83
+ community_id_ .set (pI .index_ ,index );
80
84
}
85
+
86
+ for ( PersonInfo pI : c .periphery_ ) {
87
+ is_core_ .set (pI .index_ , false );
88
+ community_id_ .set (pI .index_ ,index );
89
+ }
90
+ index ++;
81
91
}
82
92
83
93
numCommunities = communities .size ();
@@ -97,7 +107,7 @@ private Community findSolution( ArrayList<Person> persons, int begin, int last)
97
107
PersonInfo pInfo = new PersonInfo ();
98
108
pInfo .index_ = i ;
99
109
pInfo .degree_ = Knows .target_edges (p ,percentages ,stepIndex );
100
- pInfo .original_degree_ = (long )(p .maxNumKnows ()* 0.9 );
110
+ pInfo .original_degree_ = (long )(p .maxNumKnows ());
101
111
nodes .add (pInfo );
102
112
}
103
113
@@ -151,6 +161,12 @@ private Community checkBudget(ArrayList<Person> persons, ArrayList<PersonInfo> c
151
161
return community ;
152
162
}
153
163
164
+ private void testCommunity (Community c ) {
165
+ for (PersonInfo pI : c .core_ ) {
166
+ if (pI .degree_ < (c .core_ .size () - 1 )) System .out .println ("Error in building communities\n " );
167
+ }
168
+ }
169
+
154
170
private ArrayList <Community > generateCommunities ( ArrayList <Person > persons ) {
155
171
ArrayList <Community > communities = new ArrayList <Community >();
156
172
int last = 0 ;
@@ -173,6 +189,7 @@ private ArrayList<Community> generateCommunities( ArrayList<Person> persons) {
173
189
}
174
190
bestCommunity .id_ = communities .size ();
175
191
communities .add (bestCommunity );
192
+ testCommunity (bestCommunity );
176
193
177
194
last = best + 1 ;
178
195
begin = last ;
@@ -246,21 +263,23 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
246
263
float probTwoConnected = 0.0f ;
247
264
for ( Integer i : cInfo .core_nodes_ ) {
248
265
double degree1 = cInfo .core_node_expected_external_degree_ .get (i );
249
- if (degree1 > 0 ) {
266
+ if (degree1 >= 1 ) {
250
267
for (Integer ii : cInfo .core_nodes_ ) {
251
- double degree2 = cInfo .core_node_expected_external_degree_ .get (ii );
252
- if (degree2 > 0 )
253
- probTwoConnected += degree1 * degree2 / (float ) (2 * sumStubs * sumStubs );
268
+ if (cInfo .community_id_ .get (i ) != cInfo .community_id_ .get (i )) {
269
+ double degree2 = cInfo .core_node_expected_external_degree_ .get (ii );
270
+ if (degree2 >= 1 )
271
+ probTwoConnected += degree1 * degree2 / (float ) (2 * sumStubs * sumStubs );
272
+ }
254
273
}
255
274
}
256
275
}
257
276
258
277
// Computing clustering coefficient of periphery nodes
259
278
for (PersonInfo pI : c .periphery_ ) {
260
279
if (pI .degree_ > 1 ) {
261
- // cInfo.clustering_coefficient_.set(pI.index_, (double)pI.degree_*(pI.degree_-1)*prob/(pI.original_degree_*(pI.original_degree_-1)));
280
+ cInfo .clustering_coefficient_ .set (pI .index_ , (double )pI .degree_ *(pI .degree_ -1 )*prob /(pI .original_degree_ *(pI .original_degree_ -1 )));
262
281
//cInfo.clustering_coefficient_.set(pI.index_, (double)prob);
263
- cInfo .clustering_coefficient_ .set (pI .index_ , 0.0 );
282
+ // cInfo.clustering_coefficient_.set(pI.index_, 0.0);
264
283
}
265
284
}
266
285
@@ -278,32 +297,11 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
278
297
// core core triangles
279
298
double internalTriangles = 0.0 ;
280
299
double internalDegree = cInfo .core_node_expected_core_degree_ .get (pI .index_ );
281
- /*if(size > 2) {
282
- internalTriangles = ((size - 1) * (size - 2) * Math.pow(prob, 3));
283
- }*/
284
- if (internalDegree > 1.0 ) {
300
+
301
+ if (internalDegree >= 2.0 ) {
285
302
internalTriangles = (internalDegree * (internalDegree - 1 ) * prob );
286
303
}
287
304
boolean enteredOffset = false ;
288
- /*if( internalDegree >= 2.0 ) {
289
- internalTriangles = (internalDegree * (internalDegree - 1) * prob);
290
- } else if( internalDegree > 1.0) {
291
- double offset = internalDegree - 1.0;
292
- double p = rand.nextDouble();
293
- if(p < offset) {
294
- internalTriangles = prob;
295
- enteredOffset = true;
296
- }
297
- }*/
298
- /*long finalInternalDegree = (long)internalDegree;
299
- if( internalDegree > 1 ) {
300
- double offset = internalDegree - 1.0;
301
- double p = rand.nextDouble();
302
- if(p < offset) {
303
- finalInternalDegree++;
304
- }
305
- }*/
306
- //internalTriangles = (finalInternalDegree * (finalInternalDegree - 1) * prob);
307
305
308
306
// core periphery triangles
309
307
double peripheryTriangles = 0 ;
@@ -325,21 +323,18 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
325
323
external_triangles += cInfo .core_node_expected_external_degree_ .get (pI .index_ ) * (cInfo .core_node_expected_external_degree_ .get (pI .index_ ) - 1 ) * (1 - probSameCommunity ) * probTwoConnected ;
326
324
}
327
325
326
+
328
327
//double degree = finalInternalDegree;
329
- double degree = (cInfo .core_node_expected_core_degree_ .get (pI .index_ ) /* +
328
+ /* double degree = (cInfo.core_node_expected_core_degree_.get(pI.index_) +
330
329
cInfo.core_node_expected_periphery_degree_.get(pI.index_) +
331
- cInfo.core_node_expected_external_degree_.get(pI.index_)*/ );
330
+ cInfo.core_node_expected_external_degree_.get(pI.index_));*/
332
331
333
- // double degree = pI.original_degree_;
332
+ double degree = pI .original_degree_ ;
334
333
335
334
//System.out.println("Internal Triangles: "+internalTriangles+" , degree: "+degree);
336
- if ( degree > 1 .0 ) {
337
- cInfo .clustering_coefficient_ .set (pI .index_ , (internalTriangles /* +peripheryTriangles+external_triangles*/ )/(degree *(degree -1 )));
335
+ if ( degree >= 2 .0 ) {
336
+ cInfo .clustering_coefficient_ .set (pI .index_ , (internalTriangles +peripheryTriangles +external_triangles )/(degree *(degree -1 )));
338
337
}
339
- //else if( degree > 1.0 && enteredOffset ) {
340
- // degree = 2.0;
341
- // cInfo.clustering_coefficient_.set(pI.index_, (internalTriangles+peripheryTriangles+external_triangles)/(double)(degree*(degree-1)));
342
- //}
343
338
}
344
339
}
345
340
}
@@ -377,7 +372,7 @@ void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> communities,
377
372
int lookAhead = 5 ;
378
373
int tries = 0 ;
379
374
while ( Math .abs (currentCC - targetCC ) > 0.001 && tries <= lookAhead ) {
380
- System .out .println (currentCC );
375
+ // System.out.println(currentCC);
381
376
boolean found = false ;
382
377
tries +=1 ;
383
378
if ( currentCC < targetCC ) {
@@ -537,6 +532,7 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
537
532
538
533
for ( Community c : communities ) {
539
534
c .p_ = 1.0f ;//rand.nextFloat();
535
+ //c.p_ = rand.nextFloat();
540
536
estimateCCCommunity (cInfo , c , c .p_ );
541
537
}
542
538
@@ -551,12 +547,12 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
551
547
System .out .println ("Creating graph" );
552
548
for (Community c : communities ) {
553
549
createEdgesCommunityCore (persons , c );
554
- // createEdgesCommunityPeriphery(cInfo, persons,c);
550
+ createEdgesCommunityPeriphery (cInfo , persons ,c );
555
551
}
556
- // fillGraphWithRemainingEdges(cInfo, communities, persons);
552
+ fillGraphWithRemainingEdges (cInfo , communities , persons );
557
553
graph = new PersonGraph (persons );
558
554
System .out .println ("Computing clustering coefficient" );
559
- /* double finalCC = 0;
555
+ double finalCC = 0 ;
560
556
ArrayList <Double > clusteringCoefficient = GraphUtils .ClusteringCoefficientList (graph );
561
557
int i = 0 ;
562
558
for ( Person p : persons ) {
@@ -567,16 +563,16 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
567
563
i ++;
568
564
}
569
565
finalCC /= persons .size ();
570
- */
571
- double finalCC = GraphUtils .ClusteringCoefficient (graph );
566
+ //double finalCC = GraphUtils.ClusteringCoefficient(graph);
572
567
573
568
System .out .println ("Clustering coefficient of the generated graph: " +finalCC );
574
569
double delta = targetCC - finalCC ;
575
570
if ( Math .abs ( delta ) > 0.001 ) {
571
+ resetStatistics ();
576
572
for (Person person : persons ) {
577
573
person .knows ().clear ();
578
574
}
579
- fakeTargetCC += delta ;
575
+ fakeTargetCC += delta * 0.8f ;
580
576
System .out .println ("New Fake targetCC: " +fakeTargetCC );
581
577
iterate = true ;
582
578
}
@@ -617,7 +613,14 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
617
613
public void initialize ( Configuration conf ) {
618
614
targetCC = conf .getFloat ("ldbc.snb.datagen.generator.ClusteringKnowsGenerator.clusteringCoefficient" , 0.1f );
619
615
System .out .println ("Initialized clustering coefficient to " +targetCC );
620
- //targetCC /= 2.0f;
616
+ targetCC /= 2.0f ;
617
+ }
618
+
619
+ public void resetStatistics () {
620
+ numCoreCoreEdges = 0 ;
621
+ numCorePeripheryEdges = 0 ;
622
+ numCoreExternalEdges = 0 ;
623
+ numMisses = 0 ;
621
624
}
622
625
623
626
public void printStatistics () {
0 commit comments