communityDetectionEngine.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:BrainModulyzer 作者: sugeerth 项目源码 文件源码
def Find_InterModular_Edge_correlativity(self):
        # Induced graph is the data structure responsible for the adjacency matrix of the community
        self.Matrix = nx.to_numpy_matrix(self.induced_graph)
        # Matrix Before calculating the correlation strength
        # finding out the lower half values of the matrix, can discard other values as computationally intensive
        self.Matrix = np.tril(self.Matrix,-1)
        i=0
        Sum = 0 
        j=0 
        SumTemp = 0
        Edges = 0 
        nodes1 = [item for item in self.Graphwidget.scene().items() if isinstance(item, Node)]
        # ite1rateing over the indices
        for community in set(self.partition.values()):
            i= i + 1
            j=0
            for community2 in set(self.partition.values()):
                j= j + 1
                # Not Calculating the communities which are communities to itself 
                if community == community2:
                    continue
                # Calculating the correlation strength only with the lower half of the adjacency matrix
                if i <= j: 
                    continue
                # list_nodes1 and list_nodes2 indicate which nodes are actually present in these communties
                list_nodes1 = [nodes for nodes in self.partition.keys() if self.partition[nodes] == community]
                list_nodes2 = [nodes for nodes in self.partition.keys() if self.partition[nodes] == community2]
                # Re-initializing the 
                SumTemp = 0
                Edges = 0
                for node1 in nodes1:
                    if node1.counter-1 in list_nodes1:
                        for node2 in nodes1:
                            if node2.counter-1 in list_nodes2:
                                if node1.counter-1 == node2.counter-1:
                                        continue
                                if self.Graphwidget.Graph_data().ThresholdData[node1.counter-1][node2.counter-1] > 0:
                                    Edges = Edges + 1
                if Edges != 0: 
                    Sum=float("{0:.2f}".format(self.Matrix[i-1,j-1]/Edges))
                self.Matrix[i-1,j-1] = Sum

        self.induced_graph = nx.from_numpy_matrix(self.Matrix)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号