↰ Return to documentation for file (include/networkit/scoring/ModularityScoring.hpp
)
/*
* ModularityScoring.hpp
*
* Created on: 15.10.2012
* Author: Christian Staudt
*/
#ifndef NETWORKIT_SCORING_MODULARITY_SCORING_HPP_
#define NETWORKIT_SCORING_MODULARITY_SCORING_HPP_
#include <networkit/scoring/EdgeScoring.hpp>
#include <networkit/structures/Partition.hpp>
namespace NetworKit {
// TODO: implement modularity as in Python prototype
template <typename T>
class ModularityScoring final : public EdgeScoring<T> {
double totalEdgeWeight;
public:
ModularityScoring(Graph &G, double gTotalEdgeWeight = 0.0);
~ModularityScoring() override = default;
void scoreEdges(int attrId) override;
T edgeScore(node u, node v) const override;
};
template <typename T>
ModularityScoring<T>::ModularityScoring(Graph &G, double gTotalEdgeWeight)
: EdgeScoring<T>(G), totalEdgeWeight(gTotalEdgeWeight) {
if (gTotalEdgeWeight == 0.0) {
this->totalEdgeWeight = this->G->totalEdgeWeight();
}
}
template <typename T>
inline T ModularityScoring<T>::edgeScore(node u, node v) const {
assert(totalEdgeWeight != 0.0);
double volume = 2.0 * totalEdgeWeight;
double nom1 = (this->G->weightedDegree(u) / volume);
double nom2 = (this->G->weightedDegree(v) / volume);
double deltaMod = (this->G->weight(u, v) / totalEdgeWeight) - (nom1 * nom2);
return deltaMod;
}
template <typename T>
void ModularityScoring<T>::scoreEdges(int) {
// TODO: rewrite with new edge attribute system
}
} /* namespace NetworKit */
#endif // NETWORKIT_SCORING_MODULARITY_SCORING_HPP_