c - 在 IGraph 中生成按端点的 Jaccard 索引排序的边列表

标签 c algorithm graph igraph similarity

我需要一些帮助来弄清楚如何在 igraphC 接口(interface)中根据端点的 Jaccard 索引对边进行排序。

我已经能够计算所有对 Jaccard 索引,但我只想要相邻顶点的 Jaccard 索引列表。 在我的例子中,我使用的是具有 34 个顶点和 78 个边的 Zachary 空手道俱乐部网络。

igraph_t graph;
igraph_famous(&graph,"Zachary"); // load a graph
igraph_write_graph_edgelist(&graph,stderr); // print it to stderr

igraph_matrix_t res; // contains the all-pairs jaccard indices
igraph_matrix_init(&res, igraph_vcount(&graph),igraph_vcount(&graph));
igraph_matrix_resize(&res, igraph_vcount(&graph),igraph_vcount(&graph));
// vertices iterator, to select all vertices
igraph_vs_t all_vertices;
igraph_vs_all(&all_vertices);

igraph_similarity_jaccard(&graph,&res, all_vertices, IGRAPH_ALL,false);
igraph_matrix_print(&res);

我想从该矩阵中获取边选择器,就像在 Kruskal 算法中一样,它返回按端点的 Jaccard 索引降序排序的边。

我认为为了只得到相邻的顶点,我需要在边上迭代并手动计算它,但我发现使用 igraph 很难完成这个任务。

这通常适用于出现在 igraph 中的任何其他结构相似性度量。

有人知道如何在不依赖外部数据结构的情况下实现它吗?

最佳答案

I think that in order to get only the adjacent vertices, I need to iterate on edges and compute it manually

不,你不需要,你可以简单地使用 igraph_neighbors获取任何给定顶点的相邻顶点。然后你可以迭代这个 vector ,并从 Jaccard 相似度矩阵中得到相应的值。实际上,这甚至更好:获取从 igraph_neighbors 获得的 vector ,使用 igraph_vector_copy_to 将其转换为常规 C 数组然后用 qsort 对 C 数组进行排序比较器函数不比较顶点索引,而是比较 Jaccard 相似度矩阵中的相应相似度值。最后,如果你真的需要边选择器,使用 igraph_es_pairs从端点(现在已排序)构建边选择器

关于c - 在 IGraph 中生成按端点的 Jaccard 索引排序的边列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31539853/

相关文章:

python - 如何使用 Python 检查超大数据集中的重复图片?

图最长路径

python - 在大图中高效地找到最短路径

c - AT91sam7x 256 : Interrupt just run once

c# - 找出 USB 连接来自哪个端口

algorithm - 在有序简单列表中插入元素的最有效算法是什么

c++ - 如何使用 dfs O(n) 打印图形的 MaxPath?

c - 为什么 pthread_self 被标记为 attribute(const)?

c - [NSDictionary getObjects :andKeys:] 示例

c - 反转列表而不复制(递归方法)