Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide the complete PYTHON code !!! import numpy as np Fill in the missing bits of code marked with ????. class Network:

Please provide the complete PYTHON code !!!

image text in transcribed

import numpy as np
""" Fill in the missing bits of code marked with ????. """ class Network: def __init__(self): """ Creates an empty network. Nodes are stored in a dictionary. """ self.nodes = {} # note that you can access nodes within the Network class using self.nodes. # but, from outside of the class, it would be something like: # G = Network() # G.nodes def getNodes(self): """ Return dictionary of nodes. """ return self.nodes def getNeighbors(self,ID): """ Return the list of neighbor's node IDs """ ???? def addNode(self,ID): """ Add a node with a prescribed ID. By default, the new node has no neighbors. """ if not ID in self.nodes.keys(): ???? else: print("Attempting to add duplicate node!") def addEdge(self,node1,node2): """ Add an edge connecting the node with ID=node1 to the node with ID=node2. If nodes do not already exist in the network with ID=node1 or ID=node2, then add nodes. """ if not node1 in self.nodes.keys(): self.addNode(node1) if not node2 in self.nodes.keys(): self.addNode(node2) ???? def getEdges(self): """ Return a list of tuples containing the node pairs connected by an edge. """ ???? def getDegree(self,ID): """ Return the degree of the node with a given ID. """ ???? def getDegrees(self): """ Return a list containing the degrees of each node. """ ???? def localClusteringCoefficient(self,ID): """ Return the local clustering coefficient for a node with a given ID. """ if not ID in self.nodes.keys(): print("Attempting to calculate the clustering coefficient for a node that does not exist in the network!") return ???? def clusteringCoefficients(self): """ Return a list containing the local clustering coefficient of each node in the network. """ return [self.localClusteringCoefficient(node) for node in self.nodes.keys()]

So far, coding questions for homework assignments have have been answerable using network science programming packages (e.g., the Networkx package in Python). These programming packages define object for representing networks and calculating several network properties. Now, write code for your own class representing a network object (e.g., in Python or R). Do not use Networkx or igraph anywhere in your code. Your network object should - store nodes and links, - retrieve nodes and links, - retrieve a given node's neighbors, - list the degrees of every node, - and calculate the local clustering coefficient of each node. Start from the Jupyter Notebook provided and fill in the missing code for the Network class (note: you may need to adapt the notebook if coding in R) . Then, use your Network class to generate an Erdos-Renyi network with N=103 and p=0.01. (a) Plot the degree distribution. (b) Plot the distribution of local clustering coefficients

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions