uint32_t ImproveCommunities(const CGraph* graph, CommunityPartition* partition, uint32_t numThreads, uint32_t lookahead, const double64_t alfa ) { num_threads = numThreads; omp_set_num_threads(num_threads); printf("Maximum number of threads: %d\n", omp_get_max_threads()); printf("Starting improvement from a partition with WCC: %f\n", partition->m_WCC / graph->GetNumNodes()); CommunityPartition bestPartition; CopyPartition(&bestPartition, partition); uint32_t remainingTries = lookahead; bool improve = true; while(improve) { while (improve) { printf("\n"); uint64_t initTime = StartClock(); improve = false; printf("Starting improvement iteration ...\n"); if (PerformImprovementStep(graph, partition, alfa)) { printf("Error while performing an improvement step.\n"); return 1; } printf("New WCC: %f\n", partition->m_WCC / graph->GetNumNodes()); printf("Best WCC: %f\n", bestPartition.m_WCC / graph->GetNumNodes()); printf("Memory required by this iteration: %lu bytes \n", MeasureMemoryConsumption(partition) + MeasureMemoryConsumption(&bestPartition)); if (partition->m_WCC - bestPartition.m_WCC > 0.0f) { // if (((partition->m_WCC - bestPartition.m_WCC) / bestPartition.m_WCC) > 0.01f) { remainingTries = lookahead; // } FreeResources(&bestPartition); CopyPartition(&bestPartition, partition); } printf("Iteration time: %lu ms\n", StopClock(initTime)); if(remainingTries > 0) { remainingTries--; improve = true; } } } FreeResources(partition); CopyPartition(partition, &bestPartition); FreeResources(&bestPartition); return 0; }
/* --------------------------------------------------------------------- --------------------------------------------------------------------- */ int GetDecorrelationStepMB_OD(double *H, double linC, struct node_gra **nlist, struct group **glist, struct group *part, int nnod, int **G2G, int *n2gList, double **LogChooseList, int LogChooseListSize, double *LogFactList, int LogFactListSize, double *HarmonicList, gsl_rng *gen, char verbose_sw) { struct group *partRef; int step, x1, x2; double y1, y2; double mutualInfo; int rep, nrep=10; double *decay, meanDecay, sigmaDecay, result; int norm=0; x2 = nnod / 5; x1 = x2 / 4; /* Get the nrep initial estimates */ decay = allocate_d_vec(nrep); for (rep=0; rep<nrep; rep++) { switch (verbose_sw) { case 'q': break; default: fprintf(stderr, "#\n# Estimating decorrelation time (%d/%d)\n", rep + 1, nrep); break; } partRef = CopyPartition(part); for (step=0; step<=x2; step++) { LSMCStepMB_OD(1, H, linC, nlist, glist, part, nnod, G2G, n2gList, LogChooseList, LogChooseListSize, LogFactList, LogFactListSize, HarmonicList, gen); if (step == x1) y1 = MutualInformation(partRef, part); } y2 = MutualInformation(partRef, part); RemovePartition(partRef); decay[rep] = 2. * CalculateDecay(nnod, x1, y1, x2, y2); switch (verbose_sw) { case 'q': break; default: fprintf(stderr, "# Decorrelation time (estimate %d) = %g\n", rep + 1, decay[rep]); break; } if (decay[rep] < 0) { rep--; switch (verbose_sw) { case 'q': break; default: fprintf(stderr, "#\tignoring...\n"); break; } } } /* Get rid of bad estimates (Chauvenet criterion) */ meanDecay = mean(decay, nrep); sigmaDecay = stddev(decay, nrep); result = meanDecay * nrep; for (rep=0; rep<nrep; rep++) { if (fabs(decay[rep] - meanDecay) / sigmaDecay > 2) { result -= decay[rep]; switch (verbose_sw) { case 'q': break; default: fprintf(stderr, "# Disregarding estimate %d\n", rep + 1); break; } } else { norm++; } } /* Clean up */ free_d_vec(decay); return result / norm; }