This course deals with computer science (CS) aspects of social network analysis (SNA), and is open to all students in the master computer science programme at Leiden University.

If you want to participate and are in a different programme, then you should contact the lecturer in advance.

COVID-19 policy. The 2021 SNACS course is an on-site course for all students, unless valid COVID-19 related aspects prevent the student from being present. Lectures are broadcasted via Zoom; see Brightspace.

Course information

Lectures: Fridays from 11:15 to 13:00 in Gorlaeus "Havingazaal" (except Sep 17 & Dec 10: Van Steenis F104)
Lab sessions: Fridays from 9:15 to 11:00 in Snellius rooms 302/304 and 306/308
Prerequisites: a CS bachelor with courses on Algorithms, Data Structures and Data Mining
Literature: provided papers and book chapters (free and digitally available)
Examination: based on presentation, paper, programming, peer review and participation (no exam)
Brightspace link: 2122-S1 Social Network Analysis for Computer Scientists
Study points: 6 ECTS

Need help? Ask your questions during the lab sessions. If it is more urgent, walk by the lecturer or assistant's office. If they are not around, contact

Lecturer: dr. Frank Takes (, room 157b)
Assistants: Hanjo Boekhout MSc (, room 126), Yali Wang MSc (, room 142) and Bart de Zoete BSc (

[Network visualization image]

Network with 1458 nodes and 1948 edges.

Course schedule

  Date Lecture (11:15-13:00) Lab session (9:15-11:00)
1. Sep 10, 2021 Lecture 0: Course information
Lecture 1: Introduction
No lab session in the first week, but if you have not already, please
ensure your Linux account works in room 302/304 and 306/308.
2. Sep 17, 2021 Lecture 2: Advanced concepts and centrality
Example presentation
Introduction to Gephi
Work on Assignment 1
3. Sep 24, 2021 Lecture 3: Network projection and community structure Introduction to NetworkX
Work on Assignment 1
4. Oct 1, 2021 Lecture 4: Structure of the web and propgation-based centrality Work on Assignment 1
Oct 4, 2021 Deadline for Assignment 1
5. Oct 8, 2021 Lecture 5: Network evolution and model extensions Team project planning & DS Lab
Work on Assignment 2
Student presentations; room 402 is moderated by Frank, room 403 by Hanjo
Lecture (11:15-13:00)Lab session (9:15-11:00)
6. Oct 15, 2021 Track B (402) 9. Community detection 2
12. Data errors in networks 1
Track A (402) 15. Diameter computation
24. Link prediction in temporal networks
Track C (403) 7. Closeness centrality 2 (top-k)
22. Link prediction 2
Track B+C Work on Assignment 2
7. Oct 22, 2021 Track A (402) 2. Anomaly detection 2
30. Network embeddings 1
Work on Assignment 2
Track B (403) 19. Influence spread and virality 1
51. Shortest paths 2
Oct 25, 2021 Deadline for Assignment 2
8. Oct 29, 2021 Track A (402) 16. Graph compression
20. Influence spread and virality 2
Track B (402) 32. Personalized PageRank
37. Triangle counting
Track C (403) 26. Motifs in multilayer networks
45. Graph compression
Track A+C Work on course project
9. Nov 5, 2021 Track A (402) 4. Betweenness centrality 1
42. Dense subgraph detection
Track C (402) 8. Community detection 1
31. Network embeddings 2
Track B (403) 3. Anonymity in networks
17. Graph evolution rules
Track A+B Work on course project
Nov 11, 2021 Deadline for having a first version of the course project paper ready in PDF for peer review by fellow students
10. Nov 12, 2021 Track C (402) 1. Anomaly detection 1
39. Visualization algorithms 2
Peer review session
Track A (403) 11. Community detection 4
52. Link prediction 2
11. Nov 19, 2021 Track B (402) 10. Community detection 3
23. Link prediction in signed networks
Track A (402) 33. Sampling from networks 1
46. Graph obfuscation
Track C (403) 13. Data errors in networks 2
18. Graph obfuscation
Track B+C Work on course project
Nov 22, 2021 Optional deadline for preliminary course project paper feedback from course staff (hand in via Brightspace)
Nov 26, 2021 Deadline for having a substantial amount of code ready for peer review
12. Nov 26, 2021 Track B (402) 38. Visualization algorithms 1
40. Visualization algorithms 3
Code review session
Track C (403) 36.Shortest paths 2
47. Local cluster detection
13. Dec 3, 2021 Track A (402) 25. Local cluster detection
29. Neighborhood approximation
Track C (402) 41. Anonymity in networks
49. Personalized PageRank
Track B (403) 6. Closeness centrality 1
27. Motifs in networks
Track A+B Work on course project
14. Dec 10, 2021 Track A (402) 50. Shortest paths 1
21. Link prediction 1
Track B (402) 14. Dense subgraph detection
34. Sampling from networks 2
Track C (403) 44. Community detection 4
35. Shortest paths 1
Track A+C Work on course project
Dec 13, 2020 Deadline for final course project paper
Dec 20, 2020 Retake deadline for assignments
Dec 23, 2020 Course end. Grades are sent to student administration

The main goal of this lab session is to get started with both the course project and with Assignment 2, and to get to know the data science lab.

If you are working remotely, learn how-to set up remote access to the LIACS Research and Education Laboratory (REL)

Data Science Lab
The data science lab website provides necessary information and documentation. Become familiar with the lab and how to run code on it, and how to place data within the lab. This may be handy for Assignment 2 and/or the course project. Remember:

  • /home/sXXXXXX, your homedirectory ~, is for your own code (don't put large stuff there),
  • /local is for local storage on the current machine you are are on,
  • /data is for storing data across data science lab machines.

Course project
Below are some topics you can discuss and investigate together with your project team partner.

  1. Project schedule. Have a look at the deadlines for the course project in the schedule on this website, and create a sensible planning with your team partner.
  2. Paper. Read your course project paper, and spend some time at Google Scholar investigating a) what other papers exist on this topic, b) which relevant papers cite your paper, and c) what important references are presented in your paper.
  3. Data repositories. Check out the data repositories of real (social) networks such as SNAP and KONECT and think of datasets suitable for your course project.
  4. Project contribution. For the course project, you have to do something original. Ideally, this goes beyond the one paper that you were assigned, comparing techniques from multiple papers, for example comparing different algorithms or methods, using different validation metrics, or testing on (a) larger (number of diverse) datasets. Write down in at most 200 words what you plan to do for your course project, and feel free to discuss this with the lecturer or an assistant for feedback. Also see the generic instructions for the Course Project.

