packages = [ "numpy", "networkx", "matplotlib" ] plugins = [ "../build/plugins/python/py_tutor.py" ] import numpy as np import networkx as nx

Message passing with linear algebra: a demo.

Imagine we have a chain graph that looks like this:

O --> 1 --> 2 --> 3

In NetworkX this graph would look like the following:

        
G = nx.Graph()
nodes = list(range(4))
G.add_edges_from(zip(nodes[0:-1], nodes[1:]))
print(G.edges())
        
    

This chain graph has the following adjacency matrix:

        
adj_mat = np.eye(4, k=1)
print(f"A: {adj_mat}")
        
    

And imagine that we have a message that lives on the graph:

        
message = np.array([1.0, 0.0, 0.0, 0.0])
print(f"message: {message}")
        
    

Try out message passing below by doing any one of the following steps:

message @ adj_mat
message @ adj_mat @ adj_mat
message @ adj_mat @ adj_mat @ adj_mat