This is the page for the 2020 course - the 2022 course page can be found here.

# Modelling Complex Systems 2020

This webpage will be populated with material as the course progresses. The handing in of assignments is via studentportalen. The grades for all assignments are now on studentportalen. The breakdown of how marks were awarded in the final project can be found here.

UPDATE: The resit assignments are now uploaded and linked in brackets after the original assignments for the course. For Alejandro's part of the course the resit assignment can be found here.
Automaton I & II : 14th April.
Networks I : 15th April.
Networks II : 22nd April. Notes made during lecture available here.
Self-propelled particles I: 23rd April. Matlab examples available here.
Self-propelled particles II: 12th May.
Genetic Algorithms: 13th May.
Lab 2 (resit): Automaton.
Lab 4: (resit): Network properties.
Lab 5: (resit): Self-propelled particles.
Lab 6: (resit)): Genetic algorithms. Sample code in python and matlab available here.
Final Project. The resit is the same assignment (if you submit both you need to pick different papers).

Monday 18th May:
1-4pm Lab 6: Genetic algorithms.

Lab 6 Warm up: GA specifics and implementing painter robot
1. We investigate different ways to 'generate' generation g+1 from generation g. Our setup is k individuals, with 'fitnesses' f(1), f(2), ..... '. Recall parent 1 and parent 2 give rise to child 1 and child 2, via 'cross-over' as in lecture. In the mutation phase each locus on each choromosome can mutate independently with probability p. Choices - how to pick parent 1 and parent 2. E.g. tournament pick $t$ chromosomes at random then take one with highest fitness, with probability proportional to fitness, using threshold function etc. Also note one can choose parents with or without replacement.
2. Check you can implement the robot! As a starting point you may use the matlab or python implementations here.
3. For chromosome '333......3', check average score over some runs. (For 40x20 square expect about 0.3).

Monday 11th May:
9am-12noon Lab 5: Self-propelled particle models.

Lab 5 Warm up: Vicsek model
1. Run an implementation of the Vicsek alignment model with different parameter values. As a starting point you may use Align2D.m from here or the python implementation here.
2. By varying the parameter values create two videos with qualitatively different behaviour e.g. one with particles tending to become aligned and one where this does not occur.
3. Calculate the polarisation at each time step and plot how polarisation changes over time in one or more runs of the model.
NB: Polarisation of particles with angles $\theta_1, \theta_2, \ldots, \theta_N$ is defined to be $\frac{1}{N}\sqrt{(\sum_j {\rm sin}(\theta_j))^2 +(\sum_j {\rm cos}(\theta_j))^2}$.

Here are some sketched notes on the Vicsek model and on polarisation.

Some example videos from the python implementation above with noise parameters $\eta=0.2$ and $\eta=0.6$ for $N = 100$ #particles, $r = 0.1$ radius, $\delta_t = 0.01$ time-step, from time $t = 0.0$ to time $T = 2.0$.

The assignment asks for a phase diagrams as here. They are nothing but 2D histograms with the heights indicated by the shading of the squares. The idea of them is to give an indication of the proportion of runs of the models which have certain ranges of alignment as $\eta$ varies. Nice example python implementation here.

Friday 23rd April:
1-4pm Lab 4: Network analysis and statistics.

Lab 4 Warm up: Network analysis
1. Find and load a real network with n>200 vertices.
2. Find modularity* of the network (*this will be heuristically calculated value, not the max)
3. Generate ER random graph with same expected number of edges as real network
4. Generate a configuration model random graph with same degree sequence as real network

Python
Airlines example with data from here. Links for data: airlines.txt and python code of mine to load in network data and find a partition of the airlines graph into communties: airlines_mod.py, and to sample via the configuration model a random graph with same degree sequence: airlines_config_model.py.
Tutorial on plotting, including boxplots, in python: here.

Matlab
Community detection toolbox available here. It includes three different algorithms for finding community partitions of networks, and also function to calculate the modularity value of a partition of a graph.

Background theory
Nice video on statistical inference on networks here from 1:07-1:11 discusses Monte-Carlo test which is releated to 5b in the lab.

Wednesday 22nd April:
8-10am Lecture: Networks II, more on network measures, random models of networks.

Friday 17th April:
1-3pm Lab 3: Network epidemics.

Lab 3 Warm up: Friends of Friends.
1. Find and load a real network with n>200 vertices.
2. Plot the degree distribution (x-axis degree, y-axis #vertices with that degree).
3. Select S, a sample of approx n/50 vertices at random. Plot the degree distribution of the vertices in S.
4. Take the set of neighbours of vertices in S and plot their degree distribution.

Python
Links for data: airlines.txt . Python code to load in graph: airlines_network.py. Python code of mine for degrees fo sample vs. degrees of neighbours of sample: over 100 runs airline_degrees.py. Same code as a jupyter notebook here airlines.ipynb.

Matlab
Karate club with matlab adapted from here. Link for data: karate.mat . Matlab code to load in graph and plot degrees : plot_degs.m

Degrees of sample vs. degrees of neighbours of the sample. Email network with data from http://networkrepository.com/ia-email-univ.php example provided by Kasia Kowalczyk. Link for data: ia-email-univ.mtx . Matlab code to load in graph and plot degrees : degree_distribution.m

Wednesday 15th April:
3-5pm Lecture: Networks I, representing networks, network measures.

Tuesday 14th April:
9-10am Lecture: Automaton I, 10-12noon: Lab 2 exercises. BREAK.
1-2pm Lecture: Automaton II, 2-3pm Continuation of Lab/time for questions.

Lab 2: Warm up: Game of Life
1. Simulate Game of Life using your own or existing code.
2. Find an extra pattern of period 1 not covered in the lecture.
3. Find an extra pattern of period 2
4. Find an extra pattern which translates each t steps for some t

Examples shared during the lab included one in J programming language shared by Anton Wallgren - an online runnable version is here.

#### Course Details

Each lab covers a project each consisting of a series of questions. The first part of the course with Alejandro, assignments 1 and 2, will together count for 20 points of the final grade. In the second part of the course, 5 labs based assignments each worth 10 points. After each question is a number of points associated with it. There is a final project which will be worth 30 points. The total points over all the questions is 100.

To pass the course (grade 3) you must correctly answer questions amounting to at least 50 points. In order to get grade 4 you must get 70 points. In order to get a grade 5 you must get 75 points and at least 18 points on the final project (implementing scientific article).

Resits. Deadline will be 31st August. There will be an 'equivalent' re-sit version of Labs 2 to 6 and of the final project. The re-sit lab assignments will each be worth 10 points and the re-sit final project 30 points. There will be a single re-sit assignment to cover the part of the course taught by Alejandro which will count for 20 points. It will be possible to do re-sits assignment by assignment, so one could choose to re-sit only some of the assignments. Anyone can choose to re-sit any subset. You will also be able to do these in groups.