30 cost = 100.0 * ( 1.0 - CalculateModularity( network, vertexToModuleMap ) );
36 double modularity( 0.0 );
37 int numberOfModules = getNumberOfModules( vertexToModuleMap );
39 if( network->GetNumberOfVertices() != (int)vertexToModuleMap->size() )
41 MBI_ERROR <<
"Number of vertices and vertex to module map size do not match!";
45 int numberOfLinksInNetwork( 0 );
46 std::vector< int > numberOfLinksInModule, sumOfDegreesInModule;
47 numberOfLinksInModule.resize( numberOfModules, 0 );
48 sumOfDegreesInModule.resize( numberOfModules, 0 );
51 const std::vector< VertexDescriptorType > allNodesVector
52 = network->GetVectorOfAllVertexDescriptors();
54 for(
unsigned int nodeNumber( 0 ); nodeNumber < allNodesVector.size() ; nodeNumber++)
56 int correspondingModule = vertexToModuleMap->find( allNodesVector[ nodeNumber ] )->second;
57 const std::vector< VertexDescriptorType > adjacentNodexVector
58 = network->GetVectorOfAdjacentNodes( allNodesVector[ nodeNumber ] );
59 numberOfLinksInNetwork += adjacentNodexVector.size();
60 sumOfDegreesInModule[ correspondingModule ] += adjacentNodexVector.size();
62 for(
unsigned int adjacentNodeNumber( 0 ); adjacentNodeNumber < adjacentNodexVector.size() ; adjacentNodeNumber++)
64 if( correspondingModule == vertexToModuleMap->find( adjacentNodexVector[ adjacentNodeNumber ] )->second )
66 numberOfLinksInModule[ correspondingModule ]++;
72 numberOfLinksInNetwork = numberOfLinksInNetwork / 2;
75 if( numberOfLinksInNetwork < 1)
80 for(
int index( 0 ); index < numberOfModules ; index++)
82 numberOfLinksInModule[ index ] = numberOfLinksInModule[ index ] / 2;
96 for(
int moduleID( 0 ); moduleID < numberOfModules; moduleID++ )
98 modularity += (((double) numberOfLinksInModule[ moduleID ]) / ((double) numberOfLinksInNetwork)) -
100 (((
double) sumOfDegreesInModule[ moduleID ]) / ((
double) 2 * numberOfLinksInNetwork) ) *
101 (((double) sumOfDegreesInModule[ moduleID ]) / ((double) 2 * numberOfLinksInNetwork) )
112 auto iter = vertexToModuleMap->begin();
113 auto end = vertexToModuleMap->end();
116 if( iter->second > maxModule )
118 maxModule = iter->second;
124 return maxModule + 1;
int getNumberOfModules(ToModuleMapType *vertexToModuleMap) const
ConnectomicsSimulatedAnnealingCostFunctionModularity()
double Evaluate(mitk::ConnectomicsNetwork::Pointer network, ToModuleMapType *vertexToModuleMap) const
std::map< VertexDescriptorType, int > ToModuleMapType
double CalculateModularity(mitk::ConnectomicsNetwork::Pointer network, ToModuleMapType *vertexToModuleMap) const
~ConnectomicsSimulatedAnnealingCostFunctionModularity()