Igraph

Материал из Letopisi.Ru — «Время вернуться домой»
(Различия между версиями)
Перейти к: навигация, поиск
(Basic Graph Algorithms)
(Разные способы определения сообществ)
Строка 118: Строка 118:
  
  
 +
; Finding clusters of CRAN packages using igraph
 +
: http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
 +
 +
 +
; Finding clusters of CRAN packages using igraph
 +
: http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
 +
; Network basics with R and igraph
 +
: https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/
  
 
gcon <- simplify(gcon, edge.attr.comb = list(weight = "sum", function(x)length(x)))
 
gcon <- simplify(gcon, edge.attr.comb = list(weight = "sum", function(x)length(x)))
Строка 128: Строка 136:
 
; Finding clusters of CRAN packages using igraph
 
; Finding clusters of CRAN packages using igraph
 
: http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
 
: http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
 +
; Network basics with R and igraph
 +
: https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/
  
  

Версия 10:03, 22 февраля 2016

Пакет, предназначенный для работы с данными и представлениями сетевых отношений. Подробная документация:

Основные сетевые характеристики графа про помощи пакета - Basic graph analytics using igraph - http://horicky.blogspot.ru/2012/04/basic-graph-analytics-using-igraph.html

Create a directed graph using adjacency matrix - Матрица смежности

m <- matrix(runif(4*4), nrow=4) # создали матрицу смежности g <- graph.adjacency(m > 0.5) # а граф построили только для вершин со значениями больше заданного


Содержание

layouts

layout.fruchterman.reingold
layout.kamada.kawai

Процедура представления совместной деятельности как графа

В данном случае - исходные данные = действия участников блога Галактика в 2010 году - как все это начиналось и во что это сложилось. См. История образовательной Галактики

Fast, efficient two-mode to one-mode conversion in R

http://www.r-bloggers.com/working-with-bipartiteaffiliation-network-data-in-r/


library('Matrix')
A <- spMatrix(nrow=length(unique(df$person)),
       ncol=length(unique(df$group)),
       i = as.numeric(factor(df$person)),
       j = as.numeric(factor(df$group)),
       x = rep(1, length(as.numeric(df$person))) )
row.names(A) <- levels(factor(df$person))
colnames(A) <- levels(factor(df$group))
A
Arow <- A %*% t(A)  # users
Acol <- t(A) %*% A # pages

А дальше может работать отдельно с участниками и страницами и их связями

gn <- graph_from_adjacency_matrix(Arow,mode = c("directed"), weighted = NULL, diag = TRUE, add.colnames = NULL, add.rownames = NA) # получаем граф
gn <- simplify(gn) # Упрощаем граф


Объединение узлов

The function contract.vertices() merges several vertices into one. By computing the community structure, one can control how this merging happens. At conclusion of the contraction, two vertices can have multiple edges.

Contracting and simplifying a network graph
http://blog.revolutionanalytics.com/2015/08/contracting-and-simplifying-a-network-graph.html

Объединение связей

The equivalent step for edges is simplify(). A simplified graph contains only a single edge between two nodes. The simplification step can compute summary statistics for the combined edges, for example the sum of edge weights.

edge.attr.comb
http://www.inside-r.org/packages/cran/igraph/docs/attribute.combination

Варианты:

  • g4 <- simplify(g3, edge.attr.comb = list(weight = "sum"))
  • g4 <- simplify( g3, remove.multiple = T, remove.loops = T, edge.attr.comb=c(weight="sum", type="ignore") )

Атрибуты узлов

  • vertex.color цвет вершины
    • vertex.color="gold", vertex.color="dark red"
    • vertex.color="lightsteelblue2"
  • vertex.frame.color цвет контура вершины
  • vertex.shape форма обозначения вершины, одно из значений «none», «circle», «square», «csquare», «rectangle», «crectangle», «vrectangle», «pie», «raster», «sphere»
  • vertex.size размер вершины (по умолчанию 15)
  • vertex.size2 второй параметр размера вершины (например, для прямоугольника)
  • vertex.label вектор символов для обозначения вершин
    • vertex.label.color="black"
  • vertex.label.family семейство шрифтов для меток вершин (например, «Times», «Helvetica»)
  • vertex.label.font шрифт: 1 — обычный, 2 — жирный, 3 — курсив, 4 — жирный курсив, 5 — символьный
  • vertex.label.cex размер шрифта (множитель, зависит от устройства)
    • vertex.label.cex=0.8
  • vertex.label.dist расстояние между меткой и вершиной

Атрибуты связей

  • edge.arrow.size=.4 - размер стрелки
  • edge.color - цвет связи
  • edge.width - толщина связи
    • E(g4)$width <- ifelse (E(g4)$weight < 100, 0.1, 1)
  • edge.lty - 1 - solid, 2 - dashed, 3 - dotted,
    • E(g4)$lty <- ifelse (E(g4)$weight < 100, 3, 1)

Basic Graph Algorithms

  • mst <- minimum.spanning.tree(g4)

Minimum Spanning Tree algorithm is to find a Tree that connect all the nodes within a connected graph while the sum of edges weight is minimum.

clusters
clusters(g4, mode="weak")


Connected Component algorithms is to find the island of nodes that are interconnected with each other, in other words, one can traverse from one node to another one via a path.


$membership

$csize
[1] 3 2 3 932 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

2 2 2 2 2 2 2 2 2 2 2 2 2

Т.е. есть огромный кластер на 932 + еще кучки по 2-3 никак не связанных. На самом деле - эти 2-3 переводятся, что он сделал пост или 2 и не получил отклика

Разные способы определения сообществ

Finding clusters of CRAN packages using igraph
http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html


Finding clusters of CRAN packages using igraph
http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
Network basics with R and igraph
https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/

gcon <- simplify(gcon, edge.attr.comb = list(weight = "sum", function(x)length(x)))

What are the differences between community detection algorithms in igraph?
http://stackoverflow.com/questions/9471906/what-are-the-differences-between-community-detection-algorithms-in-igraph/9478989#9478989


Finding clusters of CRAN packages using igraph
http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
Network basics with R and igraph
https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/



Персональные инструменты
Инструменты