context("operators on named graphs")
test_that("disjoint union works for named graphs", {
library(igraph)
g1 <- g2 <- graph.ring(10)
g1$foo <- "bar"
V(g1)$name <- letters[ 1:10]
V(g2)$name <- letters[11:20]
E(g1)$weight <- 1:10
E(g2)$weight <- 10:1
V(g1)$a1 <- 1:10
V(g2)$a2 <- 11:20
E(g1)$b1 <- 1:10
E(g2)$b2 <- 11:20
g <- graph.disjoint.union(g1, g2)
expect_that(sort(list.graph.attributes(g)),
equals(c("circular_1", "circular_2", "foo", "mutual_1",
"mutual_2", "name_1", "name_2")))
expect_that(sort(list.vertex.attributes(g)),
equals(c("a1", "a2", "name")))
expect_that(sort(list.edge.attributes(g)),
equals(c("b1", "b2", "weight")))
expect_that(V(g)$name, equals(letters[1:20]))
expect_that(V(g)$a1, equals(c(1:10, rep(NA, 10))))
expect_that(V(g)$a2, equals(c(rep(NA, 10), 11:20)))
expect_that(E(g)$weight, equals(c(1:10, 10:1)))
expect_that(E(g)$b1, equals(c(1:10, rep(NA, 10))))
expect_that(E(g)$b2, equals(c(rep(NA, 10), 11:20)))
})
test_that("disjoint union gives warning for non-unique vertex names", {
library(igraph)
g1 <- graph.ring(5); V(g1)$name <- letters[1:5]
g2 <- graph.ring(5); V(g2)$name <- letters[5:9]
expect_that(graph.disjoint.union(g1, g2),
gives_warning("Duplicate vertex names in disjoint union"))
})
test_that("union of unnamed graphs works", {
library(igraph)
g1 <- graph.ring(10)
g2 <- graph.ring(13)
g1$foo <- "bar"
E(g1)$weight <- 1:10
E(g2)$weight <- 13:1
V(g1)$a1 <- 1:10
V(g2)$a2 <- 11:23
E(g1)$b1 <- letters[1:10]
E(g2)$b2 <- letters[11:23]
g <- graph.union(g1, g2)
expect_that(sort(list.graph.attributes(g)),
equals(c("circular_1", "circular_2", "foo", "mutual_1",
"mutual_2", "name_1", "name_2")))
expect_that(sort(list.vertex.attributes(g)),
equals(c("a1", "a2")))
expect_that(sort(list.edge.attributes(g)),
equals(c("b1", "b2", "weight_1", "weight_2")))
df1 <- get.data.frame(g)
df1 <- df1[ order(df1$from, df1$to), c(1,2,3,5,4,6)]
df2 <- merge(get.data.frame(g1), get.data.frame(g2),
by=c("from", "to"), all=TRUE)
rownames(df1) <- seq_len(nrow(df1))
colnames(df2) <- c("from", "to", "weight_1", "b1", "weight_2", "b2")
expect_that(df1, equals(df2))
})
test_that("union of named graphs works", {
library(igraph)
g1 <- graph.ring(10)
g2 <- graph.ring(13)
V(g1)$name <- letters[seq_len(vcount(g1))]
V(g2)$name <- letters[seq_len(vcount(g2))]
g1$foo <- "bar"
E(g1)$weight <- 1:10
E(g2)$weight <- 13:1
V(g1)$a1 <- 1:10
V(g2)$a2 <- 11:23
E(g1)$b1 <- letters[1:10]
E(g2)$b2 <- letters[11:23]
g <- graph.union(g1, g2)
expect_that(sort(list.graph.attributes(g)),
equals(c("circular_1", "circular_2", "foo",
"mutual_1", "mutual_2", "name_1", "name_2")))
expect_that(sort(list.vertex.attributes(g)),
equals(c("a1", "a2", "name")))
expect_that(sort(list.edge.attributes(g)),
equals(c("b1", "b2", "weight_1", "weight_2")))
df1 <- get.data.frame(g, what="both")
g.v <- read.table(stringsAsFactors=FALSE, textConnection("
a1 a2 name
a 1 11 a
b 2 12 b
c 3 13 c
d 4 14 d
e 5 15 e
f 6 16 f
g 7 17 g
h 8 18 h
i 9 19 i
j 10 20 j
k NA 21 k
l NA 22 l
m NA 23 m
"))
expect_that(df1$vertices, equals(g.v))
g.e <- read.table(stringsAsFactors=FALSE, textConnection("
from to weight_1 weight_2 b1 b2
1 l m NA 2 NA v
2 k l NA 3 NA u
3 j k NA 4 NA t
4 i j 9 5 i s
5 h i 8 6 h r
6 g h 7 7 g q
7 f g 6 8 f p
8 e f 5 9 e o
9 d e 4 10 d n
10 c d 3 11 c m
11 b c 2 12 b l
12 a m NA 1 NA w
13 a j 10 NA j NA
14 a b 1 13 a k
"))
rownames(df1$edges) <- rownames(df1$edges)
expect_that(df1$edges, equals(g.e))
})
test_that("intersection of named graphs works", {
library(igraph)
g1 <- graph.ring(10)
g2 <- graph.ring(13)
V(g1)$name <- letters[V(g1)]
V(g2)$name <- letters[V(g2)]
g1$foo <- "bar"
E(g1)$weight <- 1:10
E(g2)$weight <- 13:1
V(g1)$a1 <- 1:10
V(g2)$a2 <- 11:23
E(g1)$b1 <- letters[1:10]
E(g2)$b2 <- letters[11:23]
g <- graph.intersection(g1, g2, keep.all.vertices=FALSE)
expect_that(sort(list.graph.attributes(g)),
equals(c("circular_1", "circular_2", "foo", "mutual_1",
"mutual_2", "name_1", "name_2")))
expect_that(sort(list.vertex.attributes(g)),
equals(c("a1", "a2", "name")))
expect_that(sort(list.edge.attributes(g)),
equals(c("b1", "b2", "weight_1", "weight_2")))
df1 <- get.data.frame(g, what="both")
g.e <- read.table(stringsAsFactors=FALSE, textConnection("
from to weight_1 weight_2 b1 b2
1 i j 9 5 i s
2 h i 8 6 h r
3 g h 7 7 g q
4 f g 6 8 f p
5 e f 5 9 e o
6 d e 4 10 d n
7 c d 3 11 c m
8 b c 2 12 b l
9 a b 1 13 a k
"))
rownames(df1$edges) <- rownames(df1$edges)
expect_that(df1$edges, equals(g.e))
g.v <- read.table(stringsAsFactors=FALSE, textConnection("
a1 a2 name
a 1 11 a
b 2 12 b
c 3 13 c
d 4 14 d
e 5 15 e
f 6 16 f
g 7 17 g
h 8 18 h
i 9 19 i
j 10 20 j
"))
expect_that(df1$vertices, equals(g.v))
gg <- graph.intersection(g1, g2, keep.all.vertices=TRUE)
df2 <- get.data.frame(gg, what="both")
rownames(df2$edges) <- rownames(df2$edges)
expect_that(df2$edges, equals(g.e))
gg.v <- read.table(stringsAsFactors=FALSE, textConnection("
a1 a2 name
a 1 11 a
b 2 12 b
c 3 13 c
d 4 14 d
e 5 15 e
f 6 16 f
g 7 17 g
h 8 18 h
i 9 19 i
j 10 20 j
k NA 21 k
l NA 22 l
m NA 23 m
"))
expect_that(df2$vertices, equals(gg.v))
})
test_that("difference of named graphs works", {
library(igraph)
g1 <- graph.ring(10)
g2 <- graph.star(11, center=11, mode="undirected")
V(g1)$name <- letters[1:10]
V(g2)$name <- letters[1:11]
g <- g1 %u% g2
sg <- graph.ring(4)
V(sg)$name <- letters[c(1,2,3,11)]
df1 <- get.data.frame(g - sg, what="both")
t1.e <- read.table(stringsAsFactors=FALSE,
textConnection("
from to
1 a j
2 b k
3 c d
4 j k
5 i k
6 h k
7 g k
8 f k
9 e k
10 d k
11 d e
12 e f
13 f g
14 g h
15 h i
16 i j
"))
rownames(df1$edges) <- rownames(df1$edges)
expect_that(df1$edges, equals(t1.e))
expect_that(df1$vertices, equals(data.frame(row.names=letters[1:11],
name=letters[1:11],
stringsAsFactors=FALSE)))
gg <- sg - g
expect_that(ecount(gg), equals(0))
expect_that(V(gg)$name, equals(letters[c(1:3,11)]))
})
test_that("compose works for named graphs", {
library(igraph)
g1 <- graph.formula( A-B:D:E, B-C:D, C-D, D-E )
g2 <- graph.formula( A-B-E-A )
V(g1)$bar1 <- seq_len(vcount(g1))
V(g2)$bar2 <- seq_len(vcount(g2))
V(g1)$foo <- letters[seq_len(vcount(g1))]
V(g2)$foo <- letters[seq_len(vcount(g2))]
E(g1)$bar1 <- seq_len(ecount(g1))
E(g2)$bar2 <- seq_len(ecount(g2))
E(g1)$foo <- letters[seq_len(ecount(g1))]
E(g2)$foo <- letters[seq_len(ecount(g2))]
g <- graph.compose(g1, g2)
df <- get.data.frame(g, what="both")
df.v <- read.table(stringsAsFactors=FALSE, textConnection("
bar1 foo_1 foo_2 bar2 name
A 1 a a 1 A
B 2 b b 2 B
D 3 c NA NA
没有合适的资源?快使用搜索试试~ 我知道了~
R语言Igraph软件包0.7.1
共164个文件
r:128个
rds:8个
gz:3个
5星 · 超过95%的资源 需积分: 50 104 下载量 14 浏览量
2015-03-10
17:34:39
上传
评论 1
收藏 6.9MB ZIP 举报
温馨提示
R语言Igraph软件包0.7.1,可用作复杂网络分析及可视化
资源推荐
资源详情
资源评论
收起资源包目录
R语言Igraph软件包0.7.1 (164个子文件)
AnIndex 14KB
AUTHORS 5KB
CITATION 644B
style.css 9KB
R.css 1KB
DESCRIPTION 753B
igraph.dll 6.03MB
igraph.dll 5.99MB
tkigraph-main.gif 14KB
igraph.gif 2KB
igraph2.gif 2KB
power.gml.gz 45KB
celegansneural.gml.gz 12KB
football.gml.gz 4KB
00Index.html 66KB
index.html 6KB
communities.html 94B
igraph 1KB
INDEX 12KB
NAMESPACE 12KB
NEWS 41KB
test_operators4.R 10KB
test_indexing.R 8KB
test_graphlets.R 6KB
test_graph.adjacency.R 6KB
community.R 5KB
crashR.R 5KB
centrality.R 5KB
smallworld.R 4KB
test_bipartite.projection.R 3KB
test_maximal_cliques.R 3KB
test_motifs.R 3KB
test_indexing2.R 3KB
test_bonpow.R 3KB
test_arpack.R 3KB
test_attributes.R 3KB
test_betweenness.R 3KB
test_communities.R 3KB
test_graph.subisomorphic.lad.R 3KB
test_alpha.centrality.R 2KB
test_leading.eigenvector.community.R 2KB
test_ba.game.R 2KB
test_closeness.R 2KB
test_bipartite.random.game.R 2KB
hrg.R 2KB
test_scg.R 2KB
test_graph.adhesion.R 2KB
test_assortativity.R 2KB
test_authority.score.R 2KB
test_add.edges.R 2KB
test_evcent.R 2KB
test_print.R 2KB
test_edgenames.R 1KB
test_graph.knn.R 1KB
test_edge.connectivity.R 1KB
test_sdf.R 1KB
test_get.all.shortest.paths.R 1KB
test_decompose.graph.R 1KB
test_count.multiple.R 1KB
test_graph.data.frame.R 1KB
test_constraint.R 1KB
test_edge.betweenness.R 1KB
test_all.st.cuts.R 1KB
test_walktrap.community.R 1KB
test_operators.R 1KB
test_iterators.R 1KB
test_as.directed.R 1KB
test_is.chordal.R 1KB
test_get.adjlist.R 1KB
test_degree.sequence.game.R 1KB
test_edge.betweenness.community.R 1KB
test_operators3.R 1KB
cohesive.R 1KB
test_fastgreedy.community.R 1010B
test_diameter.R 1008B
test_sbm.game.R 999B
test_minimum.size.separators.R 992B
test_get.shortest.paths.R 961B
test_optimal.community.R 941B
test_average.path.length.R 936B
test_graphNEL.R 906B
test_degree.R 900B
test_neighborhood.R 866B
test_fartherst.nodes.R 865B
test_dominator.tree.R 864B
test_label.propagation.community.R 859B
test_layout.mds.R 787B
test_graph.kautz.R 782B
test_contract.vertices.R 760B
test_biconnected.components.R 756B
test_forestfire.R 754B
test_multilevel.community.R 754B
test_as.undirected.R 741B
test_cliques.R 724B
test_transitivity.R 723B
test_graph.eigen.R 708B
test_get.adjacency.R 683B
test_are.connected.R 682B
test_add.vertices.R 678B
dyad.census.R 662B
共 164 条
- 1
- 2
资源评论
- kill-92016-06-13windows 环境下的资源
- worm802016-01-28igraph1.0.1版本用的不爽,重装系统后,还是下载老版本稳定
- ccdbeyond2016-03-28可以用来作图,很不错的画图R包。
- authorize2015-10-19找了好久,终于找到了,感谢分享 实验了一下,好用。
hicosl
- 粉丝: 4
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 正点原子开拓者FPGA多人表决器代码项目
- EOP-Last5Years.txt
- windows 32位、64位系统常见缺少的库
- 毕业设计基于springboot+vue实现的求职招聘类型网站源码+数据库(高分项目).zip
- 535springboot + vue 体质测试数据分析及可视化设计.zip(可运行源码+数据库文件+文档)
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统源码.zip
- 基于springboot+vue实现的求职招聘类型网站源代码+数据库(优质毕设项目).zip
- iOS APP提审checklist
- 第十四届中北大学ACM程序设计竞赛.zip
- UIGF_200852355_202404242026.json
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功