根据加权图的连通性计算阈值

时间:2018-07-04 20:13:54

标签: r igraph threshold undirected-graph weighted-graph

给出如下矩阵(但更大一些)来描述加权无向图,

structure(list(from = c("TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "TPM1", 
"TPM1", "TPM1", "TPM1", "TPM1", "TPM1", "MT1G", "MT1G"), to = c("ACTA1", 
"TNNC2", "DBN1", "TNNT3", "DMD", "MYLPF", "MYBPC2", "PKM", "MYLK", 
"PXN", "LCP1", "MYO18A", "SPTBN1", "TMOD3", "PKD2", "SF3B1", 
"SMTN", "TMOD2", "NAA25", "VCL", "MYO5C", "TCAP", "ACTL8", "SPTAN1", 
"TMOD1", "PLS1", "ACTA2", "ACTL10", "EHBP1", "TAGLN", "ACTN4", 
"MYO5A", "COX4I1", "AHCYL1", "SEC23A", "RHOA", "MYH9", "SORBS3", 
"ACTRT1", "RAVER1", "FLNB", "NEB", "THOC1", "ACTN1", "TTN", "UQCRC2", 
"MYBPC3", "MYO5B", "MYBPC1", "SPTB", "CNN1", "ACTN2", "ACTR1B", 
"VIM", "SORD", "RAC3", "CFL1", "PFN4", "TPM3", "MYO1F", "KBTBD13", 
"SPTBN2", "MYH11", "SRXN1", "CFL2", "ACTB", "MYH7B", "MYL12A", 
"SPTA1", "MYH8", "FSCN3", "MYL4", "ACTR3B", "SLC25A4", "TNNT1", 
"VMP1", "ACTR1A", "MYH4", "ACTRT2", "MYH13", "MACF1", "MYO18B", 
"ATP5F1", "COX5A", "MYL10", "MYL12B", "TNNT2", "DSTN", "MYL3", 
"MYO1A", "PLS3", "TNNI3", "ACTL6A", "MYL6B", "MYOZ2", "NDUFB10", 
"MYH7", "RPS3", "MT2A", "MT1X"), weight = c(3.10788e-05, 5.958809e-05, 
6.384511e-05, 4.857867e-05, 3.833709e-05, 5.229225e-05, 4.924842e-05, 
3.225598e-05, 2.898718e-05, 8.135556e-06, 3.691475e-05, 5.009223e-05, 
2.241126e-05, 3.984557e-05, 4.087312e-05, 4.958667e-05, 5.482933e-05, 
7.170784e-05, 2.331922e-05, 2.8957e-05, 5.085006e-05, 4.037044e-05, 
5.287118e-05, 4.331423e-05, 4.904199e-05, 2.244811e-05, 2.444415e-05, 
3.39682e-05, 3.815621e-05, 6.097359e-05, 5.687818e-05, 5.921874e-05, 
5.489426e-05, 5.047384e-05, 4.028134e-05, 4.111754e-05, 6.317467e-05, 
4.741044e-05, 5.349051e-05, 8.419945e-05, 6.373862e-05, 2.202583e-05, 
5.292187e-05, 2.104257e-05, 3.063063e-05, 2.325379e-05, 2.897299e-05, 
5.694608e-05, 5.794348e-05, 3.419694e-05, 4.544227e-05, 5.685621e-05, 
3.70368e-05, 4.812005e-05, 4.707759e-05, 4.652025e-05, 3.1161e-05, 
2.135651e-05, 4.601607e-05, 4.217255e-05, 4.925196e-05, 2.101865e-05, 
5.812923e-05, 6.151076e-05, 3.965462e-05, 5.69303e-05, 4.145797e-05, 
4.619822e-05, 4.952048e-05, 5.969572e-05, 2.635453e-05, 2.956592e-05, 
4.576555e-05, 5.889256e-05, 5.63168e-05, 2.704127e-05, 2.10058e-05, 
4.418638e-05, 2.696945e-05, 5.0836e-05, 2.089578e-05, 3.58514e-05, 
6.042708e-05, 5.692903e-05, 5.903882e-05, 2.831509e-05, 4.728689e-05, 
2.156019e-05, 5.655941e-05, 3.334697e-05, 5.187546e-05, 6.976401e-05, 
2.068582e-05, 5.202582e-05, 4.009386e-05, 6.550041e-05, 2.20423e-05, 
5.175788e-05, 4.385124e-05, 2.531945e-05)), row.names = c(NA, 
100L), class = "data.frame")

我想计算最大权重( x ),以使诱导子图得以连接。由于假定初始图已连接,因此必须存在一个关键阈值 x-critical ,对于任何 x <= x-critical ,提取的子图都已连接。

由于这个原因,我构建了以下函数,用于检查图的邻接矩阵是否显示等于0的rowSums,以检查每个权重(以递增顺序排序)。

calcThreshold <- function( rel.matrix )
{
  # Sorted weights
  weights <- unique(sort( rel.matrix[,3], decreasing = FALSE))

  for( w in seq_along(weights) )
  {
    filtered_edges <- rel.matrix[ which(rel.matrix[,3] > weights[w] ), ]
    # convert it to adjacency matrix
    g <- graph.data.frame( filtered_edges, directed = FALSE )
    adj.matrix <- get.adjacency( g, attr = "weight", sparse = TRUE )

    # Check if a row has sum == 0
    if( any( Matrix::rowSums(adj.matrix[,]) == 0 ) )
      return(weights[w-1])
  }
  return(weights[w])
}

问题是这种方法确实浪费时间,我想知道是否有一种更有效的方法来计算该阈值。

0 个答案:

没有答案