Analysing the semantic network

I started using org-roam a few days ago and am migrating content to this system. The graph has me intrigued, so I began to use some analytical tools to analyse the knowledge as it exists in my Zettelkasten this far.

The code to create this graph (in R) does three things:

  • Organise the layout of the graph using a force-directed algorithm (place the most connected topics in the centre)
  • The size of the topics relates to the number of connections (the degree of the node)
  • Lastly, I used community detection to find meta-themes in the graph (the coloured areas).

Mathematical network analysis can help to uncover structure in your knowledge that you did not know to exist. If somebody can write Elisp to export the network as an edge list (from-to) CSV file, then you can use software such as Gephi to create your visualisation.

You can download the Zettel that contains the code. You will need the ESS package and the R language plus some libraries to run the code.

6 Likes

Thank you for your work, it looks fantastic!

As we’ve discussed on the tracker, I think Org-roam would really benefit from having multiple back-ends for generating the graphs, and your prototype would fit nicely in that paradigm.

We’ll need to create the infrastructure for it, but in the meantime, I encourage you to share ideas with @Memex as to devise a view or a collection of views that would be relevant for visualising your notes as nodes.

1 Like

This is really cool, but the above would be less-than-ideal from a usability standpoint: export to some intermediate format, import into some other GUI tool.

How practical would it be to add this sort of functionality to @Memex’s JS-based interactive solution?

I wrote the code in R, but the grunt is done with the iGraph package. They have libraries for R, Python, C and Mathematica. The input is a table with the names of the from and to topics. This is a triangle:

from to
A B
A C
B C

Igraph can analyse and visualise this data.

@Memex is using G6; this seems to be the place where they list the layouts they have.

Yeah, given the potential for graphing with OR, we probably should start with a separate org-roam-graph or similar project on github to consolidate discussion and innovation. The ORB experience is a good model for that :wink:

1 Like

This was something I was thinking about a few days ago in the Slack. To that end I’ve created Application of Graph Theory to Roam link network with a fleshed-out version of my thoughts. This may be of interest :slight_smile:

1 Like

If somebody can write Elisp to export the network as an edge list (from-to) CSV file, then you can use software such as Gephi to create your visualisation.

Actually gephi understands dot so you can already use it. When you run org-roam-graph a temporary .dot file is created which you can use with gephi.

Just a passing to anyone who want to try out @danderzei’s code, I got an error that the spinglass.community function requires the data to be clustered first, so the little plot in the end should be modified as:

g <- graph_from_edgelist(as.matrix(edges), directed = FALSE)
g <- simplify(g)
cl <- clusters(g)
G <- decompose.graph(g)[[which(cl$csize==max(cl$csize))]]
coms <- spinglass.community(G) # Community detection
plot(coms, G, layout = layout_with_kk,
            vertex.size=degree(G))