Search code examples
rigraphbipartitesnaclique-problem

Detect bi-cliques in r for bipartite graph


I am trying to recreate the Biclique Communities method (Lehmann, Schwartz, & Hansen, 2008) in R which relies on the definition of a Ka,b biclique. The example below shows two adjacent K2,2 bicliques - the first clique is {A,B,1,2} and the second clique is {B,C,2,3}. I would like to be able to identify these cliques using R so that I can apply this to a broader dataset.

Adjacent K2,2 Bicliques

I have included my attempt so far in R and I am stuck with the following two issues:

  1. If I use the standard walktrap.community it recognises the communities but does not allow the set {B,2} to belong in both cliques
  2. If I use an updated clique.community function this doesn't seem to identify the cliques or I don't understand correctly (or both)

Example code:

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)

Solution

  • Beware that the above solution becomes inefficient very quickly even for small (dense) graphs and values of k,l due to the fact that comb <- combn(vMode1, k) becomes extremely large.

    A more efficient solution can be found in the "biclique" package that is in development at https://github.com/YupingLu/biclique.