首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
Analytics编程设计讲解、Python程序语言调试、Python编程辅导 讲解R语言程序|辅导R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
Network Analytics, Homework 0
General Instrictions:
− For each problem, you will write the output and save it to a file named with the problem
label. For example, for Problem 1, your filename should be problem1.out. If your file
name deviates from this convention, our automated grader will skip your file without
grading it.
− In your code, assume that the input file is in the same directory as your script.
− Once you complete the assignment, make a compressed zip or compressed tarball (if you
are familiar with unix shell) named submission.zip or submission.tgz, containing
all the scripts, answers, and output you have produced. Submit your compressed tarball
to Gradescope. The entry code for this course is MB6ERE. Your compressed package
should contain no directories.
Python Scripting: Six degrees of Separation
Six degrees of separation is the theory that everyone is on average six steps away, by way of
introduction, from any other person in the world, so that a chain of ”a friend of a friend”
statements can be made to connect any two people in a maximum of six steps.
This theory was made popular by the game ”Six Degrees of Kevin Bacon” where the goal is to
link any actor to the famous actor Kevin Bacon through no more than six connections, where
two actors are directly connected if they have appeared in a movie or commercial together.
In this exercise we are going to build an engine that returns someone’s “Kevin Bacon Number”
in Python.
0.1 Dataset
We observed 100 college students over a period of 2 years. We recorded 500 occasions in
which students form parties to go eat in a restaurant in Ithaca, NY. Download the file
restaurants.txt from the course website, which lists these events, one per line, where each
line lists the names in the party and the associated restaurant. Each line has the following
format:
1
NYU Shanghai, Fall 2020; Homework 0 October 30, 2020
name1,name2,...,nameN;restaurant
Each party size varies from 1 to 9.
0.2 Building social networks
A social network is a construct to study relationships between individuals, groups, organizations,
or even entire societies. Social network models describe a social structure determined
by interactions and enable the understanding of social phenomena through the properties of
relations between individuals, instead of the properties of the individuals themselves.
In this assignment, we are going to investigate some forms of social networks using our
restaurant dataset.
The first model is a network built on the concept of affiliation networks. The idea behind
affiliation networks is that acquaintanceships among people often stem from one or more
common or shared affiliations –— living on the same street, working at the same place, being
fans of the same football club, etc. We define a relationship between two people as their
common affiliation to some entity. Therefore, we can model the network with two sets, one
corresponding to the population of interest, and the other to the entities that they connect
to. The entities do not have any connections among themselves. Moreover, people do not
directly connect to each other. We establish the existence of a relationship between two
people if both are affiliated to a common entity.
− problem1.out (10 pts): Write python code that builds the affiliation network of customers
to restaurants. Each line of the output should have the following format:
Restaurant: customer1 customer2 ... customerN
where Restaurant is the name of each restaurant that appears in the data, and
customer1 customer2 ... customerN is the list of people who have eaten in the
restaurant, according to our data, without repetition.
Another way to build a social network is by linking people in dyads using some definition of
friendship. We start by defining that two people are friends if they ever dined together at a
restaurant. For reference, let us call this definition dyad 1 (the number 1 refers to the fact
that the two parties were seen dinning together at least once).
− problem2.out (10 pts): Write python code to build all the dyadic relationships between
two people using the dyad 1 definition. Each line of your output should have
the following format:
2
NYU Shanghai, Fall 2020; Homework 0 October 30, 2020
name1 name2
where name1 has been to a restaurant with name2. The dyads are unordered (in networks
language, we say that the relationship is undirected), so “name1 name2” and “name2
name1” are the same pairs and should appear only once in the output.
We can think of a stricter definition of friendship where we connect two people if they have
dined together at a restaurant at least k times (where k is a positive integer). Let us name this
definition dyad k. The rationale behind this definition is that people may dine occasionally
with acquaintances, but the repeated observation of two people dinning together may establish
a stronger relationship.
− problem3.out (10 pts): Write python code to build all the dyadic relationships between
two people using the dyad 3 definition. Each line of your output should have
the same format as the preceding problem.
The degree of an actor is defined as the number of connections (or friends) it possesses.
− problem4.out (10 pts): Write python code to compute the degree of each node using
the dyad 1 definition of friendship. Each line of your output should be formatted as:
name degree
To check whether our previous solution is correct we can compare the number of dyads
produced by problem2.out with the sum of all the degrees produced by problem4.out.
− question1.txt (10 pts): Write in the first line of this file how many times each dyad
contributes to the sum of degrees. How many times the number of dyads should the
sum of degrees equals to? To test whether your outputs produced in problem2.out
and problem4.out match your answer, write the total number of dyads and the sum
of degrees in the second and third lines of this file, respectively.
0.3 Network Algorithms
We will break the task of find the network distance between two people into two simpler
steps.
Step 1: An adjacency list representation of a network is a collection of unordered lists, one
for each vertex in the graph. Each list describes the set of neighbors of its vertex. The main
operation performed by the adjacency list data structure is to report a list of the friends of
a given actor. In other words, the total time to report all of the neighbors of an actor is
proportional to its degree.
3
NYU Shanghai, Fall 2020; Homework 0 October 30, 2020
− problem5.out (20 pts) : write Python code to build and output an adjacency list from
the restaurants.txt file in Python using the dyad 1 definition.
Here is an example. If your input, e.g., restaurant.txt file has the following lines:
A,B;R1
B,C;R2
C,A;R1
your script should produce the following “Actor: Adjacent to” lines:
A: B C
B: A C
C: A B
(Hint1: use nested dictionaries to build the adjacency list. For example,
if ”Alice” and ”Hussam” are friends, then you would have the entries
{"Alice":{"Hussam": 1}, "Hussam":{"Alice": 1}} in your dictionary. If your dictionary
is called friends, then friends["Alice"]["Hussam"] returns the value 1 if Alice
and Hussam are friends. Otherwise, either "Alice" is not a key of friends or "Hussam" is
not a key of friends["Alice"], or vice-versa, and it returns a key error.)
(Hint2: If you want to access friends["Alice"]["Hussam"], remember to initialize both
friends and friends["Alice"] as dictionaries before its first use so as to avoid a key error.
It is easy to initialize friends, but it can be challenging to initialize friends["Alice"]
as you don’t know whether "Alice" will be in the dataset. You avoid this problem
by calling the function friends.setdefault("Alice", {}) before using the dictionary
friends["Alice"]. This function does nothing if friends["Alice"] is already a dictionary,
but initializes friends["Alice"] as a dictionary if it is not.) Another way to accomplish
this is to use the defaultdict library of the package collections.
Step 2: Now, we are interested in computing the distance between a given actor and all
other actors. To this end, we will use a network search algorithm called Breadth First Search
(BFS).
BFS begins with a given actor, whom we call the root, and then inspects all of his or her
friends. These friends have distance 1 from the root. Then for each of those friends in turn,
it inspects their unvisited friends. These “friends of friends“ have distance 2 from the root,
and so on.
BFS can be implemented using an adjacency list and a queue. Here are the steps the algorithm
performs:
4
NYU Shanghai, Fall 2020; Homework 0 October 30, 2020
1. Enqueue the root node, set the distance of root to zero, and mark root as visited.
2. Dequeue a node (let’s call this node n).
− enqueue all friends of n that have not yet been visited
− set the friends distance to the distance of n plus one
− mark the friends of n as visited
3. If the queue is empty, then the algorithm exits. Otherwise repeat from Step 2.
− problem6.out (30 pts) : write a Python function to compute the distance of all foodies
in restaurants.txt who are reachable from a given root. The first argument of your
function should be the name of the root, e.g., ”Beula”, and the second, the input file
name that encodes de network.
Here is an example. If your restaurants.txt file looked like
Alice,Hussam;CTB
Harsh,Hussam;Subway
Harsh,Atheendra;CTB
Harsh,Sangha;Subway
Then, if you run your function with the root ”Alice”, your output should be (not necessarily
sorted by distance):
Alice 0
Hussam 1
Harsh 2
Atheendra 3
Sangha 3
In this exercise you will output, for every person in the dataset, their average distance between
themselves and all other actors. The format of your output should be:
actor1 avg1
actor avg2
...
actorN avgN
5
NYU Shanghai, Fall 2020; Homework 0 October 30, 2020
(Hint1: The restaurants.txt dataset contains a group of students who attend the same college
in a small town area. Therefore, their distance to one another is expected to be small.)
(Hint2: Use a list to implement the queue. You might find these two functions useful.
− list.append(x) : inserts element x at the end of a list.
− list.pop(i) : returns and deletes element at index i from list.)
(Hint3: Use a dictionary to keep track of the actors that have been visited by BFS and their
distance from the root, i.e., dist= {"Alice": 0, "Hussam" : 1})
Important: After you finish this assignment, please fill out the course survey. The link is in
the calendar section of the course website.
6
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!