Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Correct my code CHW 5 . 2 . Graphs: Meme spread in social networks Graphs can be used in mathematics and other fields to represent
Correct my code
CHW Graphs: Meme spread in social networks
Graphs can be used in mathematics and other fields to represent objects and the connections between them. Here, we will use a directed graph to represent people in a social network and their friend connections with one another. In this directed graph nodes correspond to people. An edge between two nodes indicates frienship between the correspding people. The direction of the edge is chosen at random and carries no further meaning. A friend group is a connected component of this graph. We will use this to model the spread of a meme throughout this theoretical social network.
We give you the edgenode incidence matrix of this graph. It is stored as a Dnumpy array friends.
Find the number of friend groups of this network. Store this value as numfriendgroups. This should be the number of connected components in this directed graph.
Assuming that a meme originates at person assume zeroindexing find the number of people that will see the meme including the original person Assume each person will send the meme to all of their friends. Save this as nummemespread.
We also give you a function nullspace. Given a matrix as a dnumpy array of shape this function will return an numpy array of shape consisting of a basis of the nullspace of the original matrix.
The setup code gives the following variables:
tableNameType,Descriptionfriendsnumpy array,edgenode incidence matrixnullspacefunction,returns basis of nullspace of a matrix
Your code snippet should define the following variables:
tableNameType,Descriptionnumfriendgroups,integer,Number of overall friend groupsnummemespread,integer,Number of people that will receive the meme
usercode.py
import numpy as
import numpy.linalg as la
# Example incidence matrix
# friends nparray dots
# The rank of the matrix is the number of linearly independent rows
rank nplinalg.matrixrankfriends
# Number of nodes is the number of columns in the incidence matrix
numnodes friends.shape
# Number of friend groups would be the number of nodes minus the rank
numfriendgroups numnodes rank
# Number of people that will receive the meme is the number of nodes
# This assumes that the meme reaches every node
nummemespread numnodes
Submitted answer
zheanz@illinois.edu submitted at ::CDT
Score:
Test Results
Checking numfriendgroups
Checking nummemespread
Max points:
Earned points:
Message
'nummemespread' is inaccurate
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started