Question: Finish the calc _ grph _ statistics function to compute the network diameter, characteristic path length ( CPL ) , average clustering coefficient, transitivity, assortativity,
Finish the calcgrphstatistics function to compute the network diameter, characteristic path length CPL average clustering coefficient, transitivity, assortativity, and degree sequence a list of all degrees for each node Provide a dictionary of the results with the name of each statistic as the key.
Finish the sweeplouvaineres function to detect community structures within the graph. Utilize the Louvain algorithm to determine the optimal partition. Utilize different resolution parameters from minresolution to maxresolution inclusive and compare the result of each partition to the ground truth you can find the ground truth in the value field associated with each node in the graph using the normalized mutual information function. Return the list of resolutions and NMIs from the resulting community assignments. Additionally, complete the pltnmires function to exhibit the NMI for each resolution as a line plot.
import networkx as nx
from networkx.algorithms.community import louvaincommunities
import numpy as np
import matplotlib.pyplot as plt
from typing import Tuple, List, Dict, Union
def ldftballgraph nxGraph:
G nxreadgmlftballgml
return G
def calcgrphstatisticsG: nxGraph Dictstr Unionfloat Listint:
Inputs:
G: NetworkX graph object
Returns:
Dictionary of graph statistics
return graphstatistics
def sweeplouvaineresG: nxGraph, minresolution: int maxresolution: int TupleListint Listfloat:
Inputs:
G: NetworkX graph object
minresolution : integer
maxresolution : integer
Returns:
Tuple of list of resolutions and list of NMIs
return resolutions, nmis
def pltnmiresresolutions: Listint nmis: Listfloat save: boolFalse None:
Inputs:
resolutions : list
nmis : list
save: boolean
Returns:
None
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