Assignment 2
Get started with the practical part of Assignment 2.


About social network analysis tools and packages. There exist different tools and package for social network analysis. In this course, we will introduce you to two of them, with complementary advantages:

  1. Gephi, an easy-to-use tool with a graphical interface useful for visualization and quick analysis of relatively small network data (this week, see below).
    Download Gephi 0.9.2 for Windows, Linux or Mac (mirrors provided because of occasional slow speed of downloads).
  2. NetworkX, a more extensive Python package for network analysis that can handle larger network datasets and computations (next week).
    Other even faster tools such as SNAP (in C++) as well as igraph and graph-tool, can also be used, but require some more figuring out by the student.

Learning goals. The main goal of this lab session is to become familiar with Gephi (experimental beta-software to visualize networks for research purposes) and its input format. At the end of this session you should be able to:

  • Know how to use Gephi for social network analysis
  • Import and visualize raw network data with labeled nodes and labeled and/or weighted edges (directed or undirected),
  • Understand how to map edge and node size and color to structural network properties such as the node degree and edge type,
  • Know how to apply filters to the visualization, for example to focus only on the giant component,
  • And export a vector graphic PDF of your network,
  • Export computed node data for reuse in another program.

There is no deliverable for this lab session, but you are assumed to know the tool afterwards. Practice more at home if needed.

