#Code discussed on Mon., April 20, 2020. Modelling COVID-19 #following :COVID-19: Analyticas of COntagion on Inhompg. Random Social Networks" #by T. R. Hurd, arXiv: 2004.02779v1 [q-bio. PE] 6 Apr 2020 Help:=proc(): print(` IRG(N,T,kap); IRG(5,[1/3,2/3],[[1,2],[2,1]]); RaTT(M,K), RaKap(M,K) `): end: with(Statistics): #IRG(N,T,kap): Following assumption 1 (top of p. 6) in Hurd's paper. #Inputs a positive integers N, a probability table T (of length M, say), where T[j] is the probability that #a vertex i from 1 to N has type j and a list of lists representing the matrix, where kap[v][w] is #is the probability that a vertex of type v and a vertex of type w have a social connect (it has two be a symmetric matrix) #Try: #IRG(5,[1/3,2/3],[[1,2],[2,1]]); IRG:=proc(N,T,kap) local M,i,j,TypeT,X,IM,ra: M:=nops(kap): if {seq(nops(kap[i]),i=1..M)}<>{M} then RETURN(FAIL): fi: if max(seq(seq(kap[i][j],j=1..M),i=1..M))>N then RETURN(FAIL): fi: #Sample(RandomVariable(Bernoulli(1/2)),1)[1]; #X is the random variable to decide the type of each vertex X:=RandomVariable(ProbabilityTable( T )): #TypeT: The list of lenght N indicating the various types TypeT:=[seq(round(Sample(X,1)[1]),i=1..N)]: TypeT: #IM is the incidence of the random IRG graph with N vertices for i from 1 to N do IM[i][i]:=0: od: for i from 1 to N do for j from i+1 to N do ra:=round(Sample(RandomVariable(Bernoulli(kap[TypeT[i]][TypeT[j]]/(N-1))),1)[1]): IM[i][j]:=ra: IM[j][i]:=ra: od: od: [seq([seq(IM[i][j],j=1..N)],i=1..N)]: end: #RaTT(M,K): A random type-table with M types drawn with denominator at most M*2*K RaTT:=proc(M,K) local i,ra,T,su: ra:=rand(K..2*K): T:=[seq(ra(),i=1..M)]: su:=convert(T,`+`): T/su: end: #RaKap(M,K): a random M by M kappa table RaKap:=proc(M,K) local ra,i,j,T,r: ra:=rand(1..K): for i from 1 to M do for j from i+1 to M do r:=ra(): T[i][j]:=r: T[j][i]:=r: od: od: for i from 1 to M do r:=ra(): T[i][i]:=r: od: [seq([seq(T[i][j],j=1..M)],i=1..M)]: end: