首页 > 编程知识 正文

关联规则模型,传染病模型matlab程序

时间:2023-05-03 15:24:18 阅读:140404 作者:4624

下图所示传染病传播过程绿色正常,红色为传染病,蓝色为恢复(并免疫) importnumpyasnpimportrandomimportmatplotlib.pyplotasplt % matplotlibinlineimportnet 小世界网络defsmall_world(n,d,a ) :random.seed ) 1024 ) a=NP.zeros ) () n, n ) forIinrange(n ) :t=0whilet ) d/2 ) : a [ I ] [ I-(t1 )=1a [ I-(t1 ) [ I ]=1t=1foriinrange ] ) 1 [I-(T1 ) ]=0a [ I-(t1 ) ] ) I )=0target (N-1 ) ) whilea [ I ] [ target ]==1or target==I : target=randd 初始化零号患者defpatient_zero(n,num ) 3360 infecters=rannancters num (infect status=NP.zeros (n, int ) for i in Infecters:撒娇的万宝路I ) i]=1 return InfectStatus#感染过程def infect(A ) a,s, beta gamma=0) :n=len(a ) forIinrange(n ) :ifs(I )==1andrandom.random )=gamma 3360 s [ I ]=2if sum (s ) 3360 ifs [ I ]==0: forjinrange (n ) :ifa[I](j )==1ands[j]==1andrandom.random )=beta3360s[I]。 N0,beta,gamma,plot=true(:n=len ) a ) S=patient_zero(N ) n, N0 ) if plot : g=NX.from _ numpy _ matrix (a ) pos=nx.kamada_kawai_layout(g ) g ) nodesize=[ ] maxsize=axis=0) ) ifmaxdegree==min degree : nodesize=[ minsizeforiinrange (len (a ) ] else 3360 fornodeing 3360 size=(NP (MP ) (maxsize-minsize ) minsizenodesize.append(size ) result=[ ] time=0while true 3360 if plot 330 ' b ' ] colors=[ cmap [ CMP ] 20 ) ]NX.draw_NetWorkx_nodes ) g,pos=pos alpha=0.6 ) NX.Draw_NetWorkx_Edges(g,pos=pos,with _ labe ) alpha=0.3 ) PLT.title(time={} ).format (time ) ) (PLT.savefig ) ) }.png ).format ) str ) time ).z fill (4sususte Beta,Gamma ) time=1returnNP.Array(result ) #主程序c=small _ world (1000,4,0.2 ) result=sir(c,2,0.3 )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。