Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views8 pages

Chapter 05 NetworksA

CURSO DE IA

Uploaded by

CARLOS HENRIQUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Chapter 05 NetworksA

CURSO DE IA

Uploaded by

CARLOS HENRIQUE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
Networks A from IPython.core.asplay Amport IML Angort unpy 88 np Inport watpiotl sport Seipy fram scipy.stats import norm ‘fron seiny. stats Saport Binoe inport pandas 95 pa parans = (Figure. fgsize':(12,6), # These are plot paraneters ‘ties, labelsize': 16, faves. titlesize egend.fonesize": 28) inatplotLip.reParans vedate(parans) from natplotiib Anport pypiot as lt Sport random fram ipyeidgets inport * Angort nurpy.Linale from Ioytnon.cisplay inport display ‘fron Ihython. core. display Amore MAL from noteoook.nvextensions import enable_abextension ‘atplotlib inline Print("Ihe 2tbraries loaded successfully") the Liprartes loaded successtolly This chapter introduces models of social networks and of queuing systems. Epidemics ‘The basic epidemiology model is that one infected person infects a random number of susceptible persons after one unit of time, and that number is distributed lke some random variable Y. The model assumes also that the infected people recover after one unit of time. Section 5.1 explains that if R= B(¥) > 1 then the expected number of infected people increases without bound and there is a postive probability that the number of infected people also grows without bound. On the other hand, if B< 1, then the epidemy eventually izzles out Inthe stochastic model, Xn) isthe numberof infected people afer n units of time, BIX(n-+ 1) | X(n)] = RX(). A deterministic continous-time model of his epidemy is x(t+1) = Ra(0),t>0. ‘This section compares the deterministic and stochastic models. At frst glance, it seems that both models should behave similarly. I is indeed common to use a determin closer look reveals important differences. We simulate the stochastic model for a few distributions of ¥. Incase (a), ¥ = Ry in case (b), ¥ = R/0.3 with probability 0.3 and ¥ = 0 otherwise; in case (), ¥ = 10R with probability 0.1 and ¥ = 0 otherwise, Note that E{Y| = Rin the three cases, ic model in epidemiology. However, 3 et omy Ra, cased) label R, 6, case Ry Ns eae > #0st(Rd), Ane(Ned, str(eased) fd = widgets. ropdoun(optionse['0.8', "8.9", ‘2's Sp tay sy tidy 15" ]jvaiue. 12" descriptions "h!disabled-Fals 2 Id widgots.ropdoun(options-['20", 30", "38", "70", "186", "350", 260", 250" ],value~"109",gescription-'',disabled-False > ‘eases = wiagets. Togglesuttons(options=(°(2)"s (0)'s'@)Tyoescrapeions Case: sabled-False,button_style-"info' tool tips Description) 2 = whdgets.tntersetive(dumny, Rd = Rd, Md = Nd,cosed=cased) aisplaye2) ni n [ 100 oe ratplotLib.reParans update parans) def tseretenv(xsp): # here = Fal 8) --.X0-BI], B= [PLB], --y BOR a7 4 returns a randon volue equat to x{k) with probabitity p[k] K = lent) P = ap. zeroste) for kin range(t) Plkd = suntp(:kl) # Ped = of}, pls) = pls}, PL2) = ol) + PITY, oony PUT} = PLO] ¢ ne ¢ plea] = 1 1 = np.randon.untfora(e,2) # here ts our uniform AY for kan range(s 4) SFU < Pe) ee adie) found = True break > xtc] def epidensotogy (case, 8,0) iease = (2) oO 2,8/8.3) 18.70,0.28] p= (0:3,0.3) x= m.zerosiw) Exe np. zerasth) x{e) = t08 Ex(e] = 280 for nn range(¥-n) Ex[net} = ningie4,Px{n]-R) AE X[n) == 2084: Xinva] = 1988 ase: AF case == (0) X{ned] = nin(Rex{n},10°*8) cise for a én range(snt (x(a) X(nia] v= discreteRVea,9) X{net] = ninextnes], 10°89 ple plot(®t, colors"b*,1abers"EDx(a1)") plt-plot6e, color='r'-iabel="x(0)") ple legenat) plt-adabel("$r$") PIE-tiEre("Sinple Epidemiology Hedet”) epidentotogyi¢ease,f,§) Simple Epidemiology Model 2080) etxinlh — xn} ‘100 00 é % cy @ e 0 Not surprisingly, the stochastic model shows that Xn] has a large variability thatthe deterministic 1. We simulate the process 100 times anc ‘model overlooks. To explore ths variability, we choose R we plot the histogram of X15} ef um (eased): flobal case fase = str(casee) cased ~ widgets. Togelesuttons(options-[°(3)", 2)", (e) Tpseseription= Case: isabled False, button_style="info", toot ‘lpe' Description’) 2 = wlogets snteractive(dumny, casedecases) dtaplayte) cose a w ef eptdensotogy2(cose 8,1): Bf case == (3) eRe case == 1H) (2,803) [0.70,0.30 x= [es10°8] (23,0.2) K = mp.2eros(N) Ex = np. zerastt) x{0) = 100 ex{a] = 200 for nin range(¥-1): Exfmeay = nin(ae**s,ex[n]°R) Af X[n} == dora: Xin] = 104 ese: i case == (0) X{net] = ein(Rex{n},10°*8) For m in rangeCnt(x(a))) Xinsa} s= dascretenv (x9) X{nt] = sin(x{nea},10°"8) return x(¥-1] ef epideniology3(case) Peng. rero4(300) for kein range(29) 21k] = epideniology2(case,2.1,16) print ("The wean value E(¥(35)} = ‘, round(260"(1.2)**15)) pissnist(2); epideniotogy3 (case) The wean value €(x(15) 100 Controlling the Epidemics ‘Assume that one tres to control the epidemics by imposing socal distancing measures. These measures reduce the value of R.In our model, we introduce social distancing measures that reduce R by a factor 2 if we notice that X[n] exceeds 1000, However, it takes four units of time for the measures to be implemented. Consider the following stochastic model of this situation. If X/n — 4] > 1000, then each of the Xn] infected people infect a random number of people equal to 472 with probabily 0.125 and ‘0 zer0 with probability 0.875; if Xn — 4] < 1000, then each of the Xn] infected people infect a random number of people equal to 82 with probability 0.125 and to zero with probablity 0.875, We simulate X{n] and we compare that evolution to the predictions ofa deterministic model Run the ‘model afew times by changing the value of NV and observe the variability ofthe results. ef umn) lobed 8 n> neue) N= widgets. oropdown(options-['200", 250", 200", 250°, "300", "350" ]yvalue- 200" deserintson-"W",afsabled- False) 2 = widgets snteractive(dumny, Wd = Md) aisplay2) wn [200 ef epidensolotysin) X= mp.eros(u) Ex = mp.20ro5(W) for nin range(3): xn} = 286 a(n) = 108 for nn rango(s,¥-1): Hf Oxiond] « toee xin} = min(a0**4,Exf0)°a) ex{nsa] = min(ao"*4,ex{n)*8/2) se x(n} = 2008 x(n] = 196 ane: 4 x(n} « 2000: or m in range(int(X{01)) Xlnea] + discretenv((0,2°R], (0.875, 2.125)) xtnox} = win(xtnenT 10°78) for m an range(ant (xt) X{nea] += discretenv((e,e-R}, (0.875, @.225)) xtner} > wanextnenTs10°"8) pit.plot(@x, colors’ ,Label="e{x[01]") Pltiplet (x, celors'r",Zabel=“xI01") pit. legene()| ple adabe("Sn8") PLE-titLe("Sinple Controlled Epideny Model") pit. sow) spidentoloey$¢) Sime controlled Epidemy Model Pan — etxinll — xn 1500 a 180 250 iio ais 595 360 ‘This example shows that predictions based on a determistic model can be very misleading, More importantly, choosing control polices based on such predictions seems a bit dicey. Thus, although feedback control makes systems more robust, the combination of randomness and delays can have lasting effects Queueing Models Here we explore a simple queuing network, We examine the suitability of such models for sudying communication networks. The key question is whether i is reasonable to assume thatthe service times of the same packet are independent in successive nodes and that the packet lengths are exponentially distributed, “The model is shown in the figure below, tite “There are two sources of packets: source 0 and source 1. Packets of source 0 go through queues 0 and 1 wihereas packets of source 1 go only through queue 1. The queues are first-come, first-served and each has @ single server. The packets arrive as independent Poisson processes with rates op and 2, respectively In ease (a), the packets have iid. lengths that are exponentially distributed with mean fone, The transmission rates are equal to one in bi Units to be transmitted, We call this transmission time the service time of the packet in the queue. Ina ‘queues, Thus, a packet of length Z takes L time {queuing model, one assumes that the service times are all independent. In a communication model, a packet of stream A has the same service time in both queues, since its length does not change. How diferent are these models? Packet Length Distribution Inthe Internet, the lengths of packets are not exponentially distributed, Typically, there maximum-length packets of 1500 Bytes that cary bits from large files or audio/video streams, and minimum-length packets of about 100 Bytes that carry acknowledgments of the large packets. In ease (b) we assume t the packet lengths are equal to 0.1 with probability 0.5 and to 1.9 with probability 0.5. The average length is equal to 1, as before, at Quite remarkably, the independence and exponential apporximations yield very good approximations ‘This was conjectured in the 1960s by Leonard Kleinrock ef omy (.90, L2é,c3504)= label 12, 1, ease to, La, case * Foat(Lee), Aloar(Lae), ste(cased) Lea = widgetssropdoun(options-['0.85', '@.1', °0.35", 1.25 '0025"y 8.350.955 8.4 ]yvalue™”0.2" deseription-'S\lonbc9_96°44 sSsabied-Faise) 1a = widgets .oropdoun(options=[6.05', °8.1"s °0.15", 0.25,"0.25") 83,8098 5 8.4] values” 0.2" descriptions 'S\lanbss 36° 4 ssabled-Falee) ased = widgets Togelavuttons(options{'(3)", (0) ]adesertption="case:",alsables-False, button styles" info" tooktips"0| ceseription’) 2 = widgets snteractive(dumy, L8d = L8d, Lid ~ L1d,casee-casea) aisptayee) sslantan.os [02 ssvomaa.ss [02 ve 4 he write on event-drtven simulation 1 The code ( object-oriented. There ane three types of fects hetwors, sources, ond queues. {Fe ts eoxy to nodify this cade to accomodate an arbitrary topology 1 ond different etstrsbutions or even muLtiole priorities def matn(.9,L4 case): # LE (8 the rate of arrivals of source « lobed source 24st, queue_lést Nin seaee # Aes the number of events soureelist © (1 queues ist = (] FP Firse DIAL the network - One could generalize by giving @ topology Ceounce(,0,18, case) # generate source @ attaches to gueve @ with ceource( 1,1, ease) # generate source I attaches to gueve 1 with ‘oueve( 6,1), # generate queve 8 attached to queue 1 Caueve(3,-1) generate queue 1 attached to ext from network Network © Chetwork() # define the network forn in range(), Netore Find next_event() Network. pracess_event(Network.nextEvent) deptines ~ {] felays = ‘for Sten in queve_1ist{2) ext: Ae sono] => @ epTines. append (tten[}) ‘elays.eppend(sten(21) pit.ylabel(“beiay") ple.adabel Departure Tine") PIt-tstre("Uei5ys oF packets of source 8°) ple-scatter(deprines,celays) Print The averoze delay vor round(sun(deLays}/ien(delays),3)) Ds (2 ~ souree_168t{0].rate) # delay Sn First queue D 4 1/(2 ~ Souree_itstfe).rate ~ source_list{].rate) # detay tn Print(:The average delay when the service tines are sndependent and ‘cxponentistly aistrisuted is", round(0,3)) caass ceouree() ef init _(seif,1D, nextqueue, rate, case) “elf nextcererationTine ~ op.canden.exponentiai(3/rate) Self. packet = {1 Seif nextQueue = nextQueve Source 11st apoene(sel*) def generate( self tine, case): ease ==) Tength = np-randon.oxporentsst(1) ease Tength = discretes¥({0.1,1.9],[0.5,0:51) seif.packet = (self-10,tine, length] # [source.20, generation tine, Length] np. random exponent (1/se1f rate) ‘queue_List[sel*.nextQueue]arrival(tine, sel packet) class cqueue() Get init__(self, 10, rexequeve) Self. state = (]_ List of packets Seifvexits = [] # List of [souree.t0, departure tine, delay} Self noxtqueve = nextqueve (queue List apoend( sel“) ‘def aersval(seif,tine, packet): # packet = fsource. ID, generation time, Length) Seif state. appenatpacket) Af Len(Selfsstate) == 1: # packet Just arrived On enpty queue selfsneitaeparturetine = tine + self state[O]E2] # Length of ew packet (Sef deparsure( self tine) packet = self. statel0] fe sel stote(@] Bf self-state (1: ‘selF.nextoeparturetine = tine + self.state(®](2] Af self-nextgueue ss “1: # “1 ds 2 generte none for “Leaving the self-oxtts.append{packet{0] tine, tine ~ packet{11]) ese uoue_Jist[s0iFnextqueve].arrivat( tine, packet) class cnetwork(): def _inte_(seit): Feit. naxtevert = (] Self. queues ~ queve List self. nunberSources = len(source 11st) SeLf.nunberQueves ~ Len(eveve_tist) Netuore = e814 et Find poxt_event(self): # event = ["Generation’ or ‘Departure’, 5 ong, shen) Self neetevent = [-Generatior"ya,source_165t[6] nextGenerationTine] ‘or sin range(i,selé.nunbersources): 6 source List{s] nextéenerstiontine < self.nextvent[2] self. nextevert = [-conerstion’,s,souree_18s¢[s] .nextGenerationT ing] for in rarge(sel*nunber Queues) 4€ queue tist{a]-state I= (15 “ef queue 2ist(q]-nextDeparturetine < self nextEvent(2): welf-nextevent = (oepartuve’ ya, queue List {2} nextepartureTine) et process _event(self event): ‘ine = svert(2) AF venta] == “Generation event(] source Lists]. gonerate(tine, case) else! # ceparture ‘e evers{i] ‘queue Lista]. ceparture(tine) ain(0e14, se) ‘he average delay for source @ Ss 3.068 The average delay when the service tines are indepentent and exponentially ofstihuted $2917 Delays of packets of source 0 0 & Bx ° e 1eGoo 2000 —_saGoo——«a0d00—~50000 Departure Time By Jean Walrand © Copyright 2021

You might also like