This would be a fun project for a fun idea. Let's use graph and game theory to find hub nodes on our LinkedIn network and boost friendship with experts!😂 #systems_biology
# Import the modules
import networkx as nx
import numpy as np
# Create a network of 10 nodes, each representing a person
G = nx.Graph()
G.add_nodes_from(range(10))
# Assign some attributes to the nodes, such as name, occupation, and skills
names = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Harry", "Irene", "Jack"]
occupations = ["Engineer", "Lawyer", "Doctor", "Teacher", "Artist", "Manager", "Accountant", "Writer", "Scientist", "Entrepreneur"]
skills = [["Python", "Java", "C++"], ["Contract", "Litigation", "Tax"], ["Surgery", "Pediatrics", "Cardiology"], ["Math", "Physics", "Chemistry"], ["Painting", "Sculpture", "Photography"], ["Leadership", "Marketing", "Finance"], ["Excel", "QuickBooks", "Auditing"], ["Fiction", "Non-fiction", "Poetry"], ["Biology", "Physics", "Chemistry"], ["Innovation", "Strategy", "Networking"]]
# Assign the attributes to the nodes using a dictionary
attributes = {}
for i in range(10):
attributes[i] = {"name": names[i], "occupation": occupations[i], "skills": skills[i]}
# Set the attributes to the nodes
nx.set_node_attributes(G, attributes)
# Create some edges between the nodes, each representing a connection on LinkedIn
# The weight of the edge represents the strength of the connection, from 0 to 1
G.add_edge(0, 1, weight=0.8) # Alice and Bob are friends and colleagues
G.add_edge(0, 2, weight=0.6) # Alice and Charlie are friends and former classmates
G.add_edge(0, 3, weight=0.4) # Alice and David are acquaintances and share some interests
G.add_edge(1, 4, weight=0.7) # Bob and Eve are friends and collaborators
G.add_edge(1, 5, weight=0.5) # Bob and Frank are acquaintances and potential partners
G.add_edge(2, 6, weight=0.9) # Charlie and Grace are friends and co-workers
G.add_edge(2, 7, weight=0.3) # Charlie and Harry are acquaintances and have some common contacts
G.add_edge(3, 8, weight=0.6) # David and Irene are friends and fellow teachers
G.add_edge(3, 9, weight=0.4) # David and Jack are acquaintances and have some common interests
G.add_edge(4, 5, weight=0.8) # Eve and Frank are friends and co-founders
G.add_edge(6, 7, weight=0.7) # Grace and Harry are friends and share some hobbies
G.add_edge(8, 9, weight=0.9) # Irene and Jack are friends and partners
# Define a function to calculate the utility of a node in the network, based on game theory
# The utility is a measure of how beneficial it is for a node to be in the network, based on its connections and attributes
# For simplicity, we assume that the utility is proportional to the sum of the weights of the edges, multiplied by the number of skills of the node
def utility(node):
# Get the neighbors of the node
neighbors = G.neighbors(node)
# Get the weights of the edges
weights = [G[node][n]["weight"] for n in neighbors]
# Get the number of skills of the node
skills = len(G.nodes[node]["skills"])
# Calculate the utility
return np.sum(weights) * skills
# Define a function to find the hub nodes in the network, based on game theory
# The hub nodes are the nodes that have the highest utility in the network, and are therefore the most influential and important
def hub_nodes():
# Get the nodes in the network
nodes = G.nodes()
# Calculate the utility of each node
utilities = [utility(n) for n in nodes]
# Find the maximum utility
max_utility = np.max(utilities)
# Find the nodes that have the maximum utility
hubs = [n for n in nodes if utility(n) == max_utility]
# Return the hub nodes
return hubs
# Print the hub nodes and their attributes
hubs = hub_nodes()
print("The hub nodes in the network are:")
for h in hubs:
print(G.nodes[h]["name"], G.nodes[h]["occupation"], G.nodes[h]["skills"])