Tutorial 1 - Introduction
Submission process:
- Submission deadline is October 30, 14:00 CET (before the lecture) .
- Commit and push your solution as separate notebook files per subtask via git as ./tutorial/tutorial1/tutorial1_3.ipynb. Please take care of the correct subfolder/filename since submission is denied otherwise.
- During the first lecture after the deadline we will discuss a sample solution in class.
- Afterwards, you have time until November 4, 16:00 CET (before the lecture) to submit a corrected version of your submission:
- Rework your solution according to our discussion in class.
- Commit and push the corrected version as a separate file per subtask via git as ./tutorial/tutorial1/tutorial1_3.ipynb. Please take care of the correct filename since submission is denied otherwise.
Remarks:
- Grading is done based on both versions of your submission.
- If the first submission is missing your submission will not be graded.
- If the second submission contains major flaws after revision not more than half of the credits for this tutorial can be achieved.
- A sample solution is provided after November 4, 16:00 CET eventually.
- Please use acn@net.in.tum.de for questions regarding lecture, tutorial, and project of ACN.
Problem 3 Jupyter Introduction (0 credits)
We will shortly introduce Jupyter and its functionality: Jupyter is an interactive programming interface running in your browser. We use the interactive Python interface.
This problem does not give any bonus credits and its purpose is to familiarize yourself with jupyter.
a) [0 credits] Jupyter notebooks consist of cells with different types, e.g., code and markdown. Explain the differences between those two types and what they can be used for.
Code cells:
A code cell allows you to edit and write new code, with full syntax highlighting and tab completion. The programming language you use depends on the kernel, and the default kernel (IPython) runs Python code.
Markdown cells
You can document the computational process in a literate way, alternating descriptive text with code, using rich text. In IPython this is accomplished by marking up text with the Markdown language. The corresponding cells are called Markdown cells. The Markdown language provides a simple way to perform this text markup, that is, to specify which parts of the text should be emphasized (italics), bold, form lists, etc.
Raw cells
Raw cells provide a place in which you can write output directly. Raw cells are not evaluated by the notebook. When passed through nbconvert, raw cells arrive in the destination format unmodified. For example, you can type full LaTeX into a raw cell, which will only be rendered by LaTeX after conversion by nbconvert.
(SOURCE)
To run cells (run Python code or show layouted markdown) either press the "Play/Run" button on top of the page or press Shift+Enter.
Code type cells fail to execute when the content is not valid Python code. We use automated tests to validate your exercises. If your solution fails to execute due to syntax errors, the automated test will also fail. Such hand-ins will be graded with 0 credits. Therefore, always execute your solution at least once on the provided virtual machine. This way you can make sure the provided solution works in our environment.
b) [0 credits] The following cell contains the typical format for programming exercises. This function is used to test your solution. Never change anything outside the begin/end insert code comments and only insert code in between:
#begin insert code ...The print command will show your result in the cell output.YOUR CODE HERE¶
raise NotImplementedError() ...
end insert code¶
Errors should never occur in your handed-in notebook. Fix this code by defining the hello_world variable, assigning it a value, and returning it.
def hello_world_text():
#begin insert code
hello_world = 'Hello World!'
return hello_world
#end insert code
return None
print(hello_world_text())
Hello World!
d) [0 credits] Code cells also allow to execute shell commands. These are executed as the user who started the jupyter server. On your virtual machine this is root. Shell commands can be executed by prefixing them with the '!' character.
# just execute this cell
!pwd # the path where jupyter has been started
!echo This user is executing the commands: $USER
!ping -c 1 net.in.tum.de
/home/user/acn//tutorial1
This user is executing the commands: diec
PING net.in.tum.de (2001:4ca0:2001:13:250:56ff:feba:37ac) 56 Datenbytes 64 Bytes von unicorn.net.in.tum.de (2001:4ca0:2001:13:250:56ff:feba:37ac): icmp_seq=1 ttl=62 Zeit=2.80 ms --- net.in.tum.de Ping-Statistiken --- 1 Pakete übertragen, 1 empfangen, 0% packet loss, time 0ms rtt min/avg/max/mdev = 2.795/2.795/2.795/0.000 ms
e) [0 credits] In some exercise sheets we will use such shell commands to install missing Python modules.
Note that Python 3.11 wants you to install packages in a virtual environment (venv) to not interfere with system-site packages. You will be shown an error if you try to do so without any venv. The tutorial image uses a venv with relevant packages preinstalled. It runs the jupyter server inside this venv. If you run the notebook locally we suggest to use a venv. If you do not know how to setup a venv you can follow this tutorial. Make sure that your jupyter process is executed within the venv.
!pip3 install matplotlib
Requirement already satisfied: matplotlib in /home/user/acn/.venv/lib64/python3.13/site-packages (3.10.7) Requirement already satisfied: contourpy>=1.0.1 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (1.3.3) Requirement already satisfied: cycler>=0.10 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (4.60.1) Requirement already satisfied: kiwisolver>=1.3.1 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (1.4.9) Requirement already satisfied: numpy>=1.23 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (2.3.5) Requirement already satisfied: packaging>=20.0 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (25.0) Requirement already satisfied: pillow>=8 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (12.0.0) Requirement already satisfied: pyparsing>=3 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (3.2.5) Requirement already satisfied: python-dateutil>=2.7 in /home/user/acn/.venv/lib64/python3.13/site-packages (from matplotlib) (2.9.0.post0) Requirement already satisfied: six>=1.5 in /home/user/acn/.venv/lib64/python3.13/site-packages (from python-dateutil>=2.7->matplotlib) (1.17.0)
[notice] A new release of pip is available: 24.3.1 -> 25.3 [notice] To update, run: pip install --upgrade pip
In order to visualize measurement data tools such as matplotlib are very useful. Jupyter notebook supports inline presentation of matplotlib plots. This is a convenient way to visualize data.
In this exercise you can see how matplotlib is used. Just execute the first cell. It should show you a histogram of datapoints following a normal distribution.
# This enables inline plots
%matplotlib inline
# Example taken from https://matplotlib.org/3.1.1/gallery/statistics/histogram_features.html
import numpy as np
import matplotlib.pyplot as plt
# example data
mu = 0 # mean of distribution
sigma = 1 # standard deviation of distribution
x = mu + sigma * np.random.randn(10000) # 10k data samples
num_bins = 50
fig, ax = plt.subplots()
# the histogram of the data
counts, bins, patches = ax.hist(x, num_bins)
ax.set_xlabel('Value')
ax.set_ylabel('Count')
ax.set_title(r'Histogram of a normal distribution: $\mu=0$, $\sigma=1$')
plt.show()
fig, ax = plt.subplots()
# begin insert code
ax.hist(x, num_bins, cumulative=True, density=True)
# end insert code
ax.set_xlabel('Value')
ax.set_ylabel('Cumulated Probability')
ax.set_title(r'CDF of normal distribution: $\mu=0$, $\sigma=1$')
plt.show()
Advanced Computer Networking by Prof. Dr.-Ing. Georg Carle
Teaching assistants: Christian Dietze, Sebastian Gallenmüller, Marcel Kempf, Lorenz Lehle, Nikolas Gauder, Patrick Dirks