@@ -21,7 +21,6 @@ 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;
25
24
private float min_community_prob_ = 0.0f ;
26
25
27
26
private class PersonInfo {
@@ -208,11 +207,6 @@ private void computeCommunityInfo(ClusteringInfo cInfo, Community c, float prob)
208
207
209
208
// Initializing cInfo with expected degrees
210
209
for (PersonInfo pI : c .core_ ) {
211
- //double core_core_degree = (c.core_.size() - 1) * prob;
212
- //long complete_edges = (long)core_core_degree;
213
- //double incomplete_edge = core_core_degree - complete_edges;
214
- //if(rand.nextDouble() < incomplete_edge) complete_edges++;
215
- //cInfo.core_node_expected_core_degree_.set(pI.index_, new Double(complete_edges));
216
210
cInfo .core_node_expected_core_degree_ .set (pI .index_ ,(c .core_ .size () - 1 ) * (double )prob );
217
211
cInfo .core_node_excedence_degree_ .set (pI .index_ , pI .degree_ - cInfo .core_node_expected_core_degree_ .get (pI .index_ ));
218
212
cInfo .core_node_expected_periphery_degree_ .set (pI .index_ , 0.0 );
@@ -241,7 +235,6 @@ private void computeCommunityInfo(ClusteringInfo cInfo, Community c, float prob)
241
235
242
236
243
237
private void estimateCCCommunity ( ClusteringInfo cInfo , Community c , float prob ) {
244
- //System.out.println("Recompunting community with prob "+c.p_);
245
238
computeCommunityInfo (cInfo , c , prob );
246
239
247
240
float probSameCommunity = 0.0f ;
@@ -340,7 +333,8 @@ private void estimateCCCommunity( ClusteringInfo cInfo, Community c, float prob
340
333
}
341
334
342
335
float clusteringCoefficient (ArrayList <Community > communities , ClusteringInfo cInfo ) {
343
- return clusteringCoefficient (communities , cInfo ,true );
336
+ float CC = clusteringCoefficient (communities , cInfo ,true );
337
+ return CC ;
344
338
}
345
339
346
340
float clusteringCoefficient ( ArrayList <Community > communities , ClusteringInfo cInfo , Boolean countZeros ) {
@@ -389,7 +383,7 @@ void refineCommunities( ClusteringInfo cInfo, ArrayList<Community> communities,
389
383
}
390
384
391
385
float step (int n ) {
392
- return 1 .0f /(float )n ;
386
+ return 3 .0f /(float )n ;
393
387
}
394
388
395
389
boolean improveCC (ClusteringInfo cInfo , ArrayList <Community > communities ) {
@@ -402,7 +396,6 @@ boolean improveCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
402
396
Community c = filtered .get (index );
403
397
float step = step (c .core_ .size ());
404
398
c .p_ = c .p_ + step > 1.0f ? 1.0f : c .p_ + step ;
405
- //c.p_ = c.p_ + step_ > 1.0f ? 1.0f : c.p_ + step_;
406
399
cInfo .sumProbs +=0.01 ;
407
400
estimateCCCommunity (cInfo , c , c .p_ );
408
401
return true ;
@@ -418,7 +411,6 @@ boolean worsenCC(ClusteringInfo cInfo, ArrayList<Community> communities) {
418
411
Community c = filtered .get (index );
419
412
float step = step (c .core_ .size ());
420
413
c .p_ = c .p_ - step < min_community_prob_ ? min_community_prob_ : c .p_ - step ;
421
- //c.p_ = c.p_ - step_ < min_community_prob_ ? min_community_prob_ : c.p_ - step_ ;
422
414
cInfo .sumProbs -=0.01 ;
423
415
estimateCCCommunity (cInfo , c , c .p_ );
424
416
return true ;
@@ -443,6 +435,7 @@ void createEdgesCommunityCore(ArrayList<Person> persons, Community c) {
443
435
444
436
void createEdgesCommunityPeriphery (ClusteringInfo cInfo , ArrayList <Person > persons , Community c ) {
445
437
438
+ //long start = System.currentTimeMillis();
446
439
long [] peripheryBudget = new long [c .periphery_ .size ()];
447
440
int index = 0 ;
448
441
for (PersonInfo pI : c .periphery_ ) {
@@ -470,29 +463,35 @@ void createEdgesCommunityPeriphery(ClusteringInfo cInfo, ArrayList<Person> perso
470
463
System .out .println ("ERROR" );
471
464
}
472
465
}
466
+ //long end = System.currentTimeMillis();
467
+ //System.out.println("Time to create core-periphery edges: "+(end-start));
473
468
}
474
469
475
470
void fillGraphWithRemainingEdges (ClusteringInfo cInfo , ArrayList <Community > communities , ArrayList <Person > persons ) {
476
471
ArrayList <PersonInfo > stubs = new ArrayList <PersonInfo > ();
472
+ LinkedList <Integer > indexes = new LinkedList <Integer >();
473
+ Integer ii = 0 ;
477
474
for ( Community c : communities ) {
478
475
for (PersonInfo pI : c .core_ ) {
479
476
long diff = pI .degree_ - persons .get (pI .index_ ).knows ().size ();
480
477
if ( diff > 0 ) {
481
478
for ( int i = 0 ; i < diff ; ++i ) {
482
479
stubs .add (pI );
480
+ indexes .add (ii ++);
483
481
}
484
482
}
485
483
}
486
484
}
485
+
487
486
Collections .shuffle (stubs ,rand );
488
- while (stubs .size ()>0 ) {
489
- int index = rand .nextInt (stubs .size ());
487
+ Collections .shuffle (indexes ,rand );
488
+
489
+ while (indexes .size ()>0 ) {
490
+ int index = indexes .pop ();
490
491
PersonInfo first = stubs .get (index );
491
- stubs .remove (index );
492
- if (stubs .size () > 0 ) {
493
- int index2 = rand .nextInt (stubs .size ());
492
+ if (indexes .size () > 0 ) {
493
+ int index2 = indexes .pop ();
494
494
PersonInfo second = stubs .get (index2 );
495
- stubs .remove (index2 );
496
495
// create edge
497
496
if (persons .get (first .index_ ) == persons .get (second .index_ )) {
498
497
numMisses ++;
@@ -520,18 +519,20 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
520
519
521
520
522
521
for ( Community c : communities ) {
522
+ c .p_ = 1.0f ;
523
523
computeCommunityInfo (cInfo , c , 1.0f );
524
524
}
525
525
526
526
for ( Community c : communities ) {
527
- estimateCCCommunity (cInfo , c , 1.0f );
527
+ c .p_ = 1.0f ;
528
+ estimateCCCommunity (cInfo , c , c .p_ );
528
529
}
529
530
530
531
float maxCC = clusteringCoefficient (communities , cInfo );
531
532
System .out .println ("maxCC: " +maxCC );
532
533
533
534
for ( Community c : communities ) {
534
- c .p_ = 1.0f ;//rand.nextFloat();
535
+ c .p_ = 0.5f ;//rand.nextFloat();
535
536
//c.p_ = rand.nextFloat();
536
537
estimateCCCommunity (cInfo , c , c .p_ );
537
538
}
@@ -545,11 +546,14 @@ public void generateKnows( ArrayList<Person> persons, int seed, ArrayList<Float>
545
546
iterate = false ;
546
547
refineCommunities (cInfo , communities , fakeTargetCC );
547
548
System .out .println ("Creating graph" );
549
+
550
+ long start , end ;
548
551
for (Community c : communities ) {
549
552
createEdgesCommunityCore (persons , c );
550
- createEdgesCommunityPeriphery (cInfo , persons ,c );
553
+ createEdgesCommunityPeriphery (cInfo , persons , c );
551
554
}
552
555
fillGraphWithRemainingEdges (cInfo , communities , persons );
556
+
553
557
graph = new PersonGraph (persons );
554
558
System .out .println ("Computing clustering coefficient" );
555
559
double finalCC = 0 ;
0 commit comments