Instructions for today: Lab session on Gephi.
The following steps and tutorials will help you get to know Gephi.

  1. Install and run Gephi locally on your computer. Installation instructions, if needed, can be found on the Gephi website.
    Java should be installed on all machines; Gephi likely as well.
  2. On the Windows machines in the Snellius computer rooms, install Gephi in D:\ (ignore registry key warnings) and edit the gephi.conf file in the Gephi etc folder to state
    jdkhome="C:\Program Files\IBM\SPSS\Statistics\25\JRE"
    Then run gephi.exe
  3. If Gephi does not immediately work on your marchine, you may have to adjust one line in etc/gephi.conf so that Gephi can find the right Java version (and remove the # in front of that line), reading something like jdkhome="/usr/lib/jvm/java-8-openjdk-amd64/" (or the equivalent Windows path). Also, Windows users sometimes have to launch the gephi64.exe instead of gephi.exe (or the other way around, depending on Java and OS version(s)).
  4. Walk through the Gephi tutorials. The Gephi website has various official tutorials that you can walk through; in particular Quick start, Visualization and Layouts. You may benefit from using a more modern tutorial (courtesy of Derek Geene at UCD).
    Note: One reason to use a more modern tutorial is that the official Gephi Quick Start Guide is for a slightly older version of Gephi. On p. 9-10, contrary to what is indicated in the getting started guide, the ranking module is part of the appearance module (since Gephi 0.9), and does not appear as a separate tab. The “Ranking result” table no longer exists, and you can skip that part of the tutorial. In the tutorial on Visualization, on p. 9 the 3-D visualisation option was bugged and has been removed in Gephi 0.9. You can skip that part of the tutorial.

  5. Compute relevant real-world network dataset properties. Try out some of the Gephi datasets and see if you can understand how they differ in terms of density, degree distribution, giant components, clustering and average distance.

  6. Walk through a tutorial on data import and export. Learn how to import raw data from this short data import tutorial. Visualize the network represented by the edge list small-gephiready.tsv. Compute the degree for each node and export it to a node list file (which you can for example reuse in other plotting tools).

  7. Visualization and exporting as vector graphic. Play around with some different visualization algorithms such as ForceAtlas 2 (for example, with scaling set to a higher value and with stronger gravity checked) and Fruchterman Reingold. Try to visualize the network such that labels remain readable.
    Hints: From a random initialization, use the "ForceAtlas 2" visualization algorithm perhaps with "Stronger gravity" and usually with "Scaling" set to a much higher than default value. Increase the overall node size if needed. Once stable, you can improve the layout by enabling parameter "Prevent overlap". Run "Expansion" to make some more space between the nodes, then enable the display of node labels, properly size them, and finally run "Label Adjust" to prevent label overlap.
    Export your visualization to PDF so that you have it as a vector graphic.

  8. Create, import and export your own social network data. Make a new, very simple, edge list input file of a fictive network with say 10 nodes and 20 edges, and import it into Gephi. Now add to the edge input file (in some order) link (un)direction, link weights and link labels.
    Also import a node list file with node labels and other properties. Be sure to append it to your existing workspace and to use identifiers.
    For example, have nodes represent students, and link represent friendships, and choose node and edge labels accordingly. Make sure that you are able understand the difference in file input and visualization output, and that you are comfortable with importing and exporting data into and from Gephi.

Done? Get started with the practical part of Assignment 1. You can download the smaller datafiles medium.tsv and large.tsv. If you want to analyze huge.tsv, you will have to get it from the shared folder in the ISSC Linux or LIACS DS lab environment, as stated in the assignment.


The main goal of this lab session is to become familiar with NetworkX (a Python package to analyze networks for research purposes).
All relevant information on NetworkX can be found in the NetworkX online documentation.
For this lab session, you need a working Python environment. For this, there are two options:

  1. Use your own self-installed Python environment, and choose your own editor and way of running code (via the command line, an IDE or an interactive notebook).
  2. Alternatively, you can use the desktop machines in the student computer rooms (proceed to the next step), or the university's remote SSH functionality to work on a machine in the student computer rooms.
    • ISSC infrastructure. First, connect to the gateway Then, navigate to a student computer (see the REL page on SSH access, only accessible internally, for a list of computers), or hop on to the remote server
Installing and using conda. To create a Python environment on the university computers or servers, it is easiest to use conda.
  1. Download Miniconda by running the following command in your terminal: wget
  2. Install Miniconda: bash
    The installer will ask you some questions. Normally, the standard location suffices and you do not have to add conda to path.
  3. After installation finishes, close your terminal so that the changes take effect. Upon opening a new terminal, activate the conda virtual environment with: source miniconda3/bin/activate
    If all goes well, you will see that (base) appears in front of your shell prompt. This means that conda's base environment is active.
  4. Next, create a new conda environment: conda create --name snacs. And activate it with: conda activate snacs
    You might use conda for other courses as well, and version conflicts can arise when you install many packages. Using separate environments will prevent this issue.
    NOTE: some packages can make your conda environment take up a lot of space. So try not to use an unnecessary number of environments with duplicate packages. You can also remove an environment that you don't need anymore, see the conda cheatsheet.
  5. Packages can easily be installed with conda. To install NetworkX, run: conda install networkx
Running code from the command line. Now you should be able to run your code from the command line by typing
Bonus: If you want to use an interactive Jupyter notebook instead, this is possible with the following commands:
conda install -c conda-forge jupyterlab
When using Jupyter through SSH, make sure to use port forwarding whilst SSH-ing, using options -g -L 8888: Also add options --no-browser and --port=8888 when starting up Jupyter.

Instructions for today: Lab session on NetworkX

  1. Take some time to do the NetworkX tutorial.
  2. Have a look at functionality to read and write graphs from/to disk, and in particular learn how to import an edge list. Understand the input format and ways of including things like Weight and other attributes of edges.
  3. A lot of the common network metrics you may want to compute are implemented as NetworkX function or NetworkX algorithm. Become familiar with these, for example by computing measures such as degree assortativity, clustering, density, diameter and average distance.
  4. While at it, why not take a look at how NetworkX relates to other data formats?
  5. Try to load the network from the first lab session (small-gephiready.tsv) into NetworkX, and investigate some characteristic properties of the network, such as the degree distribution and distance distribution. Use theread_edgelistfunction and remember to select the correct separator (tab), and pay attention to the header of the file.
  6. Get the Epinions network from the SNAP repository. You may need to fiddle with the precise heading, but it is already in edge list format. Compute some common characteristics such as the degree distribution, and visualize them using appropriate figures of distributions, for example using Matplotlib.
  7. What are the differences between NetworkX and Gephi in terms of visualization and analysis capabilities?

Done? Proceed with Exercise 2 of Assignment 1.

Looking for a challenge? Check out these two alternatives (that you can also use instead of NetworkX throughout the course, if you prefer (but for which there is less help available)):

  • Graph-Tool, a python graph analysis toolkit that leaves the hard computation to parallel (OpenMP) C++ code.
  • SNAP, which is entirely written in C++ and has many interesting features.
  • Python igraph, a Python version of the R igraph package.

Course project

Teams work on a course project for 60% of the course grade. The project is about a certain topic related to social network analysis, and the project consists of:

  • Giving a 20 to 30 minute presentation (+15 minutes for questions) of the paper corresponding to the topic. At least a Powerpoint/PDF presentation and if already possible some demonstration of an implementation or visualization has to be given. Teams are also expected to provide feedback on some of the presentations given by their fellow students during the lectures.
  • Making a small contribution, i.e., doing something new compared to the paper on which the project is based. For example, a new tweak to an existing algorithm, a large number of datasets to test the algorithms to find a relation between the network characteristics and the performance, a new performance metric to evaluatie the algorithms, a new type of visualization of the algorithm or results, an improvement of a proof related to the algorithm, etc. In case of doubt about the contribution, contact the course staff well in advance; you can always ask for help.
  • Gathering and implementing the algorithms and/or techniques from the different papers, and running experiments on at least five large real-world network datasets. Teams will also give feedback on the code produced by other teams in the code review session. Some papers introduce multiple techniques. In that case, choose a logical subset to compare, and motivate your choice.
    Datasets can for example be found at SNAP, KONECT, BigDND, Networks Repository, ICON, Netzschleuder, LASAGNE and ASU. Certain topics need particular datasets (e.g. with timestamps, signed links, etc.), which should of course be taken into account when selecting datasets.
  • Writing one 6 to 10 page paper. In the paper the different techniques are analyzed and compared in detail using extensive experiments. The paper, to be written in LaTeX, has to follow the format of an actual scientific paper. Students will also give feedback on the paper produced by another team in the peer review session.

Instructions and a template for the course project paper are available.

Project topics

This list of project topics is shown below. Please choose a topic with your team (consisting of two students). Register your choice in Brightspace. Topics that do not have a number appended to it, can be chosen twice, to accomodate the large number of students this year. If you are retaking the course because you failed the project last year, you cannot choose the same topic as last year.

          Original set of topics

  1. Anomaly detection 1
  2. Anomaly detection 2
  3. Anonymity in networks
  4. Betweenness centrality 1
  5. Betweenness centrality 2
  6. Closeness centrality 1
  7. Closeness centrality 2 (top-k)
  8. Community detection 1
  9. Community detection 2
  10. Community detection 3

  11. Community detection 4
  12. Data errors in networks 1
  13. Data errors in networks 2
  14. Dense subgraph detection
  15. Diameter computation
  16. Graph compression
  17. Graph evolution rules
  18. Graph obfuscation
  19. Influence spread and virality 1
  20. Influence spread and virality 2

  21. Link prediction 1
  22. Link prediction 2
  23. Link prediction in signed networks
  24. Link prediction in temporal networks
  25. Local cluster detection
  26. Motifs in multilayer networks
  27. Motifs in networks
  28. Motifs in temporal networks
  29. Neighborhood approximation
  30. Network embeddings 1
  31. Network embeddings 2

  32. Personalized PageRank
  33. Sampling from networks 1
  34. Sampling from networks 2
  35. Shortest paths 1
  36. Shortest paths 2
  37. Triangle counting
  38. Visualization algorithms 1
  39. Visualization algorithms 2
  40. Visualization algorithms 3

    Duplicated topics

  41. Anonymity in networks
  42. Dense subgraph detection
  43. Diameter computation
  44. Community detection 4
  45. Graph compression
  46. Graph obfuscation
  47. Local cluster detection
  48. Motifs in temporal networks
  49. Personalized PageRank
  50. Shortest paths 1
  51. Shortest paths 2
  52. Link prediction 2

Note: scientific papers (ACM, Elsevier, etc.) can often only be opened from within the university domain (or from home via university SSH/Citrix/VPN/etc.). IEEE Explore papers can often be opened by looking them up via Alternative links and preprints of papers can often be found through Google Scholar by searching for "Title of the paper". Contact course staff if you have tried all of these options and are still not able to access the paper (do not pay!).

Reading material

Some students have expressed interest in additional reading material to help freshen up on skills and knowledge required for this course.

Course description

See the e-Studyguide for a more general description.

Topics include: SNA from a CS perspective (graph representation, complexity issues, examples), Graph Structure (power law, small world phenomenon, clustering coefficient, hierarchies), Paths and Distances (neighborhoods, radius, diameter), Spidering and Sampling (BFS, forest fire, random walks), Graph Compression (graph grammars, bitwise tricks, encryption, hashing), Centrality (degree centrality, closeness centrality, betweenness centrality, rating and ranking), Centrality and Webgraphs (HITS, PageRank, structure of the web), Community Detection (spectral clustering, modularity), Visualization (force-based algorithms, Gephi, NodeXL), Graph Models (random graphs, preferential attachment), Link Prediction (structure, semantics, prediction algorithms, graph mining), Contagion (diffusion of information, spreading activation, gossipping) and Privacy and Anonymity ((de-)anonymizing graphs, ethical aspects, privacy issues) and various other topics that have been added over the years but are not yet in the list above.

The course was also given in 2014, 2015, 2016, 2017, 2018, 2019 and 2020.