the kevin bacon game - new mexico cs for allcs4all.cs.unm.edu/modules/projfinal/networks/[nw2... ·...
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]