diff --git a/bootstrap/lecture/bootstrap-chapter.tex b/bootstrap/lecture/bootstrap-chapter.tex index 53099ed..cb9ec3f 100644 --- a/bootstrap/lecture/bootstrap-chapter.tex +++ b/bootstrap/lecture/bootstrap-chapter.tex @@ -1,217 +1,8 @@ \documentclass[12pt]{report} -%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} -\author{Jan Benda\\Abteilung Neuroethologie\\[2ex]\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}} -\date{WS 15/16} +\input{../../header} -%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \newcommand{\tr}[2]{#1} % en -% \usepackage[english]{babel} -\newcommand{\tr}[2]{#2} % de -\usepackage[german]{babel} - -%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{pslatex} % nice font for pdf file -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} -\setcounter{tocdepth}{1} - -%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[sf,bf,it,big,clearempty]{titlesec} -\setcounter{secnumdepth}{1} - - -%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{graphicx} -\usepackage{xcolor} -\pagecolor{white} - -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} -\newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} - -% maximum number of floats: -\setcounter{topnumber}{2} -\setcounter{bottomnumber}{0} -\setcounter{totalnumber}{2} - -% float placement fractions: -\renewcommand{\textfraction}{0.2} -\renewcommand{\topfraction}{0.8} -\renewcommand{\bottomfraction}{0.0} -\renewcommand{\floatpagefraction}{0.5} - -% spacing for floats: -\setlength{\floatsep}{12pt plus 2pt minus 2pt} -\setlength{\textfloatsep}{20pt plus 4pt minus 2pt} -\setlength{\intextsep}{12pt plus 2pt minus 2pt} - -% spacing for a floating page: -\makeatletter - \setlength{\@fptop}{0pt} - \setlength{\@fpsep}{8pt plus 2.0fil} - \setlength{\@fpbot}{0pt plus 1.0fil} -\makeatother - -% rules for floats: -\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}} -\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}} - -% captions: -\usepackage[format=plain,singlelinecheck=off,labelfont=bf,font={small,sf}]{caption} - -% put caption on separate float: -\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} - -% references to panels of a figure within the caption: -\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} -% references to figures: -\newcommand{\panel}[1]{\textsf{\uppercase{#1}}} -\newcommand{\fref}[1]{\textup{\ref{#1}}} -\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} -% references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} -\newcommand{\figref}[1]{\fig~\fref{#1}} -\newcommand{\Figref}[1]{\Fig~\fref{#1}} -\newcommand{\figsref}[1]{\figs~\fref{#1}} -\newcommand{\Figsref}[1]{\Figs~\fref{#1}} -\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}} -\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}} -\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} -\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} -% references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} -\newcommand{\figrefb}[1]{\figb~\fref{#1}} -\newcommand{\figsrefb}[1]{\figsb~\fref{#1}} -\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} -\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} - -% references to tables: -\newcommand{\tref}[1]{\textup{\ref{#1}}} -% references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} -\newcommand{\tabref}[1]{\tab~\tref{#1}} -\newcommand{\Tabref}[1]{\Tab~\tref{#1}} -\newcommand{\tabsref}[1]{\tabs~\tref{#1}} -\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} -% references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} -\newcommand{\tabrefb}[1]{\tabb~\tref{#1}} -\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - - -%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%\newcommand{\eqref}[1]{(\ref{#1})} -\newcommand{\eqn}{\tr{Eq}{Gl}.} -\newcommand{\Eqn}{\tr{Eq}{Gl}.} -\newcommand{\eqns}{\tr{Eqs}{Gln}.} -\newcommand{\Eqns}{\tr{Eqs}{Gln}.} -\newcommand{\eqnref}[1]{\eqn~\eqref{#1}} -\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}} -\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} -\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - inputpath=../code, - basicstyle=\ttfamily\footnotesize, - numbers=left, - showstringspaces=false, - language=Matlab, - commentstyle=\itshape\color{red!60!black}, - keywordstyle=\color{blue!50!black}, - stringstyle=\color{green!50!black}, - backgroundcolor=\color{blue!10}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - caption={\protect\filename@parse{\lstname}\protect\filename@base}, - captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{bm} -\usepackage{dsfont} -\newcommand{\naZ}{\mathds{N}} -\newcommand{\gaZ}{\mathds{Z}} -\newcommand{\raZ}{\mathds{Q}} -\newcommand{\reZ}{\mathds{R}} -\newcommand{\reZp}{\mathds{R^+}} -\newcommand{\reZpN}{\mathds{R^+_0}} -\newcommand{\koZ}{\mathds{C}} - - -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - -\newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% - {\medskip} - -\newcounter{maxexercise} -\setcounter{maxexercise}{9} % show listings up to exercise maxexercise -\newcounter{theexercise} -\setcounter{theexercise}{1} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} +\lstset{inputpath=../code} \graphicspath{{figures/}} diff --git a/designpattern/lecture/designpattern-chapter.tex b/designpattern/lecture/designpattern-chapter.tex index e821287..f695de3 100644 --- a/designpattern/lecture/designpattern-chapter.tex +++ b/designpattern/lecture/designpattern-chapter.tex @@ -1,217 +1,8 @@ \documentclass[12pt]{report} -%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} -\author{Jan Grewe \& Jan Benda\\Abteilung Neuroethologie\\[2ex]\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}} -\date{WS 15/16} +\input{../../header} -%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \newcommand{\tr}[2]{#1} % en -% \usepackage[english]{babel} -\newcommand{\tr}[2]{#2} % de -\usepackage[german]{babel} - -%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{pslatex} % nice font for pdf file -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} -\setcounter{tocdepth}{1} - -%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[sf,bf,it,big,clearempty]{titlesec} -\setcounter{secnumdepth}{1} - - -%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{graphicx} -\usepackage{xcolor} -\pagecolor{white} - -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} -\newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} - -% maximum number of floats: -\setcounter{topnumber}{2} -\setcounter{bottomnumber}{0} -\setcounter{totalnumber}{2} - -% float placement fractions: -\renewcommand{\textfraction}{0.2} -\renewcommand{\topfraction}{0.8} -\renewcommand{\bottomfraction}{0.0} -\renewcommand{\floatpagefraction}{0.5} - -% spacing for floats: -\setlength{\floatsep}{12pt plus 2pt minus 2pt} -\setlength{\textfloatsep}{20pt plus 4pt minus 2pt} -\setlength{\intextsep}{12pt plus 2pt minus 2pt} - -% spacing for a floating page: -\makeatletter - \setlength{\@fptop}{0pt} - \setlength{\@fpsep}{8pt plus 2.0fil} - \setlength{\@fpbot}{0pt plus 1.0fil} -\makeatother - -% rules for floats: -\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}} -\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}} - -% captions: -\usepackage[format=plain,singlelinecheck=off,labelfont=bf,font={small,sf}]{caption} - -% put caption on separate float: -\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} - -% references to panels of a figure within the caption: -\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} -% references to figures: -\newcommand{\panel}[1]{\textsf{\uppercase{#1}}} -\newcommand{\fref}[1]{\textup{\ref{#1}}} -\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} -% references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} -\newcommand{\figref}[1]{\fig~\fref{#1}} -\newcommand{\Figref}[1]{\Fig~\fref{#1}} -\newcommand{\figsref}[1]{\figs~\fref{#1}} -\newcommand{\Figsref}[1]{\Figs~\fref{#1}} -\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}} -\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}} -\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} -\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} -% references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} -\newcommand{\figrefb}[1]{\figb~\fref{#1}} -\newcommand{\figsrefb}[1]{\figsb~\fref{#1}} -\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} -\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} - -% references to tables: -\newcommand{\tref}[1]{\textup{\ref{#1}}} -% references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} -\newcommand{\tabref}[1]{\tab~\tref{#1}} -\newcommand{\Tabref}[1]{\Tab~\tref{#1}} -\newcommand{\tabsref}[1]{\tabs~\tref{#1}} -\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} -% references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} -\newcommand{\tabrefb}[1]{\tabb~\tref{#1}} -\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - - -%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%\newcommand{\eqref}[1]{(\ref{#1})} -\newcommand{\eqn}{\tr{Eq}{Gl}.} -\newcommand{\Eqn}{\tr{Eq}{Gl}.} -\newcommand{\eqns}{\tr{Eqs}{Gln}.} -\newcommand{\Eqns}{\tr{Eqs}{Gln}.} -\newcommand{\eqnref}[1]{\eqn~\eqref{#1}} -\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}} -\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} -\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - inputpath=../code, - basicstyle=\ttfamily\footnotesize, - numbers=left, - showstringspaces=false, - language=Matlab, - commentstyle=\itshape\color{red!60!black}, - keywordstyle=\color{blue!50!black}, - stringstyle=\color{green!50!black}, - backgroundcolor=\color{blue!10}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - caption={\protect\filename@parse{\lstname}\protect\filename@base}, - captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{bm} -\usepackage{dsfont} -\newcommand{\naZ}{\mathds{N}} -\newcommand{\gaZ}{\mathds{Z}} -\newcommand{\raZ}{\mathds{Q}} -\newcommand{\reZ}{\mathds{R}} -\newcommand{\reZp}{\mathds{R^+}} -\newcommand{\reZpN}{\mathds{R^+_0}} -\newcommand{\koZ}{\mathds{C}} - - -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - -\newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% - {\medskip} - -\newcounter{maxexercise} -\setcounter{maxexercise}{9} % show listings up to exercise maxexercise -\newcounter{theexercise} -\setcounter{theexercise}{1} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} +\lstset{inputpath=../code} \graphicspath{{figures/}} diff --git a/designpattern/lecture/designpattern.tex b/designpattern/lecture/designpattern.tex index 93ef588..f37fa1c 100644 --- a/designpattern/lecture/designpattern.tex +++ b/designpattern/lecture/designpattern.tex @@ -11,10 +11,10 @@ einige dieser ``Design pattern'' zusammen. \section{Plotten einer mathematischen Funktion} Eine mathematische Funktion ordnet einem beliebigen $x$-Wert einen $y$-Wert zu. Um eine solche Funktion zeichnen zu k\"onnen, m\"ussen -wir uns eine Wertetabelle aus vielen $x$-Werten und den +wir eine Wertetabelle aus vielen $x$-Werten und den dazugeh\"origen Funktionswerten $y=f(x)$ erstellen. -Wir erstellen uns dazu einen Vektor mit geeigneten $x$-Werten, die von +Wir erstellen dazu einen Vektor mit geeigneten $x$-Werten, die von dem kleinsten bis zu dem gr\"o{\ss}ten $x$-Wert laufen, den wir plotten wollen. Die Schrittweite f\"ur die $x$-Werte w\"ahlen wir klein genug, um eine sch\"one glatte Kurve zu bekommen. F\"ur jeden @@ -88,7 +88,7 @@ end \end{lstlisting} Wenn in der Schleife das Ergebnis in einen Vektor gespeichert werden soll, -sollten wir uns vor der Schleife schon einen Vektor f\"ur die Ergebnisse +sollten wir vor der Schleife schon einen Vektor f\"ur die Ergebnisse erstellen: \begin{lstlisting} x = [2:3:20]; % irgendein Vektor @@ -125,9 +125,9 @@ einzigen, durchgehenden Vektor zusammengestellt werden: x = [2:3:20]; % irgendein Vektor y = []; % Leerer Vektor fuer die Ergebnisse for i=1:length(x) - % Die Funktion get_something gibt uns einen Vektor zurueck: + % Die Funktion get_something gibt einen Vektor zurueck: z = get_something( x(i) ); - % dessen Inhalt h\"angen wir an unseren Ergebnissvektor an: + % dessen Inhalt h\"angen wir an den Ergebnissvektor an: y = [y; z(:)]; % z(:) stellt sicher, das wir auf jeden Fall einen Spaltenvektoren aneinanderreihen. end @@ -136,7 +136,6 @@ mean(y) \end{lstlisting} - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Normierung von Histogrammen} Meistens sollten Histogramme normiert werden, damit sie vergleichbar diff --git a/spike_trains/lecture/spike_trains-chapter.tex b/header.tex similarity index 66% rename from spike_trains/lecture/spike_trains-chapter.tex rename to header.tex index 88ce960..29852aa 100644 --- a/spike_trains/lecture/spike_trains-chapter.tex +++ b/header.tex @@ -1,4 +1,3 @@ -\documentclass[12pt]{report} %%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} @@ -23,46 +22,18 @@ \usepackage[sf,bf,it,big,clearempty]{titlesec} \setcounter{secnumdepth}{1} - %%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{graphicx} \usepackage{xcolor} \pagecolor{white} -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} +%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% gnuplot figures: +\newcommand{\texinputpath}{} +\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{\texinputpath#1.tex}}} \newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} % maximum number of floats: @@ -98,6 +69,7 @@ % put caption on separate float: \newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} +%%%%% figure references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % references to panels of a figure within the caption: \newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} % references to figures: @@ -105,10 +77,10 @@ \newcommand{\fref}[1]{\textup{\ref{#1}}} \newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} % references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} +\newcommand{\fig}{\tr{Fig.}{Abb.}} +\newcommand{\Fig}{\tr{Figure}{Abb.}} +\newcommand{\figs}{\tr{Figs.}{Abb.}} +\newcommand{\Figs}{\tr{Figures}{Abb.}} \newcommand{\figref}[1]{\fig~\fref{#1}} \newcommand{\Figref}[1]{\Fig~\fref{#1}} \newcommand{\figsref}[1]{\figs~\fref{#1}} @@ -118,31 +90,30 @@ \newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} \newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} % references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} +\newcommand{\figb}{\tr{Fig.}{Abb.}} +\newcommand{\figsb}{\tr{Figs.}{Abb.}} \newcommand{\figrefb}[1]{\figb~\fref{#1}} \newcommand{\figsrefb}[1]{\figsb~\fref{#1}} \newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} \newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} -% references to tables: +%%%%% table references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\tref}[1]{\textup{\ref{#1}}} % references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} +\newcommand{\tab}{\tr{Tab.}{Tabelle}} +\newcommand{\Tab}{\tr{Tabel}{Tabelle}} +\newcommand{\tabs}{\tr{Tabs.}{Tabellen}} +\newcommand{\Tabs}{\tr{Tabels.}{Tabellen}} \newcommand{\tabref}[1]{\tab~\tref{#1}} \newcommand{\Tabref}[1]{\Tab~\tref{#1}} \newcommand{\tabsref}[1]{\tabs~\tref{#1}} \newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} % references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} +\newcommand{\tabb}{\tr{Tab.}{Tabelle}} +\newcommand{\tabsb}{\tr{Tab.}{Tabelle}} \newcommand{\tabrefb}[1]{\tabb~\tref{#1}} \newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - %%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\newcommand{\eqref}[1]{(\ref{#1})} \newcommand{\eqn}{\tr{Eq}{Gl}.} @@ -154,18 +125,16 @@ \newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} \newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - %%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{listings} \lstset{ - inputpath=../code, basicstyle=\ttfamily\footnotesize, numbers=left, showstringspaces=false, language=Matlab, - commentstyle=\itshape\color{darkgray}, - keywordstyle=\color{blue}, - stringstyle=\color{green}, + commentstyle=\itshape\color{red!60!black}, + keywordstyle=\color{blue!50!black}, + stringstyle=\color{green!50!black}, backgroundcolor=\color{blue!10}, breaklines=true, breakautoindent=true, @@ -173,9 +142,10 @@ frame=single, caption={\protect\filename@parse{\lstname}\protect\filename@base}, captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt + xleftmargin=2.5em, + xrightmargin=1mm, + aboveskip=1ex, + belowskip=2ex } %%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -190,37 +160,30 @@ \newcommand{\reZpN}{\mathds{R^+_0}} \newcommand{\koZ}{\mathds{C}} +%%%%% code/matlab commands: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\code}[1]{\setlength{\fboxsep}{0.5ex}\colorbox{blue!10}{\texttt{#1}}} +\newcommand{\matlab}{MATLAB} +\newcommand{\matlabfun}[1]{(\tr{\matlab{}-function}{\matlab-Funktion} \setlength{\fboxsep}{0.5ex}\colorbox{blue!10}{\texttt{#1}})} -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%% definition environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - \newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% {\medskip} +%%%%% exercises environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{framed} \newcounter{maxexercise} -\setcounter{maxexercise}{9} % show listings up to exercise maxexercise +\setcounter{maxexercise}{10000} % show listings up to exercise maxexercise \newcounter{theexercise} \setcounter{theexercise}{1} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} - -\graphicspath{{figures/}} - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\begin{document} - -\include{psth_sta} - -\end{document} - +\newcommand{\codepath}{} +\newenvironment{exercise}[1][]% +{\newcommand{\exercisesource}{#1}% + \setlength{\fboxsep}{2mm}% + \renewcommand{\FrameCommand}{\colorbox{yellow!15}}% + \MakeFramed{\advance\hsize-\width \FrameRestore}% + \noindent\textbf{\tr{Exercise}{\"Ubung} \arabic{theexercise}:}\newline}% +{\ifthenelse{\equal{\exercisesource}{}}{}% + {\ifthenelse{\value{theexercise}>\value{maxexercise}}{}% + {\lstinputlisting[belowskip=0pt]{\codepath\exercisesource}}}% + \endMakeFramed\stepcounter{theexercise}} diff --git a/likelihood/code/mlegammafit.m b/likelihood/code/mlegammafit.m new file mode 100644 index 0000000..a477899 --- /dev/null +++ b/likelihood/code/mlegammafit.m @@ -0,0 +1,12 @@ +% generate gamma distributed random numbers: +n = 50; +shape = 2.0; +scale = 1.0; +x = gamrnd(shape, scale, n, 1); + +% maximum likelihood estimate: +p = mle(x, 'distribution', 'gamma'); + +% report results: +fprintf('shape=%.2f\n', p(1)); +fprintf('scale=%.2f\n', p(2)); diff --git a/likelihood/code/mlemean.m b/likelihood/code/mlemean.m index 90d9ef7..8ad8e8f 100644 --- a/likelihood/code/mlemean.m +++ b/likelihood/code/mlemean.m @@ -3,8 +3,8 @@ n = 100; mu = 3.0; sigma =2.0; x = randn(n,1)*sigma+mu; -fprintf(' mean of the data is %.2f\n', mean(x)) fprintf('standard deviation of the data is %.2f\n', std(x)) +fprintf(' mean of the data is %.2f\n', mean(x)) % mean as parameter: pmus = 2.0:0.01:4.0; @@ -18,12 +18,19 @@ end lm = prod(lms, 1); % likelihood loglm = sum(log(lms), 1); % log likelihood +% position of maxima: +maxlm = max(lm); % height of the maximum +pmumaxlm = pmus(lm==maxlm); % pmu where lm is at maximum +pmumaxloglm = pmus(loglm==max(loglm)); % same for loglm in one line +fprintf(' maximum of likelihood is at %.2f\n', pmumaxlm) +fprintf(' maximum of log-likelihood is at %.2f\n', pmumaxloglm) + % plot likelihood of mean: subplot(1, 2, 1); -plot(pmus, lm ); +plot(pmus, lm); xlabel('mean') ylabel('likelihood') subplot(1, 2, 2); -plot(pmus, loglm ); +plot(pmus, loglm); xlabel('mean') ylabel('log likelihood') diff --git a/likelihood/lecture/likelihood-chapter.tex b/likelihood/lecture/likelihood-chapter.tex index 2a82f79..79d95f2 100644 --- a/likelihood/lecture/likelihood-chapter.tex +++ b/likelihood/lecture/likelihood-chapter.tex @@ -1,217 +1,8 @@ \documentclass[12pt]{report} -%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} -\author{Jan Benda\\Abteilung Neuroethologie\\[2ex]\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}} -\date{WS 15/16} +\input{../../header} -%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \newcommand{\tr}[2]{#1} % en -% \usepackage[english]{babel} -\newcommand{\tr}[2]{#2} % de -\usepackage[german]{babel} - -%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{pslatex} % nice font for pdf file -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} -\setcounter{tocdepth}{1} - -%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[sf,bf,it,big,clearempty]{titlesec} -\setcounter{secnumdepth}{1} - - -%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{graphicx} -\usepackage{xcolor} -\pagecolor{white} - -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} -\newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} - -% maximum number of floats: -\setcounter{topnumber}{2} -\setcounter{bottomnumber}{0} -\setcounter{totalnumber}{2} - -% float placement fractions: -\renewcommand{\textfraction}{0.2} -\renewcommand{\topfraction}{0.8} -\renewcommand{\bottomfraction}{0.0} -\renewcommand{\floatpagefraction}{0.5} - -% spacing for floats: -\setlength{\floatsep}{12pt plus 2pt minus 2pt} -\setlength{\textfloatsep}{20pt plus 4pt minus 2pt} -\setlength{\intextsep}{12pt plus 2pt minus 2pt} - -% spacing for a floating page: -\makeatletter - \setlength{\@fptop}{0pt} - \setlength{\@fpsep}{8pt plus 2.0fil} - \setlength{\@fpbot}{0pt plus 1.0fil} -\makeatother - -% rules for floats: -\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}} -\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}} - -% captions: -\usepackage[format=plain,singlelinecheck=off,labelfont=bf,font={small,sf}]{caption} - -% put caption on separate float: -\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} - -% references to panels of a figure within the caption: -\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} -% references to figures: -\newcommand{\panel}[1]{\textsf{\uppercase{#1}}} -\newcommand{\fref}[1]{\textup{\ref{#1}}} -\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} -% references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} -\newcommand{\figref}[1]{\fig~\fref{#1}} -\newcommand{\Figref}[1]{\Fig~\fref{#1}} -\newcommand{\figsref}[1]{\figs~\fref{#1}} -\newcommand{\Figsref}[1]{\Figs~\fref{#1}} -\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}} -\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}} -\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} -\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} -% references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} -\newcommand{\figrefb}[1]{\figb~\fref{#1}} -\newcommand{\figsrefb}[1]{\figsb~\fref{#1}} -\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} -\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} - -% references to tables: -\newcommand{\tref}[1]{\textup{\ref{#1}}} -% references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} -\newcommand{\tabref}[1]{\tab~\tref{#1}} -\newcommand{\Tabref}[1]{\Tab~\tref{#1}} -\newcommand{\tabsref}[1]{\tabs~\tref{#1}} -\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} -% references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} -\newcommand{\tabrefb}[1]{\tabb~\tref{#1}} -\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - - -%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%\newcommand{\eqref}[1]{(\ref{#1})} -\newcommand{\eqn}{\tr{Eq}{Gl}.} -\newcommand{\Eqn}{\tr{Eq}{Gl}.} -\newcommand{\eqns}{\tr{Eqs}{Gln}.} -\newcommand{\Eqns}{\tr{Eqs}{Gln}.} -\newcommand{\eqnref}[1]{\eqn~\eqref{#1}} -\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}} -\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} -\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - inputpath=../code, - basicstyle=\ttfamily\footnotesize, - numbers=left, - showstringspaces=false, - language=Matlab, - commentstyle=\itshape\color{red!60!black}, - keywordstyle=\color{blue!50!black}, - stringstyle=\color{green!50!black}, - backgroundcolor=\color{blue!10}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - caption={\protect\filename@parse{\lstname}\protect\filename@base}, - captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{bm} -\usepackage{dsfont} -\newcommand{\naZ}{\mathds{N}} -\newcommand{\gaZ}{\mathds{Z}} -\newcommand{\raZ}{\mathds{Q}} -\newcommand{\reZ}{\mathds{R}} -\newcommand{\reZp}{\mathds{R^+}} -\newcommand{\reZpN}{\mathds{R^+_0}} -\newcommand{\koZ}{\mathds{C}} - - -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - -\newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% - {\medskip} - -\newcounter{maxexercise} -\setcounter{maxexercise}{9} % show listings up to exercise maxexercise -\newcounter{theexercise} -\setcounter{theexercise}{1} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} +\lstset{inputpath=../code} \graphicspath{{figures/}} diff --git a/likelihood/lecture/likelihood.tex b/likelihood/lecture/likelihood.tex index b69c5ec..5e73626 100644 --- a/likelihood/lecture/likelihood.tex +++ b/likelihood/lecture/likelihood.tex @@ -1,13 +1,14 @@ + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \chapter{\tr{Maximum likelihood estimation}{Maximum-Likelihood-Sch\"atzer}} In vielen Situationen wollen wir einen oder mehrere Parameter $\theta$ einer Wahrscheinlichkeitsverteilung sch\"atzen, so dass die Verteilung -die Daten $x_1, x_2, \ldots x_n$ am besten beschreibt. -Maximum-Likelihood-Sch\"atzer w\"ahlen die Parameter so, dass die -Wahrscheinlichkeit, dass die Daten aus der Verteilung stammen, am -gr\"o{\ss}ten ist. +die Daten $x_1, x_2, \ldots x_n$ am besten beschreibt. +Maximum-Likelihood-Sch\"atzer (maximum likelihood estimate, mle) +w\"ahlen die Parameter so, dass die Wahrscheinlichkeit, dass die Daten +aus der Verteilung stammen, am gr\"o{\ss}ten ist. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Maximum Likelihood} @@ -34,9 +35,14 @@ den Parameter $\theta$ zu haben, gegeben die Me{\ss}werte $x_1, x_2, \ldots x_n$ \begin{equation} {\cal L}(\theta|x_1,x_2, \ldots x_n) = p(x_1,x_2, \ldots x_n|\theta) \end{equation} +Hinter dieser Umformung steht eigentlich der Satz von Bayes. Bei der +einfachen Gleichsetzung von ${\cal L}$ mit $p$ fehlen +Normierungsfaktoren, so dass ${\cal L}$ sich nicht auf Eins +aufintegriert, und ${\cal L}$ deshalb keine +Wahrscheinlichkeit(sdichte) ist. Wir sind nun an dem Wert des Parameters $\theta_{mle}$ interessiert, der die -Likelihood maximiert (``mle'': Maximum-Likelihood Estimate): +Likelihood maximiert (Maximum-Likelihood Estimate ``mle''): \begin{equation} \theta_{mle} = \text{argmax}_{\theta} {\cal L}(\theta|x_1,x_2, \ldots x_n) \end{equation} @@ -46,8 +52,9 @@ bei dem die Likelihood ${\cal L}(\theta)$ ihr Maximum hat. An der Stelle eines Maximums einer Funktion \"andert sich nichts, wenn man die Funktionswerte mit einer streng monoton steigenden Funktion -transformiert. Aus gleich ersichtlichen mathematischen Gr\"unden wird meistens -das Maximum der logarithmierten Likelihood (``Log-Likelihood'') gesucht: +transformiert. Aus numerischen und gleich ersichtlichen mathematischen +Gr\"unden wird meistens das Maximum der logarithmierten Likelihood +(``Log-Likelihood'') gesucht: \begin{eqnarray} \theta_{mle} & = & \text{argmax}_{\theta}\; {\cal L}(\theta|x_1,x_2, \ldots x_n) \nonumber \\ & = & \text{argmax}_{\theta}\; \log {\cal L}(\theta|x_1,x_2, \ldots x_n) \nonumber \\ @@ -79,19 +86,24 @@ Die Log-Likelihood \eqnref{loglikelihood} ist \begin{eqnarray*} \log {\cal L}(\theta|x_1,x_2, \ldots x_n) & = & \sum_{i=1}^n \log \frac{1}{\sqrt{2\pi \sigma^2}}e^{-\frac{(x_i-\theta)^2}{2\sigma^2}} \\ - & = & \sum_{i=1}^n - \log \sqrt{2\pi \sigma^2} -\frac{(x_i-\theta)^2}{2\sigma^2} + & = & \sum_{i=1}^n - \log \sqrt{2\pi \sigma^2} -\frac{(x_i-\theta)^2}{2\sigma^2} \; . \end{eqnarray*} +Der Logarithmus hat die sch\"one Eigenschaft die Exponentialfunktion +der Normalverteilung auszul\"oschen, da der Logarithmus die +Umkehrfunktion der Exponentialfunktion ist ($\log(e^x)=x$). + Zur Bestimmung des Maximums der Log-Likelihood berechnen wir deren Ableitung nach dem Parameter $\theta$ und setzen diese gleich Null: \begin{eqnarray*} \frac{\text{d}}{\text{d}\theta} \log {\cal L}(\theta|x_1,x_2, \ldots x_n) & = & \sum_{i=1}^n \frac{2(x_i-\theta)}{2\sigma^2} \;\; = \;\; 0 \\ \Leftrightarrow \quad \sum_{i=1}^n x_i - \sum_{i=1}^n x_i \theta & = & 0 \\ \Leftrightarrow \quad n \theta & = & \sum_{i=1}^n x_i \\ - \Leftrightarrow \quad \theta & = & \frac{1}{n} \sum_{i=1}^n x_i + \Leftrightarrow \quad \theta & = & \frac{1}{n} \sum_{i=1}^n x_i \;\; = \;\; \bar x \end{eqnarray*} -Der Maximum-Likelihood-Sch\"atzer ist das arithmetische Mittel der Daten. D.h. -das arithmetische Mittel maximiert die Wahrscheinlichkeit, dass die Daten aus einer -Normalverteilung mit diesem Mittelwert gezogen worden sind. +Der Maximum-Likelihood-Sch\"atzer ist das arithmetische Mittel $\bar +x$ der Daten. D.h. das arithmetische Mittel maximiert die +Wahrscheinlichkeit, dass die Daten aus einer Normalverteilung mit +diesem Mittelwert gezogen worden sind (\figref{mlemeanfig}). \begin{exercise}[mlemean.m] Ziehe $n=50$ normalverteilte Zufallsvariablen mit einem Mittelwert $\ne 0$ @@ -100,8 +112,9 @@ Normalverteilung mit diesem Mittelwert gezogen worden sind. Plotte die Likelihood (aus dem Produkt der Wahrscheinlichkeiten) und die Log-Likelihood (aus der Summe der logarithmierten Wahrscheinlichkeiten) f\"ur den Mittelwert als Parameter. Vergleiche - die Position der Maxima mit den aus den Daten berechneten + die Position der Maxima mit dem aus den Daten berechneten Mittelwert. + \newpage \end{exercise} @@ -114,7 +127,7 @@ entsprechenden Funktionswerte $f(x_i;\theta)$ mit einer Standardabweichung $\sigma_i$ normalverteilt streuen, dann lautet die Log-Likelihood \begin{eqnarray*} - \log {\cal L}(\theta|x_1,x_2, \ldots x_n) + \log {\cal L}(\theta|(x_1,y_1,\sigma_1), \ldots, (x_n,y_n,\sigma_n)) & = & \sum_{i=1}^n \log \frac{1}{\sqrt{2\pi \sigma_i^2}}e^{-\frac{(y_i-f(x_i;\theta))^2}{2\sigma_i^2}} \\ & = & \sum_{i=1}^n - \log \sqrt{2\pi \sigma_i^2} -\frac{(x_i-f(y_i;\theta))^2}{2\sigma_i^2} \\ \end{eqnarray*} @@ -140,9 +153,12 @@ Standardabweichungen wird auch mit $\chi^2$ bezeichnet. Der Wert des Parameters $\theta$, welcher den quadratischen Abstand minimiert, ist also identisch mit der Maximierung der Wahrscheinlichkeit, dass die Daten tats\"achlich aus der Funktion stammen k\"onnen. Minimierung des -$\chi^2$ ist also eine Maximum-Likelihood Sch\"atzung. Aber nur, wenn -die Daten normalverteilt um die Funktion streuen! Bei anderen -Verteilungen m\"usste man die Log-Likelihood entsprechend +$\chi^2$ ist also eine Maximum-Likelihood Sch\"atzung. + +An der Herleitung sehen wir aber auch, dass die Minimierung des +quadratischen Abstands nur dann eine Maximum-Likelihood Absch\"atzung +ist, wenn die Daten normalverteilt um die Funktion streuen. Bei +anderen Verteilungen m\"usste man die Log-Likelihood entsprechend \eqnref{loglikelihood} ausrechnen und maximieren. \begin{figure}[t] @@ -168,21 +184,32 @@ und setzen diese gleich Null: \Leftrightarrow \quad \theta & = & \frac{\sum_{i=1}^n \frac{x_iy_i}{\sigma_i^2}}{ \sum_{i=1}^n \frac{x_i^2}{\sigma_i^2}} \label{mleslope} \end{eqnarray} Damit haben wir nun einen anlytischen Ausdruck f\"ur die Bestimmung -der Steigung $\theta$ des Regressionsgeraden gewonnen. Ein -Gradientenabstieg ist f\"ur das Fitten der Geradensteigung also gar -nicht n\"otig. Das gilt allgemein f\"ur das Fitten von Koeffizienten -von linear kombinierten Basisfunktionen. Parameter, die nichtlinear in -einer Funktion enthalten sind, k\"onnen im Gegensatz dazu nicht -analytisch aus den Daten berechnet werden. F\"ur diesen Fall bleibt -dann nur auf numerische Verfahren zur Optimierung der Kostenfunktion, -wie z.B. der Gradientenabstieg, zur\"uckzugreifen. +der Steigung $\theta$ des Regressionsgeraden gewonnen +(\figref{mleproplinefig}). + +Ein Gradientenabstieg ist f\"ur das Fitten der Geradensteigung also +gar nicht n\"otig. Das gilt allgemein f\"ur das Fitten von +Koeffizienten von linear kombinierten Basisfunktionen. Wie z.B. die +die Steigung $m$ und der y-Achsenabschnitt $b$ einer Geradengleichung +\[ y = m \cdot x +b \] +oder allgemeiner die Koeffizienten $a_k$ eines Polynoms +\[ y = \sum_{k=0}^N a_k x^k = a_o + a_1x + a_2x^2 + a_3x^4 + \ldots \] +\matlabfun{polyfit}. + +Parameter, die nichtlinear in einer Funktion enthalten sind, k\"onnen +im Gegensatz dazu nicht analytisch aus den Daten berechnet +werden. z.B. die Rate $\lambda$ eines exponentiellen Zerfalls +\[ y = c \cdot e^{\lambda x} \quad , \quad c, \lambda \in \reZ \; . \] + F\"ur diesen Fall bleibt dann nur auf numerische Verfahren zur +Optimierung der Kostenfunktion, wie z.B. der Gradientenabstieg, +zur\"uckzugreifen \matlabfun{lsqcurvefit}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Fits von Wahrscheinlichkeitsverteilungen} -Zum Abschluss betrachten wir noch den Fall, bei dem wir die Parameter -einer Wahrscheinlichkeitsdichtefunktion (z.B. Mittelwert und -Standardabweichung der Normalverteilung) an ein Datenset fitten wollen. +Jetzt betrachten wir noch den Fall, bei dem wir die Parameter einer +Wahrscheinlichkeitsdichtefunktion (z.B. den shape-Parameter einer +Gamma-Verteilung) an ein Datenset fitten wollen. Ein erster Gedanke k\"onnte sein, die Wahrscheinlichkeitsdichtefunktion durch Minimierung des quadratischen @@ -196,16 +223,7 @@ aufintegriert. Die beiden Annahmen normalverteilte und unabh\"angige Daten, die die Minimierung des quadratischen Abstands \eqnref{chisqmin} zu einem Maximum-Likelihood Sch\"atzer machen, sind also verletzt. (iii) Das Histogramm h\"angt von der Wahl der -Klassenbreite ab. - -Den direkten Weg, eine Wahrscheinlichkeitsdichtefunktion an ein -Datenset zu fitten, haben wir oben schon bei dem Beispiel zur -Absch\"atzung des Mittelwertes einer Normalverteilung gesehen --- -Maximum Likelihood! Wir suchen einfach die Parameter $\theta$ der -gesuchten Wahrscheinlichkeitsdichtefunktion bei der die Log-Likelihood -\eqnref{loglikelihood} maximal wird. Das ist im allgemeinen ein -nichtlinieares Optimierungsproblem, das mit numerischen Verfahren, wie -z.B. dem Gradientenabstieg, gel\"ost wird. +Klassenbreite ab (\figref{mlepdffig}). \begin{figure}[t] \includegraphics[width=1\textwidth]{mlepdf} @@ -216,3 +234,69 @@ z.B. dem Gradientenabstieg, gel\"ost wird. normierte Histogramm der Daten zusammen mit dem \"uber Minimierung des quadratischen Abstands zum Histogramm berechneten Fit.} \end{figure} + +Den direkten Weg, eine Wahrscheinlichkeitsdichtefunktion an ein +Datenset zu fitten, haben wir oben schon bei dem Beispiel zur +Absch\"atzung des Mittelwertes einer Normalverteilung gesehen --- +Maximum Likelihood! Wir suchen einfach die Parameter $\theta$ der +gesuchten Wahrscheinlichkeitsdichtefunktion bei der die Log-Likelihood +\eqnref{loglikelihood} maximal wird. Das ist im allgemeinen ein +nichtlinieares Optimierungsproblem, das mit numerischen Verfahren, wie +z.B. dem Gradientenabstieg, gel\"ost wird \matlabfun{mle}. + +\begin{exercise}[mlegammafit.m] + Erzeuge Gammaverteilte Zufallszahlen und benutze Maximum-Likelihood, + um die Parameter der Gammafunktion aus den Daten zu bestimmen. + \newpage +\end{exercise} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Neuronale Kodierung} +In sensorischen Systemen kodieren Populationen von Neuronen mit ihrer +Aktivit\"at Eigenschaften von sensorischen Stimuli. z.B. im visuellen +Kortex V1 die Orientierung eines Balkens. Traditionell wird die +Antwort der Neurone f\"ur verschiedene Stimuli (z.B. verschiedene +Orientierungen des Balkens) gemessen. Die mittlere Antwort der Neurone +als Funktion eines Stimulusparameters ist dann die ``Tuning-curve'' +(z.B. Feuerrate als Funktion des Orientierungswinkels). + +\begin{figure}[tp] + \includegraphics[width=1\textwidth]{mlecoding} + \caption{\label{mlecodingfig} Maximum Likelihood Sch\"atzung eines + Stimulusparameters aus der Aktivit\"at einer Population von + Neuronen. Oben: Die Tuning-Kurve eines einzelnen Neurons in + Abh\"angigkeit von der Orientierung eines Balkens. Der Stimulus + der die st\"akste Aktivit\"at in diesem Neuron hervorruft ist ein + senkrechter Balken (Pfeil, $\phi_i=90$\,\degree. Die rote Fl\"ache + deutet die Variabilit\"at $p(r)$ der Aktivit\"at $r$ um die + Tuning-Kurve herum an. Mitte: Jedes Neuron in der Population hat + eine andere bevorzugte Orientierung des Stimulus (farbige Linien). + Ein Stimulus einer bestimmten Orientierung aktiviert die Neurone + in spezifischer Weise (Punkte). Unten: Die Log-Likelihood dieser + Aktivit\"aten wir maximal in der N\"ahe der wahren Orientierung + des Stimulus.} +\end{figure} + +Das Gehirn ist aber mit dem umgekehrten Problem konfrontiert: gegeben +eine bestimmte Aktivit\"at der Neurone in der Population, was war der +Stimulus (die Orientierung des Balkens)? Eine m\"ogliche Antwort ist +im Sinne von Maximum-Likelihood: es war der Stimulus f\"ur den das +Aktivit\"atsmuster am wahrscheinlichsten ist. + +Bleiben wir mit einem Beispiel bei den orientierungssensitiven Zellen +des V1. Das Tuning $\Omega_i(\phi)$ der Zellen $i$ auf ihre bevorzugte +Orientierung $\phi_i$ l\"asst sich gut mit einer van-Mises Funktion +(entspricht der Gaussfunktion auf einer zyklischen x-Achse) +beschreiben (\figref{mlecodingfig}): +\[ \Omega_i(\phi) = c \cdot e^{\cos(2(\phi-\phi_i))} \quad , \quad c +\in \reZ \] +Die Aktivit\"at der Neurone approximieren wir hier mit einer +Normalverteilung um die Tuning-Kurve mit Standardabweichung +$\sigma=\Omega/4$ proportional zu $\Omega$, so dass die +Wahrscheinlichkeit $p_i(r|\phi)$ des $i$-ten Neurons die Aktivit\"at $r$ zu +haben, wenn ein Stimulus mit Orientierung $\phi$ anliegt, gegeben ist durch +\[ p_i(r|\phi) = \frac{1}{\sqrt{2\pi}\Omega_i(\phi)/4} e^{-\frac{1}{2}\left(\frac{r-\Omega_i(\phi)}{\Omega_i(\phi)/4}\right)^2} \; . \] +Die Log-Likelihood der Stimulusorientierung $\phi$ gegeben die +Aktivit\"aten $r_1$, $r_2$, ... $r_n$ ist damit +\[ {\cal L}(\phi|r_1, r_2, \ldots r_n) = \sum_{i=1}^n \log p_i(r_i|\phi) \] diff --git a/likelihood/lecture/mlecoding.py b/likelihood/lecture/mlecoding.py new file mode 100644 index 0000000..ba86bfd --- /dev/null +++ b/likelihood/lecture/mlecoding.py @@ -0,0 +1,101 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.cm as cm + +plt.xkcd() +fig = plt.figure( figsize=(6,6.8) ) +rng = np.random.RandomState(4637281) +lmarg=0.1 +rmarg=0.1 + +ax = fig.add_axes([lmarg, 0.75, 1.0-rmarg, 0.25]) +ax.spines['bottom'].set_position('zero') +ax.spines['left'].set_visible(False) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +ax.xaxis.set_ticks_position('bottom') +ax.get_yaxis().set_visible(False) +ax.set_xlim(0.0, np.pi) +ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi)) +ax.set_xticklabels([]) +ax.set_ylim(0.0, 3.5) +ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center') +ax.annotate('Tuning curve', + xy=(0.42*np.pi, 2.5), xycoords='data', + xytext=(0.3*np.pi, 3.2), textcoords='data', ha='right', + arrowprops=dict(arrowstyle="->", relpos=(1.0,0.5), + connectionstyle="angle3,angleA=-10,angleB=110") ) +ax.annotate('', + xy=(0.5*np.pi, 0.1), xycoords='data', + xytext=(0.5*np.pi, 2.6), textcoords='data', + arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5), + connectionstyle="angle3,angleA=80,angleB=90") ) +ax.text(0.52*np.pi, 0.7, 'preferred\norientation') +ax.plot([0, 0], [0.0, 3.5], 'k', zorder=10, clip_on=False) +xx = np.arange(0.0, 2.0*np.pi, 0.01) +pp = 0.5*np.pi +yy = np.exp(np.cos(2.0*(xx+pp))) +ax.fill_between(xx, yy+0.25*yy, yy-0.25*yy, color=cm.autumn(0.3, 1), alpha=0.5) +ax.plot(xx, yy, color=cm.autumn(0.0, 1)) + +ax = fig.add_axes([lmarg, 0.34, 1.0-rmarg, 0.38]) +ax.spines['bottom'].set_position('zero') +ax.spines['left'].set_visible(False) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +ax.xaxis.set_ticks_position('bottom') +ax.get_yaxis().set_visible(False) +ax.set_xlim(0.0, np.pi) +ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi)) +ax.set_xticklabels([]) +ax.set_ylim(-1.5, 3.0) +ax.text(0.5*np.pi, -1.8, 'Orientation', ha='center') +ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center') +ax.plot([0, 0], [0.0, 3.0], 'k', zorder=10, clip_on=False) +xx = np.arange(0.0, 1.0*np.pi, 0.01) +prefphases = np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi) +responses = [] +xresponse = 0.475*np.pi +for pp in prefphases : + yy = np.exp(np.cos(2.0*(xx+pp))) + ax.plot(xx, yy, color=cm.autumn(2.0*np.abs(pp/np.pi-0.5), 1)) + y = np.exp(np.cos(2.0*(xresponse+pp))) + responses.append(y + rng.randn()*0.25*y) + ax.plot(xresponse, y, '.', markersize=20, color=cm.autumn(2.0*np.abs(pp/np.pi-0.5), 1)) + r=0.3 + y=-0.8 + ax.plot([pp-0.5*r*np.cos(pp), pp+0.5*r*np.cos(pp)], [y-r*np.sin(pp), y+r*np.sin(pp)], 'k', lw=6) +responses = np.array(responses) + +ax = fig.add_axes([lmarg, 0.05, 1.0-rmarg, 0.22]) +ax.spines['left'].set_visible(False) +ax.spines['right'].set_visible(False) +ax.spines['top'].set_visible(False) +ax.xaxis.set_ticks_position('bottom') +ax.get_yaxis().set_visible(False) +ax.set_xlim(0.0, np.pi) +ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi)) +ax.set_xticklabels([]) +ax.set_ylim(-1600, 0) +ax.set_xlabel('Orientiation') +ax.text(-0.2, -800, 'Log-Likelihood', rotation='vertical', va='center') +ax.plot([0, 0], [-1600, 0], 'k', zorder=10, clip_on=False) +phases = np.linspace(0.0, 1.1*np.pi, 100) +probs = np.zeros((len(responses), len(phases))) +for k, (pp, r) in enumerate(zip(prefphases, responses)) : + y = np.exp(np.cos(2.0*(phases+pp))) + sigma = 0.1*y + probs[k,:] = np.exp(-0.5*((r-y)/sigma)**2.0)/np.sqrt(2.0*np.pi)/sigma +loglikelihood = np.sum(np.log(probs), 0) +maxl = np.max(loglikelihood) +maxp = phases[np.argmax(loglikelihood)] +ax.annotate('', + xy=(maxp, -1600), xycoords='data', + xytext=(maxp, -30), textcoords='data', + arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5), + connectionstyle="angle3,angleA=80,angleB=90") ) +ax.text(maxp+0.05, -1300, 'most\nlikely\norientation') +ax.plot(phases, loglikelihood, '-b') + +plt.savefig('mlecoding.pdf') +#plt.show(); diff --git a/pointprocesses/lecture/pointprocesses-chapter.tex b/pointprocesses/lecture/pointprocesses-chapter.tex index 1e68316..9c392e4 100644 --- a/pointprocesses/lecture/pointprocesses-chapter.tex +++ b/pointprocesses/lecture/pointprocesses-chapter.tex @@ -1,217 +1,8 @@ \documentclass[12pt]{report} -%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} -\author{Jan Benda\\Abteilung Neuroethologie\\[2ex]\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}} -\date{WS 15/16} +\input{../../header} -%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \newcommand{\tr}[2]{#1} % en -% \usepackage[english]{babel} -\newcommand{\tr}[2]{#2} % de -\usepackage[german]{babel} - -%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{pslatex} % nice font for pdf file -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} -\setcounter{tocdepth}{1} - -%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[sf,bf,it,big,clearempty]{titlesec} -\setcounter{secnumdepth}{1} - - -%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{graphicx} -\usepackage{xcolor} -\pagecolor{white} - -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} -\newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} - -% maximum number of floats: -\setcounter{topnumber}{2} -\setcounter{bottomnumber}{0} -\setcounter{totalnumber}{2} - -% float placement fractions: -\renewcommand{\textfraction}{0.2} -\renewcommand{\topfraction}{0.8} -\renewcommand{\bottomfraction}{0.0} -\renewcommand{\floatpagefraction}{0.5} - -% spacing for floats: -\setlength{\floatsep}{12pt plus 2pt minus 2pt} -\setlength{\textfloatsep}{20pt plus 4pt minus 2pt} -\setlength{\intextsep}{12pt plus 2pt minus 2pt} - -% spacing for a floating page: -\makeatletter - \setlength{\@fptop}{0pt} - \setlength{\@fpsep}{8pt plus 2.0fil} - \setlength{\@fpbot}{0pt plus 1.0fil} -\makeatother - -% rules for floats: -\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}} -\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}} - -% captions: -\usepackage[format=plain,singlelinecheck=off,labelfont=bf,font={small,sf}]{caption} - -% put caption on separate float: -\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} - -% references to panels of a figure within the caption: -\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} -% references to figures: -\newcommand{\panel}[1]{\textsf{\uppercase{#1}}} -\newcommand{\fref}[1]{\textup{\ref{#1}}} -\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} -% references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} -\newcommand{\figref}[1]{\fig~\fref{#1}} -\newcommand{\Figref}[1]{\Fig~\fref{#1}} -\newcommand{\figsref}[1]{\figs~\fref{#1}} -\newcommand{\Figsref}[1]{\Figs~\fref{#1}} -\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}} -\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}} -\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} -\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} -% references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} -\newcommand{\figrefb}[1]{\figb~\fref{#1}} -\newcommand{\figsrefb}[1]{\figsb~\fref{#1}} -\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} -\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} - -% references to tables: -\newcommand{\tref}[1]{\textup{\ref{#1}}} -% references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} -\newcommand{\tabref}[1]{\tab~\tref{#1}} -\newcommand{\Tabref}[1]{\Tab~\tref{#1}} -\newcommand{\tabsref}[1]{\tabs~\tref{#1}} -\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} -% references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} -\newcommand{\tabrefb}[1]{\tabb~\tref{#1}} -\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - - -%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%\newcommand{\eqref}[1]{(\ref{#1})} -\newcommand{\eqn}{\tr{Eq}{Gl}.} -\newcommand{\Eqn}{\tr{Eq}{Gl}.} -\newcommand{\eqns}{\tr{Eqs}{Gln}.} -\newcommand{\Eqns}{\tr{Eqs}{Gln}.} -\newcommand{\eqnref}[1]{\eqn~\eqref{#1}} -\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}} -\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} -\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - inputpath=../code, - basicstyle=\ttfamily\footnotesize, - numbers=left, - showstringspaces=false, - language=Matlab, - commentstyle=\itshape\color{red!60!black}, - keywordstyle=\color{blue!50!black}, - stringstyle=\color{green!50!black}, - backgroundcolor=\color{blue!10}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - caption={\protect\filename@parse{\lstname}\protect\filename@base}, - captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{bm} -\usepackage{dsfont} -\newcommand{\naZ}{\mathds{N}} -\newcommand{\gaZ}{\mathds{Z}} -\newcommand{\raZ}{\mathds{Q}} -\newcommand{\reZ}{\mathds{R}} -\newcommand{\reZp}{\mathds{R^+}} -\newcommand{\reZpN}{\mathds{R^+_0}} -\newcommand{\koZ}{\mathds{C}} - - -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - -\newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% - {\medskip} - -\newcounter{maxexercise} -\setcounter{maxexercise}{9} % show listings up to exercise maxexercise -\newcounter{theexercise} -\setcounter{theexercise}{1} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} +\lstset{inputpath=../code} \graphicspath{{figures/}} diff --git a/scientificcomputing-script.tex b/scientificcomputing-script.tex index e4049a8..2ae2f22 100644 --- a/scientificcomputing-script.tex +++ b/scientificcomputing-script.tex @@ -1,219 +1,8 @@ \documentclass[12pt]{report} -%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\title{\tr{Introduction to Scientific Computing}{Einf\"uhrung in die wissenschaftliche Datenverarbeitung}} -\author{Jan Grewe \& Jan Benda\\Abteilung Neuroethologie\\[2ex]\includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}} -\date{WS 15/16} +\input{header} -%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \newcommand{\tr}[2]{#1} % en -% \usepackage[english]{babel} -\newcommand{\tr}[2]{#2} % de -\usepackage[german]{babel} - -%%%%% packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{pslatex} % nice font for pdf file -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry} -\setcounter{tocdepth}{1} - -%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[sf,bf,it,big,clearempty]{titlesec} -\setcounter{secnumdepth}{1} - - -%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro - - -%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{graphicx} -\usepackage{xcolor} -\pagecolor{white} - -\newcommand{\ruler}{\par\noindent\setlength{\unitlength}{1mm}\begin{picture}(0,6)% - \put(0,4){\line(1,0){170}}% - \multiput(0,2)(10,0){18}{\line(0,1){4}}% - \multiput(0,3)(1,0){170}{\line(0,1){2}}% - \put(0,0){\makebox(0,0){{\tiny 0}}}% - \put(10,0){\makebox(0,0){{\tiny 1}}}% - \put(20,0){\makebox(0,0){{\tiny 2}}}% - \put(30,0){\makebox(0,0){{\tiny 3}}}% - \put(40,0){\makebox(0,0){{\tiny 4}}}% - \put(50,0){\makebox(0,0){{\tiny 5}}}% - \put(60,0){\makebox(0,0){{\tiny 6}}}% - \put(70,0){\makebox(0,0){{\tiny 7}}}% - \put(80,0){\makebox(0,0){{\tiny 8}}}% - \put(90,0){\makebox(0,0){{\tiny 9}}}% - \put(100,0){\makebox(0,0){{\tiny 10}}}% - \put(110,0){\makebox(0,0){{\tiny 11}}}% - \put(120,0){\makebox(0,0){{\tiny 12}}}% - \put(130,0){\makebox(0,0){{\tiny 13}}}% - \put(140,0){\makebox(0,0){{\tiny 14}}}% - \put(150,0){\makebox(0,0){{\tiny 15}}}% - \put(160,0){\makebox(0,0){{\tiny 16}}}% - \put(170,0){\makebox(0,0){{\tiny 17}}}% - \end{picture}\par} - -% figures: -\setlength{\fboxsep}{0pt} -\newcommand{\texinputpath}{} -\newcommand{\texpicture}[1]{{\sffamily\footnotesize\input{\texinputpath#1.tex}}} -%\newcommand{\texpicture}[1]{\fbox{\sffamily\footnotesize\input{#1.tex}}} -%\newcommand{\texpicture}[1]{\setlength{\fboxsep}{2mm}\fbox{#1}} -%\newcommand{\texpicture}[1]{} -\newcommand{\figlabel}[1]{\textsf{\textbf{\large \uppercase{#1}}}} - -% maximum number of floats: -\setcounter{topnumber}{2} -\setcounter{bottomnumber}{0} -\setcounter{totalnumber}{2} - -% float placement fractions: -\renewcommand{\textfraction}{0.2} -\renewcommand{\topfraction}{0.8} -\renewcommand{\bottomfraction}{0.0} -\renewcommand{\floatpagefraction}{0.5} - -% spacing for floats: -\setlength{\floatsep}{12pt plus 2pt minus 2pt} -\setlength{\textfloatsep}{20pt plus 4pt minus 2pt} -\setlength{\intextsep}{12pt plus 2pt minus 2pt} - -% spacing for a floating page: -\makeatletter - \setlength{\@fptop}{0pt} - \setlength{\@fpsep}{8pt plus 2.0fil} - \setlength{\@fpbot}{0pt plus 1.0fil} -\makeatother - -% rules for floats: -\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}} -\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}} - -% captions: -\usepackage[format=plain,singlelinecheck=off,labelfont=bf,font={small,sf}]{caption} - -% put caption on separate float: -\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]} - -% references to panels of a figure within the caption: -\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}} -% references to figures: -\newcommand{\panel}[1]{\textsf{\uppercase{#1}}} -\newcommand{\fref}[1]{\textup{\ref{#1}}} -\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}} -% references to figures in normal text: -\newcommand{\fig}{Fig.} -\newcommand{\Fig}{Figure} -\newcommand{\figs}{Figs.} -\newcommand{\Figs}{Figures} -\newcommand{\figref}[1]{\fig~\fref{#1}} -\newcommand{\Figref}[1]{\Fig~\fref{#1}} -\newcommand{\figsref}[1]{\figs~\fref{#1}} -\newcommand{\Figsref}[1]{\Figs~\fref{#1}} -\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}} -\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}} -\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}} -\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}} -% references to figures within bracketed text: -\newcommand{\figb}{Fig.} -\newcommand{\figsb}{Figs.} -\newcommand{\figrefb}[1]{\figb~\fref{#1}} -\newcommand{\figsrefb}[1]{\figsb~\fref{#1}} -\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}} -\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}} - -% references to tables: -\newcommand{\tref}[1]{\textup{\ref{#1}}} -% references to tables in normal text: -\newcommand{\tab}{Tab.} -\newcommand{\Tab}{Table} -\newcommand{\tabs}{Tabs.} -\newcommand{\Tabs}{Tables} -\newcommand{\tabref}[1]{\tab~\tref{#1}} -\newcommand{\Tabref}[1]{\Tab~\tref{#1}} -\newcommand{\tabsref}[1]{\tabs~\tref{#1}} -\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}} -% references to tables within bracketed text: -\newcommand{\tabb}{Tab.} -\newcommand{\tabsb}{Tab.} -\newcommand{\tabrefb}[1]{\tabb~\tref{#1}} -\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}} - - -%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%\newcommand{\eqref}[1]{(\ref{#1})} -\newcommand{\eqn}{\tr{Eq}{Gl}.} -\newcommand{\Eqn}{\tr{Eq}{Gl}.} -\newcommand{\eqns}{\tr{Eqs}{Gln}.} -\newcommand{\Eqns}{\tr{Eqs}{Gln}.} -\newcommand{\eqnref}[1]{\eqn~\eqref{#1}} -\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}} -\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}} -\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - basicstyle=\ttfamily\footnotesize, - numbers=left, - showstringspaces=false, - language=Matlab, - commentstyle=\itshape\color{red!60!black}, - keywordstyle=\color{blue!50!black}, - stringstyle=\color{green!50!black}, - backgroundcolor=\color{blue!10}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - caption={\protect\filename@parse{\lstname}\protect\filename@base}, - captionpos=t, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{bm} -\usepackage{dsfont} -\newcommand{\naZ}{\mathds{N}} -\newcommand{\gaZ}{\mathds{Z}} -\newcommand{\raZ}{\mathds{Q}} -\newcommand{\reZ}{\mathds{R}} -\newcommand{\reZp}{\mathds{R^+}} -\newcommand{\reZpN}{\mathds{R^+_0}} -\newcommand{\koZ}{\mathds{C}} - - -%%%%% structure: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{ifthen} - -\newcommand{\code}[1]{\texttt{#1}} - -\newcommand{\source}[1]{ - \begin{flushright} - \color{gray}\scriptsize \url{#1} - \end{flushright} -} - -\newenvironment{definition}[1][]{\medskip\noindent\textbf{Definition}\ifthenelse{\equal{#1}{}}{}{ #1}:\newline}% - {\medskip} - -%%%%% exercises: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcounter{maxexercise} -\setcounter{maxexercise}{10} % show listings up to exercise maxexercise -\newcounter{theexercise} -\setcounter{theexercise}{1} -\newcommand{\codepath}{} -\newenvironment{exercise}[1][]{\medskip\noindent\textbf{\tr{Exercise}{\"Ubung} - \arabic{theexercise}:}\newline \newcommand{\exercisesource}{#1}}% - {\ifthenelse{\equal{\exercisesource}{}}{}{\ifthenelse{\value{theexercise}>\value{maxexercise}}{}{\medskip\lstinputlisting{\codepath\exercisesource}}}\medskip\stepcounter{theexercise}} +\setcounter{maxexercise}{10000} % show listings up to exercise maxexercise \graphicspath{{statistics/lecture/}{statistics/lecture/figures/}{bootstrap/lecture/}{bootstrap/lecture/figures/}{likelihood/lecture/}{likelihood/lecture/figures/}{pointprocesses/lecture/}{pointprocesses/lecture/figures/}} @@ -226,20 +15,20 @@ \tableofcontents -\renewcommand{\codepath}{statistics/code/} +\lstset{inputpath=statistics/code} \include{statistics/lecture/statistics} -\renewcommand{\codepath}{bootstrap/code/} +\lstset{inputpath=bootstrap/code} \include{bootstrap/lecture/bootstrap} -\renewcommand{\codepath}{likelihood/code/} +\lstset{inputpath=likelihood/code} \include{likelihood/lecture/likelihood} -\renewcommand{\codepath}{pointprocesses/code/} +\lstset{inputpath=pointprocesses/code/} \renewcommand{\texinputpath}{pointprocesses/lecture/} \include{pointprocesses/lecture/pointprocesses} -\renewcommand{\codepath}{designpattern/code/} +\lstset{inputpath=designpattern/code/} \include{designpattern/lecture/designpattern} \end{document} diff --git a/spike_trains/lecture/Makefile b/spike_trains/lecture/Makefile index 96b7d0e..492b266 100644 --- a/spike_trains/lecture/Makefile +++ b/spike_trains/lecture/Makefile @@ -1,20 +1,70 @@ -TEXFILES=$(wildcard *.tex) -TEXFILES=psth_sta.tex +BASENAME=psth_sta -PDFFILES=$(TEXFILES:.tex=.pdf) +PYFILES=$(wildcard *.py) +PYPDFFILES=$(PYFILES:.py=.pdf) -pdf : $(PDFFILES) +GPTFILES=$(wildcard *.gpt) +GPTTEXFILES=$(GPTFILES:.gpt=.tex) -$(PDFFILES) : %.pdf : %.tex + +all: pdf slides thumbs + +# script: +pdf : $(BASENAME)-chapter.pdf +$(BASENAME)-chapter.pdf : $(BASENAME)-chapter.tex $(BASENAME).tex $(GPTTEXFILES) $(PYPDFFILES) pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true -clean : - rm -f *~ $(TEXFILES:.tex=.aux) $(TEXFILES:.tex=.log) $(TEXFILES:.tex=.out) $(TEXFILES:.tex=.nav) $(TEXFILES:.tex=.snm) $(TEXFILES:.tex=.toc) $(TEXFILES:.tex=.vrb) -cleanall : clean - rm -f $(PDFFILES) +# slides: +slides: $(BASENAME)-slides.pdf +$(BASENAME)-slides.pdf : $(BASENAME)-slides.tex $(GPTTEXFILES) $(PYPDFFILES) + pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true + +# thumbnails: +thumbs: $(BASENAME)-handout.pdf +$(BASENAME)-handout.pdf: $(BASENAME)-slides.tex $(GPTTEXFILES) + sed -e 's/setboolean{presentation}{true}/setboolean{presentation}{false}/; s/usepackage{crop}/usepackage[frame]{crop}/' $< > thumbsfoils.tex + pdflatex thumbsfoils | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex thumbsfoils || true + pdfnup --nup 2x4 --no-landscape --paper a4paper --trim "-1cm -1cm -1cm -1cm" --outfile $@ thumbsfoils.pdf # 1-19 + rm thumbsfoils.* -watch : +watchpdf : while true; do ! make -q pdf && make pdf; sleep 0.5; done +watchslides : + while true; do ! make -q slides && make slides; sleep 0.5; done + +# python plots: +$(PYPDFFILES) : %.pdf: %.py + python $< + +# gnuplot plots: +$(GPTTEXFILES) : %.tex: %.gpt whitestyles.gp + gnuplot whitestyles.gp $< + epstopdf $*.eps + + +clean : + rm -f *~ + rm -f $(BASENAME).aux $(BASENAME).log + rm -f $(BASENAME)-chapter.aux $(BASENAME)-chapter.log $(BASENAME)-chapter.out + rm -f $(BASENAME)-slides.aux $(BASENAME)-slides.log $(BASENAME)-slides.out $(BASENAME)-slides.toc $(BASENAME)-slides.nav $(BASENAME)-slides.snm $(BASENAME)-slides.vrb + rm -f $(PYPDFFILES) $(GPTTEXFILES) + +cleanall : clean + rm -f $(BASENAME)-chapter.pdf $(BASENAME)-slides.pdf $(BASENAME)-handout.pdf + +help : + @echo -e \ + "make pdf: make the pdf file of the script.\n"\ + "make slides: make the pdf file of the slides.\n"\ + "make thumbs: make color thumbnails of the talk.\n"\ + "make watchpdf: make the pdf file of the script\n"\ + " whenever the tex file is modified.\n"\ + "make watchpdf: make the pdf file of the slides\n"\ + " whenever the tex file is modified.\n"\ + "make clean: remove all intermediate files,\n"\ + " just leave the source files and the final .pdf files.\n"\ + "make cleanup: remove all intermediate files as well as\n"\ + " the final .pdf files.\n"\ diff --git a/spike_trains/lecture/psth_sta-chapter.tex b/spike_trains/lecture/psth_sta-chapter.tex new file mode 100644 index 0000000..54499f1 --- /dev/null +++ b/spike_trains/lecture/psth_sta-chapter.tex @@ -0,0 +1,17 @@ +\documentclass[12pt]{report} + +\input{../../header} + +\lstset{inputpath=../code} + +\graphicspath{{figures/}} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{document} + +\include{psth_sta} + +\end{document} + diff --git a/statistics/code/checkmymedian.m b/statistics/code/checkmymedian.m index 5c90834..a2f6b09 100644 --- a/statistics/code/checkmymedian.m +++ b/statistics/code/checkmymedian.m @@ -3,7 +3,7 @@ for i = 1:140 % loop over different length for k = 1:10 % try several times a = randn( i, 1 ); % generate some data - m = mymedian( a ) % compute median + m = mymedian( a ); % compute median if length( a(a>m) ) ~= length( a(a=x1)&(x<=x2)), p((x>=x1)&(x<=x2)), 'FaceColor', 'r' ) hold off % compute integral between x1 and x2: -x1=1.0; -x2=2.0; P = sum(p((x>=x1)&(x=x1)&(r\value{maxexercise}}{}{\medskip\lstinputlisting{\exercisesource}}}\medskip\stepcounter{theexercise}} +\lstset{inputpath=../code} \graphicspath{{figures/}} diff --git a/statistics/lecture/statistics.tex b/statistics/lecture/statistics.tex index 2ca6481..678fcee 100644 --- a/statistics/lecture/statistics.tex +++ b/statistics/lecture/statistics.tex @@ -53,7 +53,7 @@ {Schreibe eine Funktion, die den Median eines Vektors zur\"uckgibt.} \end{exercise} -\code{matlab} stellt die Funktion \code{median()} zur Berechnung des Medians bereit. +\matlab{} stellt die Funktion \code{median()} zur Berechnung des Medians bereit. \begin{exercise}[checkmymedian.m] \tr{Write a script that tests whether your median function really @@ -70,24 +70,24 @@ \caption{\label{quartilefig} Median und Quartile einer Normalverteilung.} \end{figure} -\begin{definition}[\tr{quartile}{Quartile}] - Die Quartile Q1, Q2 und Q3 unterteilen die Daten in vier gleich - gro{\ss}e Gruppen, die jeweils ein Viertel der Daten enthalten. - Das mittlere Quartil entspricht dem Median. -\end{definition} +% \begin{definition}[\tr{quartile}{Quartile}] +% Die Quartile Q1, Q2 und Q3 unterteilen die Daten in vier gleich +% gro{\ss}e Gruppen, die jeweils ein Viertel der Daten enthalten. +% Das mittlere Quartil entspricht dem Median. +% \end{definition} -\begin{exercise}[quartiles.m] - \tr{Write a function that computes the first, second, and third quartile of a vector.} - {Schreibe eine Funktion, die das erste, zweite und dritte Quartil als Vektor zur\"uckgibt.} -\end{exercise} +% \begin{exercise}[quartiles.m] +% \tr{Write a function that computes the first, second, and third quartile of a vector.} +% {Schreibe eine Funktion, die das erste, zweite und dritte Quartil als Vektor zur\"uckgibt.} +% \end{exercise} \section{\tr{Histogram}{Histogramm}} Histogramme z\"ahlen die H\"aufigkeit $n_i$ des Auftretens von $N=\sum_{i=1}^M n_i$ Messwerten in $M$ Messbereichsklassen $i$ (Bins). Die Klassen unterteilen den Wertebereich meist in angrenzende und -gleich gro{\ss}e Intervalle. Histogramme sch\"atzen die -Wahrscheinlichkeitsverteilung der Messwerte ab. +gleich gro{\ss}e Intervalle. Histogramme k\"onnen verwendet werden, um die +Wahrscheinlichkeitsverteilung der Messwerte abzusch\"atzen. \begin{exercise}[rollthedie.m] \tr{Write a function that simulates rolling a die $n$ times.} @@ -99,7 +99,7 @@ Wahrscheinlichkeitsverteilung der Messwerte ab. the plain hist(x) function, force 6 bins via hist( x, 6 ), and set meaningfull bins positions.} {Plotte Histogramme von 20, 100, und 1000-mal w\"urfeln. Benutze \code{hist(x)}, erzwinge sechs Bins - mit \code{hist(x,6)}, und setze selbst sinnvolle Bins. Normiere + mit \code{hist(x,6)}, oder setze selbst sinnvolle Bins. Normiere anschliessend das Histogram auf geeignete Weise.} \end{exercise} @@ -216,7 +216,7 @@ Korrelationskoeffizient (x-\langle x \rangle)(y-\langle y \rangle) \rangle}{\sqrt{\langle (x-\langle x \rangle)^2} \rangle \sqrt{\langle (y-\langle y \rangle)^2} \rangle} \] quantifiziert einfache lineare -Zusammenh\"ange. Perfekt korrelierte Variablen ergeben einen +Zusammenh\"ange \matlabfun{corr}. Perfekt korrelierte Variablen ergeben einen Korrelationskoeffizienten von $+1$, antikorrelierte Daten einen Korrelationskoeffizienten von $-1$ und nicht korrelierte Daten einen Korrelationskoeffizienten nahe 0 (\figrefb{correlationfig}).