<commit_before>/*
 * DynCDSetup.cpp
 *
 *  Created on: 16.06.2013
 *      Author: cls
 */

#include "DynCDSetup.h"

namespace NetworKit {

DynCDSetup::DynCDSetup(DynamicGraphSource& dynGen, std::vector<DynamicCommunityDetector*>& dynDetectors, count tMax, count deltaT) :
		gen(&dynGen),
		detectors(dynDetectors),
		nDetectors(dynDetectors.size()),
		tMax(tMax),
		deltaT(deltaT),
		staticAlgo(NULL),
		dynamicClusteringTimelines(nDetectors),
		qualityTimelines(nDetectors),
		nCommunitiesTimelines(nDetectors),
		continuityTimelines(nDetectors),
		checkMod(false),
		checkNumCom(false),
		checkSampledRand(false),
		checkNMID(false) {
	if (deltaT >= tMax) {
		ERROR("deltaT >= tMax");
		throw std::runtime_error("deltaT must be smaller than tMax");
	} else {
		INFO("deltaT " << deltaT);
		INFO("tMax " << tMax);

	}

	// create graph and proxy instances
	Gproxy = this->gen->newGraph();
	G = Gproxy->G;

	DEBUG("setting up " << detectors.size() << " community detection algorithms");
	// register algorithms
	for (DynamicCommunityDetector* dynCD : detectors) {
		Gproxy->registerObserver(dynCD); 	// register community detection algorithm as observer
		dynCD->setGraph(*G);				// point the community detection algorithm to the graph
	}

}

DynCDSetup::~DynCDSetup() {
	// TODO Auto-generated destructor stub
}

void DynCDSetup::run() {
	Aux::Timer runtime;
	runtime.start();

	// helpers
	Modularity modularity;
	DynamicNMIDistance NMID;
	SampledRandMeasure sampledRand(500);

	// initialize graph
	gen->initializeGraph();


	auto runIt = [&](){
		// run algorithms and evaluation
		// inspect the current graph
		INFO("current graph : " << G->toString());

		nTimeline.push_back(G->numberOfNodes());
		mTimeline.push_back(G->numberOfEdges());

		// run the dynamic community detectors
		for (index detectorIndex = 0; detectorIndex < this->detectors.size(); ++detectorIndex) {
			DynamicCommunityDetector* dynCD = this->detectors.at(detectorIndex);

			INFO("running dynamic community detector " << dynCD->toString());
			dynamicClusteringTimelines.at(detectorIndex).push_back(dynCD->run());

			// TRACE("clustering looks like: " << Aux::vectorToString(results.at(detectorIndex).back().getVector()));
			assert (dynamicClusteringTimelines.at(detectorIndex).back().isProper(*G));

			// evaluations which need the current graph
			if (checkNumCom) {
				INFO("calculating number of clusters");
				count nCom = dynamicClusteringTimelines.at(detectorIndex).back().numberOfClusters();
				INFO("[RESULT] number of communities \t "<< detectors.at(detectorIndex)->toString() << "\t" << nCom);
				nCommunitiesTimelines.at(detectorIndex).push_back(nCom);
			}

			// modularity
			if (checkMod) {
				double mod = modularity.getQuality(dynamicClusteringTimelines.at(detectorIndex).back(), *G);
				INFO("[RESULT] modularity \t " << detectors.at(detectorIndex)->toString() << " \t " << mod);
				qualityTimelines.at(detectorIndex).push_back(mod);
			}

			// continuity by sampling
			if (checkSampledRand  && (dynamicClusteringTimelines[detectorIndex].size() >= 2)) {
				double cont = sampledRand.getDissimilarity(*G, dynamicClusteringTimelines.at(detectorIndex).at(dynamicClusteringTimelines.at(detectorIndex).size() - 2), dynamicClusteringTimelines.at(detectorIndex).back());
				INFO("[RESULT] continuity \t " << detectors.at(detectorIndex)->toString() << " \t " << cont);
				continuityTimelines.at(detectorIndex).push_back(cont);

			}
		} // end for multiple detectors

		// optionally also run a static community detector
		if (staticAlgo != NULL) {
			Aux::Timer staticRuntime;
			staticRuntime.start();
			//
			staticClusteringTimeline.push_back(staticAlgo->run(*G));
			//
			staticRuntime.stop();
			staticTimerTimeline.push_back(staticRuntime.elapsed().count());

			assert (staticClusteringTimeline.back().isProper(*G));

			if (checkNumCom) {

				INFO("calculating number of communities");
				count nCom = staticClusteringTimeline.back().numberOfClusters();
				INFO("[RESULT] number of communities \t " << staticAlgo->toString() << "\t " << nCom);<commit_msg>testing NMID modified version<commit_after>/*
 * DynCDSetup.cpp
 *
 *  Created on: 16.06.2013
 *      Author: cls
 */

#include "DynCDSetup.h"

namespace NetworKit {

DynCDSetup::DynCDSetup(DynamicGraphSource& dynGen, std::vector<DynamicCommunityDetector*>& dynDetectors, count tMax, count deltaT) :
		gen(&dynGen),
		detectors(dynDetectors),
		nDetectors(dynDetectors.size()),
		tMax(tMax),
		deltaT(deltaT),
		staticAlgo(NULL),
		dynamicClusteringTimelines(nDetectors),
		qualityTimelines(nDetectors),
		nCommunitiesTimelines(nDetectors),
		continuityTimelines(nDetectors),
		checkMod(false),
		checkNumCom(false),
		checkSampledRand(false),
		checkNMID(false) {
	if (deltaT >= tMax) {
		ERROR("deltaT >= tMax");
		throw std::runtime_error("deltaT must be smaller than tMax");
	} else {
		INFO("deltaT " << deltaT);
		INFO("tMax " << tMax);

	}

	// create graph and proxy instances
	Gproxy = this->gen->newGraph();
	G = Gproxy->G;

	DEBUG("setting up " << detectors.size() << " community detection algorithms");
	// register algorithms
	for (DynamicCommunityDetector* dynCD : detectors) {
		Gproxy->registerObserver(dynCD); 	// register community detection algorithm as observer
		dynCD->setGraph(*G);				// point the community detection algorithm to the graph
	}

}

DynCDSetup::~DynCDSetup() {
	// TODO Auto-generated destructor stub
}

void DynCDSetup::run() {
	Aux::Timer runtime;
	runtime.start();

	// helpers
	Modularity modularity;
	DynamicNMIDistance NMID;
	SampledRandMeasure sampledRand(500);

	// initialize graph
	gen->initializeGraph();


	auto runIt = [&](){
		// run algorithms and evaluation
		// inspect the current graph
		INFO("current graph : " << G->toString());

		nTimeline.push_back(G->numberOfNodes());
		mTimeline.push_back(G->numberOfEdges());

		// run the dynamic community detectors
		for (index detectorIndex = 0; detectorIndex < this->detectors.size(); ++detectorIndex) {
			DynamicCommunityDetector* dynCD = this->detectors.at(detectorIndex);

			INFO("running dynamic community detector " << dynCD->toString());
			dynamicClusteringTimelines.at(detectorIndex).push_back(dynCD->run());

			// TRACE("clustering looks like: " << Aux::vectorToString(results.at(detectorIndex).back().getVector()));
			assert (dynamicClusteringTimelines.at(detectorIndex).back().isProper(*G));

			// evaluations which need the current graph
			if (checkNumCom) {
				INFO("calculating number of clusters");
				count nCom = dynamicClusteringTimelines.at(detectorIndex).back().numberOfClusters();
				INFO("[RESULT] number of communities \t "<< detectors.at(detectorIndex)->toString() << "\t" << nCom);
				nCommunitiesTimelines.at(detectorIndex).push_back(nCom);
			}

			// modularity
			if (checkMod) {
				double mod = modularity.getQuality(dynamicClusteringTimelines.at(detectorIndex).back(), *G);
				INFO("[RESULT] modularity \t " << detectors.at(detectorIndex)->toString() << " \t " << mod);
				qualityTimelines.at(detectorIndex).push_back(mod);
			}

			// continuity by sampling
			if (checkSampledRand  && (dynamicClusteringTimelines[detectorIndex].size() >= 2)) {
				double cont = sampledRand.getDissimilarity(*G, dynamicClusteringTimelines.at(detectorIndex).at(dynamicClusteringTimelines.at(detectorIndex).size() - 2), dynamicClusteringTimelines.at(detectorIndex).back());
				INFO("[RESULT] continuity \t " << detectors.at(detectorIndex)->toString() << " \t " << cont);
				continuityTimelines.at(detectorIndex).push_back(cont);
			} else if (checkNMID && (dynamicClusteringTimelines.at(detectorIndex).size() >= 2)) {
				double cont = NMID.getDissimilarity(*G, dynamicClusteringTimelines.at(detectorIndex).at(dynamicClusteringTimelines.at(detectorIndex).size() - 2), dynamicClusteringTimelines.at(detectorIndex).back());
				INFO("[RESULT] continuity NMID \t " << detectors.at(detectorIndex)->toString() << " \t " << cont);
				continuityTimelines.at(detectorIndex).push_back(cont);
			}
		} // end for multiple detectors

		// optionally also run a static community detector
		if (staticAlgo != NULL) {
			Aux::Timer staticRuntime;
			staticRuntime.start();
			//
			staticClusteringTimeline.push_back(staticAlgo->run(*G));
			//
			staticRuntime.stop();
			staticTimerTimeline.push_back(staticRuntime.elapsed().count());

			assert (staticClusteringTimeline.back().isProper(*G));

			if (checkNumCom) {

				INFO("calculating number of communities");
				count nCom = staticClusteringTimeline.back().numberOfClusters();
				INFO("[RESULT] number of communities \t " << staticAlgo->toString() << "\t " << nCom);
{'fraction_non_alphanumeric': 0.14683368128044538, 'fraction_numerical': 0.003479471120389701, 'mean_word_length': 4.854039375424304, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6681878', 'n_tokens_mistral': 3069, 'n_tokens_neox': 2658, 'n_words': 513}