the kevin bacon game - new mexico cs for allcs4all.cs.unm.edu/modules/projfinal/networks/[nw2... ·...

10
Version 1.0 Jan 2017 Networks 2: The Kevin Bacon Game 1 The Kevin Bacon Game Have you ever run into a friend somewhere you didn’t expect to? Have you ever met someone new and found out you had friends or family in common? When this happens, we often say Well, there’s a network for that! Small world networks are a type of network used to model a social group or social connections. Q: Why are they called small world networks? A: In a small world network, the path from any given node to any other node will be relatively short. In other words, the mean path length is short. (ericwrobbel.com)

Upload: truongdung

Post on 13-May-2018

215 views

Category:

Documents


1 download

TRANSCRIPT

Version1.0Jan2017

Networks2:TheKevinBaconGame 1

TheKevinBaconGame

Haveyoueverrunintoafriendsomewhereyoudidn’texpectto?Haveyouevermetsomeone

newandfoundoutyouhadfriendsorfamilyincommon?Whenthishappens,weoftensay

Well,there’sanetworkforthat!

Smallworldnetworksareatypeofnetworkusedto

modelasocialgrouporsocialconnections.

Q:Whyaretheycalledsmallworldnetworks?A:Inasmallworldnetwork,thepathfromanygivennodetoanyothernodewillberelativelyshort.Inotherwords,themeanpathlengthisshort.

(ericwrobbel.com)

Version1.0Jan2017

Networks2:TheKevinBaconGame 2

Thepopularideaofthesixdegreesofseparation,firstexploredbypsychologistStanley

Milgraminthe1950s,describeshumansocietyasasmallworldnetworkwherethemeanpath

lengthissix.(Ifyou’renotfamiliarwiththeideaofthesixdegreesofseparation,clickhereto

learnmore.)

TheKevinBacongamecameoutoftheideaofthesixdegreesofseparation,andissometimes

calledtheSixDegreesofKevinBacon.Givenanyactressoractor,thegoalistolinkthatperson

toKevinBaconintheleastamountofstepspossible.Thenumberofstepsiscalledsomeone’s

Baconnumber.ItisalmostimpossibletofindanyonewithaBaconnumberhigherthansix!

GooglehasahiddenBaconnumberfeature!Searchthenameplus“BaconNumber.”

Lookatthegraphtotheleft.Isthereapathlongerthan6steps?

Pickanystartingnodeinthegraph/networkontheleft.

Nowpickanendingnode.

Countthenumberofedgesbetweenthem.Thisisthelengthofyourpath.

(Wikipedia)

EXAMPLE1:WhatisWillSmith’sBaconnumber?

Version1.0Jan2017

Networks2:TheKevinBaconGame 3

Let’sgetstarted!

ActivitiesOverviewYouwillcreateasmallworldnetworkfromtheKevinBacongame.You’llreviewandusetheseconcepts:

1. Breeds2. Links3. Labels4. Degree5. Thenetworkextension/networkformatting

You’lllearnthesenewconcepts:

1. Influenceofanode(Eigenvectorcentrality)2. foreach(loopsandnestedloops)

EXAMPLE2:MakeagraphofExample1.

Version1.0Jan2017

Networks2:TheKevinBaconGame 4

InfluenceofaNode(Eigenvectorcentrality)Eigenvectorcentralityisacomplicatednameforasimpleconcept:ifyourfriendshavealotof

influence,thenyouprobablydotoo.We’lljustcallitinfluencefromhereon.Influenceisa

decimalvaluebetween0and1.Avalueof0indicatesthatanodehasminimuminfluenceona

graph,andavalueof1indicatesthatanodehasthemaximuminfluenceonagraph.

InNetLogo,wecancalculatetheinfluenceofanodebyusingthenetworksextension.Besure

toincludeitatthetopofeachfileasyoudidinthepreviousactivities.

Wecanmakeamonitortoobserveanode’sinfluencelikethis:

Whydowecareaboutinfluence?Ifwecanidentifyinfluentialnodesinagraph,wecanlearnmoreaboutthesetypesofsituations:

• Whostartsfashiontrendsamongfriends?

• Whichcountry’seconomyhasthemosteffectonothercountriesintheregion?

• Ifthere’sanoutbreakofavirus,who’sthemostatriskofspreadingittootherpeople?

(Youwillmodelavirusoutbreakinthenextlesson!)

Version1.0Jan2017

Networks2:TheKevinBaconGame 5

Noticethenw: beforeeigenvector-centrality.Thenw: tellsNetLogotolookinthe

networksextensiontofindtheeigenvector-centralitycommand.

Rememberthatwecanusebreedstonameour turtles

whateverwewant(herewenamedthempeople). Also,

wecanuselabelstotellourpeopleapart.

foreachInthelastlesson,wehadtomakeeachedgebyhand.Byusingforeach,wecansimplymakealistofnodeswewanttomakeoraddpropertiesto,andthenspecifyagenericbehaviorforeachofthem.(Ifyou’renotfamiliarwithlistsinNetLogo,gohere.)Let’sstartwithasimpleexample.Let’smakealistofnumbersanduseforeachtoshowthem:Howaboutsomethingalittlemoreinteresting?Let’susethesamelist,butcreateturtlesinstead:

Version1.0Jan2017

Networks2:TheKevinBaconGame 6

TROUBLESHOOTINGforeachblocks

• youmayhavetoaddparentheses,likethis:

(foreach num move [create-turtles ?1] [ask turtles [forward ?2]])

(Here,moveisanotherlist.)

Activity1:KevinBaconCreateanewNetLogofile.Nameityourlastname_yourfirstname_BaconGame.nlogo.

WHAT’STHATQUESTIONMARKABOUT?• NetLogoprocessesalistinorderwhenaforeachloopusesit.The?is

theelementinthelistthatNetLogoiscurrentlyusing.

• Intheexampleabove,NetLogowillcreate1turtle.Then,itwillgotothe

nextelementintheloopandcreate2turtles,then3,then4.

• Ifyou’reworkingwithmultiplelists,youcanuse?1,?2,etc.

Version1.0Jan2017

Networks2:TheKevinBaconGame 7

RefertotheboxbelowforanexampleofpeoplewithBaconnumberoneandBaconnumbertwo,orfindyourownusingtheGoogletoolmentionedearlier.

1. Createabreedofpeople.2. Createabacon-game procedureandaddabuttonforitontheinterfacetab.Your

bacon-game procedureshouldclear-allandsetthedefaultshapeofyourpeopleto“person”.Then,yourbacon-game proceduremustcallthefollowingprocedures:• setup-kevin-bacon• setup-bacon-number-one• setup-bacon-number-two• setup-intermediate-links• setup-size-degree

3. Createtheproceduresfrom2).Theydon’tneedbuttons.Usethetablebelow.setup-kevin-bacon

