可能存在错误,大家发现了请评论指正。

1 Analyzing the Wikipedia voters network [27 points]

import snapG = snap.LoadEdgeList(snap.TNGraph, "Wiki-Vote.txt", 0, 1)
snap.PrintInfo(G, "Wiki-Vote", "result.txt", False)

result.txt:

Wiki-Vote: DirectedNodes:                    7115Edges:                    103689Zero Deg Nodes:           0Zero InDeg Nodes:         4734Zero OutDeg Nodes:        1005NonZero In-Out Deg Nodes: 1376Unique directed edges:    103689Unique undirected edges:  100762Self Edges:               0BiDir Edges:              5854Closed triangles:         608389Open triangles:           12720413Frac. of closed triads:   0.045645Connected component size: 0.993113Strong conn. comp. size:  0.182713Approx. full diameter:    690% effective diameter:  3.791225

1. The number of nodes in the network.

7115

2. The number of nodes with a self-edge (self-loop).

0

3. The number of directed edges in the network.

103689

4. The number of undirected edges in the network.

100762

5. The number of reciprocated edges in the network.

5854

6. The number of nodes of zero out-degree.

1005

7. The number of nodes of zero in-degree.

4734

k1 = 0
k2 = 0
for NI in G.Nodes():if NI.GetOutDeg() > 10:k1 += 1if NI.GetInDeg() < 10:k2 += 1
print(k1, k2)

8. The number of nodes with more than 10 outgoing edges (out-degree > 10).

1612

9. The number of nodes with fewer than 10 incoming edges (in-degree < 10).

5165

2 Further Analyzing the Wikipedia voters network [33 points]

1. (18 points) Plot the distribution of out-degrees of nodes in the network on a log-log scale. Each data point is a pair (x, y) where x is a positive integer and y is the number of nodes in the network with out-degree equal to x. Restrict the range of x between the minimum and maximum out-degrees. You may filter out data points with a 0 entry. For the log-log scale, use base 10 for both x and y axes.

snap.PlotOutDegDistr(G, "Wiki-Vote", "Wiki-Vote Out Degree")

2. (15 points) Compute and plot the least-square regression line for the out-degree distribution in the log-log scale plot. Note we want to find coefficients a and b such that the function log10 y = a · log10 x + b, equivalently, y = 10b · x a , best fits the out-degree distribution. What are the coefficients a and b? For this part, you might want to use the method called polyfit in NumPy with deg parameter equal to 1.

import math
import numpy as np
maxOutDeg = 0
for NI in G.Nodes():if NI.GetOutDeg() > maxOutDeg:maxOutDeg = NI.GetOutDeg()log10x = []
y = []
for deg in range(1, maxOutDeg):pointNo = G.CntOutDegNodes(deg)if pointNo != 0:log10x.append(math.log10(int(deg)))y.append(pointNo)print(np.polyfit(log10x, y, deg=1))

result:

[-164.99965984  355.24262157]

3 Finding Experts on the Java Programming Language on StackOveflow [40 points]

1. The number of weakly connected components in the network.

G = snap.LoadEdgeList(snap.TNGraph, "stackoverflow-Java.txt", 0, 1)Components = G.GetWccs()
print(len(Components))

result:

10143

2. The number of edges and the number of nodes in the largest weakly connected component.

MxWcc = G.GetMxWcc()
snap.PrintInfo(MxWcc, "MxWcc", "result-MxWcc.txt", False)

result-MxWcc.txt:

MxWcc: DirectedNodes:                    131188Edges:                    322486Zero Deg Nodes:           0Zero InDeg Nodes:         78365Zero OutDeg Nodes:        26008NonZero In-Out Deg Nodes: 26815Unique directed edges:    322486Unique undirected edges:  322371Self Edges:               15035BiDir Edges:              15265Closed triangles:         41388Open triangles:           51596519Frac. of closed triads:   0.000802Connected component size: 1.000000Strong conn. comp. size:  0.032953Approx. full diameter:    1290% effective diameter:  5.527031

result:

322486 131188

3. IDs of the top 3 most central nodes in the network by PagePank scores.

PRankH = G.GetPageRank()
top1, top2, top3 = [0, 0], [0, 0], [0, 0]
for item in PRankH:if PRankH[item] > top1[1]:top3 = top2top2 = top1top1 = [item, PRankH[item]]elif PRankH[item] > top2[1]:top3 = top2top2 = [item, PRankH[item]]elif PRankH[item] > top3[1]:top3 = [item, PRankH[item]]print(top1[0], top2[0], top3[0])

result:

992484 135152 22656

4. IDs of the top 3 hubs and top 3 authorities in the network by HITS scores.

NIdHubH, NIdAuthH = G.GetHits()
top1, top2, top3 = [0, 0], [0, 0], [0, 0]
for item in NIdHubH:if PRankH[item] > top1[1]:top3 = top2top2 = top1top1 = [item, PRankH[item]]elif PRankH[item] > top2[1]:top3 = top2top2 = [item, PRankH[item]]elif PRankH[item] > top3[1]:top3 = [item, PRankH[item]]
print(top1[0], top2[0], top3[0])top1, top2, top3 = [0, 0], [0, 0], [0, 0]
for item in NIdAuthH:if PRankH[item] > top1[1]:top3 = top2top2 = top1top1 = [item, PRankH[item]]elif PRankH[item] > top2[1]:top3 = top2top2 = [item, PRankH[item]]elif PRankH[item] > top3[1]:top3 = [item, PRankH[item]]
print(top1[0], top2[0], top3[0])

