From 7dcc73af8f405f2bedf0b0b3749f0f592c3adfb6 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 30 Apr 2022 22:33:43 +0000 Subject: [PATCH] Providing an example for message passing + interactive REPL --- pyscriptjs/examples/message_passing.html | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pyscriptjs/examples/message_passing.html diff --git a/pyscriptjs/examples/message_passing.html b/pyscriptjs/examples/message_passing.html new file mode 100644 index 0000000..ee10a74 --- /dev/null +++ b/pyscriptjs/examples/message_passing.html @@ -0,0 +1,53 @@ + + + + + + + + + + - numpy + - networkx + - matplotlib + + +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
+
+ +
+ + +