Createaperson.Setitslabelto“KevinBacon.”

BACONNUMBERof1MichaelFassbender--X-MenFirstClassw/KevinBaconIdrisElba--X-MenFirstClassw/KevinBaconJenniferLawrence--X-MenFirstClassw/KevinBaconAndyGarcia--TheAirIBreathew/KevinBaconJohnLithgow--Footloosew/KevinBaconBACONNUMBERof2PenelopeCruz--TheCounselorw/MichaelFassbenderBeyoncé--Dreamgirlsw/JohnLithgow

Version1.0Jan2017

Networks2:TheKevinBaconGame 8

setup-bacon-number-one

Makealist.Thelistshouldcontainthelabels(names)ofeveryonewithaBaconnumberofone.foreachofthenamesinyourlist,createaperson,settheirlabeltothelistvalue,andlinkthemtoKevinBacon.

setup-bacon-number-two

Make2lists.Thefirstlistshouldcontainthelabels(names)ofeveryonewithaBaconnumberoftwo.Thesecondlistcontainsthecorrespondingpersonlinkedwiththepersoninthefirstlist.Tobeclear,thefirstpersoninthefirstlistislinkedwiththefirstpersoninthesecondlist.Thesecondpersoninthefirstlistislinkedwiththesecondpersoninthesecondlist…etc.Youalreadycreatedthepeopleinthesecondlistinsetup-bacon-number-one.foreachofthelabelsinlistone,createapersonandmakealinkwiththecorrespondingpersoninlisttwo.

setup-intermediate-links

Allofthesepeoplestarredinthesamemovie.Maketwoidenticallistsoftheirlabels(names).foreachofthepeopleinlistone,gothroughthesecondidenticallist(withanestedforeach)andmakelinkswitheveryone(exceptthemselves).

Version1.0Jan2017

Networks2:TheKevinBaconGame 9

setup-size-degree

Setthepeoples’sizetotheirdegree.(Wecangetthedegreeofapersonbycountinghowmanylink-neighborsthereare.)

4. Usealayouttoorganizethenodes.Putthiscodeattheendofyourbacon-gameprocedure.

5. Createthefollowingmonitors.(Lookatpage4ofthisdocumentforadditionalhelpwiththeInfluencemonitors):

DegreeofKevinBacon[countlink-neighbors]ofpeoplewith[label="KevinBacon"]AverageDegreeofNetworkmean[countlink-neighbors]ofpeopleDegreeofJ.LawrenceInfluenceofKevinBacon[nw:eigenvector-centrality]ofpeoplewith[label="KevinBacon"]AverageInfluencemean[nw:eigenvector-centrality]ofpeopleInfluenceofJ.LawrenceInfluenceofM.FassbenderInfluenceofBeyonce

HINTS:

1. Don’tforgettoincludethenwextension.2. Turnoffworldwrapping,oryouredgeswilllookcrazy.

Version1.0Jan2017

Networks2:TheKevinBaconGame 10

TurninginYourProjectPre-submissionchecklist

¨ Isyourname,date,andprojecttitleatthetopofyourfileincomments?¨ Isyourcodeorganizedandformattedtocoursestandards?¨ Doesitworkwithouterrors?¨ Isyourfilenamedcorrectly?

IfyouansweredYEStoallofthesequestions,congrats!Youarereadytoturninyourproject.Youwillbegiveninstructionsforhowtoturn-ininclass.

Rubric

Networks2:TheKevinBaconGame(10points)

Points Tasktobecompleted

2Clarityandprofessionalism:Yourfileisnamedandcommentedappropriately.[1point]Thecodeisformattedandisreadable.[1point]

8Activity1:TheKevinBaconNetworkActivityiscompleteandworksasexpected.[8points]