算法原理不在赘述,请参考:
http://blog.csdn.net/hguisu/article/details/8013489
将代码保存为.py格式,默认使用的数据是代码文件所在目录下data目录下的 pgr_data.txt 文件分别作为源数据输入。以上参数可以在源代码中修改,也可以使用命令行参数传入,参考以下启动方式:
python hits.py pgr_data.txt命令中后参数为输入数据的途径。
代码中设立了三个参数,分别为:
size = 100 ### the size of the networks
times = 200 ### the maxmim times for iterations
error = 0.0001 ### the error used for stoping the iterations
分别为hits算法的网络的最大节点数,迭代最大次数,最大误差允许。最后两个参数用来限制迭代次数。
python 源代码如下:
__author__ = 'Administrator'
import re
import sys
size = 100 ### the size of the networks
times = 200 ### the maxmim times for iterations
error = 0.0001 ### the error used for stoping the iterations
tr_data = [[0 for i in range(size)] f