result:

992484 135152 22656
992484 135152 22656

cs224w homework 0相关推荐

  1. 估算带卷积核二分类0,3的网络的收敛时间和迭代次数

    制作一个网络分类minst的0和3求出这网络的迭代次数曲线表达式n(δ),和准确率表达式p-max(δ),用预期准确率去估算n,并推算需要的时间. 将minst的28*28的图片缩小到9*9,网络用一 ...

  2. 现代软件工程 作业 3 团队作业

    这是现代软件工程课的作业列表, 老师可以根据情况选用, 建议要保证每周都有作业. 团队作业 Team Homework: 适合团队完成的作业 这些作业都要团队的成员互相配合才能完成,  团队可以选出一 ...

  3. hdu 1789 贪心算法

    http://acm.hdu.edu.cn/showproblem.php?pid=1789 此题大致思路,既然要计算最少扣多少分,就要在最后时间之前把扣分最多的作业先安排了.如果扣分一样多的话,那必 ...

  4. Codecademy网学习Python第六天

    先回顾一下昨天的内容,本文前半部分主要是关于for loop的内容,loop是循环的意思.前文有关于for的一般用法,for item in list. 本次将其拓展为在Dictionary里的用法, ...

  5. 小甲鱼python入门014课后题_小甲鱼零基础入门学习Python-014

    ==========ClassNote========= 1.接触过C语言的朋友应该知道,在C语言中,字符串和字符是两个不同的概念(C语言用单引号表示字符,双引号表示字符串).但在Python中并没有 ...

  6. 零基础学习Python 作业 第28章

    ============= CH28 homework ============ 0 下边只有一种方式不能打开文件, 请问是哪一种, 为什么? f = open('E:/test.txt', 'w') ...

  7. SDU_week4_A - DDL 的恐惧(贪心+作业调度问题)

    题目描述 ZJM 有 n 个作业,每个作业都有自己的 DDL,如果 ZJM 没有在 DDL 前做完这个作业,那么老师会扣掉这个作业的全部平时分. 所以 ZJM 想知道如何安排做作业的顺序,才能尽可能少 ...

  8. lec 1-4 _ 高质量实时渲染

    文章目录 前言 lec1 课程及简介 Lec2 回顾一些以往的知识 渲染管线 OPENGL 着色语言(shading language) 渲染方程 Homework 0 Lec03 shadow ma ...

  9. 零基础学习Python 作业 第22章

    x**============ CH22 homework ============** 0 递归在编程的形式上是如何表现的呢? Answer: 函数本身不断迭代调用自身 1 递归必须满足哪两个基本条 ...

最新文章

  1. HTTP与HTTPS握手的那些事
  2. Linux kernel block device 的 submit_bio 都做了什么?
  3. 用matlab做一个有刻度的网格,已知45个点X Y Z的坐标值已知,如何用matlab画出网格图,另外每个小方格里带颜色 - 程序语言 - 小木虫 - 学术 科研 互动社区...
  4. Linux学习之系统编程篇:mmap 内存映射区
  5. Windows核心编程:第14章 探索虚拟内存
  6. vlan绑定_图文并茂深入了解VLAN工作原理,不能错过干货
  7. java多线程访问beans对象_java-多线程同时操作同一个对象之解决方法:读写锁ReadWriteLock的使用...
  8. 两块stm32单片机串口通信讲解
  9. 人工智能:智能优化算法
  10. Leftist Heaps 习题解
  11. npm包rimraf介绍
  12. 前三十年看父敬子,后三十年看子敬父
  13. 从Linux内核角度看中间人攻击(ARP欺骗)并利用Python scapy实现
  14. 不止音乐与露营——聊聊极狐汽车的微信生态营销
  15. mysql复制表的数据和结构(可跨越数据库)
  16. WebGL技术学习之路
  17. 临时链接转为永久链接的三种方法
  18. Arduino ESP8266读取土壤湿度传感器 ADC
  19. 新时尚Windows8开发(21):分组视图
  20. 白帽,黑帽,灰帽,绿帽!一文了解黑客的所有信息

热门文章

  1. 有不有比加密更强的加密呢,有.拼音加密
  2. three.js案例解析之代码实现morph动画
  3. html如何制作一个漂亮的表格?+ 列表制作 + 表单制作(干货!直接收代码)
  4. 科技新品 | 荣耀Magic3系列智能手机;iQOO 8系列高端旗舰手机;卡西欧两款G-SHOCK品牌防震手表新品...
  5. python 电梯运行_面向对象电梯系列总结
  6. AE 多进程渲染-命令行-aerender-多cmd窗口实现
  7. 人工智能意念控制打字_智能打字稿批量属性分配
  8. Python运用urllib2和BeautifulSoup爬取网站ZOL桌面壁纸上的精美电脑壁纸
  9. 浙江大学计算机学院 00级,“00”后来了!浙江大学2018级新生报到啦!
  10. 高并发大型互联网站架构设计