Answered step by step
Verified Expert Solution
Link Copied!

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
CHW5.2. 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 edge-node incidence matrix of this graph. It is stored as a 2D-numpy array friends.
Find the number of friend groups of this network. Store this value as num_friend_groups. This should be the number of connected components in this directed graph.
Assuming that a meme originates at person 25(assume zero-indexing), 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 num_meme_spread.
We also give you a function nullspace. Given a matrix as a 2d-numpy array of shape (m,n), this function will return an 2d-numpy array of shape (n,d) consisting of a basis of the nullspace of the original matrix.
The setup code gives the following variables:
\table[[Name,Type,Description],[friends,numpy array,edge-node incidence matrix],[nullspace,function,returns basis of nullspace of a matrix]]
Your code snippet should define the following variables:
\table[[Name,Type,Description],[num_friend_groups,integer,Number of overall friend groups],[num_meme_spread,integer,Number of people that will receive the meme]]
user_code.py
import numpy as np
import numpy.linalg as la
# Example incidence matrix
# friends = np.array ([[dots],[dots],dots])
# The rank of the matrix is the number of linearly independent rows
rank = np.linalg.matrix_rank(friends)
# Number of nodes is the number of columns in the incidence matrix
num_nodes = friends.shape[1]
# Number of friend groups would be the number of nodes minus the rank
num_friend_groups = num_nodes - rank
# Number of people that will receive the meme is the number of nodes
# This assumes that the meme reaches every node
num_meme_spread = num_nodes
Submitted answer 11
zheanz2@illinois.edu submitted at 2024-03-2012:54:56(CDT)50%
Score: 1/2(50%)
Test Results
[11] Checking num_friend_groups
[0/1] Checking num_meme_spread
Max points: 1
Earned points: 0
Message
'num_meme_spread' is inaccurate
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago