From c063cc9f0e2ea936632cb33753ae9f5015d02824 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 10 Dec 2019 00:09:48 +0100 Subject: [PATCH] improved indices --- bootstrap/lecture/bootstrap.tex | 2 +- debugging/lecture/debugging.tex | 69 +++++----- plotting/lecture/plotting.tex | 4 +- pointprocesses/lecture/pointprocesses.tex | 156 ++++++++++++---------- programming/lecture/programming.tex | 106 +++++++-------- statistics/lecture/statistics.tex | 2 +- 6 files changed, 175 insertions(+), 164 deletions(-) diff --git a/bootstrap/lecture/bootstrap.tex b/bootstrap/lecture/bootstrap.tex index b01b227..667c833 100644 --- a/bootstrap/lecture/bootstrap.tex +++ b/bootstrap/lecture/bootstrap.tex @@ -171,7 +171,7 @@ A good example for the application of a assessment of \entermde[correlation]{Korrelation}{correlations}. Given are measured pairs of data points $(x_i, y_i)$. By calculating the \entermde[correlation!correlation -coefficient]{Korrelation!-skoeffizient}{correlation +coefficient]{Korrelationskoeffizient}{correlation coefficient} we can quantify how strongly $y$ depends on $x$. The correlation coefficient alone, however, does not tell whether the correlation is significantly different from a random correlation. The diff --git a/debugging/lecture/debugging.tex b/debugging/lecture/debugging.tex index 6c70fab..6be3277 100644 --- a/debugging/lecture/debugging.tex +++ b/debugging/lecture/debugging.tex @@ -6,10 +6,10 @@ When writing a program from scratch we almost always make mistakes. Accordingly, a quite substantial amount of time is invested into finding and fixing errors. This process is called -\codeterm{debugging}. Don't be frustrated that a self-written program -does not work as intended and produces errors. It is quite exceptional -if a program appears to be working on the first try and, in fact, -should leave you suspicious. +\entermde{Debugging}{debugging}. Don't be frustrated that a +self-written program does not work as intended and produces errors. It +is quite exceptional if a program appears to be working on the first +try and, in fact, should leave you suspicious. In this chapter we will talk about typical mistakes, how to read and understand error messages, how to actually debug your program code and @@ -20,7 +20,7 @@ some hints that help to minimize errors. There are a number of different classes of programming errors and it is good to know the common ones. Some of your programming errors will will lead to violations of the syntax or to invalid operations that -will cause \matlab{} to \codeterm{throw} an error. Throwing an error +will cause \matlab{} to \code{throw} an error. Throwing an error ends the execution of a program and there will be an error messages shown in the command window. With such messages \matlab{} tries to explain what went wrong and to provide a hint on the possible cause. @@ -30,8 +30,9 @@ are generally easier to find and to fix than logical errors that stay hidden and the results of, e.g. an analysis, are seemingly correct. \begin{important}[Try --- catch] - There are ways to \codeterm{catch} errors during \codeterm{runtime} - (i.e. when the program is executed) and handle them in the program. + There are ways to \code{catch} errors during \enterm{runtime} + (\determ{Laufzeit}, i.e. when the program is executed) and handle + them in the program. \begin{lstlisting}[label=trycatch, caption={Try catch clause}] try @@ -43,15 +44,15 @@ hidden and the results of, e.g. an analysis, are seemingly correct. This way of solving errors may seem rather convenient but is risky. Having a function throwing an error and catching it in the -\codeterm{catch} clause will keep your command line clean but may -obscure logical errors! Take care when using the \codeterm{try-catch - clause}. +\code{catch} clause will keep your command line clean but may obscure +logical errors! Take care when using the \code{try}-\code{catch} +clause. \end{important} \subsection{Syntax errors}\label{syntax_error} The most common and easiest to fix type of error. A -\entermde[error!syntax]{Fehler!Syntax\~}{syntax error} violates the +\entermde[error!syntax]{Fehler!Syntax@Syntax\texttildelow}{syntax error} violates the rules (spelling and grammar) of the programming language. For example every opening parenthesis must be matched by a closing one or every \code{for} loop has to be closed by an \code{end}. Usually, the @@ -69,7 +70,7 @@ Did you mean: \subsection{Indexing error}\label{index_error} Second on the list of common errors are the -\entermde[error!indexing]{Fehler!Index\~}{indexing errors}. Usually +\entermde[error!indexing]{Fehler!Index@Index\texttildelow}{indexing errors}. Usually \matlab{} gives rather precise infromation about the cause, once you know what they mean. Consider the following code. @@ -108,21 +109,21 @@ dimensions. This indicates that we are trying to read data behind the length of our variable \varcode{my\_array} which has 100 elements. One could have expected that the character is an invalid index, but apparently it is valid but simply too large. The fith attempt finally -succeeds. But why? \matlab{} implicitely converts the \codeterm{char} -to a number and uses this number to address the element in -\varcode{my\_array}. The \codeterm{char} has the ASCII code 65 and -thus the 65th element of \varcode{my\_array} is returned. +succeeds. But why? \matlab{} implicitely converts the character to a +number and uses this number to address the element in +\varcode{my\_array}. The character \varcode{'A'} has the ASCII code 65 +and thus the 65th element of \varcode{my\_array} is returned. \subsection{Assignment error} Related to the indexing error, an -\entermde[error!assignment]{Fehler!Zuweisungs\~}{assignment error} -occurs when we want to write data into a variable, that does not fit -into it. Listing \ref{assignmenterror} shows the simple case for 1-d -data but, of course, it extents to n-dimensional data. The data that -is to be filled into a matrix hat to fit in all dimensions. The -command in line 7 works due to the fact, that matlab automatically -extends the matrix, if you assign values to a range outside its -bounds. +\entermde[error!assignment]{Fehler!Zuweisungs@Zuweisungs\texttildelow}{assignment + error} occurs when we want to write data into a variable, that does +not fit into it. Listing \ref{assignmenterror} shows the simple case +for 1-d data but, of course, it extents to n-dimensional data. The +data that is to be filled into a matrix hat to fit in all +dimensions. The command in line 7 works due to the fact, that matlab +automatically extends the matrix, if you assign values to a range +outside its bounds. \begin{lstlisting}[label=assignmenterror, caption={Assignment errors.}] >> a = zeros(1, 100); @@ -191,7 +192,7 @@ few strategies that should we can employ to solve the task. it. Comment, but only where necessary. Correctly indent your code. Use descriptive variable and function names. \item Keep it simple. -\item Test your code by writing \codeterm{unit tests} that test every +\item Test your code by writing \entermde[unit test]{Modultest}{unit tests} that test every aspect of your program (\ref{unittests}). \item Use scripts and functions and call them from the command line. \matlab{} can then provide you with more information. It will @@ -264,13 +265,13 @@ The idea of unit tests to write small programs that test \emph{all} functions of a program by testing the program's results against expectations. The pure lore of test-driven development requires that the tests are written \textbf{before} the actual program is -written. In parts the tests put the \codeterm{functional +written. In parts the tests put the \enterm{functional specification}, the agreement between customer and programmer, into code. This helps to guarantee that the delivered program works as specified. In the scientific context, we tend to be a little bit more relaxed and write unit tests, where we think them helpful and often test only the obvious things. To write \emph{complete} test suits that -lead to full \codeterm{test coverage} is a lot of work and is often +lead to full \enterm{test coverage} is a lot of work and is often considered a waste of time. The first claim is true, the second, however, may be doubted. Consider that you change a tiny bit of a standing program to adjust it to the current needs, how will you be @@ -446,8 +447,8 @@ that help to solve the problem. line. Often, it is not necessary that the other person is a programmer or exactly understands what is going on. Rather, it is the own reflection on the problem and the chosen approach that helps - finding the bug (This strategy is also known as \codeterm{Rubber - duck debugging}). + finding the bug (this strategy is also known as \enterm{Rubber + ducking}). \end{enumerate} @@ -457,11 +458,11 @@ The \matlab{} editor (figure\,\ref{editor_debugger}) supports interactive debugging. Once you save an m-file in the editor and it passes the syntax check, i.e. the little box in the upper right corner of the editor window is green or orange, you can set one or several -\codeterm{break point}s. When the program is executed by calling it -from the command line it will be stopped at the line with the -breakpoint. In the editor this is indicated by a green arrow. The -command line will change to indicate that we are now stopped in -debug mode (listing\,\ref{debuggerlisting}). +\entermde[break point]{Haltepunkt}{break points}. When the program is +executed by calling it from the command line it will be stopped at the +line with the breakpoint. In the editor this is indicated by a green +arrow. The command line will change to indicate that we are now +stopped in debug mode (listing\,\ref{debuggerlisting}). \begin{figure} \centering diff --git a/plotting/lecture/plotting.tex b/plotting/lecture/plotting.tex index ae531ba..17e09d5 100644 --- a/plotting/lecture/plotting.tex +++ b/plotting/lecture/plotting.tex @@ -280,8 +280,8 @@ the last one defines the output format (box\,\ref{graphicsformatbox}). \begin{ibox}[t]{\label{graphicsformatbox}File formats for digital artwork.} There are two fundamentally different types of formats for digital artwork: \begin{enumerate} - \item \enterm{Bitmaps} - \item \enterm{Vector graphics} + \item \enterm[bitmap]{Bitmaps} (\determ{Rastergrafik}) + \item \enterm[vector graphics]{Vector graphics} (\determ{Vektorgrafik}) \end{enumerate} When using bitmaps a color value is given for each pixel of the stored figure. Bitmaps do have a fixed resolution (e.g.\,300\,dpi diff --git a/pointprocesses/lecture/pointprocesses.tex b/pointprocesses/lecture/pointprocesses.tex index e658f8f..5ec4abf 100644 --- a/pointprocesses/lecture/pointprocesses.tex +++ b/pointprocesses/lecture/pointprocesses.tex @@ -3,11 +3,12 @@ \chapter{Spiketrain analysis} \exercisechapter{Spiketrain analysis} -\enterm[action potential]{Action potentials} (\enterm{spikes}) are -the carriers of information in the nervous system. Thereby it is the -time at which the spikes are generated that is of importance for -information transmission. The waveform of the action potential is -largely stereotyped and therefore does not carry information. +\entermde[action potential]{Aktionspotential}{Action potentials} +(\enterm[spike|seealso{action potential}]{spikes}) are the carriers of +information in the nervous system. Thereby it is the time at which the +spikes are generated that is of importance for information +transmission. The waveform of the action potential is largely +stereotyped and therefore does not carry information. The result of the pre-processing of electrophysiological recordings are series of spike times, which are termed \enterm{spiketrains}. If @@ -15,8 +16,8 @@ measurements are repeated we get several \enterm{trials} of spiketrains (\figref{rasterexamplesfig}). Spiketrains are times of events, the action potentials. The analysis -of these leads into the realm of the so called \enterm[point - process]{point processes}. +of these leads into the realm of the so called \entermde[point + process]{Punktprozess}{point processes}. \begin{figure}[ht] \includegraphics[width=1\textwidth]{rasterexamples} @@ -57,12 +58,13 @@ of these leads into the realm of the so called \enterm[point $T_i=t_{i+1}-t_i$ and the number of events $n_i$. } \end{figure} -A temporal \enterm{point process} is a stochastic process that -generates a sequence of events at times $\{t_i\}$, $t_i \in \reZ$. In -the neurosciences, the statistics of point processes is of importance -since the timing of neuronal events (action potentials, post-synaptic -potentials, events in EEG or local-field recordings, etc.) is crucial -for information transmission and can be treated as such a process. +A temporal \entermde{Punktprozess}{point process} is a stochastic +process that generates a sequence of events at times $\{t_i\}$, $t_i +\in \reZ$. In the neurosciences, the statistics of point processes is +of importance since the timing of neuronal events (action potentials, +post-synaptic potentials, events in EEG or local-field recordings, +etc.) is crucial for information transmission and can be treated as +such a process. The events of a point process can be illustrated by means of a raster plot in which each vertical line indicates the time of an event. The @@ -76,7 +78,7 @@ number of observed events within a certain time window $n_i$ Implement a function \varcode{rasterplot()} that displays the times of action potentials within the first \varcode{tmax} seconds in a raster plot. The spike times (in seconds) recorded in the individual trials - are stored as vectors of times within a \codeterm{cell array}. + are stored as vectors of times within a cell array. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -84,9 +86,10 @@ number of observed events within a certain time window $n_i$ The intervals $T_i=t_{i+1}-t_i$ between successive events are real positive numbers. In the context of action potentials they are -referred to as \enterm{interspike intervals}. The statistics of -interspike intervals are described using common measures for -describing the statistics of stochastic real-valued variables: +referred to as \entermde{Interspikeintervalle}{interspike + intervals}. The statistics of interspike intervals are described +using common measures for describing the statistics of stochastic +real-valued variables: \begin{figure}[t] \includegraphics[width=0.96\textwidth]{isihexamples}\vspace{-2ex} @@ -110,9 +113,9 @@ describing the statistics of stochastic real-valued variables: \frac{1}{n}\sum\limits_{i=1}^n T_i$. \item Standard deviation of the interspike intervals: $\sigma_{ISI} = \sqrt{\langle (T - \langle T \rangle)^2 \rangle}$\vspace{1ex} -\item \enterm[coefficient of variation]{Coefficient of variation}: $CV_{ISI} = - \frac{\sigma_{ISI}}{\mu_{ISI}}$. -\item \enterm[diffusion coefficient]{Diffusion coefficient}: $D_{ISI} = +\item \entermde[coefficient of variation]{Variationskoeffizient}{Coefficient of variation}: + $CV_{ISI} = \frac{\sigma_{ISI}}{\mu_{ISI}}$. +\item \entermde[diffusion coefficient]{Diffusionskoeffizient}{Diffusion coefficient}: $D_{ISI} = \frac{\sigma_{ISI}^2}{2\mu_{ISI}^3}$. \end{itemize} @@ -133,12 +136,12 @@ describing the statistics of stochastic real-valued variables: \end{exercise} \subsection{Interval correlations} -So called \enterm{return maps} are used to illustrate -interdependencies between successive interspike intervals. The return -map plots the delayed interval $T_{i+k}$ against the interval -$T_i$. The parameter $k$ is called the \enterm{lag} $k$. Stationary -and non-stationary return maps are distinctly different -\figref{returnmapfig}. +So called \entermde[return map]{return map}{return maps} are used to +illustrate interdependencies between successive interspike +intervals. The return map plots the delayed interval $T_{i+k}$ against +the interval $T_i$. The parameter $k$ is called the \enterm{lag} +(\determ{Verz\"ogerung}) $k$. Stationary and non-stationary return +maps are distinctly different \figref{returnmapfig}. \begin{figure}[t] \includegraphics[width=1\textwidth]{returnmapexamples} @@ -149,14 +152,16 @@ and non-stationary return maps are distinctly different lower panels the serial correlations of successive intervals separated by lag $k$. All the interspike intervals of the stationary spike trains are independent of each other --- this is - a so called \enterm{renewal process}. In contrast, the ones of the + a so called \enterm{renewal process} + (\determ{Erneuerungsprozess}). In contrast, the ones of the non-stationary spike trains show positive correlations that decay for larger lags. The positive correlations in this example are caused by a common stimulus that slowly increases and decreases the mean firing rate of the spike trains.} \end{figure} -Such dependencies can be further quantified using the \enterm{serial +Such dependencies can be further quantified using the +\entermde[correlation!serial]{Korrelation!serielle}{serial correlations} \figref{returnmapfig}. The serial correlation is the correlation coefficient of the intervals $T_i$ and the intervals delayed by the lag $T_{i+k}$: @@ -189,11 +194,11 @@ using the following measures: \item Histogram of the counts $n_i$. \item Average number of counts: $\mu_n = \langle n \rangle$. \item Variance of counts: $\sigma_n^2 = \langle (n - \langle n \rangle)^2 \rangle$. -\item \determ{Fano Factor} (variance of counts divided by average count): $F = \frac{\sigma_n^2}{\mu_n}$. +\item \entermde{Fano Faktor}{Fano factor} (variance of counts divided by average count): $F = \frac{\sigma_n^2}{\mu_n}$. \end{itemize} -Of particular interest is the average firing rate $r$ (spike count per -time interval , \determ{Feuerrate}) that is given in Hertz -\sindex[term]{firing rate!average rate} +Of particular interest is the \enterm[firing rate!average]{average + firing rate} $r$ (spike count per time interval, \determ{Feuerrate}) +that is given in Hertz \begin{equation} \label{firingrate} r = \frac{\langle n \rangle}{W} \; . @@ -227,11 +232,12 @@ time interval , \determ{Feuerrate}) that is given in Hertz The Gaussian distribution is, because of the central limit theorem, the standard distribution for continuous measures. The equivalent in -the realm of point processes is the \enterm{Poisson distribution}. +the realm of point processes is the +\entermde[distribution!Poisson]{Verteilung!Poisson-}{Poisson distribution}. -In a \enterm[Poisson process!homogeneous]{homogeneous Poisson process} -the events occur at a fixed rate $\lambda=\text{const}$ and are -independent of both the time $t$ and occurrence of previous events +In a \entermde[Poisson process!homogeneous]{Poissonprozess!homogener}{homogeneous Poisson + process} the events occur at a fixed rate $\lambda=\text{const}$ and +are independent of both the time $t$ and occurrence of previous events (\figref{hompoissonfig}). The probability of observing an event within a small time window of width $\Delta t$ is given by \begin{equation} @@ -239,7 +245,7 @@ a small time window of width $\Delta t$ is given by P = \lambda \cdot \Delta t \; . \end{equation} -In an \enterm[Poisson process!inhomogeneous]{inhomogeneous Poisson +In an \entermde[Poisson process!inhomogeneous]{Poissonprozess!inhomogener}{inhomogeneous Poisson process}, however, the rate $\lambda$ depends on time: $\lambda = \lambda(t)$. @@ -281,7 +287,7 @@ The homogeneous Poisson process has the following properties: \item Thus, the coefficient of variation is always $CV_{ISI} = 1$ . \item The serial correlation is $\rho_k =0$ for $k>0$, since the occurrence of an event is independent of all previous events. Such a - process is also called a \enterm{renewal process}. + process is also called a \enterm{renewal process} (\determ{Erneuerungsprozess}). \item The number of events $k$ within a temporal window of duration $W$ is Poisson distributed: \begin{equation} @@ -356,10 +362,9 @@ closely. \end{figure} A very simple method for estimating the time-dependent firing rate is -the \enterm[firing rate!instantaneous]{instantaneous firing rate}. The -firing rate can be directly estimated as the inverse of the time -between successive spikes, the interspike-interval -(\figref{instratefig}). +the \entermde[firing rate!instantaneous]{Feuerrate!instantane}{instantaneous firing rate}. +The firing rate can be directly estimated as the inverse of the time +between successive spikes, the interspike-interval (\figref{instratefig}). \begin{equation} \label{instantaneousrateeqn} @@ -384,12 +389,12 @@ not fire an action potential for a long time. \subsection{Peri-stimulus-time-histogram} -While the \emph{instantaneous firing rate} uses the interspike -interval, the \enterm{peri stimulus time histogram} (PSTH) uses the -spike count within observation windows of the duration $W$. It +While the instantaneous firing rate is based on the interspike +intervals, the \enterm{peri stimulus time histogram} (PSTH) is based on +spike counts within observation windows of the duration $W$. It estimates the probability of observing a spike within that observation -time. It tries to estimat the average rate in the limit of small -obersvation times \eqnref{psthrate}: +time. It tries to estimate the average rate in the limit of small +obersvation times: \begin{equation} \label{psthrate} r(t) = \lim_{W \to 0} \frac{\langle n \rangle}{W} \; , @@ -399,10 +404,11 @@ potentials observed within the interval $(t, t+W)$. Such description matches the time-dependent firing rate $\lambda(t)$ of an inhomogeneous Poisson process. -The firing probability can be estimated using the \emph{binning - method} or by using \emph{kernel density estimations}. Both methods -make an assumption about the relevant observation time-scale ($W$ in -\eqnref{psthrate}). +The firing probability can be estimated using the \enterm[firing +rate!binning method]{binning method} or by using \enterm[firing +rate!kernel density estimation]{kernel density estimations}. Both +methods make an assumption about the relevant observation time-scale +($W$ in \eqnref{psthrate}). \subsubsection{Binning-method} @@ -416,14 +422,15 @@ make an assumption about the relevant observation time-scale ($W$ in binwidth.}\label{binpsthfig} \end{figure} -The binning method separates the time axis into regular bins of the -bin width $W$ and counts for each bin the number of observed action -potentials (\figref{binpsthfig} top). The resulting histogram is then -normalized with the bin width $W$ to yield the firing rate shown in -the bottom trace of figure \ref{binpsthfig}. The above sketched -process is equivalent to estimating the probability density. It is -possible to estimate the PSTH using the \code{hist()} function -\sindex[term]{Feuerrate!Binningmethode} +The \entermde[firing rate!binning +method]{Feuerrate!Binningmethode}{binning method} separates the time +axis into regular bins of the bin width $W$ and counts for each bin +the number of observed action potentials (\figref{binpsthfig} +top). The resulting histogram is then normalized with the bin width +$W$ to yield the firing rate shown in the bottom trace of figure +\ref{binpsthfig}. The above sketched process is equivalent to +estimating the probability density. For computing a PSTH the +\code{hist()} function can be used. The estimated firing rate is valid for the total duration of each bin. This leads to the step-like plot shown in @@ -436,7 +443,7 @@ time-scale. \pagebreak[4] \begin{exercise}{binnedRate.m}{} Implement a function that estimates the firing rate using the - ``binning method''. The method should take the spike-times as an + binning method. The method should take the spike-times as an input argument and returns the firing rate. Plot the PSTH. \end{exercise} @@ -453,20 +460,22 @@ time-scale. superposition of the kernels.}\label{convratefig} \end{figure} -With the convolution method we avoid the sharp edges of the binning -method. The spiketrain is convolved with a \enterm{convolution - kernel}. Technically speaking we need to first create a binary -representation of the spike train. This binary representation is a -series of zeros and ones in which the ones denote the spike. Then this binary vector is convolved with a kernel of a certain width: - +With the \entermde[firing rate!convolution +method]{Feuerrate!Faltungsmethode}{convolution method} we avoid the +sharp edges of the binning method. The spiketrain is convolved with a +\entermde{Faltungskern}{convolution kernel}. Technically speaking we +need to first create a binary representation of the spike train. This +binary representation is a series of zeros and ones in which the ones +denote the spike. Then this binary vector is convolved with a kernel +of a certain width: \[r(t) = \int_{-\infty}^{\infty} \omega(\tau) \, \rho(t-\tau) \, {\rm d}\tau \; , \] where $\omega(\tau)$ represents the kernel and $\rho(t)$ the binary representation of the response. The process of convolution can be imagined as replacing each event of the spiketrain with the kernel (figure \ref{convratefig} top). The superposition of the replaced -kernels is then the firing rate (if the kerel is correctly normalized +kernels is then the firing rate (if the kernel is correctly normalized to an integral of one, figure \ref{convratefig} -bottom). \sindex[term]{Feuerrate!Faltungsmethode} +bottom). In contrast to the other methods the convolution methods leads to a continuous function which is often desirable (in particular when @@ -489,8 +498,9 @@ relevate time-scale. The graphical representation of the neuronal activity alone is not sufficient tot investigate the relation between the neuronal response -and a stimulus. One method to do this is the \enterm[STA|see - spike-triggered average]{spike-triggered average}. The STA +and a stimulus. One method to do this is the \entermde{Spike-triggered + Average}{spike-triggered average}, \enterm[STA|see{spike-triggered + average}]{STA}. The STA \begin{equation} STA(\tau) = \langle s(t - \tau) \rangle = \frac{1}{N} \sum_{i=1}^{N} s(t_i - \tau) \end{equation} @@ -504,9 +514,9 @@ snippets are then averaged (\figref{stafig}). \includegraphics[width=\columnwidth]{sta} \titlecaption{Spike-triggered average of a P-type electroreceptors and the stimulus reconstruction.}{The neuron was driven by a - ``white-noise'' stimulus (blue curve, right panel). The STA (left) - is the average stimulus that surrounds the times of the recorded - action potentials (40\,ms before and 20\,ms after the + \enterm{white-noise} stimulus (blue curve, right panel). The STA + (left) is the average stimulus that surrounds the times of the + recorded action potentials (40\,ms before and 20\,ms after the spike). Using the STA as a convolution kernel for convolving the spiketrain we can reconstruct the stimulus from the neuronal response. In this way we can get an impression of the stimulus diff --git a/programming/lecture/programming.tex b/programming/lecture/programming.tex index 1137832..17eea72 100644 --- a/programming/lecture/programming.tex +++ b/programming/lecture/programming.tex @@ -1177,11 +1177,11 @@ segment of data of a certain time span (the stimulus was on, required. \codeterm[Timetable]{Timetables} offer specific convenience functions to work with timestamps. - \textbf{Maps} In a \codeterm{map} a \codeterm{value} is associated - with an arbitrary \codeterm{key}. The \codeterm{key} is not - restricted to be an integer but can be almost anything. Maps are an - alternative to structures with the additional advantage that the key - can be used during indexing: \varcode{my\_map('key')}. + \textbf{Maps} In a \code{containers.Map} a \entermde{Wert}{value} is + associated with an arbitrary \entermde{Schl\"ussel}{key}. The key is + not restricted to be an integer but can be almost anything. Maps are + an alternative to structures with the additional advantage that the + key can be used for indexing: \varcode{my\_map('key')}. \textbf{Categorical arrays} are used to stored values that come from a limited set of values, e.g. Months. Such categories can then be @@ -1251,18 +1251,19 @@ used whenever the same commands have to be repeated. \subsubsection{The \varcode{for} --- loop} -The most common type of loop is the \codeterm{for-loop}. It -consists of a \codeterm[Loop!head]{head} and the -\codeterm[Loop!body]{body}. The head defines how often the code in the -body is executed. In \matlab{} the head begins with the keyword -\code{for} which is followed by the \codeterm{running variable}. In -\matlab{} a for-loop always operates on vectors. With each -\codeterm{iteration} of the loop, the running variable assumes the -next value of this vector. In the body of the loop any code can be -executed which may or may not use the running variable for a certain -purpose. The \code{for} loop is closed with the keyword +The most common type of loop is the +\entermde{For-Schleife}{for-loop}. It consists of a head and the +body. The head defines how often the code in the body is executed. In +\matlab{} a for-loop always operates on vectors. The head of the +\varcode{for}-loop begins with the keyword \code{for} which is +followed by the \enterm[for-loop!running variable]{running variable} +to which a vector is assigned. With each +\entermde{Iteration}{iteration} of the loop, the running variable +assumes the next value of this vector. In the body of the loop any +code can be executed which may or may not use the running variable for +a certain purpose. The \varcode{for}-loop is closed with the keyword \code{end}. Listing~\ref{looplisting} shows a simple version of such a -\codeterm{for-loop}. +for-loop. \begin{lstlisting}[caption={Example of a \varcode{for}-loop.}, label=looplisting] >> for x = 1:3 % head @@ -1284,14 +1285,14 @@ purpose. The \code{for} loop is closed with the keyword \subsubsection{The \varcode{while} --- loop} -The \codeterm{while-loop} is the second type of loop that is available in -almost all programming languages. Other, than the \codeterm{for-loop}, -that iterates with the running variable over a vector, the while loop -uses a Boolean expression to determine when to execute the code in -it's body. The head of the loop starts with the keyword \code{while} -that is followed by a Boolean expression. If this can be evaluated to -true, the code in the body is executed. The loop is closed with an -\code{end}. +The \entermde{While-Schleife}{while-loop} is the second type of loop +that is available in almost all programming languages. Other than the +\varcode{for}-loop, that iterates with the running variable over a +vector, the while loop uses a Boolean expression to determine when to +execute the code in it's body. The head of the loop starts with the +keyword \code{while} that is followed by a Boolean expression. If this +can be evaluated to true, the code in the body is executed. The loop +is closed with an \code{end}. \begin{lstlisting}[caption={Basic structure of a \varcode{while} loop.}, label=whileloop] while x == true % head with a Boolean expression @@ -1303,7 +1304,6 @@ end Implement the factorial of a number \varcode{n} using a \varcode{while}-loop. \end{exercise} - \begin{exercise}{neverendingWhile.m}{} Implement a \varcode{while}-loop that is never-ending. Hint: the body is executed as long as the Boolean expression in the head is @@ -1316,15 +1316,15 @@ end \begin{itemize} \item Both execute the code in the body iterative. -\item When using a \code{for}-loop the body of the loop is executed +\item When using a \varcode{for}-loop the body of the loop is executed at least once (except when the vector used in the head is empty). -\item In a \code{while}-loop, the body is not necessarily +\item In a \varcode{while}-loop, the body is not necessarily executed. It is entered only if the Boolean expression in the head yields true. -\item The \code{for}-loop is best suited for cases in which the +\item The \varcode{for}-loop is best suited for cases in which the elements of a vector have to be used for a computation or when the number of iterations is known. -\item The \code{while}-loop is best suited for cases when it is not +\item The \varcode{while}-loop is best suited for cases when it is not known in advance how often a certain piece of code has to be executed. \item Any problem that can be solved with one type can also be solve @@ -1334,25 +1334,24 @@ end \subsection{Conditional expressions} -The conditional expression are used to control that the enclosed code -is only executed under a certain condition. +With a \enterm{conditional expression} (\determ{bedingte Anweisung}) +the enclosed code is only executed under a certain condition. \subsubsection{The \varcode{if} -- statement} The most prominent representative of the conditional expressions is -the \codeterm{if statement} (sometimes also called \codeterm{if - else -statement}). It constitutes a kind of branching point. It allows to -control which branch of the code is executed. +the \code{if} statement. It constitutes a kind of branching point. It +allows to control which branch of the code is executed. Again, the statement consists of the head and the body. The head -begins with the keyword \code{if} followed by a Boolean expression +begins with the keyword \code{if} followed by a boolean expression that controls whether or not the body is entered. Optionally, the body can be either ended by the \code{end} keyword or followed by -additional statements \code{elseif}, which allows to add another -Boolean expression and to catch another condition or the \code{else} -the provide a default case. The last body of the \varcode{if - elseif - - else} statement has to be finished with the \code{end} -(listing~\ref{ifelselisting}). +additional \code{elseif} statements, that allow to add further boolean +expressions and to catch other conditions, or the \code{else} +expression to provide a default case. The last body of the +\varcode{if} - \varcode{elseif} - \varcode{else} statement has to be +finished with the \code{end} (listing~\ref{ifelselisting}). \begin{lstlisting}[label=ifelselisting, caption={Structure of an \varcode{if} statement.}] if x < y % head @@ -1377,17 +1376,18 @@ end \subsubsection{The \varcode{switch} -- statement} -The \codeterm{switch statement} is used whenever a set of conditions +The \code{switch} statement is used whenever a set of conditions requires separate treatment. The statement is initialized with the -\code{switch} keyword that is followed by a \emph{switch expression} (a -number or string). It is followed by a set of \emph{case expressions} -which start with the keyword \code{case} followed by the condition -that defines against which the \emph{switch expression} is tested. It -is important to note that the case expression always checks for -equality! Optional the case expressions may be followed by the keyword -\code{otherwise} which catches all cases that were not explicitly -stated above (listing~\ref{switchlisting}). - +\code{switch} keyword that is followed by a \emph{switch expression} +returning a number or string. It is followed by a set of \emph{case + expressions} which start with the keyword \code{case} followed by +the condition that defines against which the \emph{switch expression} +is tested. It is important to note that the \emph{case expression} +always checks for equality! Optional the \emph{case expressions} may +be followed by the keyword \code{otherwise} which catches all cases +that were not explicitly stated above (listing~\ref{switchlisting}). +As usual the \code{switch} statement needs to be closed with an +\code{end}. \begin{lstlisting}[label=switchlisting, caption={Structure of a \varcode{switch} statement.}] mynumber = input('Enter a number:'); @@ -1406,7 +1406,7 @@ end \begin{itemize} \item Using the \code{if} statement one can test for arbitrary cases and treat them separately. -\item The \code{switch} statement does something similar but is always +\item The \code{switch} statement does something similar but always checks for the equality of \emph{switch} and \emph{case} expressions. \item The \code{switch} is a little bit more compact and nicer to read @@ -1610,10 +1610,10 @@ define (i) how to name the function, (ii) which information it needs (arguments), and (iii) what it should return to the caller. \begin{enumerate} -\item \entermde[function!name]{Funktion!-sname}{Name}: the name should be descriptive +\item \entermde[function!name]{Funktionsname}{Name}: the name should be descriptive of the function's purpose, i.e. the calculation of a sine wave. A appropriate name might be \varcode{sinewave()}. -\item \entermde[function!arguments]{Funktion!-sargument}{Arguments}: +\item \entermde[function!arguments]{Funktionsargument}{Arguments}: What information does the function need to do the calculation? There are obviously the frequency as well as the amplitude. Further we may want to be able to define the duration of the sine wave and the diff --git a/statistics/lecture/statistics.tex b/statistics/lecture/statistics.tex index 1af9ef6..28b5443 100644 --- a/statistics/lecture/statistics.tex +++ b/statistics/lecture/statistics.tex @@ -468,7 +468,7 @@ data values (e.g. size and weight of elephants) we want to analyze dependencies between the variables. The -\entermde[correlation!coefficient]{Korrelation!-skoeffizient}{correlation +\entermde[correlation!coefficient]{Korrelationskoeffizient}{correlation coefficient} \begin{equation} \label{correlationcoefficient}