@@ -21,7 +21,7 @@ public class ClusteringKnowsGenerator implements KnowsGenerator {
21
21
private int numCoreCoreEdges = 0 ;
22
22
private int numCorePeripheryEdges = 0 ;
23
23
private int numCoreExternalEdges = 0 ;
24
- private float step_ = 0.10f ;
24
+ // private float step_ = 0.10f;
25
25
private float min_community_prob_ = 0.0f ;
26
26
27
27
private class PersonInfo {
@@ -174,18 +174,6 @@ private ArrayList<Community> generateCommunities( ArrayList<Person> persons) {
174
174
bestCommunity .id_ = communities .size ();
175
175
communities .add (bestCommunity );
176
176
177
- /*System.out.print("Core: ");
178
- for( PersonInfo pI : bestCommunity.core_ ) {
179
- System.out.print(pI.degree_+" ");
180
- }
181
- System.out.println();
182
- System.out.print("Periphery: ");
183
- for( PersonInfo pI : bestCommunity.periphery_ ) {
184
- System.out.print(pI.degree_+" ");
185
- }
186
- System.out.println();
187
- */
188
-
189
177
last = best + 1 ;
190
178
begin = last ;
191
179
}
@@ -270,8 +258,9 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
270
258
// Computing clustering coefficient of periphery nodes
271
259
for (PersonInfo pI : c .periphery_ ) {
272
260
if (pI .degree_ > 1 ) {
273
- cInfo .clustering_coefficient_ .set (pI .index_ , (double )pI .degree_ *(pI .degree_ -1 )*prob /(pI .original_degree_ *(pI .original_degree_ -1 )));
261
+ // cInfo.clustering_coefficient_.set(pI.index_, (double)pI.degree_*(pI.degree_-1)*prob/(pI.original_degree_*(pI.original_degree_-1)));
274
262
//cInfo.clustering_coefficient_.set(pI.index_, (double)prob);
263
+ cInfo .clustering_coefficient_ .set (pI .index_ , 0.0 );
275
264
}
276
265
}
277
266
@@ -292,8 +281,11 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
292
281
/*if(size > 2) {
293
282
internalTriangles = ((size - 1) * (size - 2) * Math.pow(prob, 3));
294
283
}*/
284
+ if (internalDegree > 1.0 ) {
285
+ internalTriangles = (internalDegree * (internalDegree - 1 ) * prob );
286
+ }
295
287
boolean enteredOffset = false ;
296
- if ( internalDegree >= 2.0 ) {
288
+ /* if( internalDegree >= 2.0 ) {
297
289
internalTriangles = (internalDegree * (internalDegree - 1) * prob);
298
290
} else if( internalDegree > 1.0) {
299
291
double offset = internalDegree - 1.0;
@@ -302,7 +294,17 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
302
294
internalTriangles = prob;
303
295
enteredOffset = true;
304
296
}
305
- }
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
+
306
308
// core periphery triangles
307
309
double peripheryTriangles = 0 ;
308
310
long remainingDegree = pI .degree_ ;
@@ -323,15 +325,16 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
323
325
external_triangles += cInfo .core_node_expected_external_degree_ .get (pI .index_ ) * (cInfo .core_node_expected_external_degree_ .get (pI .index_ ) - 1 ) * (1 - probSameCommunity ) * probTwoConnected ;
324
326
}
325
327
326
- /*double degree = (cInfo.core_node_expected_core_degree_.get(pI.index_) +
328
+ //double degree = finalInternalDegree;
329
+ double degree = (cInfo .core_node_expected_core_degree_ .get (pI .index_ ) /*+
327
330
cInfo.core_node_expected_periphery_degree_.get(pI.index_) +
328
- cInfo.core_node_expected_external_degree_.get(pI.index_));*/
331
+ cInfo.core_node_expected_external_degree_.get(pI.index_)*/ );
329
332
330
- double degree = pI .original_degree_ ;
333
+ // double degree = pI.original_degree_;
331
334
332
335
//System.out.println("Internal Triangles: "+internalTriangles+" , degree: "+degree);
333
336
if ( degree > 1.0 ) {
334
- cInfo .clustering_coefficient_ .set (pI .index_ , (internalTriangles + peripheryTriangles /* +external_triangles*/ )/(degree *(degree -1 )));
337
+ cInfo .clustering_coefficient_ .set (pI .index_ , (internalTriangles /*+peripheryTriangles +external_triangles*/ )/(degree *(degree -1 )));
335
338
}
336
339
//else if( degree > 1.0 && enteredOffset ) {
337
340
// degree = 2.0;
@@ -374,6 +377,7 @@ void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> communities,
374
377
int lookAhead = 5 ;
375
378
int tries = 0 ;
376
379
while ( Math .abs (currentCC - targetCC ) > 0.001 && tries <= lookAhead ) {
380
+ System .out .println (currentCC );
377
381
boolean found = false ;
378
382
tries +=1 ;
379
383
if ( currentCC < targetCC ) {
@@ -383,13 +387,16 @@ void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> communities,
383
387
}
384
388
if ( found ) {
385
389
currentCC = clusteringCoefficient (communities , cInfo );
386
- //System.out.println(currentCC);
387
390
tries = 0 ;
388
391
}
389
392
}
390
393
System .out .println ("Clustering Coefficient after refinement: " + currentCC );
391
394
}
392
395
396
+ float step (int n ) {
397
+ return 1.0f /(float )n ;
398
+ }
399
+
393
400
boolean improveCC (ClusteringInfo cInfo , ArrayList <Community > communities ) {
394
401
ArrayList <Community > filtered = new ArrayList <Community >();
395
402
for (Community c : communities ) {
@@ -398,7 +405,9 @@ boolean improveCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
398
405
if (filtered .size () == 0 ) return false ;
399
406
int index = rand .nextInt (filtered .size ());
400
407
Community c = filtered .get (index );
401
- c .p_ = c .p_ + step_ > 1.0f ? 1.0f : c .p_ + step_ ;
408
+ float step = step (c .core_ .size ());
409
+ c .p_ = c .p_ + step > 1.0f ? 1.0f : c .p_ + step ;
410
+ //c.p_ = c.p_ + step_ > 1.0f ? 1.0f : c.p_ + step_;
402
411
cInfo .sumProbs +=0.01 ;
403
412
estimateCCCommunity (cInfo , c , c .p_ );
404
413
return true ;
@@ -412,7 +421,9 @@ boolean worsenCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
412
421
if (filtered .size () == 0 ) return false ;
413
422
int index = rand .nextInt (filtered .size ());
414
423
Community c = filtered .get (index );
415
- c .p_ = c .p_ - step_ < min_community_prob_ ? min_community_prob_ : c .p_ - step_ ;
424
+ float step = step (c .core_ .size ());
425
+ c .p_ = c .p_ - step < min_community_prob_ ? min_community_prob_ : c .p_ - step ;
426
+ //c.p_ = c.p_ - step_ < min_community_prob_ ? min_community_prob_ : c.p_ - step_ ;
416
427
cInfo .sumProbs -=0.01 ;
417
428
estimateCCCommunity (cInfo , c , c .p_ );
418
429
return true ;
@@ -525,40 +536,51 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
525
536
System .out .println ("maxCC: " +maxCC );
526
537
527
538
for ( Community c : communities ) {
528
- estimateCCCommunity (cInfo , c , rand .nextFloat ());
539
+ c .p_ = 1.0f ;//rand.nextFloat();
540
+ estimateCCCommunity (cInfo , c , c .p_ );
529
541
}
530
542
531
543
PersonGraph graph ;
532
544
boolean iterate ;
533
545
float fakeTargetCC = targetCC ;
546
+ int numIterations = 0 ;
534
547
do {
535
548
System .out .println ("Starting refinement iteration" );
536
549
iterate = false ;
537
550
refineCommunities (cInfo , communities , fakeTargetCC );
538
551
System .out .println ("Creating graph" );
539
552
for (Community c : communities ) {
540
553
createEdgesCommunityCore (persons , c );
541
- createEdgesCommunityPeriphery (cInfo , persons ,c );
554
+ // createEdgesCommunityPeriphery(cInfo, persons,c);
542
555
}
543
- fillGraphWithRemainingEdges (cInfo , communities , persons );
556
+ // fillGraphWithRemainingEdges(cInfo, communities, persons);
544
557
graph = new PersonGraph (persons );
545
558
System .out .println ("Computing clustering coefficient" );
546
- double clusteringCoefficient = GraphUtils .ClusteringCoefficient (graph );
547
- System .out .println ("Clustering coefficient of the generated graph: " +clusteringCoefficient );
548
- double delta = targetCC - clusteringCoefficient ;
559
+ /*double finalCC = 0;
560
+ ArrayList<Double> clusteringCoefficient = GraphUtils.ClusteringCoefficientList(graph);
561
+ int i = 0;
562
+ for( Person p : persons) {
563
+ long degree = graph.neighbors(p.accountId()).size();
564
+ long originalDegree = p.maxNumKnows();
565
+ if(originalDegree > 1)
566
+ finalCC += clusteringCoefficient.get(i) * degree*(degree - 1) / (originalDegree*(originalDegree-1));
567
+ i++;
568
+ }
569
+ finalCC /= persons.size();
570
+ */
571
+ double finalCC = GraphUtils .ClusteringCoefficient (graph );
572
+
573
+ System .out .println ("Clustering coefficient of the generated graph: " +finalCC );
574
+ double delta = targetCC - finalCC ;
549
575
if ( Math .abs ( delta ) > 0.001 ) {
550
576
for (Person person : persons ) {
551
577
person .knows ().clear ();
552
578
}
553
- if ( delta < 0.0 ) {
554
- fakeTargetCC /= 2.0f ;
555
- } else {
556
- fakeTargetCC *= 1.5f ;
557
- }
558
-
579
+ fakeTargetCC += delta ;
559
580
System .out .println ("New Fake targetCC: " +fakeTargetCC );
560
581
iterate = true ;
561
582
}
583
+ numIterations ++;
562
584
}while ( iterate );
563
585
564
586
int countMore = 0 ;
@@ -583,6 +605,7 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
583
605
++index ;
584
606
}
585
607
608
+ System .out .println ("Number of iterations to converge: " +numIterations );
586
609
System .out .println ("Number of persons with more degree than expected: " +countMore );
587
610
System .out .println ("Sum of excess degree: " +sumMore );
588
611
System .out .println ("Number of persons with less degree than expected: " +countLess );
@@ -594,7 +617,7 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
594
617
public void initialize ( Configuration conf ) {
595
618
targetCC = conf .getFloat ("ldbc.snb.datagen.generator.ClusteringKnowsGenerator.clusteringCoefficient" , 0.1f );
596
619
System .out .println ("Initialized clustering coefficient to " +targetCC );
597
- targetCC /= 2.0f ;
620
+ // targetCC /= 2.0f;
598
621
}
599
622
600
623
public void printStatistics () {
0 commit comments