0

Ka,b biclique の定義に依存するBiclique Communities メソッド ( Lehmann, Schwartz, & Hansen, 2008 ) を R で再現しようとしています。次の例は、隣接する 2 つの K2,2 バイクリークを示しています。最初のクリークは {A,B,1,2} で、2 番目のクリークは {B,C,2,3} です。これをより広範なデータセットに適用できるように、R を使用してこれらのクリークを識別できるようにしたいと考えています。

隣接する K2,2 Bicliques

これまでの試行を R に含めましたが、次の 2 つの問題に悩まされています。

  1. 標準の walktrap.community を使用すると、コミュニティは認識されますが、セット {B,2} が両方のクリークに属することは許可されません
  2. 更新されたclique.community関数を使用すると、これはクリークを識別していないように見えるか、正しく理解していません (またはその両方)。

コード例:

library(igraph)

clique.community <- function(graph, k) {
  clq <- cliques(graph, min=k, max=k)
  edges <- c()
  for (i in seq_along(clq)) {
    for (j in seq_along(clq)) {
      if ( length(unique(c(clq[[i]], clq[[j]]))) == k+1 ) {
        edges <- c(edges, c(i,j))
      }
    }
  }
  clq.graph <- simplify(graph(edges))
  V(clq.graph)$name <- seq_len(vcount(clq.graph))
  comps <- decompose.graph(clq.graph)

  lapply(comps, function(x) {
    unique(unlist(clq[ V(x)$name ]))
  })
}

users <- c('A', 'A', 'B', 'B', 'B', 'C', 'C')
resources <- c(1, 2, 1, 2, 3, 2, 3)
cluster <- data.frame(users, resources)
matrix <- as.data.frame.matrix(table(cluster))

igraph <- graph.incidence(matrix)

clique.community(igraph, 2)
walktrap.community(igraph)
4

2 に答える 2

0

Sisob ワークベンチでこのスクリプトを見つけることができました

computeBicliques <- function(graph, k, l) {

  vMode1 <- c()
  if (!is.null(V(graph)$type)) {

    vMode1 <- which(!V(graph)$type)
    vMode1 <- intersect(vMode1, which(degree(graph) >= l))
  }

  nb <- get.adjlist(graph)

  bicliques <- list()

  if (length(vMode1) >= k) {

    comb <- combn(vMode1, k)
    i <- 1
    sapply(1:ncol(comb), function(c) {

      commonNeighbours <- c()
      isFirst <- TRUE

      sapply(comb[,c], function(n) {

        if (isFirst) {

          isFirst <<- FALSE
          commonNeighbours <<- nb[[n]]
        } else {

          commonNeighbours <<- intersect(commonNeighbours, nb[[n]])
        }
      })

      if (length(commonNeighbours) >= l) {

        bicliques[[i]] <<- list(m1=comb[,c], m2=commonNeighbours)
      }

      i <<- i + 1
    })
  }
  bicliques
}
于 2015-06-25T10:44:42.407 に答える