0
$\begingroup$

Apologies if this is too general but I have been thinking about it all weekend and wasn't sure how to move forward with the idea.

Here are the types of networks I am dealing with below:

  • I have 2 networks: (state_1) from a control population; and (state_2) from a conditional population.

  • Each network has the same nodes with the only difference being the edge weights between the nodes.

  • Each network has self-loops for each node (e.g. A <-0.5-> A)
  • Each network is fully-connected
  • I have "transition" weights that are + and - which are essentially the difference between state_2 (conditional) - state_1 (control)

I am confused on how to approach this situation in terms of constructing the comparative/transitional network. I felt the closest analog would be networks from time series data but the biggest difference between time series networks and my situation would be that transitions between the time states would be directional (e.g. t_0 -> t_1 -> ... -> t_final) whereas my states are categorical.

My question: What type of network can I implement to accurately visualize, use graph algorithms (e.g. pagerank), and naturally store the transition data between nodes within a state and between states?

Here were my thoughts on implementation:

(1) Duplicate the nodes and have the connections between nodes within the same network be undirected and then connections between states be directional depending on which network has the higher value. The problem with this is that I will now have 2 sets of redundant nodes when in reality they are actually the same node. Maybe this is the correct way to think about the graph but I wanted to ask the community if there is a better way to reduce the redundancy.

(2) A Multigraph where I have multiple edges connecting the nodes. This seems like the most compact way but I'm not sure if many algorithms can handle this type of architecture and I'm worried edges wouldn't be organized in the correct way with respect to the states.

It seems like I'm making this overly complicated so I would appreciate it if someone could steer me down the right path. I feel that maybe someone familiar with timeseries has solved this problem?

import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt

# Create adjacency matrix
def get_adjacency(number_of_nodes=3, random_state=0):
    A = np.random.RandomState(random_state).randint(0,100, size=number_of_nodes**2).reshape((number_of_nodes,number_of_nodes))
    df_adj = pd.DataFrame((A + A.T)/2)
    df_adj.index = df_adj.columns = list("ABC")
    return df_adj

# Adjacency to graph
def adjacency_to_graph(name):
    df_adj = adjacencies[name]
    return nx.from_pandas_adjacency(df_adj, nx.Graph(name=name))

# Container for storing the adjacencies for the 2 graphs
adjacencies = {
    "state_1":get_adjacency(random_state=1),
    "state_2":get_adjacency(random_state=2),

}
adjacencies["diff"] = adjacencies["state_2"] - adjacencies["state_1"]

# print(adjacencies["state_1"])
#       A     B     C
# A  37.0  10.5  75.5
# B  10.5  75.0  34.5
# C  75.5  34.5  16.0

# print(adjacencies["state_2"])
#       A     B     C
# A  40.0  18.5  73.5
# B  18.5  43.0  44.5
# C  73.5  44.5  34.0

# print(adjacencies["diff"])
#      A     B     C
# A  3.0   8.0  -2.0
# B  8.0 -32.0  10.0
# C -2.0  10.0  18.0


# Showing graphs
with plt.style.context("seaborn-white"):
    fig, axes = plt.subplots(figsize=(8,3), ncols=2)
    for i, name in enumerate(["state_1", "state_2"]):
        graph = adjacency_to_graph(name)
        pos = nx.spring_layout(graph, seed=0)
        nx.draw(graph, pos=pos, ax=axes[i], with_labels=True, node_color="teal", node_size=610)
        axes[i].set_title(name, fontsize=15, fontweight="bold")

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.