Last active
August 29, 2015 14:09
-
-
Save robinfang/b04680d6d8ff9ee9d134 to your computer and use it in GitHub Desktop.
传播模拟
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #coding=utf-8 | |
| import diffusion_i as dfi | |
| import numpy as np | |
| import pylab as pl | |
| from igraph import * | |
| def countN(g,beta,times): | |
| count = [] | |
| for i in xrange(times): | |
| result = dfi.diffusion(g=g,beta=beta) | |
| print('.'), | |
| count.append(len(result)) | |
| mean = np.mean(count) | |
| std = np.std(count) | |
| print "\nmean: %f" % mean | |
| print "standard deviation: %f" % std | |
| return mean, std | |
| if __name__ == "__main__": | |
| g = Graph.Read_Pajek("facebook_combined.net") | |
| mean = [] | |
| std = [] | |
| x = np.linspace(0.1,0.5,10) | |
| for i in xrange(len(x)): | |
| m, s=countN(g,x[i],10) | |
| mean.append(m) | |
| std.append(s) | |
| pl.subplot(2,1,1) | |
| pl.plot(x, mean, 'x-.') | |
| pl.xlim(0.0, 0.55) | |
| pl.subplot(2,1,2) | |
| pl.plot(x,std,'ko-') | |
| pl.xlim(0.0, 0.55) | |
| pl.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment