Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkConnectomicsSimulatedAnnealingPermutationModularity.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkConnectomicsSimulatedAnnealingPermutationModularity_h
18 #define mitkConnectomicsSimulatedAnnealingPermutationModularity_h
19 
21 
23 
24 namespace mitk
25 {
29  {
30  public:
31 
33  typedef std::map< VertexDescriptorType, int > ToModuleMapType;
34  typedef std::map< VertexDescriptorType, VertexDescriptorType > VertexToVertexMapType;
35 
40  itkFactorylessNewMacro(Self)
41  itkCloneMacro(Self)
42 
43  // Initialize the permutation
44  virtual void Initialize() override;
45 
46  // Do a permutation for a specific temperature
47  virtual void Permutate( double temperature ) override;
48 
49  // Do clean up necessary after a permutation
50  virtual void CleanUp() override;
51 
52  // set the network permutation is to be run upon
53  void SetNetwork( mitk::ConnectomicsNetwork::Pointer theNetwork );
54 
55  // Get the number of modules the graph has ( highest number - 1 )
56  int getNumberOfModules( ToModuleMapType *vertexToModuleMap ) const;
57 
58  // Get the number of vertices belonging to a given module
59  int getNumberOfVerticesInModule( ToModuleMapType *vertexToModuleMap, int module ) const;
60 
61  // Set the mapping
62  void SetMapping( ToModuleMapType mapping );
63 
64  // Get the mapping
65  ToModuleMapType GetMapping();
66 
67  // Set depth
68  void SetDepth( int depth );
69 
70  // Set stepSize
71  void SetStepSize( double size );
72 
73  protected:
74 
77  ~ConnectomicsSimulatedAnnealingPermutationModularity();
78 
79  // This function moves one single node from a module to another
80  void permutateMappingSingleNodeShift(
81  ToModuleMapType *vertexToModuleMap,
82  mitk::ConnectomicsNetwork::Pointer network );
83 
84  // This function splits and joins modules
85  void permutateMappingModuleChange(
86  ToModuleMapType *vertexToModuleMap,
87  double currentTemperature,
88  mitk::ConnectomicsNetwork::Pointer network );
89 
90  // join the two given modules to a single one
91  void joinTwoModules( ToModuleMapType *vertexToModuleMap, int moduleA, int moduleB );
92 
93  // split the given module recursively up to a certain level
94  // first randomly assigns nodes and then starts another simulated annealing
95  // on the sub network, as long as depthOfModuleChange > 0
96  void splitModule(
97  ToModuleMapType *vertexToModuleMap,
98  double currentTemperature,
100  int moduleToSplit );
101 
102  // Extract the subgraph of a network containing all nodes
103  // of a given module and the egdes between them
104  void extractModuleSubgraph(
105  ToModuleMapType *vertexToModuleMap,
106  mitk::ConnectomicsNetwork::Pointer network,
107  int moduleToSplit,
108  mitk::ConnectomicsNetwork::Pointer subNetwork,
109  VertexToVertexMapType* graphToSubgraphVertexMap,
110  VertexToVertexMapType* subgraphToGraphVertexMap );
111 
112  // Remove empty modules by moving all nodes of the highest module to the given module
113  void removeModule( ToModuleMapType *vertexToModuleMap, int module );
114 
115  // Randomly assign nodes to modules, this makes sure each module contains at least one node
116  // as long as numberOfIntendedModules < number of nodes
117  void randomlyAssignNodesToModules(ToModuleMapType *vertexToModuleMap, int numberOfIntendedModules );
118 
119  // Evaluate mapping using a modularity cost function
120  double Evaluate( ToModuleMapType* mapping ) const;
121 
122  // Whether to accept the permutation
123  bool AcceptChange( double costBefore, double costAfter, double temperature ) const;
124 
125  // the current best solution
126  ToModuleMapType m_BestSolution;
127 
128  // the network
130 
131  // How many levels of recursive calls can be gone down
132  int m_Depth;
133 
134  // The step size for recursive configuring of simulated annealing manager
135  double m_StepSize;
136  };
137 
138 }// end namespace mitk
139 
140 #endif // mitkConnectomicsSimulatedAnnealingPermutationModularity_h
DataCollection - Class to facilitate loading/accessing structured data.
A class providing permutations for the calculation of modularity using simulated annealing.
Base class of a permutation to be used in simulated annealing.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
boost::graph_traits< NetworkType >::vertex_descriptor VertexDescriptorType
Connectomics Network Class.