From 08382f94d45feeca9b18e96ae40df2668fd99944 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 7 Dec 2020 19:21:17 +0100 Subject: [PATCH 01/37] updated statistics exercise instructions --- README.fonts | 14 + .../lecture/pointprocessscetchA.eps | 120 ++++-- .../lecture/pointprocessscetchA.pdf | Bin 2786 -> 2924 bytes .../lecture/pointprocessscetchB.eps | 389 ++++++++++++------ .../lecture/pointprocessscetchB.pdf | Bin 4694 -> 4877 bytes statistics/exercises/exercises01.tex | 5 +- statistics/lecture/diehistograms.py | 12 +- 7 files changed, 379 insertions(+), 161 deletions(-) diff --git a/README.fonts b/README.fonts index ab7a941..638013d 100644 --- a/README.fonts +++ b/README.fonts @@ -1,6 +1,20 @@ Fonts for matplotlib -------------------- +Install Humor Sans font +``` +sudo apt install fonts-humor-sans +``` + +Clear matplotlib font cache: +``` +cd ~/.cache/matplotlib/ +rm -r * +``` + +Older problems +-------------- + Make sure the right fonts are installed: ``` sudo apt-get install ttf-lyx2.0 diff --git a/pointprocesses/lecture/pointprocessscetchA.eps b/pointprocesses/lecture/pointprocessscetchA.eps index 2383569..67537f6 100644 --- a/pointprocesses/lecture/pointprocessscetchA.eps +++ b/pointprocesses/lecture/pointprocessscetchA.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchA.tex -%%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Tue Oct 27 23:58:04 2020 +%%Creator: gnuplot 5.2 patchlevel 8 +%%CreationDate: Mon Dec 7 16:09:58 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 135 %%EndComments @@ -18,6 +18,7 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def +/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -29,11 +30,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -47,7 +48,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 4.6 (September 2012) +% Gnuplot Prolog Version 5.2 (Dec 2017) % %/SuppressPDFMark true def % @@ -64,11 +65,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -82,7 +83,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Default Line colors +% Classic Line colors (version 5.0) /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -95,19 +96,21 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default Line Types +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def /LTw {PL [] 1 setgray} def -/LTb {BL [] LCb DL} def +/LTb {PL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [4 dl1 2 dl2] LC1 DL} def -/LT2 {PL [2 dl1 3 dl2] LC2 DL} def -/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def -/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def -/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def -/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -302,7 +305,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -329,9 +332,14 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse - 2 lt - {/InterpretLevel1 true def} - {/InterpretLevel1 Level1 def} +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } ifelse % % PostScript level 2 pattern fill definitions @@ -420,6 +428,7 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop +% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -429,14 +438,39 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchA.tex) /Subject (gnuplot plot) - /Creator (gnuplot 4.6 patchlevel 4) - /Author (jan) + /Creator (gnuplot 5.2 patchlevel 8) % /Producer (gnuplot) % /Keywords () - /CreationDate (Tue Oct 27 23:58:04 2020) + /CreationDate (Mon Dec 7 16:09:58 2020) /DOCINFO pdfmark end } ifelse +% +% Support for boxed text - Ethan A Merritt Sep 2016 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { dup type /stringtype eq + { Boxing { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } + {} ifelse} def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% end %%EndProlog %%Page: 1 1 @@ -450,27 +484,33 @@ newpath 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 824 M +stroke +6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V +Z stroke 528 824 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 573 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 573 M 0 503 V 1412 573 M 0 503 V @@ -488,12 +528,18 @@ LC0 setrgbcolor 0 503 V 5685 573 M 0 503 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C stroke +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchA.pdf b/pointprocesses/lecture/pointprocessscetchA.pdf index 59b05836210d0388b698c5ca52f9fff0e76a8257..6154f40cf355478e936160beb372f4f6d2d68ea2 100644 GIT binary patch delta 1092 zcma)+e@GKi9Kf0RgIy{Tlu{5cY-Hi-d*|Kmw%lTEce-21*S-^a_Y zU0jzk`CJl>nmEezc=5sw%4BlK1~oZ|BU;P~`gA}a2DIXLNMbkXySzR}k6$FCosNLB zo%Bv^AWq~^BpSg-cd3JF)J7HqwC)mjyPcvfu7r;yB3LEFo5b-XmLgHrwuAgh;`+sa z5^#65`RkkG36(UR#8WzhL;hq)SFumVHUuF-zvq$`!@3P8l4LbS90;k3BO3h&I+9rH z)^HH3zF?oK*Ee@*F(QvuZ%NJD!ErO`-=+emphcOM#`FBwjJ-E(|wX@h~yR2q&NRZ&spXq9h<`;K6y|0obZ*F9;egg z7j8N^?ViI2UKy@=3J(kSmgmdz|KC38-OA8*!F( zvAGkckZ9-Iv2V6c1_obAevzF`QA(OsaB3lhk&|hcm6&Iv4-y2jAq=preoC?xRL|x& z?D>qUMrN8^`pzIzGV}9X5=&AwK>qhnE>SQtSAd3#$>au3aZUpxb0cF@3t%WM;IuM9 z4+x+s!KF!AsmUc8>3O9EIr$|DAOa}tSXz>iU!(za&}2p~{dyBKQw31e87Sl_aDf>H zMn(p}m`4>eFu@{bWR9uMz!1Yc10z#&4D(ElEJ0!_$QB!znj2s$w6vUjnad{D&DGi5 z#M#K%5@@TXi=m^lo2!eni>rx+p|iQGnSraF4M7#LTy}O`#U+VFB^5=fXQN# Js;>TSTmWFbAXWeX diff --git a/pointprocesses/lecture/pointprocessscetchB.eps b/pointprocesses/lecture/pointprocessscetchB.eps index d55c96f..6ef7b10 100644 --- a/pointprocesses/lecture/pointprocessscetchB.eps +++ b/pointprocesses/lecture/pointprocessscetchB.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchB.tex -%%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Tue Oct 27 23:58:04 2020 +%%Creator: gnuplot 5.2 patchlevel 8 +%%CreationDate: Mon Dec 7 16:09:59 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 237 %%EndComments @@ -18,6 +18,7 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def +/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -29,11 +30,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -47,7 +48,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 4.6 (September 2012) +% Gnuplot Prolog Version 5.2 (Dec 2017) % %/SuppressPDFMark true def % @@ -64,11 +65,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -82,7 +83,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Default Line colors +% Classic Line colors (version 5.0) /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -95,19 +96,21 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default Line Types +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def /LTw {PL [] 1 setgray} def -/LTb {BL [] LCb DL} def +/LTb {PL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [4 dl1 2 dl2] LC1 DL} def -/LT2 {PL [2 dl1 3 dl2] LC2 DL} def -/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def -/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def -/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def -/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -302,7 +305,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -329,9 +332,14 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse - 2 lt - {/InterpretLevel1 true def} - {/InterpretLevel1 Level1 def} +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } ifelse % % PostScript level 2 pattern fill definitions @@ -420,6 +428,7 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop +% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -429,14 +438,39 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchB.tex) /Subject (gnuplot plot) - /Creator (gnuplot 4.6 patchlevel 4) - /Author (jan) + /Creator (gnuplot 5.2 patchlevel 8) % /Producer (gnuplot) % /Keywords () - /CreationDate (Tue Oct 27 23:58:04 2020) + /CreationDate (Mon Dec 7 16:09:59 2020) /DOCINFO pdfmark end } ifelse +% +% Support for boxed text - Ethan A Merritt Sep 2016 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { dup type /stringtype eq + { Boxing { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } + {} ifelse} def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% end %%EndProlog %%Page: 1 1 @@ -450,27 +484,33 @@ newpath 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 3165 M +stroke +6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V --5680 0 R +Z stroke +528 3165 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 3029 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 3029 M 0 272 V 502 -272 R 0 272 V @@ -488,99 +528,167 @@ LC0 setrgbcolor 0 272 V 5685 3029 M 0 272 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +1.000 UP +2.000 UL LTb -LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP +LCb setrgbcolor 1.000 UL -LTb +[] 0 setdash gsave 6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 2043 M +stroke +6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V --5680 0 R +Z stroke +528 2043 M 5680 0 V +stroke +1.000 UL +[] 0 setdash 1291 1929 M +stroke +1291 1929 N 121 32 V -121 32 V --260 -64 R --121 32 V -121 32 V -910 1961 M +-260 0 R +stroke +1031 1993 N +910 1961 L +121 -32 V +-121 32 R 502 0 V -590 -32 R +stroke +1.000 UL +[] 0 setdash +2002 1929 M +stroke +2002 1929 N 121 32 V -121 32 V --469 -64 R --121 32 V -121 32 V --121 -32 R +-469 0 R +stroke +1533 1993 N +-121 -32 V +121 -32 V +-121 32 R 711 0 V -206 -22 R +stroke +1.000 UL +[] 0 setdash +2329 1939 M +stroke +2329 1939 N 84 22 V -84 22 V --122 -44 R --84 22 V -84 22 V --84 -22 R +-122 0 R +stroke +2207 1983 N +-84 -22 V +84 -22 V +-84 22 R 290 0 V -216 -23 R +stroke +1.000 UL +[] 0 setdash +2629 1938 M +stroke +2629 1938 N 88 23 V -88 23 V --128 -46 R --88 23 V -88 23 V --88 -23 R +-128 0 R +stroke +2501 1984 N +-88 -23 V +88 -23 V +-88 23 R 304 0 V -329 -32 R +stroke +1.000 UL +[] 0 setdash +3046 1929 M +stroke +3046 1929 N 121 32 V -121 32 V --208 -64 R --121 32 V -121 32 V --121 -32 R +-208 0 R +stroke +2838 1993 N +-121 -32 V +121 -32 V +-121 32 R 450 0 V -745 -32 R +stroke +1.000 UL +[] 0 setdash +3912 1929 M +stroke +3912 1929 N 121 32 V -121 32 V --624 -64 R --121 32 V -121 32 V --121 -32 R +-624 0 R +stroke +3288 1993 N +-121 -32 V +121 -32 V +-121 32 R 866 0 V -496 -32 R +stroke +1.000 UL +[] 0 setdash +4529 1929 M +stroke +4529 1929 N 121 32 V -121 32 V --375 -64 R --121 32 V -121 32 V --121 -32 R +-375 0 R +stroke +4154 1993 N +-121 -32 V +121 -32 V +-121 32 R 617 0 V -914 -32 R +stroke +1.000 UL +[] 0 setdash +5564 1929 M +stroke +5564 1929 N 121 32 V -121 32 V --793 -64 R --121 32 V -121 32 V --121 -32 R +-793 0 R +stroke +4771 1993 N +-121 -32 V +121 -32 V +-121 32 R 1035 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 1907 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 1907 M 0 272 V 502 -272 R 0 272 V @@ -598,74 +706,100 @@ LC0 setrgbcolor 0 272 V 5685 1907 M 0 272 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 268 M +[] 0 setdash +0.00 0.00 0.00 C +528 268 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 460 M +[] 0 setdash +0.00 0.00 0.00 C +528 460 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 652 M +[] 0 setdash +0.00 0.00 0.00 C +528 652 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 844 M +[] 0 setdash +0.00 0.00 0.00 C +528 844 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1036 M +[] 0 setdash +0.00 0.00 0.00 C +528 1036 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1228 M +[] 0 setdash +0.00 0.00 0.00 C +528 1228 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1276 M +[] 0 setdash +0.00 0.00 0.00 C +528 1276 M 528 220 L 5801 0 R 0 1056 R -5801 0 R 1.000 UP stroke -LTb LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 268 M +stroke +6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V +Z stroke 528 268 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 3.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 528 268 M +0.00 0.00 0.00 C +% Begin plot #1 +3.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +528 268 M 382 0 V 0 96 R 502 0 V @@ -685,12 +819,17 @@ LC0 setrgbcolor 1035 0 V 0 96 R 533 0 V -1.500 UP stroke +LTw +% End plot #1 +% Begin plot #2 +1.500 UP 2.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 268 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -699,11 +838,16 @@ LC0 setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF +LTw +% End plot #2 +% Begin plot #3 1.000 UP 2.000 UL -LT0 -LC0 setrgbcolor -1.00 1.00 1.00 C 910 268 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +1.00 1.00 1.00 C +910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -712,11 +856,16 @@ LC0 setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF +LTw +% End plot #3 +% Begin plot #4 1.500 UP 2.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 364 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 364 CircleF 1412 460 CircleF 2123 556 CircleF 2413 652 CircleF @@ -725,11 +874,17 @@ LC0 setrgbcolor 4033 940 CircleF 4650 1036 CircleF 5685 1132 CircleF -1.000 UP +LTw +% End plot #4 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C stroke +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchB.pdf b/pointprocesses/lecture/pointprocessscetchB.pdf index 205565805ff79bbb04692d7dda387c0c89c38943..1f5548d3dd891119f31f208cdaf3e96a08f1625d 100644 GIT binary patch delta 3077 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 AfdBvi delta 2859 zcma)4X*d*W8@3dm$sVUrG$Ij(qHK{ZTlnalAK!KQuIual@x1qSzxVw-&-=V@lG+;;QB@nf85pXK2B@~p zrWB-oz|t*~RnekD&2|k3$0v0rgaja?*M?7k+>StIujwb&ZQFS5D|wJTB7EJfQ0n~& z20lS%zB{CT@%U%@+U7#rjAC=w>MFgN_I0a&)$wIXBlX>ErH%_FZVCM@+0*FYchV7H150YD_!Urs)C&pKx}^DWuf(TzmIo3CaD8 zal~R!mIS-u?m{X*yW#7~UM$~8<+nRah*(n(4h7${PkZ5@Ddy_d(L9z#Xm7hy)T?-& zOvnwszl2X6i{4Qqho$EY86pOQLsA}O=kPi_y(g={nE zt*yPkZk^*bGS<($vU2_eHD$9izq{u+e{q-wJ(x()$m=Q3z3{9)Ei;c8!jbF08ueaX zJ=JI-HGE~jG6`O-NAC!9sGB%0WuR*-BW*q4m=~frClIv6;Jozt92Zq`J>lMLVmBc$ z>N$Cy*^89qQT&aGzLiyxy=^+QJnPjOr zL#_=VD>ijOC(P*}{Y=&Fx?u0qM+XxYA_$%QSF^hBB?dK1P0vgz&E^{G{nOt{$)#Zp5#vrFDdA1`>D$R# z>J9f$ZHLbB*WB6oF!P|bFhospdUpNEj^f9QR&C?8{Sn*UCcRe)H$F5h~Aw*nGBs^*?n-R^H*{6tCp2o4_%cGKduR%2_&;$ z1|{{>`4*tcdq1+1is;llESU>N(YG&EXXu!Bq`tY*7wU8{k<3xkFlP>7)o(j;4=17= ziy3L0jrdIyf=9-?iZfE2;l3B0wcFrDk%~_%8<6cwN$fwZyM))BUY~UT>~tj&m4<)B z^a0lvEq&czTOn39OE43dfzLIHl}txWOt0N+U*0Fk8>r##}<(csFI zFm%@D2DNr1ZJ346_SzP7YQy258+k*%52z9>`op@_eYm|0R-MgJ0*71YRlK9(EE zuHEamE++nLh+UERi4{QwA7_b7mx+rEH?k(>0uP!SNmz<-7JJA@K@39#bIq%x>i?*4 zMQdK9j;!&m4QiW_0u<6_tTIx?24rqY+Envtm#&6uH#$eLtdUJT#P-%|yQAgdi(@<( zojw5zhnA{(rfyfLv)Kizipxi(cC*B)`Uv^P z7q0@&obf~5O?MNJrV|qW971{2WH=>wRN?cHTFEyyzp55prfHcBihWAv?+O39RH15y z-X|Fm5b9Y|c$(uERV6)L&rs4BRDilF=hQo*jPnypAD9Gd`FG7F`$Ig%*jvn0i|Ovy zzZ}*V2PsFn-2yj`4!n9(6LiefK0p>aqp-nTc{(4EPy7S)h)z0Z`GPU*dncjja<#l* zk%^`fDT=cm8T*^EKRe_8s=hs}zeviq&i@JNRQYsc#T4&vn&!UPO)J;Fm4QW#4(G5p zU4og#USg8|QPoFvI~+2qPPwp_b8LD}XAsjxkt9ovHJj z!H2lX2OVRT&t$ERL$%4CTnbjB(7Zy-yi&vH!=9M%xYCTH5!_)LhG?M8lp0SWlyUH*4cDq!^TT;$s@L5ZmpYCEN}HO4@fE?dO+ zzA#34Lr}I#z<5t>7IxKJ`rGeUx};lHhj=T3B$Rp-UD6d=!@sDP%>&}QJTXR5 z-Phi(oz3ER%{;2aOVJ(>-MiyW(9`&rFO?SsWqTEs*K3-oWf#U$!PvWy&gxKzOw z&m2-krl9OBGl!H4dFuxHo_l`y+v0|fci*HtF~EyTqY&Nwr2xB-?BNGM0U^M>9R@*T zSTRCjy!=QwwDN#HuL{Z&ibkW*?qDRu69I-oy-{Gu?gFEb-b4(>1L*;Uq0`-kE%{)m z^fF=9pVO}j8;L-`Ftj}kjzway5M;Wk23Q)rhc SL~j5Bj(`GGRZXqU0RI88|K<|_ diff --git a/statistics/exercises/exercises01.tex b/statistics/exercises/exercises01.tex index 68455b3..22f1131 100644 --- a/statistics/exercises/exercises01.tex +++ b/statistics/exercises/exercises01.tex @@ -15,7 +15,7 @@ \else \newcommand{\stitle}{} \fi -\header{{\bfseries\large Exercise 8\stitle}}{{\bfseries\large Statistics}}{{\bfseries\large December 2nd, 2019}} +\header{{\bfseries\large Exercise 7\stitle}}{{\bfseries\large Statistics}}{{\bfseries\large December 8th, 2020}} \firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: jan.benda@uni-tuebingen.de} \runningfooter{}{\thepage}{} @@ -97,12 +97,13 @@ jan.benda@uni-tuebingen.de} \item Initially test computationally expensive \code{for} loops, vectors, matrices, etc. with small numbers of repetitions and/or sizes. Once it is working use large repetitions and/or sizes for - getting a good statistics. + getting a good statistics, i.e. smooth curves. \item Use the help functions of \code{matlab} (\code{help command} or \code{doc command}) and the internet to figure out how specific \code{matlab} functions are used and what features they offer. In addition, the internet offers a lot of material and suggestions for any question you have regarding your code ! +\item Work in groups! Nevertheless everybody should write down his/her own solution. \item Please upload your solution to the exercises to ILIAS as a zip-archive with the name ``statistics\_\{last name\}\_\{first name\}.zip''. \end{itemize} diff --git a/statistics/lecture/diehistograms.py b/statistics/lecture/diehistograms.py index 2458412..241bde7 100644 --- a/statistics/lecture/diehistograms.py +++ b/statistics/lecture/diehistograms.py @@ -15,7 +15,7 @@ ax1.set_xticks(range(1, 7)) ax1.set_xlabel('x') ax1.set_ylim(0, 98) ax1.set_ylabel('Frequency') -fs = fsC +fs = dict(**fsC) fs['color'] = [fsC['facecolor'], fsE['facecolor']] del fs['facecolor'] ax1.hist([x2, x1], bins, **fs) @@ -26,9 +26,11 @@ ax2.set_xlabel('x') ax2.set_ylim(0, 0.23) ax2.set_ylabel('Probability') ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=-10, **lsAm) -if mpl_major > 1: - ax2.hist([x2, x1], bins, density=True, zorder=-5, **fs) -else: - ax2.hist([x2, x1], bins, normed=True, zorder=-5, **fs) +h1, b1 = np.histogram(x1, bins) +h2, b2 = np.histogram(x2, bins) +h1 = h1/np.sum(h1) +h2 = h2/np.sum(h2) +ax2.bar(b1[:-1]+0.3, h1, zorder=-5, width=0.4, **fsC) +ax2.bar(b2[:-1]+0.7, h2, zorder=-5, width=0.4, **fsE) fig.subplots_adjust(left=0.125) fig.savefig('diehistograms.pdf') From e1c6c32db0157894cc2208f6ef1e46efe72fd8c8 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 7 Dec 2020 19:53:13 +0100 Subject: [PATCH 02/37] [statistics] imporved code style --- header.tex | 2 +- plotstyle.py | 2 +- statistics/code/checkmymedian.m | 12 ++++---- statistics/code/correlations.m | 6 ++-- statistics/code/cumulative.m | 2 +- statistics/code/diehistograms.m | 2 +- statistics/code/gaussianpdf.m | 8 +++--- statistics/code/histogramquartiles.m | 20 ++++++------- statistics/code/quartiles.m | 22 +++++++-------- statistics/code/rollthedie.m | 4 +-- statistics/code/sprintfexamples.m | 42 ++++++++++++++-------------- 11 files changed, 61 insertions(+), 61 deletions(-) diff --git a/header.tex b/header.tex index 29f6ba8..4e98c6b 100644 --- a/header.tex +++ b/header.tex @@ -304,7 +304,7 @@ % \newboolean{showexercisesolutions} \setboolean{showexercisesolutions}{true} -\newcommand{\exercisesolutions}{end} % 0: here, 1: chapter, 2: end +\newcommand{\exercisesolutions}{here} % 0: here, 1: chapter, 2: end % we need this also as numbers: \ifthenelse{\equal{\exercisesolutions}{end}}{\newcommand{\exercisesolutionsnum}{2}}{% \ifthenelse{\equal{\exercisesolutions}{chapter}}{\newcommand{\exercisesolutionsnum}{1}}{% diff --git a/plotstyle.py b/plotstyle.py index 7e3ba8c..cb453f3 100644 --- a/plotstyle.py +++ b/plotstyle.py @@ -43,7 +43,7 @@ filllw = 1.0 fillec = colors['white'] fillalpha = 0.4 filledge = {'linewidth': filllw, 'joinstyle': 'round'} -if int(mpl.__version__.split('.')[0]) < 2: +if mpl_major < 2: del filledge['joinstyle'] # helper lines: diff --git a/statistics/code/checkmymedian.m b/statistics/code/checkmymedian.m index d2d101d..31c7e1a 100644 --- a/statistics/code/checkmymedian.m +++ b/statistics/code/checkmymedian.m @@ -1,11 +1,11 @@ % check whether the median returned by mymedian % really separates a vector into two halfs -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 - if length( a(a>m) ) ~= length( a(am)) ~= length(a(a=x1)&(x=x1)&(r=q(1)) & (b=q(1)) & (b=q(2)) & (b=q(2)) & (b=q(3)), h(b>=q(3)), 'FaceColor', [0.5 0 0.5] ); +bar(b(b=q(1)) & (b=q(1)) & (b=q(2)) & (b=q(2)) & (b=q(3)), h(b>=q(3)), 'FaceColor', [0.5 0 0.5]); hold off; diff --git a/statistics/code/quartiles.m b/statistics/code/quartiles.m index 8123733..d78a8db 100644 --- a/statistics/code/quartiles.m +++ b/statistics/code/quartiles.m @@ -1,16 +1,16 @@ -function q = quartiles( x ) +function q = quartiles(x) % returns a vector with the first, second, and third quartile % of the vector x - xs = sort( x ); - if ( length( xs ) == 0 ) % no data + xs = sort(x); + if (length(xs) == 0) % no data q = []; - elseif ( rem( length( xs ), 2 ) == 0 ) % even number of data - index = length( xs )/2; - m = (xs( index ) + xs( index+1 ))/2; - q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ]; - else % odd number of data - index = (length( xs ) + 1)/2; - m = xs( index ); - q = [ round( xs(length(xs)/4) ), m, xs(round(3*length(xs)/4)) ]; + elseif (rem(length(xs), 2) == 0) % even number of data + index = length(xs)/2; + m = (xs(index) + xs(index+1))/2; + q = [round(xs(length(xs)/4)), m, xs(round(3*length(xs)/4))]; + else % odd number of data + index = (length(xs) + 1)/2; + m = xs(index); + q = [round(xs(length(xs)/4)), m, xs(round(3*length(xs)/4))]; end end diff --git a/statistics/code/rollthedie.m b/statistics/code/rollthedie.m index 1842da8..1eeefc6 100644 --- a/statistics/code/rollthedie.m +++ b/statistics/code/rollthedie.m @@ -1,4 +1,4 @@ -function x = rollthedie( n ) +function x = rollthedie(n) % return a vector with the result of rolling a die n times - x = randi( [1, 6], n, 1 ); + x = randi([1, 6], n, 1); end diff --git a/statistics/code/sprintfexamples.m b/statistics/code/sprintfexamples.m index b8f6b75..b08a5c2 100644 --- a/statistics/code/sprintfexamples.m +++ b/statistics/code/sprintfexamples.m @@ -1,48 +1,48 @@ % sprintf returns a string. % This string can be used to annotate plots using the text() function. -s = sprintf( 'x=%f', pi ) +s = sprintf('x=%f', pi) % fprintf writes directly to console (or into files). % for fprintf you usually want to add the line break '\n': % '%f' formats floating point numbers: -fprintf( 'x=%f\n', pi ) +fprintf('x=%f\n', pi) % The '%f' formatting string can be anywhere in the string: -fprintf( 'x=%fms\n', pi ) +fprintf('x=%fms\n', pi) % There can be arbitrary many '%' formatting strings: -fprintf( 'x=%fms, y=%fkHz\n', pi, 2*pi ) +fprintf('x=%fms, y=%fkHz\n', pi, 2*pi) % The '%' itself is generated by '%%': -fprintf( 'x=%f%%\n', pi ) +fprintf('x=%f%%\n', pi) % A point followed by a number sets the number of digits after the point: -fprintf( 'x=%.2fms\n', pi ) +fprintf('x=%.2fms\n', pi) % The numbers are appropriately rounded: -fprintf( 'x=%.3fms\n', pi ) +fprintf('x=%.3fms\n', pi) % A number right before the point sets the width of the generated output: -fprintf( 'x=%10.3fms\n', pi ) +fprintf('x=%10.3fms\n', pi) % '%e' also formats floating point numbers but forces to write in % exponential style: -fprintf( 'x=%e\n', pi ) +fprintf('x=%e\n', pi) % again, a point and number set the number of digits after the point. -fprintf( 'x=%.1e\n', pi ) +fprintf('x=%.1e\n', pi) % '%g% formats the floating point number to a given number of valid digits % (default is 5): -fprintf( 'x=%g\n', pi ) +fprintf('x=%g\n', pi) % The number of valid digits is not the number of digits after the point: -fprintf( 'x=%.2g\n', pi ) -fprintf( 'x=%.2g\n', 10.123 ) -fprintf( 'x=%.2g\n', 18765.123 ) -fprintf( 'x=%.5g\n', 18765.123 ) +fprintf('x=%.2g\n', pi) +fprintf('x=%.2g\n', 10.123) +fprintf('x=%.2g\n', 18765.123) +fprintf('x=%.5g\n', 18765.123) % '%d' formats integers: -fprintf( 'x=%d\n', 5 ) +fprintf('x=%d\n', 5) % the number defines the width of the output: -fprintf( 'x=%3d\n', 5 ) +fprintf('x=%3d\n', 5) % precedig the width with a '0' fills up the space with leading zeros: -fprintf( 'x=%03d\n', 5 ) +fprintf('x=%03d\n', 5) % '%s' formats a string: -fprintf( 'x=%s\n', 'hallo' ) +fprintf('x=%s\n', 'hallo') % ... aligned to the right: -fprintf( 'x=%10s\n', 'hallo' ) +fprintf('x=%10s\n', 'hallo') % ... unless the width is negative: -fprintf( 'x=%-10s!\n', 'hallo' ) +fprintf('x=%-10s!\n', 'hallo') From 430bdfb7fd63f4c4559591ace600ccb2ac87bf96 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 7 Dec 2020 22:37:36 +0100 Subject: [PATCH 03/37] [bootstrap] improved code --- bootstrap/code/bootstrapsem.m | 29 ++++++++++++------------ bootstrap/code/correlationsignificance.m | 10 ++++---- statistics/code/correlations.m | 2 +- statistics/code/gaussiankerneldensity.m | 26 ++++++++++----------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/bootstrap/code/bootstrapsem.m b/bootstrap/code/bootstrapsem.m index 18ebae3..f496071 100644 --- a/bootstrap/code/bootstrapsem.m +++ b/bootstrap/code/bootstrapsem.m @@ -1,24 +1,25 @@ nsamples = 100; nresamples = 1000; -% draw a SRS (simple random sample, "Stichprobe") from the population: -x = randn( 1, nsamples ); -fprintf('%-30s %-5s %-5s %-5s\n', '', 'mean', 'stdev', 'sem' ) -fprintf('%30s %5.2f %5.2f %5.2f\n', 'single SRS', mean( x ), std( x ), std( x )/sqrt(nsamples) ) +% draw a simple random sample ("Stichprobe") from the population: +x = randn(1, nsamples); +fprintf('%-30s %-5s %-5s %-5s\n', '', 'mean', 'stdev', 'sem') +fprintf('%30s %5.2f %5.2f %5.2f\n', 'single SRS', mean(x), std(x), std(x)/sqrt(nsamples)) % bootstrap the mean: -mus = zeros(nresamples,1); % vector for storing the means -for i = 1:nresamples % loop for generating the bootstraps +mus = zeros(nresamples,1); % vector for storing the means +for i = 1:nresamples % loop for generating the bootstraps inx = randi(nsamples, 1, nsamples); % range, 1D-vector, number - xr = x(inx); % resample the original SRS - mus(i) = mean(xr); % compute statistic of the resampled SRS + xr = x(inx); % resample the original SRS + mus(i) = mean(xr); % compute statistic of the resampled SRS end -fprintf('%30s %5.2f %5.2f -\n', 'bootstrapped distribution', mean( mus ), std( mus ) ) +fprintf('%30s %5.2f %5.2f -\n', 'bootstrapped distribution', mean(mus), std(mus)) -% many SRS (we can do that with the random number generator, but not in real life!): -musrs = zeros(nresamples,1); % vector for the means of each SRS +% many SRS (we can do that with the random number generator, +% but not in real life!): +musrs = zeros(nresamples,1); % vector for the means of each SRS for i = 1:nresamples - x = randn( 1, nsamples ); % draw a new SRS - musrs(i) = mean( x ); % compute its mean + x = randn(1, nsamples); % draw a new SRS + musrs(i) = mean(x); % compute its mean end -fprintf('%30s %5.2f %5.2f -\n', 'sampling distribution', mean( musrs ), std( musrs ) ) +fprintf('%30s %5.2f %5.2f -\n', 'sampling distribution', mean(musrs), std(musrs)) diff --git a/bootstrap/code/correlationsignificance.m b/bootstrap/code/correlationsignificance.m index f5ccb1c..d9b0fff 100644 --- a/bootstrap/code/correlationsignificance.m +++ b/bootstrap/code/correlationsignificance.m @@ -6,7 +6,7 @@ y = randn(n, 1) + a*x; % correlation coefficient: rd = corr(x, y); -fprintf('correlation coefficient of data r = %.2f\n', rd ); +fprintf('correlation coefficient of data r = %.2f\n', rd); % distribution of null hypothesis by permutation: nperm = 1000; @@ -16,12 +16,12 @@ for i=1:nperm yr=y(randperm(length(y))); % shuffle y rs(i) = corr(xr, yr); end -[h,b] = hist(rs, 20 ); -h = h/sum(h)/(b(2)-b(1)); % normalization +[h,b] = hist(rs, 20); +h = h/sum(h)/(b(2)-b(1)); % normalization % significance: rq = quantile(rs, 0.95); -fprintf('correlation coefficient of null hypothesis at 5%% significance = %.2f\n', rq ); +fprintf('correlation coefficient of null hypothesis at 5%% significance = %.2f\n', rq); if rd >= rq fprintf('--> correlation r=%.2f is significant\n', rd); else @@ -32,7 +32,7 @@ end bar(b, h, 'facecolor', 'b'); hold on; bar(b(b>=rq), h(b>=rq), 'facecolor', 'r'); -plot( [rd rd], [0 4], 'r', 'linewidth', 2 ); +plot([rd rd], [0 4], 'r', 'linewidth', 2); xlabel('Correlation coefficient'); ylabel('Probability density of H0'); hold off; diff --git a/statistics/code/correlations.m b/statistics/code/correlations.m index 9be872c..e6eb0b7 100644 --- a/statistics/code/correlations.m +++ b/statistics/code/correlations.m @@ -3,7 +3,7 @@ corrs = [1.0, 0.6, 0.0, -0.9]; for k = [1:length(corrs)] r = corrs(k); x = randn(n, 1); - y = r*x; % linear dependence of y on x + y = r*x; % linear dependence of y on x % add noise to destroy perfect correlations: y = y + sqrt(1.0-r*r)*randn(n, 1); % compute correlation coefficient of data: diff --git a/statistics/code/gaussiankerneldensity.m b/statistics/code/gaussiankerneldensity.m index 8f97818..b01a1c2 100644 --- a/statistics/code/gaussiankerneldensity.m +++ b/statistics/code/gaussiankerneldensity.m @@ -1,15 +1,15 @@ -data = randn(100, 1); % generate some data -sigma = 0.2; % std. dev. of Gaussian kernel -xmin = -4.0; % minimum x value for kernel density -xmax = 4.0; % maximum x value for kernel density -dx = 0.05*sigma; % step size for kernel density -xg = [-4.0*sigma:dx:4.0*sigma]; % x-axis for single Gaussian kernel +data = randn(100, 1); % generate some data +sigma = 0.2; % std. dev. of Gaussian kernel +xmin = -4.0; % minimum x value for kernel density +xmax = 4.0; % maximum x value for kernel density +dx = 0.05*sigma; % step size for kernel density +xg = [-4.0*sigma:dx:4.0*sigma]; % x-axis for single Gaussian kernel % single Gaussian kernel: kernel = exp(-0.5*(xg/sigma).^2)/sqrt(2.0*pi)/sigma; ng = floor((length(kernel)-1)/2); % half the length of the Gaussian -x = [xmin:dx:xmax+0.5*dx]; % x-axis for kernel density -kd = zeros(1, length(x)); % vector for kernel density -for i = 1:length(data) % for every data value ... +x = [xmin:dx:xmax+0.5*dx]; % x-axis for kernel density +kd = zeros(1, length(x)); % vector for kernel density +for i = 1:length(data) % for every data value ... xd = data(i); % index of data value in kernel density vector: inx = round((xd-xmin)/dx)+1; @@ -17,8 +17,8 @@ for i = 1:length(data) % for every data value ... k0 = inx-ng; % end index for Gaussian in kernel density vector: k1 = inx+ng; - g0 = 1; % start index in Gaussian - g1 = length(kernel); % end index in Gaussian + g0 = 1; % start index in Gaussian + g1 = length(kernel); % end index in Gaussian % check whether left side of Gaussian extends below xmin: if inx < ng+1 % adjust start indices accordingly: @@ -34,7 +34,7 @@ for i = 1:length(data) % for every data value ... % add Gaussian on kernel density: kd(k0:k1) = kd(k0:k1) + kernel(g0:g1); end -kd = kd/length(data); % normalize by number of data points +kd = kd/length(data); % normalize by number of data points % plot the computed kernel density: plot(x, kd, 'b', 'linewidth', 4, 'displayname', 'manual') @@ -45,4 +45,4 @@ plot(x, kd, '--r', 'linewidth', 4, 'displayname', 'ksdensity()') hold off xlabel('x') ylabel('Probability density') -legend('show') \ No newline at end of file +legend('show') From e2f026c53f0cea2b5b1b67f5a3e865a3d52be3c7 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 7 Dec 2020 22:51:10 +0100 Subject: [PATCH 04/37] [pointprocesses] improved code --- pointprocesses/code/binnedRate.m | 2 +- pointprocesses/code/convolutionRate.m | 17 +++++---- pointprocesses/code/counthist.m | 6 ++-- pointprocesses/code/instantaneousRate.m | 2 +- pointprocesses/code/isihist.m | 2 +- pointprocesses/code/rasterplot.m | 36 +++++++++---------- .../lecture/pointprocesses-chapter.tex | 4 +-- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/pointprocesses/code/binnedRate.m b/pointprocesses/code/binnedRate.m index e34366c..cf9ad65 100644 --- a/pointprocesses/code/binnedRate.m +++ b/pointprocesses/code/binnedRate.m @@ -18,7 +18,7 @@ function [time, rate] = binned_rate(spikes, bin_width, dt, t_max) rate = zeros(size(time)); h = hist(spikes, bins) ./ bin_width; for i = 2:length(bins) - rate(round(bins(i - 1) / dt) + 1:round(bins(i) / dt)) = h(i); + rate(round(bins(i-1)/dt) + 1:round(bins(i)/dt)) = h(i); end end diff --git a/pointprocesses/code/convolutionRate.m b/pointprocesses/code/convolutionRate.m index a2b1344..4fe5bb8 100644 --- a/pointprocesses/code/convolutionRate.m +++ b/pointprocesses/code/convolutionRate.m @@ -10,19 +10,18 @@ function [time, rate] = convolution_rate(spikes, sigma, dt, t_max) % t_max : the trial duration in seconds. % % Returns: - two vectors containing the time and the rate. +% two vectors containing the time and the rate. -time = 0:dt:t_max - dt; -rate = zeros(size(time)); -spike_indices = round(spikes / dt); -rate(spike_indices) = 1; -kernel = gaussKernel(sigma, dt); - -rate = conv(rate, kernel, 'same'); + time = 0:dt:t_max - dt; + rate = zeros(size(time)); + spike_indices = round(spikes / dt); + rate(spike_indices) = 1; + kernel = gaussKernel(sigma, dt); + rate = conv(rate, kernel, 'same'); end function y = gaussKernel(s, step) x = -4 * s:step:4 * s; - y = exp(-0.5 .* (x ./ s) .^ 2) ./ sqrt(2 * pi) / s; + y = exp(-0.5 .* (x ./ s).^ 2) ./ sqrt(2 * pi) / s; end diff --git a/pointprocesses/code/counthist.m b/pointprocesses/code/counthist.m index 6885b1a..67b4cae 100644 --- a/pointprocesses/code/counthist.m +++ b/pointprocesses/code/counthist.m @@ -37,8 +37,8 @@ function [counts, bins] = counthist(spikes, w) % plot: if nargout == 0 - bar( bins, counts ); - xlabel( 'counts k' ); - ylabel( 'P(k)' ); + bar(bins, counts); + xlabel('counts k'); + ylabel('P(k)'); end end diff --git a/pointprocesses/code/instantaneousRate.m b/pointprocesses/code/instantaneousRate.m index 8928c31..da8ee29 100644 --- a/pointprocesses/code/instantaneousRate.m +++ b/pointprocesses/code/instantaneousRate.m @@ -19,6 +19,6 @@ function [time, rate] = instantaneous_rate(spikes, dt, t_max) spike_indices = [1 round(spikes ./ dt)]; for i = 2:length(spike_indices) - rate(spike_indices(i - 1):spike_indices(i)) = inst_rate(i - 1); + rate(spike_indices(i-1):spike_indices(i)) = inst_rate(i-1); end end diff --git a/pointprocesses/code/isihist.m b/pointprocesses/code/isihist.m index 33ad4f5..00b02c3 100644 --- a/pointprocesses/code/isihist.m +++ b/pointprocesses/code/isihist.m @@ -13,7 +13,7 @@ function [pdf, centers] = isihist(isis, binwidth) if nargin < 2 % compute good binwidth: - nperbin = 200; % average number of data points per bin + nperbin = 200; % average number of data points per bin bins = length(isis)/nperbin; % number of bins binwidth = max(isis)/bins; if binwidth < 5e-4 % half a millisecond diff --git a/pointprocesses/code/rasterplot.m b/pointprocesses/code/rasterplot.m index 0bcdb8d..7b28820 100644 --- a/pointprocesses/code/rasterplot.m +++ b/pointprocesses/code/rasterplot.m @@ -5,25 +5,25 @@ function rasterplot(spikes, tmax) % spikes: a cell array of vectors of spike times in seconds % tmax: plot spike raster upto tmax seconds -ntrials = length(spikes); -for k = 1:ntrials - times = spikes{k}; - times = times(times Date: Tue, 8 Dec 2020 11:48:07 +0100 Subject: [PATCH 05/37] [bootstrap] notes on how to extend the permutation tests --- bootstrap/lecture/bootstrap-chapter.tex | 7 ++++++- bootstrap/lecture/bootstrap.tex | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bootstrap/lecture/bootstrap-chapter.tex b/bootstrap/lecture/bootstrap-chapter.tex index 845b6b1..b61d395 100644 --- a/bootstrap/lecture/bootstrap-chapter.tex +++ b/bootstrap/lecture/bootstrap-chapter.tex @@ -17,10 +17,15 @@ \include{bootstrap} \section{TODO} + This chapter easily covers two lectures: \begin{itemize} \item 1. Bootstrapping with a proper introduction of of confidence intervals -\item 2. Permutation test with a proper introduction of statistical tests (dsitribution of nullhypothesis, significance, power, etc.) +\item 2. Permutation test with a proper introduction of statistical tests (distribution of nullhypothesis, significance, power, etc.) \end{itemize} +Add jacknife methods to bootstrapping + +Add permutation test for significant different means of two distributions. + \end{document} diff --git a/bootstrap/lecture/bootstrap.tex b/bootstrap/lecture/bootstrap.tex index 667c833..20f01c2 100644 --- a/bootstrap/lecture/bootstrap.tex +++ b/bootstrap/lecture/bootstrap.tex @@ -1,8 +1,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\chapter{Bootstrap methods} +\chapter{Resampling methods} \label{bootstrapchapter} -\exercisechapter{Bootstrap methods} +\exercisechapter{Resampling methods} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Bootstrapping} Bootstrapping methods are applied to create distributions of statistical measures via resampling of a sample. Bootstrapping offers several @@ -94,7 +98,8 @@ sample. This can be implemented by generating random indices into the data set using the \code{randi()} function. -\section{Bootstrap of the standard error} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{Bootstrap of the standard error} Bootstrapping can be nicely illustrated at the example of the \enterm{standard error} of the mean (\determ{Standardfehler}). The @@ -138,7 +143,9 @@ distribution is the standard error of the mean. \end{exercise} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Permutation tests} + Statistical tests ask for the probability of a measured value to originate from a null hypothesis. Is this probability smaller than the desired \entermde{Signifikanz}{significance level}, the @@ -166,6 +173,12 @@ while we conserve all other statistical properties of the data. statistically significant.} \end{figure} +%\subsection{Significance of a difference in the mean} + +%See \url{https://en.wikipedia.org/wiki/Resampling_(statistics)#Permutation_tests.} + +\subsection{Significance of correlations} + A good example for the application of a \entermde{Permutationstest}{permutaion test} is the statistical assessment of \entermde[correlation]{Korrelation}{correlations}. Given From 0e30a01a45f0cf232ba86da6b1b3b3ef4a41db01 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Fri, 11 Dec 2020 23:22:40 +0100 Subject: [PATCH 06/37] fixed page breaking of code and exercises --- codestyle/lecture/codestyle.tex | 15 +- debugging/lecture/debugging.tex | 36 +- designpattern/lecture/designpattern.tex | 69 ++-- header.tex | 42 +- plotting/lecture/plotting-chapter.tex | 2 +- plotting/lecture/plotting.tex | 27 +- .../lecture/pointprocessscetchA.eps | 120 ++---- .../lecture/pointprocessscetchA.pdf | Bin 2924 -> 2786 bytes .../lecture/pointprocessscetchB.eps | 389 ++++++------------ .../lecture/pointprocessscetchB.pdf | Bin 4877 -> 4694 bytes programming/code/vectorsize.m | 9 +- programming/code/vectorsize.out | 6 +- programming/lecture/programming.tex | 181 ++++---- 13 files changed, 360 insertions(+), 536 deletions(-) diff --git a/codestyle/lecture/codestyle.tex b/codestyle/lecture/codestyle.tex index 42f7429..01d1d12 100644 --- a/codestyle/lecture/codestyle.tex +++ b/codestyle/lecture/codestyle.tex @@ -204,7 +204,7 @@ random walk\footnote{A random walk is a simple simulation of Brownian (listing \ref{chaoticcode}) then in cleaner way (listing \ref{cleancode}) -\begin{lstlisting}[label=chaoticcode, caption={Chaotic implementation of the random-walk.}] +\begin{pagelisting}[label=chaoticcode, caption={Chaotic implementation of the random-walk.}] num_runs = 10; max_steps = 1000; positions = zeros(max_steps, num_runs); @@ -217,18 +217,15 @@ for step = 2:max_steps x = randn(1); if x<0 positions(step, run)= positions(step-1, run)+1; - elseif x>0 positions(step,run)=positions(step-1,run)-1; end end end -\end{lstlisting} - -\pagebreak[4] +\end{pagelisting} -\begin{lstlisting}[label=cleancode, caption={Clean implementation of the random-walk.}] +\begin{pagelisting}[label=cleancode, caption={Clean implementation of the random-walk.}] num_runs = 10; max_steps = 1000; positions = zeros(max_steps, num_runs); @@ -243,7 +240,7 @@ for run = 1:num_runs end end end -\end{lstlisting} +\end{pagelisting} \section{Using comments} @@ -275,7 +272,6 @@ avoided:\\ \varcode{ x = x + 2; \% add two to x}\\ make it even clearer.}{Steve McConnell} \end{important} -\pagebreak[4] \section{Documenting functions} All pre-defined \matlab{} functions begin with a comment block that describes the purpose of the function, the required and optional @@ -335,8 +331,7 @@ used within the context of another function \matlab{} allows to define within the same file. Listing \ref{localfunctions} shows an example of a local function definition. -\pagebreak[3] -\lstinputlisting[label=localfunctions, caption={Example for local +\pageinputlisting[label=localfunctions, caption={Example for local functions.}]{calculateSines.m} \emph{Local function} live in the same \entermde{m-File}{m-file} as diff --git a/debugging/lecture/debugging.tex b/debugging/lecture/debugging.tex index 6be3277..b83c24e 100644 --- a/debugging/lecture/debugging.tex +++ b/debugging/lecture/debugging.tex @@ -59,14 +59,14 @@ every opening parenthesis must be matched by a closing one or every respective error messages are clear and the editor will point out and highlight most syntax errors. -\begin{lstlisting}[label=syntaxerror, caption={Unbalanced parenthesis error.}] +\begin{pagelisting}[label=syntaxerror, caption={Unbalanced parenthesis error.}] >> mean(random_numbers | Error: Expression or statement is incorrect--possibly unbalanced (, {, or [. Did you mean: >> mean(random_numbers) -\end{lstlisting} +\end{pagelisting} \subsection{Indexing error}\label{index_error} Second on the list of common errors are the @@ -125,7 +125,7 @@ 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.}] +\begin{pagelisting}[label=assignmenterror, caption={Assignment errors.}] >> a = zeros(1, 100); >> b = 0:10; @@ -136,7 +136,7 @@ outside its bounds. >> size(a) ans = 110 1 -\end{lstlisting} +\end{pagelisting} \subsection{Dimension mismatch error} Similarly, some arithmetic operations are only valid if the variables @@ -154,7 +154,7 @@ in listing\,\ref{dimensionmismatch} does not throw an error but the result is something else than the expected elementwise multiplication. % XXX Some arithmetic operations make size constraints, violating them leads to dimension mismatch errors. -\begin{lstlisting}[label=dimensionmismatch, caption={Dimension mismatch errors.}] +\begin{pagelisting}[label=dimensionmismatch, caption={Dimension mismatch errors.}] >> a = randn(100, 1); >> b = randn(10, 1); >> a + b @@ -171,7 +171,7 @@ result is something else than the expected elementwise multiplication. >> size(c) ans = 100 10 -\end{lstlisting} +\end{pagelisting} @@ -239,7 +239,7 @@ but it requires a deep understanding of the applied functions and also the task at hand. % XXX Converting a series of spike times into the firing rate as a function of time. Many tasks can be solved with a single line of code. But is this readable? -\begin{lstlisting}[label=easyvscomplicated, caption={One-liner versus readable code.}] +\begin{pagelisting}[label=easyvscomplicated, caption={One-liner versus readable code.}] % the one-liner rate = conv(full(sparse(1, round(spike_times/dt), 1, 1, length(time))), kernel, 'same'); @@ -248,7 +248,7 @@ rate = zeros(size(time)); spike_indices = round(spike_times/dt); rate(spike_indices) = 1; rate = conv(rate, kernel, 'same'); -\end{lstlisting} +\end{pagelisting} The preferred way depends on several considerations. (i) How deep is your personal understanding of the programming language? (ii) What @@ -291,7 +291,7 @@ example given in the \matlab{} help and assume that there is a function \varcode{rightTriangle()} (listing\,\ref{trianglelisting}). % XXX Slightly more readable version of the example given in the \matlab{} help system. Note: The variable name for the angles have been capitalized in order to not override the matlab defined functions \code{alpha, beta,} and \code{gamma}. -\begin{lstlisting}[label=trianglelisting, caption={Example function for unit testing.}] +\begin{pagelisting}[label=trianglelisting, caption={Example function for unit testing.}] function angles = rightTriangle(length_a, length_b) ALPHA = atand(length_a / length_b); BETA = atand(length_a / length_b); @@ -300,7 +300,7 @@ function angles = rightTriangle(length_a, length_b) angles = [ALPHA BETA GAMMA]; end -\end{lstlisting} +\end{pagelisting} This function expects two input arguments that are the length of the sides $a$ and $b$ and assumes a right angle between them. From this @@ -337,7 +337,7 @@ The test script for the \varcode{rightTriangle()} function (listing\,\ref{trianglelisting}) may look like in listing\,\ref{testscript}. -\begin{lstlisting}[label=testscript, caption={Unit test for the \varcode{rightTriangle()} function stored in an m-file testRightTriangle.m}] +\begin{pagelisting}[label=testscript, caption={Unit test for the \varcode{rightTriangle()} function stored in an m-file testRightTriangle.m}] tolerance = 1e-10; % preconditions @@ -373,7 +373,7 @@ angles = rightTriangle(1, 1500); smallAngle = (pi / 180) * angles(1); % radians approx = sin(smallAngle); assert(abs(approx - smallAngle) <= tolerance, 'Problem with small angle approximation') -\end{lstlisting} +\end{pagelisting} In a test script we can execute any code. The actual test whether or not the results match our predictions is done using the @@ -390,16 +390,16 @@ executed. We further define a \varcode{tolerance} variable that is used when comparing double values (Why might the test on equality of double values be tricky?). -\begin{lstlisting}[label=runtestlisting, caption={Run the test!}] +\begin{pagelisting}[label=runtestlisting, caption={Run the test!}] result = runtests('testRightTriangle') -\end{lstlisting} +\end{pagelisting} During the run, \matlab{} will put out error messages onto the command line and a summary of the test results is then stored within the \varcode{result} variable. These can be displayed using the function \code[table()]{table(result)}. -\begin{lstlisting}[label=testresults, caption={The test results.}, basicstyle=\ttfamily\scriptsize] +\begin{pagelisting}[label=testresults, caption={The test results.}, basicstyle=\ttfamily\scriptsize] table(result) ans = 4x6 table @@ -411,7 +411,7 @@ _________________________________ ______ ______ ___________ ________ _____ 'testR.../Test_IsoscelesTriangles' true false false 0.004893 [1x1 struct] 'testR.../Test_30_60_90Triangle' true false false 0.005057 [1x1 struct] 'testR.../Test_SmallAngleApprox' true false false 0.0049 [1x1 struct] -\end{lstlisting} +\end{pagelisting} So far so good, all tests pass and our function appears to do what it is supposed to do. But tests are only as good as the programmer who @@ -479,11 +479,11 @@ stopped in debug mode (listing\,\ref{debuggerlisting}). \end{figure} -\begin{lstlisting}[label=debuggerlisting, caption={Command line when the program execution was stopped in the debugger.}] +\begin{pagelisting}[label=debuggerlisting, caption={Command line when the program execution was stopped in the debugger.}] >> simplerandomwalk 6 for run = 1:num_runs K>> -\end{lstlisting} +\end{pagelisting} When stopped in the debugger we can view and change the state of the program at this point, we can also issue commands to try the next diff --git a/designpattern/lecture/designpattern.tex b/designpattern/lecture/designpattern.tex index 1fb191d..5baada5 100644 --- a/designpattern/lecture/designpattern.tex +++ b/designpattern/lecture/designpattern.tex @@ -10,7 +10,8 @@ pattern]{design pattern}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Looping over vector elements} Iterating over vector elements by means of a \mcode{for}-loop is a very commen pattern: -\begin{lstlisting}[caption={\varcode{for}-loop for accessing vector elements by indices}] + +\begin{pagelisting}[caption={\varcode{for}-loop for accessing vector elements by indices}] x = [2:3:20]; % Some vector. for i=1:length(x) % For loop over the indices of the vector. i % This is the index (an integer number) @@ -22,12 +23,14 @@ for i=1:length(x) % For loop over the indices of the vector. % as an argument to a function: do_something(x(i)); end -\end{lstlisting} +\end{pagelisting} +\noindent If the result of the computation within the loop are single numbers that are to be stored in a vector, you should create this vector with the right size before the loop: -\begin{lstlisting}[caption={\varcode{for}-loop for writing a vector}] + +\begin{pagelisting}[caption={\varcode{for}-loop for writing a vector}] x = [1.2 2.3 2.6 3.1]; % Some vector. % Create a vector for the results, as long as the number of loops: y = zeros(length(x),1); @@ -38,13 +41,15 @@ for i=1:length(x) end % Now the result vector can be further processed: mean(y); -\end{lstlisting} +\end{pagelisting} +\noindent The computation within the loop could also result in a vector of some length and not just a single number. If the length of this vector (here 10) is known beforehand, then you should create a matrix of appropriate size for storing the results: -\begin{lstlisting}[caption={\varcode{for}-loop for writing rows of a matrix}] + +\begin{pagelisting}[caption={\varcode{for}-loop for writing rows of a matrix}] x = [2:3:20]; % Some vector. % Create space for results - % as many rows as loops, as many columns as needed: @@ -56,11 +61,13 @@ for i=1:length(x) end % Process the results stored in matrix y: mean(y, 1) -\end{lstlisting} +\end{pagelisting} +\noindent Another possibility is that the result vectors (here of unknown size) need to be combined into a single large vector: -\begin{lstlisting}[caption={\varcode{for}-loop for appending vectors}] + +\begin{pagelisting}[caption={\varcode{for}-loop for appending vectors}] x = [2:3:20]; % Some vector. y = []; % Empty vector for storing the results. for i=1:length(x) @@ -72,14 +79,15 @@ for i=1:length(x) end % Process the results stored in the vector z: mean(y) -\end{lstlisting} +\end{pagelisting} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Scaling and shifting random numbers, zeros, and ones} Random number generators usually return random numbers of a given mean and standard deviation. Multiply those numbers by a factor to change their standard deviation and add a number to shift the mean. -\begin{lstlisting}[caption={Scaling and shifting of random numbers}] + +\begin{pagelisting}[caption={Scaling and shifting of random numbers}] % 100 random numbers drawn from a normal distribution % with mean 0 and standard deviation 1: x = randn(100, 1); @@ -89,18 +97,20 @@ x = randn(100, 1); mu = 4.8; sigma = 2.3; y = randn(100, 1)*sigma + mu; -\end{lstlisting} +\end{pagelisting} +\noindent The same principle can be useful for in the context of the functions \mcode{zeros()} or \mcode{ones()}: -\begin{lstlisting}[caption={Scaling and shifting of \varcode{zeros()} and \varcode{ones()}}] + +\begin{pagelisting}[caption={Scaling and shifting of \varcode{zeros()} and \varcode{ones()}}] x = -1:0.01:2; % Vector of x-values for plotting plot(x, exp(-x.*x)); % Plot for the same x-values a horizontal line with y=0.8: plot(x, zeros(size(x))+0.8); % ... or a line with y=0.5: plot(x, ones(size(x))*0.5); -\end{lstlisting} +\end{pagelisting} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -119,25 +129,26 @@ can plot the values of the $y$ vector against the ones of the $x$ vector. The following scripts compute and plot the function $f(x)=e^{-x^2}$: -\begin{lstlisting}[caption={Plotting a mathematical function --- very detailed}] + +\begin{pagelisting}[caption={Plotting a mathematical function --- very detailed}] xmin = -1.0; xmax = 2.0; dx = 0.01; % Step size x = xmin:dx:xmax; % Vector with x-values. y = exp(-x.*x); % No for loop! '.*' for multiplying the vector elements. plot(x, y); -\end{lstlisting} +\end{pagelisting} -\begin{lstlisting}[caption={Plotting a mathematical function --- shorter}] +\begin{pagelisting}[caption={Plotting a mathematical function --- shorter}] x = -1:0.01:2; y = exp(-x.*x); plot(x, y); -\end{lstlisting} +\end{pagelisting} -\begin{lstlisting}[caption={Plotting a mathematical function --- compact}] +\begin{pagelisting}[caption={Plotting a mathematical function --- compact}] x = -1:0.01:2; plot(x, exp(-x.*x)); -\end{lstlisting} +\end{pagelisting} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -146,28 +157,34 @@ For estimating probabilities or probability densities from histograms we need to normalize them appropriately. The \mcode{histogram()} function does this automatically with the appropriate arguments: -\begin{lstlisting}[caption={Probability density with the \varcode{histogram()}-function}] + +\begin{pagelisting}[caption={Probability density with the \varcode{histogram()}-function}] x = randn(100, 1); % Some real-valued data. histogram(x, 'Normalization', 'pdf'); -\end{lstlisting} -\begin{lstlisting}[caption={Probability with the \varcode{histogram()}-function}] +\end{pagelisting} + +\begin{pagelisting}[caption={Probability with the \varcode{histogram()}-function}] x = randi(6, 100, 1); % Some integer-valued data. histogram(x, 'Normalization', 'probability'); -\end{lstlisting} +\end{pagelisting} + +\noindent Alternatively one can normalize the histogram data as returned by the \code{hist()}-function manually: -\begin{lstlisting}[caption={Probability density with the \varcode{hist()}- and \varcode{bar()}-function}] + +\begin{pagelisting}[caption={Probability density with the \varcode{hist()}- and \varcode{bar()}-function}] x = randn(100, 1); % Some real-valued data. [h, b] = hist(x); % Compute histogram. h = h/sum(h)/(b(2)-b(1)); % Normalization to a probability density. bar(b, h); % Plot the probability density. -\end{lstlisting} -\begin{lstlisting}[caption={Probability with the \varcode{hist()}- and \varcode{bar()}-function}] +\end{pagelisting} + +\begin{pagelisting}[caption={Probability with the \varcode{hist()}- and \varcode{bar()}-function}] x = randi(6, 100, 1); % Some integer-valued data. [h, b] = hist(x); % Compute histogram. h = h/sum(h); % Normalize to probability. bar(b, h); % Plot the probabilities. -\end{lstlisting} +\end{pagelisting} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/header.tex b/header.tex index 4e98c6b..fcaaa87 100644 --- a/header.tex +++ b/header.tex @@ -2,7 +2,7 @@ \title{\textbf{\huge\sffamily\tr{Introduction to\\[1ex] Scientific Computing}% {Einf\"uhrung in die\\[1ex] wissenschaftliche Datenverarbeitung}}} -\author{{\LARGE Jan Grewe \& Jan Benda}\\[5ex]Abteilung Neuroethologie\\[2ex]% +\author{{\LARGE Jan Grewe \& Jan Benda}\\[5ex]Neuroethology Lab\\[2ex]% \includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}\vspace{3ex}} \date{WS 2020/2021\\\vfill% @@ -77,7 +77,7 @@ \setcounter{totalnumber}{2} % float placement fractions: -\renewcommand{\textfraction}{0.2} +\renewcommand{\textfraction}{0.1} \renewcommand{\topfraction}{0.9} \renewcommand{\bottomfraction}{0.0} \renewcommand{\floatpagefraction}{0.7} @@ -209,6 +209,21 @@ \let\l@lstlisting\l@figure \makeatother +% \lstinputlisting wrapped in a minipage to avoid page breaks: +\newcommand{\pageinputlisting}[2][]{\vspace{-2ex}\noindent\begin{minipage}[t]{1\linewidth}\lstinputlisting[#1]{#2}\end{minipage}} + +%%%%% listing environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% usage: +% +% \begin{pagelisting}[label=listing1, caption={A script.}] +% >> x = 6 +% \end{pagelisting} +% +% This is the lstlisting environment but wrapped in a minipage to avoid page breaks. +\lstnewenvironment{pagelisting}[1][]% + {\vspace{-2ex}\lstset{#1}\noindent\minipage[t]{1\linewidth}}% + {\endminipage} + %%%%% english, german, code and file terms: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{ifthen} @@ -304,7 +319,7 @@ % \newboolean{showexercisesolutions} \setboolean{showexercisesolutions}{true} -\newcommand{\exercisesolutions}{here} % 0: here, 1: chapter, 2: end +\newcommand{\exercisesolutions}{chapter} % 0: here, 1: chapter, 2: end % we need this also as numbers: \ifthenelse{\equal{\exercisesolutions}{end}}{\newcommand{\exercisesolutionsnum}{2}}{% \ifthenelse{\equal{\exercisesolutions}{chapter}}{\newcommand{\exercisesolutionsnum}{1}}{% @@ -349,11 +364,12 @@ }{% \immediate\write\solutions{\unexpanded{\subsection}{Exercise \thechapter.\arabic{exercisef}}}% \immediate\write\solutions{\unexpanded{\label}{solution\arabic{chapter}-\arabic{exercisef}}}% - \immediate\write\solutions{\unexpanded{\lstinputlisting[belowskip=0ex,aboveskip=0ex,% - nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{\codepath#1}}% + \immediate\write\solutions{\unexpanded{\begin{minipage}{1\linewidth}\lstinputlisting[belowskip=0ex,aboveskip=0ex,% + nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{\codepath#1}\unexpanded{\end{minipage}}}% \ifthenelse{\equal{#2}{}}{}% - {\immediate\write\solutions{\unexpanded{\lstinputlisting[language={},% - nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{\codepath#2}}}% + {\immediate\write\solutions{\unexpanded{\begin{minipage}{1\linewidth}\lstinputlisting[language={},% + nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{\codepath#2}\unexpanded{\end{minipage}}}}% + \immediate\write\solutions{\unexpanded{\vspace*{\fill}}}% \immediate\write\solutions{}% }% }% @@ -362,14 +378,18 @@ { \hypersetup{hypertexnames=false}% \ifthenelse{\equal{\exercisesource}{}}{}% { \addtocounter{lstlisting}{-1}% - \lstinputlisting[belowskip=0pt,aboveskip=1ex,nolol=true,% + \par\noindent\begin{minipage}[t]{1\linewidth}% + \lstinputlisting[belowskip=1ex,aboveskip=-1ex,nolol=true,% title={\textbf{Solution:} \exercisefile}]% {\exercisesource}% + \end{minipage}% \ifthenelse{\equal{\exerciseoutput}{}}{}% { \addtocounter{lstlisting}{-1}% + \par\noindent\begin{minipage}[t]{1\linewidth}% \lstinputlisting[language={},title={\textbf{Output:}},% - nolol=true,belowskip=0pt]% + nolol=true,belowskip=0pt,aboveskip=-0.5ex]% {\exerciseoutput}% + \end{minipage}% }% }% \hypersetup{hypertexnames=true}% @@ -452,12 +472,12 @@ { \captionsetup{singlelinecheck=off,hypcap=false,labelformat={empty},% labelfont={large,sf,it,bf},font={large,sf,it,bf}} \ifthenelse{\equal{#1}{}}% - { \begin{mdframed}[linecolor=importantline,linewidth=1ex,% + { \begin{mdframed}[nobreak=true,linecolor=importantline,linewidth=1ex,% backgroundcolor=importantback,font={\sffamily}]% \setlength{\parindent}{0pt}% \setlength{\parskip}{1ex}% }% - { \begin{mdframed}[linecolor=importantline,linewidth=1ex,% + { \begin{mdframed}[nobreak=true,linecolor=importantline,linewidth=1ex,% backgroundcolor=importantback,font={\sffamily},% frametitle={\captionof{iboxf}{#1}},frametitleaboveskip=-1ex,% frametitlebackgroundcolor=importantline]% diff --git a/plotting/lecture/plotting-chapter.tex b/plotting/lecture/plotting-chapter.tex index 6a96c4a..85d9cc5 100644 --- a/plotting/lecture/plotting-chapter.tex +++ b/plotting/lecture/plotting-chapter.tex @@ -3,7 +3,7 @@ \input{../../header} \lstset{inputpath=../code} -\graphicspath{{images/}} +\graphicspath{{figures/}} \typein[\pagenumber]{Number of first page} \typein[\chapternumber]{Chapter number} diff --git a/plotting/lecture/plotting.tex b/plotting/lecture/plotting.tex index d895f8b..b27b919 100644 --- a/plotting/lecture/plotting.tex +++ b/plotting/lecture/plotting.tex @@ -148,7 +148,7 @@ or the color. For additional options consult the help. The following listing shows a simple line plot with axis labeling and a title -\lstinputlisting[caption={A simple plot showing a sinewave.}, +\pageinputlisting[caption={A simple plot showing a sinewave.}, label=simpleplotlisting]{simple_plot.m} @@ -162,10 +162,10 @@ chosen, and star marker symbols is used. Finally, the name of the curve is set to \emph{plot 1} which will be displayed in a legend, if chosen. -\begin{lstlisting}[label=settinglineprops, caption={Setting line properties when calling \varcode{plot}.}] +\begin{pagelisting}[label=settinglineprops, caption={Setting line properties when calling \varcode{plot}.}] x = 0:0.1:2*pi; y = sin(x); plot( x, y, 'color', 'r', 'linestyle', ':', 'marker', '*', 'linewidth', 1.5, 'displayname', 'plot 1') -\end{lstlisting} +\end{pagelisting} \begin{important}[Choosing the right color.] Choosing the perfect color goes a little bit beyond personal @@ -277,7 +277,7 @@ the last one defines the output format (box\,\ref{graphicsformatbox}). listing\,\ref{niceplotlisting}.}\label{spikedetectionfig} \end{figure} -\begin{ibox}[t]{\label{graphicsformatbox}File formats for digital artwork.} +\begin{ibox}[tp]{\label{graphicsformatbox}File formats for digital artwork.} There are two fundamentally different types of formats for digital artwork: \begin{enumerate} \item \enterm[bitmap]{Bitmaps} (\determ{Rastergrafik}) @@ -322,7 +322,7 @@ the last one defines the output format (box\,\ref{graphicsformatbox}). efficient. \end{ibox} -\lstinputlisting[caption={Script for creating the plot shown in +\pageinputlisting[caption={Script for creating the plot shown in \figref{spikedetectionfig}.}, label=niceplotlisting]{automatic_plot.m} @@ -380,7 +380,7 @@ draw the data. In the example we also provide further arguments to set the size, color of the dots and specify that they are filled (listing\,\ref{scatterlisting1}). -\lstinputlisting[caption={Creating a scatter plot with red filled dots.}, +\pageinputlisting[caption={Creating a scatter plot with red filled dots.}, label=scatterlisting1, firstline=9, lastline=9]{scatterplot.m} We could have used plot for this purpose and set the marker to @@ -395,8 +395,7 @@ manipulate the color we need to specify a length(x)-by-3 matrix. For each dot we provide an individual color (i.e. the RGB triplet in each row of the color matrix, lines 2-4 in listing\,\ref{scatterlisting2}) - -\lstinputlisting[caption={Creating a scatter plot with size and color +\pageinputlisting[caption={Creating a scatter plot with size and color variations. The RGB triplets define the respective color intensity in a range 0:1. Here, we modify only the red color channel.}, label=scatterlisting2, linerange={15-15, 21-23}]{scatterplot.m} @@ -431,7 +430,7 @@ figures\,\ref{regularsubplotsfig}, \ref{irregularsubplotsfig}). also below).}\label{regularsubplotsfig} \end{figure} -\lstinputlisting[caption={Script for creating subplots in a regular +\pageinputlisting[caption={Script for creating subplots in a regular grid \figref{regularsubplotsfig}.}, label=regularsubplotlisting, basicstyle=\ttfamily\scriptsize]{regular_subplot.m} @@ -458,7 +457,7 @@ create a grid with larger numbers of columns and rows, and specify the used cells of the grid by passing a vector as the third argument to \code{subplot()}. -\lstinputlisting[caption={Script for creating subplots of different +\pageinputlisting[caption={Script for creating subplots of different sizes \figref{irregularsubplotsfig}.}, label=irregularsubplotslisting, basicstyle=\ttfamily\scriptsize]{irregular_subplot.m} @@ -516,7 +515,7 @@ its properties. See the \matlab{} help for more information. listing\,\ref{errorbarlisting} for A and C and listing\,\ref{errorbarlisting2} }\label{errorbarplot} \end{figure} -\lstinputlisting[caption={Illustrating estimation errors using error bars. Script that +\pageinputlisting[caption={Illustrating estimation errors using error bars. Script that creates \figref{errorbarplot}. A, B}, label=errorbarlisting, firstline=13, lastline=31, basicstyle=\ttfamily\scriptsize]{errorbarplot.m} @@ -550,7 +549,7 @@ leading to invisibility and a value of one to complete opaqueness. Finally, we use the normal plot command to draw a line connecting the average values (line 12). -\lstinputlisting[caption={Illustrating estimation errors using a shaded area. Script that +\pageinputlisting[caption={Illustrating estimation errors using a shaded area. Script that creates \figref{errorbarplot} C.}, label=errorbarlisting2, firstline=33, basicstyle=\ttfamily\scriptsize]{errorbarplot.m} @@ -575,7 +574,7 @@ listing\,\ref{annotationsplotlisting}. For more options consult the listing\,\ref{annotationsplotlisting}}\label{annotationsplot} \end{figure} -\lstinputlisting[caption={Adding annotations to figures. Script that +\pageinputlisting[caption={Adding annotations to figures. Script that creates \figref{annotationsplot}.}, label=annotationsplotlisting, basicstyle=\ttfamily\scriptsize]{annotations.m} @@ -632,7 +631,7 @@ Lissajous figure. The basic steps are: \item Finally, close the file (line 31). \end{enumerate} -\lstinputlisting[caption={Making animations and saving them as a +\pageinputlisting[caption={Making animations and saving them as a movie.}, label=animationlisting, firstline=16, lastline=36, basicstyle=\ttfamily\scriptsize]{movie_example.m} diff --git a/pointprocesses/lecture/pointprocessscetchA.eps b/pointprocesses/lecture/pointprocessscetchA.eps index 67537f6..441b034 100644 --- a/pointprocesses/lecture/pointprocessscetchA.eps +++ b/pointprocesses/lecture/pointprocessscetchA.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchA.tex -%%Creator: gnuplot 5.2 patchlevel 8 -%%CreationDate: Mon Dec 7 16:09:58 2020 +%%Creator: gnuplot 4.6 patchlevel 4 +%%CreationDate: Fri Dec 11 21:08:22 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 135 %%EndComments @@ -18,7 +18,6 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def -/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -30,11 +29,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -48,7 +47,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 5.2 (Dec 2017) +% Gnuplot Prolog Version 4.6 (September 2012) % %/SuppressPDFMark true def % @@ -65,11 +64,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -83,7 +82,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Classic Line colors (version 5.0) +% Default Line colors /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -96,21 +95,19 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default dash patterns (version 5.0) -/LTB {BL [] LCb DL} def +% Default Line Types /LTw {PL [] 1 setgray} def -/LTb {PL [] LCb DL} def +/LTb {BL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [2 dl1 3 dl2] LC1 DL} def -/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def -/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def -/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [4 dl1 2 dl2] LC5 DL} def -/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def -/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def -/SL {[] 0 setdash} def +/LT1 {PL [4 dl1 2 dl2] LC1 DL} def +/LT2 {PL [2 dl1 3 dl2] LC2 DL} def +/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def +/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def +/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def +/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -305,7 +302,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -332,14 +329,9 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse -dup 2 lt - {/InterpretLevel1 true def - /InterpretLevel3 false def} - {/InterpretLevel1 Level1 def - 2 gt - {/InterpretLevel3 Level3 def} - {/InterpretLevel3 false def} - ifelse } + 2 lt + {/InterpretLevel1 true def} + {/InterpretLevel1 Level1 def} ifelse % % PostScript level 2 pattern fill definitions @@ -428,7 +420,6 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop -% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -438,39 +429,14 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchA.tex) /Subject (gnuplot plot) - /Creator (gnuplot 5.2 patchlevel 8) + /Creator (gnuplot 4.6 patchlevel 4) + /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Mon Dec 7 16:09:58 2020) + /CreationDate (Fri Dec 11 21:08:22 2020) /DOCINFO pdfmark end } ifelse -% -% Support for boxed text - Ethan A Merritt Sep 2016 -% -/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put - userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put - /Boxing true def } def -/ExtendTextBox { dup type /stringtype eq - { Boxing { gsave dup false charpath pathbbox - dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse - dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse - dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse - dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse - grestore } if } - {} ifelse} def -/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M - TBx1 TBxmargin sub TBy2 TBymargin add L - TBx2 TBxmargin add TBy2 TBymargin add L - TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def -/DrawTextBox { PopTextBox stroke /Boxing false def} def -/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def -0 0 0 0 InitTextBox -/TBxmargin 20 def -/TBymargin 20 def -/Boxing false def -/textshow { ExtendTextBox Gshow } def -% end %%EndProlog %%Page: 1 1 @@ -484,33 +450,27 @@ newpath 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 824 M -stroke -6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke 528 824 M 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 573 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 573 M 0 503 V 1412 573 M 0 503 V @@ -528,18 +488,12 @@ LCb setrgbcolor 0 503 V 5685 573 M 0 503 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -stroke +0.00 0.00 0.00 C stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchA.pdf b/pointprocesses/lecture/pointprocessscetchA.pdf index 6154f40cf355478e936160beb372f4f6d2d68ea2..3d417334e8f4f0885323a9268c63697c84990acd 100644 GIT binary patch delta 951 zcmaDO_DGaZHNeG9*HF)#OZE7h{zVfXTi0_j8S=P(w{-OjxV_}$6=9Ah?&HcFd?(I0 z#a7fV_my}Z=JoRbf7Si`J&K8Ij^BUHw7c-YOIF>Z&spXq9h<`;K6y|0obZ*F9;egg z7j8N^?ViI2UKy@=3J(kSmgmdz|KC38-$vhf4#e1c#xak)eSFFpw5-TA84S1JID* z(xj}^6)(g3<=G9#CMy@{Er0w~@L6!H|fzzhQ;BLiTx zqly`rU=cGi$5dxvh+&?Ak*PU`d8S5|ATbqWiw#W84KNj2T28*qWfN;|W@cn*=xpp_ zW@c$%?Cfl4WMt{;YylK?Hg$G$at>&sQ^Su7;*nCxAQ+lp) zI+K~YSv*|zdS3pbj(rf8evV#A>qQl|K-uYg?Te)iVmqGvc<#JsQQ7nG(n|R zEj*dJa3*t5gNA3X9*l07&ji}r4z$m{$LSt8`0mYJuDo~j$A#-VIjMK}_FVOyg{G;Q zu218W-IDFwjo^8dnAkk4Pn>MM|G4Dkis8i9{l_n_Y%#E@GQ*G|pEdERvw2oSt%8)G z-_IhNhXFs0P|!p}^3V*AI9X=ZV1Q?mpY!+RaWJ{H$hba#q`*-Mc^@)apxMF+$rlB6 z)g4+C&`y<>fe-K&fGn#YEkd%qu)dOOU;wGM+!x6f8VE^Op|rkGslwLviR<2cs3?`{ zDegCj9Na-QI^yc;k#&;N*JX2XsxkmP_>&u8Ad~evG-XwBTCxB!kVhtHCb^fCShlZC zkND)^^{XWFs=qEhT{>rCq%bI{Q~yfPY(b9 diff --git a/pointprocesses/lecture/pointprocessscetchB.eps b/pointprocesses/lecture/pointprocessscetchB.eps index 6ef7b10..b9863a7 100644 --- a/pointprocesses/lecture/pointprocessscetchB.eps +++ b/pointprocesses/lecture/pointprocessscetchB.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchB.tex -%%Creator: gnuplot 5.2 patchlevel 8 -%%CreationDate: Mon Dec 7 16:09:59 2020 +%%Creator: gnuplot 4.6 patchlevel 4 +%%CreationDate: Fri Dec 11 21:08:22 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 237 %%EndComments @@ -18,7 +18,6 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def -/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -30,11 +29,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -48,7 +47,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 5.2 (Dec 2017) +% Gnuplot Prolog Version 4.6 (September 2012) % %/SuppressPDFMark true def % @@ -65,11 +64,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -83,7 +82,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Classic Line colors (version 5.0) +% Default Line colors /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -96,21 +95,19 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default dash patterns (version 5.0) -/LTB {BL [] LCb DL} def +% Default Line Types /LTw {PL [] 1 setgray} def -/LTb {PL [] LCb DL} def +/LTb {BL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [2 dl1 3 dl2] LC1 DL} def -/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def -/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def -/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [4 dl1 2 dl2] LC5 DL} def -/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def -/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def -/SL {[] 0 setdash} def +/LT1 {PL [4 dl1 2 dl2] LC1 DL} def +/LT2 {PL [2 dl1 3 dl2] LC2 DL} def +/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def +/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def +/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def +/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -305,7 +302,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -332,14 +329,9 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse -dup 2 lt - {/InterpretLevel1 true def - /InterpretLevel3 false def} - {/InterpretLevel1 Level1 def - 2 gt - {/InterpretLevel3 Level3 def} - {/InterpretLevel3 false def} - ifelse } + 2 lt + {/InterpretLevel1 true def} + {/InterpretLevel1 Level1 def} ifelse % % PostScript level 2 pattern fill definitions @@ -428,7 +420,6 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop -% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -438,39 +429,14 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchB.tex) /Subject (gnuplot plot) - /Creator (gnuplot 5.2 patchlevel 8) + /Creator (gnuplot 4.6 patchlevel 4) + /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Mon Dec 7 16:09:59 2020) + /CreationDate (Fri Dec 11 21:08:22 2020) /DOCINFO pdfmark end } ifelse -% -% Support for boxed text - Ethan A Merritt Sep 2016 -% -/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put - userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put - /Boxing true def } def -/ExtendTextBox { dup type /stringtype eq - { Boxing { gsave dup false charpath pathbbox - dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse - dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse - dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse - dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse - grestore } if } - {} ifelse} def -/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M - TBx1 TBxmargin sub TBy2 TBymargin add L - TBx2 TBxmargin add TBy2 TBymargin add L - TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def -/DrawTextBox { PopTextBox stroke /Boxing false def} def -/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def -0 0 0 0 InitTextBox -/TBxmargin 20 def -/TBymargin 20 def -/Boxing false def -/textshow { ExtendTextBox Gshow } def -% end %%EndProlog %%Page: 1 1 @@ -484,33 +450,27 @@ newpath 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 3165 M -stroke -6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke -528 3165 M +-5680 0 R 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 3029 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 3029 M 0 272 V 502 -272 R 0 272 V @@ -528,167 +488,99 @@ LCb setrgbcolor 0 272 V 5685 3029 M 0 272 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 2043 M -stroke -6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke -528 2043 M +-5680 0 R 5680 0 V -stroke -1.000 UL -[] 0 setdash 1291 1929 M -stroke -1291 1929 N 121 32 V -121 32 V --260 0 R -stroke -1031 1993 N -910 1961 L -121 -32 V --121 32 R +-260 -64 R +-121 32 V +121 32 V +910 1961 M 502 0 V -stroke -1.000 UL -[] 0 setdash -2002 1929 M -stroke -2002 1929 N +590 -32 R 121 32 V -121 32 V --469 0 R -stroke -1533 1993 N --121 -32 V -121 -32 V --121 32 R +-469 -64 R +-121 32 V +121 32 V +-121 -32 R 711 0 V -stroke -1.000 UL -[] 0 setdash -2329 1939 M -stroke -2329 1939 N +206 -22 R 84 22 V -84 22 V --122 0 R -stroke -2207 1983 N --84 -22 V -84 -22 V --84 22 R +-122 -44 R +-84 22 V +84 22 V +-84 -22 R 290 0 V -stroke -1.000 UL -[] 0 setdash -2629 1938 M -stroke -2629 1938 N +216 -23 R 88 23 V -88 23 V --128 0 R -stroke -2501 1984 N --88 -23 V -88 -23 V --88 23 R +-128 -46 R +-88 23 V +88 23 V +-88 -23 R 304 0 V -stroke -1.000 UL -[] 0 setdash -3046 1929 M -stroke -3046 1929 N +329 -32 R 121 32 V -121 32 V --208 0 R -stroke -2838 1993 N --121 -32 V -121 -32 V --121 32 R +-208 -64 R +-121 32 V +121 32 V +-121 -32 R 450 0 V -stroke -1.000 UL -[] 0 setdash -3912 1929 M -stroke -3912 1929 N +745 -32 R 121 32 V -121 32 V --624 0 R -stroke -3288 1993 N --121 -32 V -121 -32 V --121 32 R +-624 -64 R +-121 32 V +121 32 V +-121 -32 R 866 0 V -stroke -1.000 UL -[] 0 setdash -4529 1929 M -stroke -4529 1929 N +496 -32 R 121 32 V -121 32 V --375 0 R -stroke -4154 1993 N --121 -32 V -121 -32 V --121 32 R +-375 -64 R +-121 32 V +121 32 V +-121 -32 R 617 0 V -stroke -1.000 UL -[] 0 setdash -5564 1929 M -stroke -5564 1929 N +914 -32 R 121 32 V -121 32 V --793 0 R -stroke -4771 1993 N --121 -32 V -121 -32 V --121 32 R +-793 -64 R +-121 32 V +121 32 V +-121 -32 R 1035 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 1907 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 1907 M 0 272 V 502 -272 R 0 272 V @@ -706,100 +598,74 @@ LCb setrgbcolor 0 272 V 5685 1907 M 0 272 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 268 M +0.00 0.00 0.00 C 528 268 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 460 M +0.00 0.00 0.00 C 528 460 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 652 M +0.00 0.00 0.00 C 528 652 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 844 M +0.00 0.00 0.00 C 528 844 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1036 M +0.00 0.00 0.00 C 528 1036 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1228 M +0.00 0.00 0.00 C 528 1228 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1276 M +0.00 0.00 0.00 C 528 1276 M 528 220 L 5801 0 R 0 1056 R -5801 0 R 1.000 UP stroke +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 268 M -stroke -6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke 528 268 M 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -3.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 268 M +0.00 0.00 0.00 C 3.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 528 268 M 382 0 V 0 96 R 502 0 V @@ -819,17 +685,12 @@ LCb setrgbcolor 1035 0 V 0 96 R 533 0 V -stroke -LTw -% End plot #1 -% Begin plot #2 1.500 UP +stroke 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 268 CircleF +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -838,16 +699,11 @@ LCb setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF -LTw -% End plot #2 -% Begin plot #3 1.000 UP 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -1.00 1.00 1.00 C -910 268 CircleF +LT0 +LC0 setrgbcolor +1.00 1.00 1.00 C 910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -856,16 +712,11 @@ LCb setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF -LTw -% End plot #3 -% Begin plot #4 1.500 UP 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 364 CircleF +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 364 CircleF 1412 460 CircleF 2123 556 CircleF 2413 652 CircleF @@ -874,17 +725,11 @@ LCb setrgbcolor 4033 940 CircleF 4650 1036 CircleF 5685 1132 CircleF -LTw -% End plot #4 -2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash 1.000 UP 2.000 UL LTb -0.00 0.00 0.00 C -stroke +LCb setrgbcolor +0.00 0.00 0.00 C stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchB.pdf b/pointprocesses/lecture/pointprocessscetchB.pdf index 1f5548d3dd891119f31f208cdaf3e96a08f1625d..d172e5c62c65027bc4b578fa5f6b7634f9b9e8ef 100644 GIT binary patch delta 2856 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 PQWFV)6%>puO~C&KDRkqr delta 3074 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 x = 38 x = 38 @@ -72,7 +73,7 @@ y = >> z = 'A' z = A -\end{lstlisting} +\end{pagelisting} Line 1 can be read like: ``Create a variable with the name \varcode{x} and assign the value 38''. The equality sign is the so called @@ -93,8 +94,7 @@ information but it is not suited to be used in programs (see also the \code{who} function that returns a list of all defined variables, listing~\ref{varListing2}). -\newpage -\begin{lstlisting}[label=varListing2, caption={Requesting information about defined variables and their types.}] +\begin{pagelisting}[label=varListing2, caption={Requesting information about defined variables and their types.}] >>class(x) ans = double @@ -110,7 +110,7 @@ x y z x 1x1 8 double y 0x0 0 double z 1x1 2 char -\end{lstlisting} +\end{pagelisting} \begin{important}[Naming conventions] There are a few rules regarding variable names. \matlab{} is @@ -120,7 +120,6 @@ x y z variable names. \end{important} -\pagebreak[4] \subsection{Working with variables} We can certainly work, i.e. do calculations, with variables. \matlab{} knows all basic \entermde[Operator!arithmetic]{Operator!arithmetischer}{arithmetic operators} @@ -131,7 +130,7 @@ such as \code[Operator!arithmetic!1add@+]{+}, \code[Operator!arithmetic!5pow@\^{}]{\^{}}. Listing~\ref{varListing3} shows their use. -\begin{lstlisting}[label=varListing3, caption={Working with variables.}] +\begin{pagelisting}[label=varListing3, caption={Working with variables.}] >> x = 1; >> x + 10 ans = @@ -149,13 +148,12 @@ ans = z = 3 ->> z = z * 5; ->> z +>> z = z * 5 z = 15 >> clear z % deleting a variable -\end{lstlisting} +\end{pagelisting} Note: in lines 2 and 10 the variables have been used without changing their values. Whenever the value of a variable should change, the @@ -271,8 +269,8 @@ step-sizes unequal to 1. Line 5 can be read like: ``Create a variable \varcode{b} and assign the values from 0 to 9 in increasing steps of 1.''. Line 9 reads: ``Create a variable \varcode{c} and assign the values from 0 to 10 in steps of 2''. -\pagebreak -\begin{lstlisting}[label=generatevectorslisting, caption={Creating simple row-vectors.}] + +\begin{pagelisting}[label=generatevectorslisting, caption={Creating simple row-vectors.}] >> a = [0 1 2 3 4 5 6 7 8 9] % Creating a row-vector a = 0 1 2 3 4 5 6 7 8 9 @@ -284,7 +282,7 @@ b = >> c = (0:2:10) c = 0 2 4 6 8 10 -\end{lstlisting} +\end{pagelisting} The length of a vector, that is the number of elements, can be requested using the \code{length()} or \code{numel()} @@ -292,14 +290,14 @@ functions. \code{size()} provides the same information in a slightly, yet more powerful way (listing~\ref{vectorsizeslisting}). The above used vector \varcode{a} has the following size: -\begin{lstlisting}[label=vectorsizeslisting, caption={Size of a vector.}] +\begin{pagelisting}[label=vectorsizeslisting, caption={Size of a vector.}] >> length(a) ans = 10 >> size(a) ans = 1 10 -\end{lstlisting} +\end{pagelisting} The answer provided by the \code{size()} function demonstrates that vectors are nothing else but 2-dimensional matrices in which one @@ -310,7 +308,7 @@ create a column-vector and how the \code[Operator!Matrix!']{'} --- operator is used to transpose the column-vector into a row-vector (lines 14 and following). -\begin{lstlisting}[label=columnvectorlisting, caption={Column-vectors.}] +\begin{pagelisting}[label=columnvectorlisting, caption={Column-vectors.}] >> b = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10] % Creating a column-vector b = 1 @@ -333,7 +331,7 @@ b = >> size(b) ans = 1 10 -\end{lstlisting} +\end{pagelisting} \subsubsection{Accessing elements of a vector} @@ -354,7 +352,7 @@ number of elements irrespective of the type of vector. Elements of a vector are accessed via their index. This process is called \entermde{Indizierung}{indexing}. - In \matlab{} the first element has the index one. + In \matlab{} the first element in a vector has the index one. The last element's index equals the length of the vector. \end{important} @@ -365,25 +363,25 @@ individual values by providing a single index or use the \code[Operator!Matrix!:]{:} notation to access multiple values with a single command. -\begin{lstlisting}[label=vectorelementslisting, caption={Access to individual elements of a vector.}] ->> a = (11:20) +\begin{pagelisting}[label=vectorelementslisting, caption={Access to individual elements of a vector.}] +>> a = (11:20) % generate a vector a = 11 12 13 14 15 16 17 18 19 20 ->> a(1) % the 1. element +>> a(1) % the 1. element ans = 11 ->> a(5) % the 5. element +>> a(5) % the 5. element ans = 15 ->> a(end) % the last element +>> a(end) % the last element ans = 20 -\end{lstlisting} +\end{pagelisting} -\begin{lstlisting}[caption={Access to multiple elements.}, label=vectorrangelisting] +\begin{pagelisting}[caption={Access to multiple elements.}, label=vectorrangelisting] >> a([1 3 5]) % 1., 3. and 5. element ans = 11 13 15 ->> a(2:4) % all elements with the indices 2 to 4 +>> a(2:4) % elements at indices 2 to 4 ans = 12 13 14 @@ -394,7 +392,7 @@ ans = >> a(:) % all elements as row-vector ans = 11 12 13 14 15 16 17 18 19 20 -\end{lstlisting} +\end{pagelisting} \begin{exercise}{vectorsize.m}{vectorsize.out} Create a row-vector \varcode{a} with 5 elements. The return value of @@ -403,13 +401,13 @@ ans = \end{exercise} \begin{important}[The : (colon) operator] - The colon \code[Operator!colon@:]{:} operator is often used when working with vectors. It has multiple purposes. + The colon \code[Operator!colon@:]{:} operator is often used when working with vectors. It has multiple purposes.\vspace{-1ex} \begin{enumerate} - \item In the simplest form, \code{x = a:b} with \code{a} and \code{b} being two numbers, it creates - a vector \code{x} containing the numbers \code{a} to \code{b} in integer steps. In \matlab{} the borders $a$ and $b$ are included $[a, b]$ or $a\leq x \leq b$. - \item In the form \code{x = a:c:b} the vector \code{x} uses a \emph{stepsize} of \code{c} to create the range of numbers. - \item When used in the context of indexing such as \code{x(:)} all elements of the vector x are accessed. + \item In the simplest form, \code{x = a:b} with \code{a} and \code{b} being two numbers, it generates + a vector \code{x} containing the numbers \code{a} to \code{b} inclusively in integer steps. + \item In the form \code{x = a:c:b} the vector \code{x} uses a \emph{stepsize} of \code{c} to generate the range of numbers. \item As vectors are often used for indexing in other vectors one use the colon operator to create such vectors implicitely, e.g. \varcode{x(1:2:end)} to access every seond element of \code{x}. + \item Indexing with a single colon, e.g. \code{x(:)}, returns all elements of the vector \code{x} as a row vector. \end{enumerate} \end{important} @@ -423,7 +421,7 @@ how vectors and scalars can be combined with the operators \code[Operator!arithm \code[Operator!arithmetic!4div@/]{/} \code[Operator!arithmetic!5powe@.\^{}]{.\^}. -\begin{lstlisting}[caption={Calculating with vectors and scalars.},label=vectorscalarlisting] +\begin{pagelisting}[caption={Calculations with vectors and scalars.},label=vectorscalarlisting] >> a = (0:2:8) a = 0 2 4 6 8 @@ -447,7 +445,7 @@ ans = >> a .^ 2 % exponentiation ans = 0 4 16 36 64 -\end{lstlisting} +\end{pagelisting} When doing calculations with scalars and vectors the same mathematical operation is done to each element of the vector. In case of, e.g. an @@ -460,7 +458,7 @@ element-wise operations of two vectors, e.g. each element of vector layout (row- or column vectors). Addition and subtraction are always element-wise (listing~\ref{vectoradditionlisting}). -\begin{lstlisting}[caption={Element-wise addition and subtraction of two vectors.},label=vectoradditionlisting] +\begin{pagelisting}[caption={Element-wise addition and subtraction of two vectors.},label=vectoradditionlisting] >> a = [4 9 12]; >> b = [4 3 2]; >> a + b % addition @@ -479,7 +477,7 @@ Matrix dimensions must agree. >> a + d % both vectors must have the same layout! Error using + Matrix dimensions must agree. -\end{lstlisting} +\end{pagelisting} Element-wise multiplication, division, or raising a vector to a given power requires a different operator with a preceding '.'. \matlab{} defines the @@ -489,7 +487,7 @@ following operators for element-wise operations on vectors \code[Operator!arithmetic!5powe@.\^{}]{.\^{}} (listing~\ref{vectorelemmultiplicationlisting}). -\begin{lstlisting}[caption={Element-wise multiplication, division and +\begin{pagelisting}[caption={Element-wise multiplication, division and exponentiation of two vectors.},label=vectorelemmultiplicationlisting] >> a .* b % element-wise multiplication ans = @@ -509,7 +507,7 @@ Matrix dimensions must agree. >> a .* d % Both vectors must have the same layout! Error using .* Matrix dimensions must agree. -\end{lstlisting} +\end{pagelisting} The simple operators \code[Operator!arithmetic!3mul@*]{*}, \code[Operator!arithmetic!4div@/]{/} and @@ -519,7 +517,7 @@ matrix-operations known from linear algebra (Box~ of a row-vectors $\vec a$ with a column-vector $\vec b$ the scalar-poduct (or dot-product) $\sum_i = a_i b_i$. -\begin{lstlisting}[caption={Multiplication of vectors.},label=vectormultiplicationlisting] +\begin{pagelisting}[caption={Multiplication of vectors.},label=vectormultiplicationlisting] >> a * b % multiplication of two vectors Error using * Inner matrix dimensions must agree. @@ -536,14 +534,13 @@ ans = 16 12 8 36 27 18 48 36 24 -\end{lstlisting} - -\pagebreak[4] +\end{pagelisting} To remove elements from a vector an empty value (\code[Operator!Matrix!{[]}]{[]}) is assigned to the respective elements: -\begin{lstlisting}[label=vectoreraselisting, caption={Deleting elements of a vector.}] + +\begin{pagelisting}[label=vectoreraselisting, caption={Deleting elements of a vector.}] >> a = (0:2:8); >> length(a) ans = 5 @@ -556,7 +553,7 @@ a = 4 8 >> length(a) ans = 2 -\end{lstlisting} +\end{pagelisting} In addition to deleting of vector elements one also add new elements or concatenate two vectors. When performing a concatenation the two @@ -718,7 +715,7 @@ remapping, but can be really helpful rows in each column and so on.}\label{matrixlinearindexingfig} \end{figure} -\begin{lstlisting}[label=matrixLinearIndexing, caption={Lineares indexing in matrices.}] +\begin{pagelisting}[label=matrixLinearIndexing, caption={Lineares indexing in matrices.}] >> x = randi(100, [3, 4, 5]); % 3-D matrix filled with random numbers >> size(x) ans = @@ -735,17 +732,17 @@ ans = >> min(x(:)) % or even simpler ans = 4 -\end{lstlisting} +\end{pagelisting} \matlab{} defines functions that convert subscript indices to linear indices and back (\code{sub2ind()} and \code{ind2sub()}). -\begin{ibox}[tp]{\label{matrixmultiplication} The matrix--multiplication.} +\begin{ibox}[t]{\label{matrixmultiplication} The matrix--multiplication.} The matrix--multiplication from linear algebra is \textbf{not} an element--wise multiplication of each element in a matrix \varcode{A} and the respective element of matrix \varcode{B}. It is something completely different. Confusing element--wise and matrix--multiplication is one of the most common mistakes in - \matlab{}. \linebreak + \matlab{}. The matrix--multiplication of two 2-D matrices is only possible if the number of columns in the first matrix agrees with the number of @@ -795,8 +792,7 @@ box~\ref{matrixmultiplication}). To do a matrix-multiplication the inner dimensions of the matrices must agree (box~\ref{matrixmultiplication}). -\pagebreak[4] -\begin{lstlisting}[label=matrixOperations, caption={Two kinds of multiplications of matrices.}] +\begin{pagelisting}[label=matrixOperations, caption={Two kinds of multiplications of matrices.}] >> A = randi(5, [2, 3]) % 2-D matrix A = 1 5 3 @@ -822,7 +818,7 @@ ans = 10 15 20 24 23 35 16 17 25 -\end{lstlisting} +\end{pagelisting} \section{Boolean expressions} @@ -854,7 +850,7 @@ synonymous for the logical values 1 and 0. Listing~\ref{logicaldatatype} exemplifies the use of the logical data type. -\begin{lstlisting}[caption={The logical data type. Please note that the actual \matlab{} output looks a little different.}, label=logicaldatatype] +\begin{pagelisting}[caption={The logical data type. Please note that the actual \matlab{} output looks a little different.}, label=logicaldatatype] >> true ans = 1 >> false @@ -871,7 +867,7 @@ ans = 0 ans = 1 1 1 1 >> logical([1 2 3 4 0 0 10]) ans = 1 1 1 1 0 0 1 -\end{lstlisting} +\end{pagelisting} \varcode{true} and \varcode{false} are reserved keywords that evaluate to the logical values 1 and 0, respectively. If you want to create a @@ -884,7 +880,7 @@ code of each character in ``test'' is non-zero value, thus, the result of casting it to logical is a vector of logicals. A similar thing happens upon casting a vector (or matrix) of numbers to logical. Each value is converted to logical and the result is true for all non-zero -values (line 21). +values (line 15). Knowing how to represent true and false values in \matlab{} using the logical data type allows us to take a step towards more complex @@ -922,8 +918,8 @@ stored in variable \varcode{b}?''. The result of such questions is then given as a logical value. Listing~\ref{relationaloperationslisting} shows examples using relational operators. -\pagebreak -\begin{lstlisting}[caption={Relational Boolean expressions.}, label=relationaloperationslisting] + +\begin{pagelisting}[caption={Relational Boolean expressions.}, label=relationaloperationslisting] >> true == logical(1) ans = 1 >> false ~= logical(1) @@ -941,7 +937,7 @@ ans = 0 0 1 0 0 ans = 0 1 0 0 1 >> [2 0 0 5 0] >= [1 0 3 2 0] ans = 1 1 0 1 1 -\end{lstlisting} +\end{pagelisting} Testing the relations between numbers and scalar variables is straight forward. When comparing vectors, the relational operator will be @@ -1038,7 +1034,7 @@ for implementing such expressions. Listing~\ref{logicaloperatorlisting} shows a few examples and respective illustrations are shown in figure~\ref{logicaloperationsfig}. -\begin{lstlisting}[caption={Boolean expressions.}, label=logicaloperatorlisting] +\begin{pagelisting}[caption={Boolean expressions.}, label=logicaloperatorlisting] >> x = rand(1) % create a single random number in the range [0, 1] x = 0.3452 >> x > 0.25 & x < 0.75 @@ -1049,7 +1045,7 @@ x = 0.4920, 0.9106, 0.7218, 0.8749, 0.1574, 0.0201, 0.9107, 0.8357, 0.0357, 0.47 ans = 1 0 1 0 0 0 0 0 0 1 >> x < 0.25 | x > 0.75 ans = 0 1 0 1 1 1 1 1 1 0 -\end{lstlisting} +\end{pagelisting} \begin{figure}[ht] \includegraphics[]{logical_operations} @@ -1064,7 +1060,6 @@ ans = 0 1 0 1 1 1 1 1 1 0 data.}\label{logicaloperationsfig} \end{figure} -\pagebreak \begin{important}[Assignment and equality operators] The assignment operator \code[Operator!Assignment!=]{=} and the relational equality operator \code[Operator!relational!==]{==} are @@ -1093,7 +1088,7 @@ elements of \varcode{x} where the Boolean expression \varcode{x < 0} evaluates to true and store the result in the variable \varcode{x\_smaller\_zero}''. -\begin{lstlisting}[caption={Logical indexing.}, label=logicalindexing1] +\begin{pagelisting}[caption={Logical indexing.}, label=logicalindexing1] >> x = randn(1, 6) % a vector with 6 random numbers x = -1.4023 -1.4224 0.4882 -0.1774 -0.1961 1.4193 @@ -1110,7 +1105,7 @@ elements_smaller_zero = >> elements_smaller_zero = x(x < 0) elements_smaller_zero = -1.4023 -1.4224 -0.1774 -0.1961 -\end{lstlisting} +\end{pagelisting} \begin{exercise}{logicalVector.m}{logicalVector.out} Create a vector \varcode{x} containing the values 0--10. @@ -1119,8 +1114,7 @@ elements_smaller_zero = \item Display the content of \varcode{y} in the command window. \item What is the data type of \varcode{y}? \item Return only those elements \varcode{x} that are less than 5. - \end{enumerate} - \pagebreak[4] + \end{enumerate}\vspace{-1ex} \end{exercise} \begin{figure}[t] @@ -1142,7 +1136,6 @@ segment of data of a certain time span (the stimulus was on, \begin{exercise}{logicalIndexingTime.m}{} Assume that measurements have been made for a certain time. Usually measured values and the time are stored in two vectors. - \begin{itemize} \item Create a vector that represents the recording time \varcode{t = 0:0.001:10;}. @@ -1150,9 +1143,9 @@ segment of data of a certain time span (the stimulus was on, that has the same length as \varcode{t}. The values stored in \varcode{x} represent the measured data at the times in \varcode{t}. - \item Use logical indexing to select those values that have been - recorded in the time span from 5--6\,s. - \end{itemize} + \item Use logical indexing to select values that have been + recorded in the time span 5--6\,s. + \end{itemize}\vspace{-1ex} \end{exercise} \begin{ibox}[ht]{\label{advancedtypesbox}Advanced data types} @@ -1230,7 +1223,7 @@ As the name already suggests loops are used to execute the same parts of the code repeatedly. In one of the earlier exercises the factorial of five has been calculated as depicted in listing~\ref{facultylisting}. -\begin{lstlisting}[caption={Calculation of the factorial of 5 in five steps}, label=facultylisting] +\begin{pagelisting}[caption={Calculation of the factorial of 5 in five steps}, label=facultylisting] >> x = 1; >> x = x * 2; >> x = x * 3; @@ -1239,7 +1232,7 @@ five has been calculated as depicted in listing~\ref{facultylisting}. >> x x = 120 -\end{lstlisting} +\end{pagelisting} This kind of program solves the taks but it is rather repetitive. The only thing that changes is the increasing factor. The repetition of such @@ -1279,7 +1272,7 @@ a certain purpose. The \varcode{for}-loop is closed with the keyword \code{end}. Listing~\ref{looplisting} shows a simple version of such a for-loop. -\begin{lstlisting}[caption={Example of a \varcode{for}-loop.}, label=looplisting] +\begin{pagelisting}[caption={Example of a \varcode{for}-loop.}, label=looplisting] >> for x = 1:3 % head disp(x) % body end @@ -1288,7 +1281,7 @@ for-loop. 1 2 3 -\end{lstlisting} +\end{pagelisting} \begin{exercise}{factorialLoop.m}{factorialLoop.out} @@ -1308,11 +1301,11 @@ 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 +\begin{pagelisting}[caption={Basic structure of a \varcode{while} loop.}, label=whileloop] +while x == true % head with a Boolean expression % execute this code if the expression yields true end -\end{lstlisting} +\end{pagelisting} \begin{exercise}{factorialWhileLoop.m}{} Implement the factorial of a number \varcode{n} using a \varcode{while}-loop. @@ -1367,7 +1360,7 @@ 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.}] +\begin{pagelisting}[label=ifelselisting, caption={Structure of an \varcode{if} statement.}] if x < y % head % body I, executed only if x < y elseif x > y @@ -1375,7 +1368,7 @@ elseif x > y else % body III, executed only if the previous conditions did not match end - \end{lstlisting} + \end{pagelisting} \begin{exercise}{ifelse.m}{} Draw a random number and check with an appropriate \varcode{if} @@ -1403,7 +1396,7 @@ 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.}] +\begin{pagelisting}[label=switchlisting, caption={Structure of a \varcode{switch} statement.}] mynumber = input('Enter a number:'); switch mynumber case -1 @@ -1413,7 +1406,7 @@ switch mynumber otherwise disp('something else'); end -\end{lstlisting} +\end{pagelisting} \subsubsection{Comparison \varcode{if} and \varcode{switch} -- statements} @@ -1437,7 +1430,7 @@ skip the execution of the body under certain circumstances, one can use the keywords \code{break} and \code{continue} (listings~\ref{continuelisting} and \ref{continuelisting}). -\begin{lstlisting}[caption={Stop the execution of a loop using \varcode{break}.}, label=breaklisting] +\begin{pagelisting}[caption={Stop the execution of a loop using \varcode{break}.}, label=breaklisting] >> x = 1; while true if (x > 3) @@ -1450,9 +1443,9 @@ use the keywords \code{break} and \code{continue} 1 2 3 -\end{lstlisting} +\end{pagelisting} -\begin{lstlisting}[caption={Skipping iterations using \varcode{continue}.}, label=continuelisting] +\begin{pagelisting}[caption={Skipping iterations using \varcode{continue}.}, label=continuelisting] for x = 1:5 if(x > 2 & x < 5) continue; @@ -1463,7 +1456,7 @@ end 1 2 5 -\end{lstlisting} +\end{pagelisting} \begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out} Above we claimed that logical indexing is faster and much more @@ -1535,11 +1528,11 @@ has one \entermde{Argument}{argument} $x$ that is transformed into the function's output value $y$. In \matlab{} the syntax of a function declaration is very similar (listing~\ref{functiondefinitionlisting}). -\begin{lstlisting}[caption={Declaration of a function in \matlab{}}, label=functiondefinitionlisting] +\begin{pagelisting}[caption={Declaration of a function in \matlab{}}, label=functiondefinitionlisting] function [y] = functionName(arg_1, arg_2) % ^ ^ ^ % return value argument_1, argument_2 -\end{lstlisting} +\end{pagelisting} The keyword \code{function} is followed by the return value(s) (it can be a list \varcode{[]} of values), the function name and the @@ -1572,7 +1565,7 @@ The following listing (\ref{badsinewavelisting}) shows a function that calculates and displays a bunch of sine waves with different amplitudes. -\begin{lstlisting}[caption={Bad example of a function that displays a series of sine waves.},label=badsinewavelisting] +\begin{pagelisting}[caption={Bad example of a function that displays a series of sine waves.},label=badsinewavelisting] function myFirstFunction() % function head t = (0:0.01:2); frequency = 1.0; @@ -1583,7 +1576,7 @@ function myFirstFunction() % function head hold on; end end -\end{lstlisting} +\end{pagelisting} \varcode{myFirstFunction} (listing~\ref{badsinewavelisting}) is a prime-example of a bad function. There are several issues with it's @@ -1644,7 +1637,7 @@ define (i) how to name the function, (ii) which information it needs Having defined this we can start coding (listing~\ref{sinefunctionlisting}). -\begin{lstlisting}[caption={Function that calculates a sine wave.}, label=sinefunctionlisting] +\begin{pagelisting}[caption={Function that calculates a sine wave.}, label=sinefunctionlisting] function [time, sine] = sinewave(frequency, amplitude, t_max, t_step) % Calculate a sinewave of a given frequency, amplitude, % duration and temporal resolution. @@ -1662,7 +1655,7 @@ function [time, sine] = sinewave(frequency, amplitude, t_max, t_step) time = (0:t_step:t_max); sine = sin(frequency .* time .* 2 .* pi) .* amplitude; end -\end{lstlisting} +\end{pagelisting} \paragraph{II. Plotting a single sine wave} @@ -1689,7 +1682,7 @@ specification of the function: With this specification we can start to implement the function (listing~\ref{sineplotfunctionlisting}). -\begin{lstlisting}[caption={Function for the graphical display of data.}, label=sineplotfunctionlisting] +\begin{pagelisting}[caption={Function for the graphical display of data.}, label=sineplotfunctionlisting] function plotFunction(x_data, y_data, name) % Plots x-data against y-data and sets the display name. % @@ -1701,7 +1694,7 @@ function plotFunction(x_data, y_data, name) % name : the displayname plot(x_data, y_data, 'displayname', name) end -\end{lstlisting} +\end{pagelisting} \paragraph{III. One script to rule them all} @@ -1728,7 +1721,7 @@ Again, we need to specify what needs to be done: The implementation is shown in listing~\ref{sinesskriptlisting}. -\begin{lstlisting}[caption={Control script for the plotting of sine waves.},label=sinesskriptlisting] +\begin{pagelisting}[caption={Control script for the plotting of sine waves.},label=sinesskriptlisting] amplitudes = 0.25:0.25:1.25; frequency = 2.0; duration = 10.0; % seconds @@ -1744,11 +1737,11 @@ for i = 1:length(amplitudes) end hold off legend('show') -\end{lstlisting} +\end{pagelisting} +\pagebreak[4] \begin{exercise}{plotMultipleSinewaves.m}{} Extend the program to plot also a range of frequencies. - \pagebreak[4] \end{exercise} From 3dd0660b21b5d8c973a24e5be7effa7bee7378e7 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 12 Dec 2020 20:34:43 +0100 Subject: [PATCH 07/37] [bootstrap] added difference of mean --- bootstrap/code/correlationsignificance.m | 14 +- bootstrap/code/meandiffsignificance.m | 40 ++++++ bootstrap/code/meandiffsignificance.out | 4 + bootstrap/lecture/bootstrap-chapter.tex | 2 - bootstrap/lecture/bootstrap.tex | 160 ++++++++++++++++++----- bootstrap/lecture/bootstrapsem.py | 2 +- bootstrap/lecture/permuteaverage.py | 103 +++++++++++++++ bootstrap/lecture/permutecorrelation.py | 52 ++++++-- chapter.mk | 3 + plotstyle.py | 7 +- 10 files changed, 326 insertions(+), 61 deletions(-) create mode 100644 bootstrap/code/meandiffsignificance.m create mode 100644 bootstrap/code/meandiffsignificance.out create mode 100644 bootstrap/lecture/permuteaverage.py diff --git a/bootstrap/code/correlationsignificance.m b/bootstrap/code/correlationsignificance.m index d9b0fff..7426cc5 100644 --- a/bootstrap/code/correlationsignificance.m +++ b/bootstrap/code/correlationsignificance.m @@ -1,6 +1,6 @@ % generate correlated data: -n=200; -a=0.2; +n = 200; +a = 0.2; x = randn(n, 1); y = randn(n, 1) + a*x; @@ -11,13 +11,13 @@ fprintf('correlation coefficient of data r = %.2f\n', rd); % distribution of null hypothesis by permutation: nperm = 1000; rs = zeros(nperm,1); -for i=1:nperm - xr=x(randperm(length(x))); % shuffle x - yr=y(randperm(length(y))); % shuffle y +for i = 1:nperm + xr = x(randperm(length(x))); % shuffle x + yr = y(randperm(length(y))); % shuffle y rs(i) = corr(xr, yr); end -[h,b] = hist(rs, 20); -h = h/sum(h)/(b(2)-b(1)); % normalization +[h, b] = hist(rs, 20); +h = h/sum(h)/(b(2)-b(1)); % normalization % significance: rq = quantile(rs, 0.95); diff --git a/bootstrap/code/meandiffsignificance.m b/bootstrap/code/meandiffsignificance.m new file mode 100644 index 0000000..96a328e --- /dev/null +++ b/bootstrap/code/meandiffsignificance.m @@ -0,0 +1,40 @@ +% generate two data sets: +n = 200; +d = 0.2; +x = randn(n, 1); +y = randn(n, 1) + d; + +% difference of sample means: +md = mean(y) - mean(x); +fprintf('difference of means of data d = %.2f\n', md); + +% distribution of null hypothesis by permutation: +nperm = 1000; +xy = [x; y]; % x and y data in one column vector +ds = zeros(nperm,1); +for i = 1:nperm + xyr = xy(randperm(length(xy))); % shuffle data + xr = xyr(1:length(x)); % random x-data + yr = xyr(length(x)+1:end); % random y-data + ds(i) = mean(yr) - mean(xr); % difference of means +end +[h, b] = hist(ds, 20); +h = h/sum(h)/(b(2)-b(1)); % normalization + +% significance: +dq = quantile(ds, 0.95); +fprintf('difference of means of null hypothesis at 5%% significance = %.2f\n', dq); +if md >= dq + fprintf('--> difference of means d=%.2f is significant\n', md); +else + fprintf('--> d=%.2f is not a significant difference of means\n', md); +end + +% plot: +bar(b, h, 'facecolor', 'b'); +hold on; +bar(b(b>=dq), h(b>=dq), 'facecolor', 'r'); +plot([md md], [0 4], 'r', 'linewidth', 2); +xlabel('Difference of means'); +ylabel('Probability density of H0'); +hold off; diff --git a/bootstrap/code/meandiffsignificance.out b/bootstrap/code/meandiffsignificance.out new file mode 100644 index 0000000..e17ad8d --- /dev/null +++ b/bootstrap/code/meandiffsignificance.out @@ -0,0 +1,4 @@ +>> meandiffsignificance +difference of means of data d = 0.18 +difference of means of null hypothesis at 5% significance = 0.17 +--> difference of means d=0.18 is significant diff --git a/bootstrap/lecture/bootstrap-chapter.tex b/bootstrap/lecture/bootstrap-chapter.tex index b61d395..78d7d3c 100644 --- a/bootstrap/lecture/bootstrap-chapter.tex +++ b/bootstrap/lecture/bootstrap-chapter.tex @@ -26,6 +26,4 @@ This chapter easily covers two lectures: Add jacknife methods to bootstrapping -Add permutation test for significant different means of two distributions. - \end{document} diff --git a/bootstrap/lecture/bootstrap.tex b/bootstrap/lecture/bootstrap.tex index 20f01c2..8f72366 100644 --- a/bootstrap/lecture/bootstrap.tex +++ b/bootstrap/lecture/bootstrap.tex @@ -125,7 +125,6 @@ Via bootstrapping we create a distribution of the mean values (\figref{bootstrapsemfig}) and the standard deviation of this distribution is the standard error of the mean. -\pagebreak[4] \begin{exercise}{bootstrapsem.m}{bootstrapsem.out} Create the distribution of mean values from bootstrapped samples resampled from a single SRS. Use this distribution to estimate the @@ -152,67 +151,156 @@ desired \entermde{Signifikanz}{significance level}, the \entermde{Nullhypothese}{null hypothesis} may be rejected. Traditionally, such probabilities are taken from theoretical -distributions which are based on assumptions about the data. Thus the -applied statistical test has to be appropriate for the type of +distributions which are based on some assumptions about the data. For +example, the data should be normally distributed. Given some data one +has to find an appropriate test that matches the properties of the data. An alternative approach is to calculate the probability density -of the null hypothesis directly from the data itself. To do this, we +of the null hypothesis directly from the data themselves. To do so, we need to resample the data according to the null hypothesis from the SRS. By such permutation operations we destroy the feature of interest -while we conserve all other statistical properties of the data. +while conserving all other statistical properties of the data. + + +\subsection{Significance of a difference in the mean} + +Often we would like to know whether two data sets differ in their +mean. Whether the ears of foxes are larger in southern Europe compared +to the ones from Scandinavia, whether a drug decreases blood pressure +in humans, whether a sensory stimulus increases the firing rate of a +neuron, etc. The \entermde{Nullhypothese}{null hypothesis} is that +they do not differ in their means, i.e. that both data sets come from +the same distribution. But even if the two data sets come from the +same distribution, their sample means may nevertheless differ by +chance. We need to figure out how these differences of the means are +distributed. Only if the measured difference between the means is +significantly larger than the ones obtained by chance we can reject +the null hypothesis and consider the two data sets to differ +significantly in their means. + +We can easily estimate the distribution of the null hypothesis by +putting the data of both data sets in one big bag. By merging the two +data sets we assume that all the data values come from the same +distribution. We then randomly separate the data values into two new +data sets. These random data sets contain data from both original data +sets and thus come from the same distribution. From these random data +sets we compute the difference of their sample means. This procedure +is repeated many, say one thousand, times and each time we get a value +for a difference of means. The distribution of these values is the +distribution of the null hypothesis. It is the distribution of +differences of mean values that we get by chance although the two data +sets come from the same distribution. For a one-sided test that checks +whether the measured difference of means is significantly larger than +zero at a significance level of 5\,\% we compute the value of the +95\,\% percentile of the null distribution. If the measured value is +larger, we can reject the null hypothesis and consider the two data +sets to differ significantly in their means. + +By using the original data to estimate the null hypothesis, we make no +assumption about the properties of the data. We do not need to worry +about the data being normally distributed. We do not need to memorize +which test to use in which situation. And we better understand what we +are testing, because we design the test ourselves. Nowadays, computer +are powerful enough to iterate even ten thousand times over the data +to compute the distribution of the null hypothesis --- with only a few +lines of code. This is why \entermde{Permutationstest}{permutaion + test} are getting quite popular. \begin{figure}[tp] - \includegraphics[width=1\textwidth]{permutecorrelation} - \titlecaption{\label{permutecorrelationfig}Permutation test for - correlations.}{Let the correlation coefficient of a dataset with - 200 samples be $\rho=0.21$. The distribution of the null - hypothesis (yellow), optained from the correlation coefficients of - permuted and therefore uncorrelated datasets is centered around - zero. The measured correlation coefficient is larger than the - 95\,\% percentile of the null hypothesis. The null hypothesis may - thus be rejected and the measured correlation is considered - statistically significant.} + \includegraphics[width=1\textwidth]{permuteaverage} + \titlecaption{\label{permuteaverage}Permutation test for differences + in means.}{We want to test whether two datasets + $\left\{x_i\right\}$ (red) and $\left\{y_i\right\}$ (blue) come + from different distributions by assessing the significance of the + difference in their sample means. The data sets were generated + with a difference in their population means of $d=0.7$. For + generating the distribution of the null hypothesis, i.e. the + distribution of differences in the means if the two data sets come + from the same distribution, we randomly select the same number of + samples from both data sets (top right). This is repeated many + times and results in the desired distribution of differences of + means (bottom). The measured difference is clearly beyond the + 95\,\% percentile of this distribution and thus indicates a + significant difference between the distributions of the two + original data sets.} \end{figure} -%\subsection{Significance of a difference in the mean} +\begin{exercise}{meandiffsignificance.m}{meandiffsignificance.out} +Estimate the statistical significance of a difference in the mean of two data sets. +\vspace{-1ex} +\begin{enumerate} +\item Generate two independent data sets, $\left\{x_i\right\}$ and + $\left\{y_i\right\}$, of $n=200$ samples each, by drawing random + numbers from a normal distribution. Add 0.2 to all the $y_i$ samples + to ensure the population means to differ by 0.2. +\item Calculate the difference between the sample means of the two data sets. +\item Estimate the distribution of the null hypothesis of no + difference of the means by generating new data sets with the same + number of samples randomly selected from both data sets. For this + lump the two data sets together into a single vector. Then permute + the order of the elements in this vector using the function + \varcode{randperm()}, split it into two data sets and calculate + the difference of their means. Repeat this 1000 times. +\item Read out the 95\,\% percentile from the resulting distribution + of the differences in the mean, the null hypothesis using the + \varcode{quantile()} function, and compare it with the difference of + means measured from the original data sets. +\end{enumerate} +\end{exercise} -%See \url{https://en.wikipedia.org/wiki/Resampling_(statistics)#Permutation_tests.} \subsection{Significance of correlations} -A good example for the application of a -\entermde{Permutationstest}{permutaion test} is the statistical -assessment of \entermde[correlation]{Korrelation}{correlations}. Given -are measured pairs of data points $(x_i, y_i)$. By calculating the +Another nice example for the application of a +\entermde{Permutationstest}{permutaion test} is testing for +significant \entermde[correlation]{Korrelation}{correlations} +(figure\,\ref{permutecorrelationfig}). Given are measured pairs of +data points $(x_i, y_i)$. By calculating the \entermde[correlation!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 -\entermde{Nullhypothese}{null hypothesis} for such a situation is that -$y$ does not depend on $x$. In order to perform a permutation test, we -need to destroy the correlation by permuting the $(x_i, y_i)$ pairs, -i.e. we rearrange the $x_i$ and $y_i$ values in a random +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 non-zero correlation that we might get although there +is no true correlation in the data. The \entermde{Nullhypothese}{null + hypothesis} for such a situation is that $y$ does not depend on +$x$. In order to perform a permutation test, we need to destroy the +correlation between the data pairs by permuting the $(x_i, y_i)$ +pairs, i.e. we rearrange the $x_i$ and $y_i$ values in a random fashion. Generating many sets of random pairs and computing the -resulting correlation coefficients yields a distribution of -correlation coefficients that result randomly from uncorrelated +corresponding correlation coefficients yields a distribution of +correlation coefficients that result randomly from truly uncorrelated data. By comparing the actually measured correlation coefficient with this distribution we can directly assess the significance of the -correlation (figure\,\ref{permutecorrelationfig}). +correlation. + +\begin{figure}[tp] + \includegraphics[width=1\textwidth]{permutecorrelation} + \titlecaption{\label{permutecorrelationfig}Permutation test for + correlations.}{Let the correlation coefficient of a dataset with + 200 samples be $\rho=0.21$ (top left). By shuffling the data pairs + we destroy any true correlation (top right). The resulting + distribution of the null hypothesis (bottm, yellow), optained from + the correlation coefficients of permuted and therefore + uncorrelated datasets is centered around zero. The measured + correlation coefficient is larger than the 95\,\% percentile of + the null hypothesis. The null hypothesis may thus be rejected and + the measured correlation is considered statistically significant.} +\end{figure} \begin{exercise}{correlationsignificance.m}{correlationsignificance.out} Estimate the statistical significance of a correlation coefficient. \begin{enumerate} -\item Create pairs of $(x_i, y_i)$ values. Randomly choose $x$-values +\item Generate pairs of $(x_i, y_i)$ values. Randomly choose $x$-values and calculate the respective $y$-values according to $y_i =0.2 \cdot x_i + u_i$ where $u_i$ is a random number drawn from a normal distribution. \item Calculate the correlation coefficient. -\item Generate the distribution of the null hypothesis by generating +\item Estimate the distribution of the null hypothesis by generating uncorrelated pairs. For this permute $x$- and $y$-values \matlabfun{randperm()} 1000 times and calculate for each permutation the correlation coefficient. \item Read out the 95\,\% percentile from the resulting distribution - of the null hypothesis and compare it with the correlation - coefficient computed from the original data. + of the null hypothesis using the \varcode{quantile()} function and + compare it with the correlation coefficient computed from the + original data. \end{enumerate} \end{exercise} diff --git a/bootstrap/lecture/bootstrapsem.py b/bootstrap/lecture/bootstrapsem.py index 3a276bd..837b0b1 100644 --- a/bootstrap/lecture/bootstrapsem.py +++ b/bootstrap/lecture/bootstrapsem.py @@ -24,7 +24,7 @@ for i in range(nresamples) : musrs.append(np.mean(rng.randn(nsamples))) hmusrs, _ = np.histogram(musrs, bins, density=True) -fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height)) +fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.05*figure_height)) fig.subplots_adjust(**adjust_fs(left=4.0, bottom=2.7, right=1.5)) ax.set_xlabel('Mean') ax.set_xlim(-0.4, 0.4) diff --git a/bootstrap/lecture/permuteaverage.py b/bootstrap/lecture/permuteaverage.py new file mode 100644 index 0000000..53cfc0b --- /dev/null +++ b/bootstrap/lecture/permuteaverage.py @@ -0,0 +1,103 @@ +import numpy as np +import scipy.stats as st +import matplotlib.pyplot as plt +import matplotlib.gridspec as gridspec +import matplotlib.ticker as ticker +from plotstyle import * + +rng = np.random.RandomState(637281) + +# generate data that differ in their mein by d: +n = 200 +d = 0.7 +x = rng.randn(n) + d; +y = rng.randn(n); +#x = rng.exponential(1.0, n); +#y = rng.exponential(1.0, n) + d; + +# histogram of data: +db = 0.5 +bins = np.arange(-2.5, 2.6, db) +hx, _ = np.histogram(x, bins) +hy, _ = np.histogram(y, bins) + +# Diference of means, pooled standard deviation and Cohen's d: +ad = np.mean(x)-np.mean(y) +s = np.sqrt(((len(x)-1)*np.var(x)+(len(y)-1)*np.var(y))/(len(x)+len(y)-2)) +cd = ad/s + +# permutation: +nperm = 1000 +ads = [] +xy = np.hstack((x, y)) +for i in range(nperm) : + xyp = rng.permutation(xy) + ads.append(np.mean(xyp[:len(x)])-np.mean(xyp[len(x):])) + +# histogram of shuffled data: +hxp, _ = np.histogram(xyp[:len(x)], bins) +hyp, _ = np.histogram(xyp[len(x):], bins) + +# pdf of the differences of means: +h, b = np.histogram(ads, 20, density=True) + +# significance: +dq = np.percentile(ads, 95.0) +print('Measured difference of means = %.2f, difference at 95%% percentile of permutation = %.2f' % (ad, dq)) +da = 1.0-0.01*st.percentileofscore(ads, ad) +print('Measured difference of means %.2f is at %.2f%% percentile of permutation' % (ad, 100.0*da)) + +ap, at = st.ttest_ind(x, y) +print('Measured difference of means %.2f is at %.2f%% percentile of test' % (ad, ap)) + + +fig = plt.figure(figsize=cm_size(figure_width, 1.8*figure_height)) +gs = gridspec.GridSpec(nrows=2, ncols=2, wspace=0.35, hspace=0.8, + **adjust_fs(fig, left=5.0, right=1.5, top=1.0, bottom=2.7)) + +ax = fig.add_subplot(gs[0,0]) +ax.bar(bins[:-1]-0.25*db, hy, 0.5*db, **fsA) +ax.bar(bins[:-1]+0.25*db, hx, 0.5*db, **fsB) +ax.annotate('', xy=(0.0, 45.0), xytext=(d, 45.0), arrowprops=dict(arrowstyle='<->')) +ax.text(0.5*d, 50.0, 'd=%.1f' % d, ha='center') +ax.set_xlim(-2.5, 2.5) +ax.set_ylim(0.0, 50) +ax.yaxis.set_major_locator(ticker.MultipleLocator(20.0)) +ax.set_xlabel('Original x and y values') +ax.set_ylabel('Counts') + +ax = fig.add_subplot(gs[0,1]) +ax.bar(bins[:-1]-0.25*db, hyp, 0.5*db, **fsA) +ax.bar(bins[:-1]+0.25*db, hxp, 0.5*db, **fsB) +ax.set_xlim(-2.5, 2.5) +ax.set_ylim(0.0, 50) +ax.yaxis.set_major_locator(ticker.MultipleLocator(20.0)) +ax.set_xlabel('Shuffled x and y values') +ax.set_ylabel('Counts') + +ax = fig.add_subplot(gs[1,:]) +ax.annotate('Measured\ndifference\nis significant!', + xy=(ad, 1.2), xycoords='data', + xytext=(ad-0.1, 2.2), textcoords='data', ha='right', + arrowprops=dict(arrowstyle="->", relpos=(1.0,0.5), + connectionstyle="angle3,angleA=-20,angleB=100") ) +ax.annotate('95% percentile', + xy=(0.19, 0.9), xycoords='data', + xytext=(0.3, 5.0), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(0.1,0.0), + connectionstyle="angle3,angleA=40,angleB=80") ) +ax.annotate('Distribution of\nnullhypothesis', + xy=(-0.08, 3.0), xycoords='data', + xytext=(-0.22, 4.5), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(0.2,0.0), + connectionstyle="angle3,angleA=60,angleB=150") ) +ax.bar(b[:-1], h, width=b[1]-b[0], **fsC) +ax.bar(b[:-1][b[:-1]>=dq], h[b[:-1]>=dq], width=b[1]-b[0], **fsB) +ax.plot( [ad, ad], [0, 1], **lsA) +ax.set_xlim(-0.25, 0.85) +ax.set_ylim(0.0, 5.0) +ax.yaxis.set_major_locator(ticker.MultipleLocator(2.0)) +ax.set_xlabel('Difference of means') +ax.set_ylabel('PDF of H0') + +plt.savefig('permuteaverage.pdf') diff --git a/bootstrap/lecture/permutecorrelation.py b/bootstrap/lecture/permutecorrelation.py index c5f0db7..3357140 100644 --- a/bootstrap/lecture/permutecorrelation.py +++ b/bootstrap/lecture/permutecorrelation.py @@ -1,9 +1,11 @@ import numpy as np import scipy.stats as st import matplotlib.pyplot as plt +import matplotlib.gridspec as gridspec +import matplotlib.ticker as ticker from plotstyle import * -rng = np.random.RandomState(637281) +rng = np.random.RandomState(37281) # generate correlated data: n = 200 @@ -19,32 +21,56 @@ rd = np.corrcoef(x, y)[0, 1] nperm = 1000 rs = [] for i in range(nperm) : - xr=rng.permutation(x) - yr=rng.permutation(y) - rs.append( np.corrcoef(xr, yr)[0, 1] ) + xr = rng.permutation(x) + yr = rng.permutation(y) + rs.append(np.corrcoef(xr, yr)[0, 1]) +rr = np.corrcoef(xr, yr)[0, 1] # pdf of the correlation coefficients: h, b = np.histogram(rs, 20, density=True) # significance: rq = np.percentile(rs, 95.0) -print('Measured correlation coefficient = %.2f, correlation coefficient at 95%% percentile of bootstrap = %.2f' % (rd, rq)) +print('Measured correlation coefficient = %.2f, correlation coefficient at 95%% percentile of permutation = %.2f' % (rd, rq)) ra = 1.0-0.01*st.percentileofscore(rs, rd) -print('Measured correlation coefficient %.2f is at %.4f percentile of bootstrap' % (rd, ra)) +print('Measured correlation coefficient %.2f is at %.4f percentile of permutation' % (rd, ra)) rp, ra = st.pearsonr(x, y) print('Measured correlation coefficient %.2f is at %.4f percentile of test' % (rp, ra)) -fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height)) -fig.subplots_adjust(**adjust_fs(left=4.0, bottom=2.7, right=0.5, top=1.0)) +fig = plt.figure(figsize=cm_size(figure_width, 1.8*figure_height)) +gs = gridspec.GridSpec(nrows=2, ncols=2, wspace=0.35, hspace=0.8, + **adjust_fs(fig, left=5.0, right=1.5, top=1.0, bottom=2.7)) + +ax = fig.add_subplot(gs[0,0]) +ax.text(0.0, 4.0, 'r=%.2f' % rd, ha='center') +ax.plot(x, y, **psAm) +ax.set_xlim(-4.0, 4.0) +ax.set_ylim(-4.0, 4.0) +ax.xaxis.set_major_locator(ticker.MultipleLocator(2.0)) +ax.yaxis.set_major_locator(ticker.MultipleLocator(2.0)) +ax.set_xlabel('x') +ax.set_ylabel('y') + +ax = fig.add_subplot(gs[0,1]) +ax.text(0.0, 4.0, 'r=%.2f' % rr, ha='center') +ax.plot(xr, yr, **psAm) +ax.set_xlim(-4.0, 4.0) +ax.set_ylim(-4.0, 4.0) +ax.xaxis.set_major_locator(ticker.MultipleLocator(2.0)) +ax.yaxis.set_major_locator(ticker.MultipleLocator(2.0)) +ax.set_xlabel('Shuffled x') +ax.set_ylabel('Shuffled y') + +ax = fig.add_subplot(gs[1,:]) ax.annotate('Measured\ncorrelation\nis significant!', xy=(rd, 1.1), xycoords='data', - xytext=(rd, 2.2), textcoords='data', ha='left', - arrowprops=dict(arrowstyle="->", relpos=(0.2,0.0), + xytext=(rd-0.01, 3.0), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(0.3,0.0), connectionstyle="angle3,angleA=10,angleB=80") ) ax.annotate('95% percentile', xy=(0.14, 0.9), xycoords='data', - xytext=(0.18, 4.0), textcoords='data', ha='left', + xytext=(0.16, 6.2), textcoords='data', ha='left', arrowprops=dict(arrowstyle="->", relpos=(0.1,0.0), connectionstyle="angle3,angleA=30,angleB=80") ) ax.annotate('Distribution of\nuncorrelated\nsamples', @@ -56,7 +82,9 @@ ax.bar(b[:-1], h, width=b[1]-b[0], **fsC) ax.bar(b[:-1][b[:-1]>=rq], h[b[:-1]>=rq], width=b[1]-b[0], **fsB) ax.plot( [rd, rd], [0, 1], **lsA) ax.set_xlim(-0.25, 0.35) +ax.set_ylim(0.0, 6.0) +ax.yaxis.set_major_locator(ticker.MultipleLocator(2.0)) ax.set_xlabel('Correlation coefficient') -ax.set_ylabel('Prob. density of H0') +ax.set_ylabel('PDF of H0') plt.savefig('permutecorrelation.pdf') diff --git a/chapter.mk b/chapter.mk index 50d1708..3afd160 100644 --- a/chapter.mk +++ b/chapter.mk @@ -42,6 +42,9 @@ $(BASENAME)-chapter.pdf : $(BASENAME)-chapter.tex $(BASENAME).tex $(wildcard $(B watchchapter : while true; do ! make -q chapter && make chapter; sleep 0.5; done +watchplots : + while true; do ! make -q plots && make plots; sleep 0.5; done + cleantex: rm -f *~ rm -f $(BASENAME).aux $(BASENAME).log *.idx diff --git a/plotstyle.py b/plotstyle.py index cb453f3..ecada61 100644 --- a/plotstyle.py +++ b/plotstyle.py @@ -33,13 +33,14 @@ colors['white'] = '#FFFFFF' # general settings for plot styles: lwthick = 3.0 lwthin = 1.8 +edgewidth = 0.0 if xkcd_style else 1.0 mainline = {'linestyle': '-', 'linewidth': lwthick} minorline = {'linestyle': '-', 'linewidth': lwthin} -largemarker = {'marker': 'o', 'markersize': 9, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} -smallmarker = {'marker': 'o', 'markersize': 6, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} +largemarker = {'marker': 'o', 'markersize': 9, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth} +smallmarker = {'marker': 'o', 'markersize': 6, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth} largelinepoints = {'linestyle': '-', 'linewidth': lwthick, 'marker': 'o', 'markersize': 10, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} smalllinepoints = {'linestyle': '-', 'linewidth': 1.4, 'marker': 'o', 'markersize': 7, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} -filllw = 1.0 +filllw = edgewidth fillec = colors['white'] fillalpha = 0.4 filledge = {'linewidth': filllw, 'joinstyle': 'round'} From b76b2d35cce208d129f86594243831d1a9acbf41 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 13 Dec 2020 09:08:05 +0100 Subject: [PATCH 08/37] [bootstrap] generalized intro --- bootstrap/lecture/bootstrap-chapter.tex | 11 +++++- bootstrap/lecture/bootstrap.tex | 51 ++++++++++++++----------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/bootstrap/lecture/bootstrap-chapter.tex b/bootstrap/lecture/bootstrap-chapter.tex index 78d7d3c..9009d78 100644 --- a/bootstrap/lecture/bootstrap-chapter.tex +++ b/bootstrap/lecture/bootstrap-chapter.tex @@ -23,7 +23,14 @@ This chapter easily covers two lectures: \item 1. Bootstrapping with a proper introduction of of confidence intervals \item 2. Permutation test with a proper introduction of statistical tests (distribution of nullhypothesis, significance, power, etc.) \end{itemize} - -Add jacknife methods to bootstrapping +ToDo: +\begin{itemize} +\item Add jacknife methods to bootstrapping +\item Add discussion of confidence intervals to descriptive statistics chapter +\item Have a separate chapter on statistical tests before. What is the + essence of a statistical test (null hypothesis distribution), power + analysis, and a few examples of existing functions for statistical + tests. +\end{itemize} \end{document} diff --git a/bootstrap/lecture/bootstrap.tex b/bootstrap/lecture/bootstrap.tex index 8f72366..f71b268 100644 --- a/bootstrap/lecture/bootstrap.tex +++ b/bootstrap/lecture/bootstrap.tex @@ -5,20 +5,24 @@ \exercisechapter{Resampling methods} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\section{Bootstrapping} - -Bootstrapping methods are applied to create distributions of -statistical measures via resampling of a sample. Bootstrapping offers several -advantages: +\entermde{Resampling methoden}{Resampling methods} are applied to +generate distributions of statistical measures via resampling of +existing samples. Resampling offers several advantages: \begin{itemize} \item Fewer assumptions (e.g. a measured sample does not need to be normally distributed). \item Increased precision as compared to classical methods. %such as? -\item General applicability: the bootstrapping methods are very +\item General applicability: the resampling methods are very similar for different statistics and there is no need to specialize the method to specific statistic measures. \end{itemize} +Resampling methods can be used for both estimating the precision of +estimated statistics (e.g. standard error of the mean, confidence +intervals) and testing for significane. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Bootstrapping} \begin{figure}[tp] \includegraphics[width=0.8\textwidth]{2012-10-29_16-26-05_771}\\[2ex] @@ -88,20 +92,20 @@ of the statistical population. We can use the bootstrap distribution to draw conclusion regarding the precision of our estimation (e.g. standard errors and confidence intervals). -Bootstrapping methods create bootstrapped samples from a SRS by +Bootstrapping methods generate bootstrapped samples from a SRS by resampling. The bootstrapped samples are used to estimate the sampling distribution of a statistical measure. The bootstrapped samples have -the same size as the original sample and are created by randomly +the same size as the original sample and are generated by randomly drawing with replacement. That is, each value of the original sample -can occur once, multiple time, or not at all in a bootstrapped +can occur once, multiple times, or not at all in a bootstrapped sample. This can be implemented by generating random indices into the data set using the \code{randi()} function. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\subsection{Bootstrap of the standard error} +\subsection{Bootstrap the standard error} -Bootstrapping can be nicely illustrated at the example of the +Bootstrapping can be nicely illustrated on the example of the \enterm{standard error} of the mean (\determ{Standardfehler}). The arithmetic mean is calculated for a simple random sample. The standard error of the mean is the standard deviation of the expected @@ -121,9 +125,9 @@ population. the standard error of the mean.} \end{figure} -Via bootstrapping we create a distribution of the mean values +Via bootstrapping we generate a distribution of mean values (\figref{bootstrapsemfig}) and the standard deviation of this -distribution is the standard error of the mean. +distribution is the standard error of the sample mean. \begin{exercise}{bootstrapsem.m}{bootstrapsem.out} Create the distribution of mean values from bootstrapped samples @@ -148,17 +152,18 @@ distribution is the standard error of the mean. Statistical tests ask for the probability of a measured value to originate from a null hypothesis. Is this probability smaller than the desired \entermde{Signifikanz}{significance level}, the -\entermde{Nullhypothese}{null hypothesis} may be rejected. +\entermde{Nullhypothese}{null hypothesis} can be rejected. Traditionally, such probabilities are taken from theoretical -distributions which are based on some assumptions about the data. For -example, the data should be normally distributed. Given some data one -has to find an appropriate test that matches the properties of the -data. An alternative approach is to calculate the probability density -of the null hypothesis directly from the data themselves. To do so, we -need to resample the data according to the null hypothesis from the -SRS. By such permutation operations we destroy the feature of interest -while conserving all other statistical properties of the data. +distributions which have been derived based on some assumptions about +the data. For example, the data should be normally distributed. Given +some data one has to find an appropriate test that matches the +properties of the data. An alternative approach is to calculate the +probability density of the null hypothesis directly from the data +themselves. To do so, we need to resample the data according to the +null hypothesis from the SRS. By such permutation operations we +destroy the feature of interest while conserving all other statistical +properties of the data. \subsection{Significance of a difference in the mean} From 68784b0e23125cc3cfe32557a0b4c7ac69c6bddd Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 13 Dec 2020 09:43:44 +0100 Subject: [PATCH 09/37] random fixes and notes --- Makefile | 2 +- chapter.mk | 2 ++ codestyle/lecture/codestyle.tex | 1 + header.tex | 2 +- plotting/lecture/plotting.tex | 28 +++++++++--------- .../lecture/pointprocessscetchA.eps | 4 +-- .../lecture/pointprocessscetchA.pdf | Bin 2786 -> 2786 bytes .../lecture/pointprocessscetchB.eps | 4 +-- .../lecture/pointprocessscetchB.pdf | Bin 4694 -> 4694 bytes scientificcomputing-script.tex | 15 +++++----- 10 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index a743d0a..b59d881 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BASENAME=scientificcomputing-script SUBDIRS=programming debugging plotting codestyle statistics bootstrap regression likelihood pointprocesses designpattern SUBTEXS=$(foreach subd, $(SUBDIRS), $(subd)/lecture/$(subd).tex) -all : script chapters +all : plots chapters index script chapters : for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture chapter; done diff --git a/chapter.mk b/chapter.mk index 3afd160..0482aed 100644 --- a/chapter.mk +++ b/chapter.mk @@ -10,6 +10,8 @@ pythonplots : $(PYPDFFILES) $(PYPDFFILES) : %.pdf: %.py ../../plotstyle.py PYTHONPATH="../../" python3 $< + #ps2pdf $@ $(@:.pdf=-temp.pdf) # strip fonts, saves only about 1.5MB + #mv $(@:.pdf=-temp.pdf) $@ cleanpythonplots : rm -f $(PYPDFFILES) diff --git a/codestyle/lecture/codestyle.tex b/codestyle/lecture/codestyle.tex index 01d1d12..8e2ee7e 100644 --- a/codestyle/lecture/codestyle.tex +++ b/codestyle/lecture/codestyle.tex @@ -4,6 +4,7 @@ more months might as well have been written by someone else.}{Eagleson's law} +\noindent Cultivating a good code style is not just a matter of good taste but rather is a key ingredient for readability and maintainability of code and, in the end, facilitates reproducibility of scientific diff --git a/header.tex b/header.tex index fcaaa87..ab412ef 100644 --- a/header.tex +++ b/header.tex @@ -319,7 +319,7 @@ % \newboolean{showexercisesolutions} \setboolean{showexercisesolutions}{true} -\newcommand{\exercisesolutions}{chapter} % 0: here, 1: chapter, 2: end +\newcommand{\exercisesolutions}{end} % 0: here, 1: chapter, 2: end % we need this also as numbers: \ifthenelse{\equal{\exercisesolutions}{end}}{\newcommand{\exercisesolutionsnum}{2}}{% \ifthenelse{\equal{\exercisesolutions}{chapter}}{\newcommand{\exercisesolutionsnum}{1}}{% diff --git a/plotting/lecture/plotting.tex b/plotting/lecture/plotting.tex index b27b919..1d30084 100644 --- a/plotting/lecture/plotting.tex +++ b/plotting/lecture/plotting.tex @@ -74,20 +74,20 @@ the data was changed or the same kind of plot has to be created for a number of datasets. \begin{important}[Why manual editing should be avoided.] - On first glance the manual editing of a figure using tools such as - Corel draw, Illustrator, etc.\,appears much more convenient and less - complex than coding everything into the analysis scripts. This, - however, is not entirely true. What if the figure has to be re-drawn - or updated? Then the editing work starts all over again. Rather, - there is a great risk associated with the manual editing - approach. Axes may be shifted, fonts have not been embedded into the - final document, annotations have been copy pasted between figures - and are not valid. All of these mistakes can be found in - publications and then require an erratum, which is not - desirable. Even if it appears more cumbersome in the beginning one - should always try to create publication-ready figures directly from - the data analysis tool using scripts or functions to properly layout - the plot. + On first glance manual editing of a figure using tools such as + inkscape, Corel draw, Illustrator, etc.\,appears much more + convenient and less complex than coding everything into the analysis + scripts. This, however, is not entirely true. What if the figure has + to be re-drawn or updated, because, for example, you got more data? + Then the editing work starts all over again. In addition, there is a + great risk associated with the manual editing approach. Axes may be + shifted, fonts have not been embedded into the final document, + annotations have been copy-pasted between figures and are not + valid. All of these mistakes can be found in publications and then + require an erratum, which is not desirable. Even if it appears more + cumbersome in the beginning, one should always try to generate + publication-ready figures directly from the data analysis tool using + scripts or functions to properly layout and annotate the plot. \end{important} \subsection{Simple plotting} diff --git a/pointprocesses/lecture/pointprocessscetchA.eps b/pointprocesses/lecture/pointprocessscetchA.eps index 441b034..5a4bb00 100644 --- a/pointprocesses/lecture/pointprocessscetchA.eps +++ b/pointprocesses/lecture/pointprocessscetchA.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchA.tex %%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Fri Dec 11 21:08:22 2020 +%%CreationDate: Sun Dec 13 09:18:35 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 135 %%EndComments @@ -433,7 +433,7 @@ SDict begin [ /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Fri Dec 11 21:08:22 2020) + /CreationDate (Sun Dec 13 09:18:35 2020) /DOCINFO pdfmark end } ifelse diff --git a/pointprocesses/lecture/pointprocessscetchA.pdf b/pointprocesses/lecture/pointprocessscetchA.pdf index 3d417334e8f4f0885323a9268c63697c84990acd..b06226f27816fe77a57084746e940457f8cc9dc1 100644 GIT binary patch delta 309 zcmaDP`bc!cQD$CK3nODwGlL{ub5moB$pLKglRq+NVG(U-vEecfF|f2Uw6HQZoqU!> zLn62|PeIouRX157#L(DE!N3YEX=OT@m$eCt3AKgA`nBvr%33M61?WN2()X=q_=x|x%+hB4O3)Y8<{)YZbo z+|bR^#n{Ed(8ATy&C%S^#nIBx$kffwhMRntYZ; zL&B{nQ$g1yRX157#L&=6!N>|MX=OB-m$eCt3AKgA`nBvr%33M61?WC%nC7Dh&!IXP<>W6jOXj4TbEja|&l zEDemEoehnQEM1)~fTGT(&TdXlb~Xf6#B$l$aTS*&7L`;KrKWKinHU>$sj9mAyKw;k D@|;U- diff --git a/pointprocesses/lecture/pointprocessscetchB.eps b/pointprocesses/lecture/pointprocessscetchB.eps index b9863a7..a0b1ee2 100644 --- a/pointprocesses/lecture/pointprocessscetchB.eps +++ b/pointprocesses/lecture/pointprocessscetchB.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchB.tex %%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Fri Dec 11 21:08:22 2020 +%%CreationDate: Sun Dec 13 09:18:35 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 237 %%EndComments @@ -433,7 +433,7 @@ SDict begin [ /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Fri Dec 11 21:08:22 2020) + /CreationDate (Sun Dec 13 09:18:35 2020) /DOCINFO pdfmark end } ifelse diff --git a/pointprocesses/lecture/pointprocessscetchB.pdf b/pointprocesses/lecture/pointprocessscetchB.pdf index d172e5c62c65027bc4b578fa5f6b7634f9b9e8ef..6d49213180fa4a5b33b784fef75bb8f5208c60a8 100644 GIT binary patch delta 266 zcmcbna!qA}B{#3Bg^{tTnL(1Sxv8D^SDeWM<;zY~pHUVrXJyVQFS*>}+XbX5{Q@Wa?yQ R;p}4MY-dAA#bj$CX#h%9KrR3P delta 266 zcmcbna!qA}B{#28l97q2fw`%!xru@0WC33J$*J5~7@`W3|8QG#8HN}cS{Yba85vD> zX3A!Z0BYLquZoWL^~vQTfe}dDEGML1w$8 zCMy^kD!}cG6_8{%G%_@>Ff!U)D^SDeWN7YW;b>@JY-VN*q+CqR9Zg-Foy`rMUCqoK Qoh*#)YzV2CY%L@W00J>TyZ`_I diff --git a/scientificcomputing-script.tex b/scientificcomputing-script.tex index 4847455..21daaba 100644 --- a/scientificcomputing-script.tex +++ b/scientificcomputing-script.tex @@ -71,19 +71,18 @@ \includechapter{regression} +\includechapter{likelihood} + % add chapter on generalized linear models (versus ANOVA) -% add chapter on nonlinear fitting (methods, initial values, local minima) - -\includechapter{likelihood} +% add chapter on nonlinear fitting (methods, initial values, local minima, power law fits on log-log data) \includechapter{pointprocesses} % add chapter on time series (amplitude distribution, autocorrelation, crosscorrelation) - %\includechapter{spectral} -% add chapter on digital filtering +% add chapter on filtering and envelopes % add chapter on event detection, signal detection, ROC @@ -97,11 +96,11 @@ %\part{Tools} % Latex -% markdown +% markdown, html % Makefile % version control (git and github) only put source files into repository! % distributed computing (ssh and grid engines) -% data handling (structure, data bases, storage (rsync), backup) +% data handling (structure, storage (rsync), backup, data bases) % data annotation, meta data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -111,7 +110,7 @@ %\chapter{Cheat-Sheet} %%%% solutions: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% \printallsolutions +\printallsolutions %%%% indices: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% From c9dd1ffbe64c39f52d972fa5ad5a091aba1bb53e Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 13 Dec 2020 13:43:27 +0100 Subject: [PATCH 10/37] [bootstrap] expanding exercise by difference of mean permutation test --- bootstrap/exercises/bootstrapmean.m | 2 +- bootstrap/exercises/correlationbootstrap.m | 14 ++--- bootstrap/exercises/correlationsignificance.m | 20 +++---- bootstrap/exercises/exercises01.tex | 54 +++++++++++++++++-- bootstrap/exercises/meandiffpermutation.m | 29 ++++++++++ bootstrap/exercises/meandiffsignificance.m | 48 +++++++++++++++++ bootstrap/exercises/tdistribution.m | 16 +++--- .../exercises/fitting.tex | 0 8 files changed, 152 insertions(+), 31 deletions(-) create mode 100644 bootstrap/exercises/meandiffpermutation.m create mode 100644 bootstrap/exercises/meandiffsignificance.m rename {statistics => regression}/exercises/fitting.tex (100%) diff --git a/bootstrap/exercises/bootstrapmean.m b/bootstrap/exercises/bootstrapmean.m index 6f3b494..686df9e 100644 --- a/bootstrap/exercises/bootstrapmean.m +++ b/bootstrap/exercises/bootstrapmean.m @@ -10,7 +10,7 @@ function [bootsem, mu] = bootstrapmean(x, resample) for i = 1:resample % resample: xr = x(randi(nsamples, nsamples, 1)); - % compute statistics on sample: + % compute statistics of resampled sample: mu(i) = mean(xr); end bootsem = std(mu); diff --git a/bootstrap/exercises/correlationbootstrap.m b/bootstrap/exercises/correlationbootstrap.m index 707285f..8f6f16f 100644 --- a/bootstrap/exercises/correlationbootstrap.m +++ b/bootstrap/exercises/correlationbootstrap.m @@ -1,18 +1,18 @@ %% (a) bootstrap: nperm = 1000; -rb = zeros(nperm,1); +rb = zeros(nperm, 1); for i=1:nperm % indices for resampling the data: inx = randi(length(x), length(x), 1); % resampled data pairs: - xb=x(inx); - yb=y(inx); + xb = x(inx); + yb = y(inx); rb(i) = corr(xb, yb); end %% (b) pdf of the correlation coefficients: -[hb,bb] = hist(rb, 20); -hb = hb/sum(hb)/(bb(2)-bb(1)); % normalization +[hb, bb] = hist(rb, 20); +hb = hb/sum(hb)/(bb(2)-bb(1)); % normalization %% (c) significance: rbq = quantile(rb, 0.05); @@ -25,8 +25,8 @@ end %% plot: hold on; -bar(b, h, 'facecolor', [0.5 0.5 0.5]); -bar(bb, hb, 'facecolor', 'b'); +bar(b, h, 'facecolor', [0.5 0.5 0.5]); % permuation test +bar(bb, hb, 'facecolor', 'b'); % bootstrap bar(bb(bb<=rbq), hb(bb<=rbq), 'facecolor', 'r'); plot([rd rd], [0 4], 'r', 'linewidth', 2); xlim([-0.25 0.75]) diff --git a/bootstrap/exercises/correlationsignificance.m b/bootstrap/exercises/correlationsignificance.m index d44af84..c7b1939 100644 --- a/bootstrap/exercises/correlationsignificance.m +++ b/bootstrap/exercises/correlationsignificance.m @@ -1,4 +1,4 @@ -%% (a) generate correlated data +%% (a) generate correlated data: n = 1000; a = 0.2; x = randn(n, 1); @@ -8,7 +8,7 @@ y = randn(n, 1) + a*x; subplot(1, 2, 1); plot(x, a*x, 'r', 'linewidth', 3); hold on -%scatter(x, y ); % either scatter ... +%scatter(x, y ); % either scatter ... plot(x, y, 'o', 'markersize', 2 ); % ... or plot - same plot. xlim([-4 4]) ylim([-4 4]) @@ -20,20 +20,20 @@ hold off %c = corrcoef(x, y); % returns correlation matrix %rd = c(1, 2); rd = corr(x, y); -fprintf('correlation coefficient = %.2f\n', rd ); +fprintf('correlation coefficient = %.2f\n', rd); %% (e) permutation: nperm = 1000; -rs = zeros(nperm,1); -for i=1:nperm - xr=x(randperm(length(x))); % shuffle x - yr=y(randperm(length(y))); % shuffle y +rs = zeros(nperm, 1); +for i = 1:nperm + xr = x(randperm(length(x))); % shuffle x + yr = y(randperm(length(y))); % shuffle y rs(i) = corr(xr, yr); end %% (g) pdf of the correlation coefficients: -[h,b] = hist(rs, 20); -h = h/sum(h)/(b(2)-b(1)); % normalization +[h, b] = hist(rs, 20); +h = h/sum(h)/(b(2)-b(1)); % normalization %% (h) significance: rq = quantile(rs, 0.95); @@ -49,7 +49,7 @@ subplot(1, 2, 2) hold on; bar(b, h, 'facecolor', 'b'); bar(b(b>=rq), h(b>=rq), 'facecolor', 'r'); -plot( [rd rd], [0 4], 'r', 'linewidth', 2); +plot([rd rd], [0 4], 'r', 'linewidth', 2); xlim([-0.25 0.25]) xlabel('Correlation coefficient'); ylabel('Probability density of H0'); diff --git a/bootstrap/exercises/exercises01.tex b/bootstrap/exercises/exercises01.tex index 0917579..dd2380d 100644 --- a/bootstrap/exercises/exercises01.tex +++ b/bootstrap/exercises/exercises01.tex @@ -15,7 +15,7 @@ \else \newcommand{\stitle}{} \fi -\header{{\bfseries\large Exercise 9\stitle}}{{\bfseries\large Bootstrap}}{{\bfseries\large December 9th, 2019}} +\header{{\bfseries\large Exercise 8\stitle}}{{\bfseries\large Resampling}}{{\bfseries\large December 14th, 2020}} \firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: jan.benda@uni-tuebingen.de} \runningfooter{}{\thepage}{} @@ -86,6 +86,9 @@ jan.benda@uni-tuebingen.de} \begin{questions} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\question \qt{Read chapter 7 of the script on ``resampling methods''!}\vspace{-3ex} + \question \qt{Bootstrap the standard error of the mean} We want to compute the standard error of the mean of a data set by means of the bootstrap method and compare the result with the formula @@ -149,10 +152,10 @@ normally distributed? \continue -\question \qt{Permutation test} \label{permutationtest} +\question \qt{Permutation test of correlations} \label{correlationtest} We want to compute the significance of a correlation by means of a permutation test. \begin{parts} - \part \label{permutationtestdata} Generate 1000 correlated pairs + \part \label{correlationtestdata} Generate 1000 correlated pairs $x$, $y$ of random numbers according to: \begin{verbatim} n = 1000 @@ -188,9 +191,13 @@ correlation coefficient of zero we can conclude that the correlation coefficient of the data indeed quantifies correlated data. We take the same data set that we have generated in exercise -\ref{permutationtest} (\ref{permutationtestdata}). +\ref{correlationtest} (\ref{correlationtestdata}). \begin{parts} - \part Bootstrap 1000 times the correlation coefficient from the data. + \part Bootstrap 1000 times the correlation coefficient from the + data, i.e. generate bootstrap data by randomly resampling the + original data pairs with replacement. Use the \code{randi()} + function for generating random indices that you can use to select a + random sample from the original data. \part Compute and plot the probability density of these correlation coefficients. \part Is the correlation of the original data set significant? @@ -200,6 +207,43 @@ We take the same data set that we have generated in exercise \includegraphics[width=1\textwidth]{correlationbootstrap} \end{solution} + +\continuepage +\question \qt{Permutation test of difference of means} +We want to test whether two data sets come from distributions that +differ in their mean by means of a permutation test. +\begin{parts} + \part Generate two normally distributed data sets $x$ and $y$ + containing each $n=200$ samples. Let's assume the $x$ samples are + measurements of the membrane potential of a mammalian photoreceptor + in darkness with a mean of $-40$\,mV and a standard deviation of + 1\,mV. The $y$ values are the membrane potentials measured under dim + illumination and come from a distribution with the same standard + deviation and a mean of $-40.5$\,mV. See section 5.2 ``Scaling and + shifting random numbers'' in the script. + \part Plot histograms of the $x$ and $y$ data in a single + plot. Choose appropriate bins. + \part Compute the means of $x$ and $y$ and their difference. + \part The null hypothesis is that the $x$ and $y$ data come from the + same distribution. How can you generate new samples $x_r$ and $y_r$ + from the original data that come from the same distribution? + \part Do exactly this 1000 times and compute each time the + difference of the means of the two resampled samples. + \part Compute and plot the probability density of the resulting + distribution of the null hypothesis. + \part Is the difference of the means of the original data sets significant? + \part Repeat this procedure for $y$ samples that are closer or + further apart from the mean of the $x$ data set. For this put the + computations of the permuation test in a function and all the plotting + in another function. +\end{parts} +\begin{solution} + \lstinputlisting{meandiffpermutation.m} + %\lstinputlisting{meandiffplots.m} + \lstinputlisting{meandiffsignificance.m} + \includegraphics[width=1\textwidth]{meandiffsignificance} +\end{solution} + \end{questions} \end{document} \ No newline at end of file diff --git a/bootstrap/exercises/meandiffpermutation.m b/bootstrap/exercises/meandiffpermutation.m new file mode 100644 index 0000000..f8fb58a --- /dev/null +++ b/bootstrap/exercises/meandiffpermutation.m @@ -0,0 +1,29 @@ +function [md, ds, dq] = meandiffpermutation(x, y, nperm, alpha) +% Permutation test for difference of means of two independent samples. +% +% [md, ds] = meandiffpermutation(x, y, nperm, alpha); +% +% Arguments: +% x: vector with the samples of the x data set. +% y: vector with the samples of the y data set. +% nperm: number of permutations run. +% alpha: significance level. +% +% Returns: +% md: difference of the means +% ds: vector containing the differences of the means of the resampled data sets +% dq: difference of the means at a significance of alpha. + + md = mean(x) - mean(y); % measured difference + xy = [x; y]; % merge data sets + % permutations: + ds = zeros(nperm, 1); + for i = 1:nperm + xyr = xy(randperm(length(xy))); % shuffle xy + xr = xyr(1:length(x)); % random x sample + yr = xyr(length(x)+1:end); % random y sample + ds(i) = mean(xr) - mean(yr); + end + % significance: + dq = quantile(ds, 1.0 - alpha); +end diff --git a/bootstrap/exercises/meandiffsignificance.m b/bootstrap/exercises/meandiffsignificance.m new file mode 100644 index 0000000..cf6586d --- /dev/null +++ b/bootstrap/exercises/meandiffsignificance.m @@ -0,0 +1,48 @@ +%% (a) generate data: +n = 200; +mx = -40.0; +my = -40.5; +x = randn(n, 1) + mx; +y = randn(n, 1) + my; + +%% (b) plot histograms: +subplot(1, 2, 1); +bmin = min([x; y]); +bmax = max([x; y]); +bins = bmin:(bmax-bmin)/20.0:bmax; +hist(x, bins, 'facecolor', 'b'); +hold on +hist(y, bins, 'facecolor', 'r'); +xlabel('x and y') +ylabel('counts') +hold off + +% permutation test: +[md, ds, dq] = meandiffpermutation(x, y, nperm, alpha); + +%% (c) difference of means: +fprintf('difference of means = %.2fmV\n', md); + +%% (f) pdf of the differences: +[h, b] = hist(ds, 20); +h = h/sum(h)/(b(2)-b(1)); % normalization + +%% (g) significance: +fprintf('difference of means at 5%% significance = %.2fmV\n', dq); +if md >= dq + fprintf('--> difference of means %.2fmV is significant\n', md); +else + fprintf('--> %.2fmV is not a significant difference of means\n', md); +end + +%% plot: +subplot(1, 2, 2) +bar(b, h, 'facecolor', 'b'); +hold on; +bar(b(b>=dq), h(b>=dq), 'facecolor', 'r'); +plot([md md], [0 4], 'r', 'linewidth', 2); +xlabel('Difference of means'); +ylabel('Probability density of H0'); +hold off; + +savefigpdf(gcf, 'meandiffsignificance.pdf', 12, 6); diff --git a/bootstrap/exercises/tdistribution.m b/bootstrap/exercises/tdistribution.m index 5fe8341..e20aebc 100644 --- a/bootstrap/exercises/tdistribution.m +++ b/bootstrap/exercises/tdistribution.m @@ -1,10 +1,10 @@ %% (a) generate random numbers: n = 100000; -x=randn(n, 1); +x = randn(n, 1); -for nsamples=[3 5 10 50] +for nsamples = [3 5 10 50] nsamples - %% compute mean, standard deviation and t: + % compute mean, standard deviation and t: nmeans = 10000; means = zeros(nmeans, 1); sdevs = zeros(nmeans, 1); @@ -19,14 +19,14 @@ for nsamples=[3 5 10 50] % Gaussian pdfs: msdev = std(means); tsdev = 1.0; - dxg=0.01; + dxg = 0.01; xmax = 10.0; xmin = -xmax; xg = [xmin:dxg:xmax]; pm = exp(-0.5*(xg/msdev).^2)/sqrt(2.0*pi)/msdev; pt = exp(-0.5*(xg/tsdev).^2)/sqrt(2.0*pi)/tsdev; - %% plots + % plots: subplot(1, 2, 1) bins = xmin:0.2:xmax; [h,b] = hist(means, bins); @@ -35,7 +35,7 @@ for nsamples=[3 5 10 50] hold on plot(xg, pm, 'r', 'linewidth', 2) title(sprintf('sample size = %d', nsamples)); - xlim( [-3, 3] ); + xlim([-3, 3]); xlabel('Mean'); ylabel('pdf'); hold off; @@ -48,11 +48,11 @@ for nsamples=[3 5 10 50] hold on plot(xg, pt, 'r', 'linewidth', 2) title(sprintf('sample size = %d', nsamples)); - xlim( [-8, 8] ); + xlim([-8, 8]); xlabel('Student-t'); ylabel('pdf'); hold off; savefigpdf(gcf, sprintf('tdistribution-n%02d.pdf', nsamples), 14, 5); - pause( 3.0 ) + pause(3.0) end diff --git a/statistics/exercises/fitting.tex b/regression/exercises/fitting.tex similarity index 100% rename from statistics/exercises/fitting.tex rename to regression/exercises/fitting.tex From af45ae7f9eb926156a162f8e549e2a8b2f7a2f98 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 13 Dec 2020 23:35:37 +0100 Subject: [PATCH 11/37] [bootstrap] finished code for new exercises --- bootstrap/exercises/exercises01.tex | 4 +- bootstrap/exercises/meandiffpermutation.m | 2 +- bootstrap/exercises/meandiffplot.m | 40 +++++++++++ bootstrap/exercises/meandiffsignificance.m | 77 ++++++++++------------ bootstrap/exercises/savefigpdf.m | 38 +++++------ 5 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 bootstrap/exercises/meandiffplot.m diff --git a/bootstrap/exercises/exercises01.tex b/bootstrap/exercises/exercises01.tex index dd2380d..12ffb94 100644 --- a/bootstrap/exercises/exercises01.tex +++ b/bootstrap/exercises/exercises01.tex @@ -37,7 +37,7 @@ jan.benda@uni-tuebingen.de} commentstyle=\itshape\color{darkgray}, breaklines=true, breakautoindent=true, - columns=flexible, + % columns=flexible, frame=single, xleftmargin=1em, xrightmargin=1em, @@ -239,7 +239,7 @@ differ in their mean by means of a permutation test. \end{parts} \begin{solution} \lstinputlisting{meandiffpermutation.m} - %\lstinputlisting{meandiffplots.m} + \lstinputlisting{meandiffplot.m} \lstinputlisting{meandiffsignificance.m} \includegraphics[width=1\textwidth]{meandiffsignificance} \end{solution} diff --git a/bootstrap/exercises/meandiffpermutation.m b/bootstrap/exercises/meandiffpermutation.m index f8fb58a..5b02a53 100644 --- a/bootstrap/exercises/meandiffpermutation.m +++ b/bootstrap/exercises/meandiffpermutation.m @@ -1,7 +1,7 @@ function [md, ds, dq] = meandiffpermutation(x, y, nperm, alpha) % Permutation test for difference of means of two independent samples. % -% [md, ds] = meandiffpermutation(x, y, nperm, alpha); +% [md, ds, dq] = meandiffpermutation(x, y, nperm, alpha); % % Arguments: % x: vector with the samples of the x data set. diff --git a/bootstrap/exercises/meandiffplot.m b/bootstrap/exercises/meandiffplot.m new file mode 100644 index 0000000..24fd625 --- /dev/null +++ b/bootstrap/exercises/meandiffplot.m @@ -0,0 +1,40 @@ +function meandiffplot(x, y, md, ds, dq, k, nrows) +% Plot histogram of data sets and of null hypothesis for differences in mean. +% +% meandiffplot(x, y, md, ds, dq, k, rows); +% +% Arguments: +% x: vector with the samples of the x data set. +% y: vector with the samples of the y data set. +% md: difference of means of the two data sets. +% ds: vector containing the differences of the means of the resampled data sets +% dq: minimum difference of the means considered significant. +% k: current row for the plot panels. +% nrows: number of rows of panels in the figure. + + %% (b) plot histograms: + subplot(nrows, 2, k*2-1); + bmin = min([x; y]); + bmax = max([x; y]); + bins = bmin:(bmax-bmin)/20.0:bmax; + hist(x, bins, 'facecolor', 'b'); + hold on + hist(y, bins, 'facecolor', 'r'); + xlabel('x and y') + ylabel('counts') + hold off + + %% (f) pdf of the differences: + [h, b] = hist(ds, 20); + h = h/sum(h)/(b(2)-b(1)); % normalization + + %% plot: + subplot(nrows, 2, k*2) + bar(b, h, 'facecolor', 'b'); + hold on; + bar(b(b>=dq), h(b>=dq), 'facecolor', 'r'); + plot([md md], [0 4], 'r', 'linewidth', 2); + xlabel('Difference of means'); + ylabel('Probability density of H0'); + hold off; +end diff --git a/bootstrap/exercises/meandiffsignificance.m b/bootstrap/exercises/meandiffsignificance.m index cf6586d..e234270 100644 --- a/bootstrap/exercises/meandiffsignificance.m +++ b/bootstrap/exercises/meandiffsignificance.m @@ -1,48 +1,37 @@ -%% (a) generate data: n = 200; mx = -40.0; -my = -40.5; -x = randn(n, 1) + mx; -y = randn(n, 1) + my; - -%% (b) plot histograms: -subplot(1, 2, 1); -bmin = min([x; y]); -bmax = max([x; y]); -bins = bmin:(bmax-bmin)/20.0:bmax; -hist(x, bins, 'facecolor', 'b'); -hold on -hist(y, bins, 'facecolor', 'r'); -xlabel('x and y') -ylabel('counts') -hold off - -% permutation test: -[md, ds, dq] = meandiffpermutation(x, y, nperm, alpha); - -%% (c) difference of means: -fprintf('difference of means = %.2fmV\n', md); - -%% (f) pdf of the differences: -[h, b] = hist(ds, 20); -h = h/sum(h)/(b(2)-b(1)); % normalization - -%% (g) significance: -fprintf('difference of means at 5%% significance = %.2fmV\n', dq); -if md >= dq - fprintf('--> difference of means %.2fmV is significant\n', md); -else - fprintf('--> %.2fmV is not a significant difference of means\n', md); +nperm = 1000; +alpha = 0.05; + +%% (h) repeat for various means of the y-data set: +mys = [-40.1, -40.2, -40.5]; +for k=1:length(mys) + + %% (a) generate data: + my = mys(k); + x = randn(n, 1) + mx; + y = randn(n, 1) + my; + + %% (d), (e) permutation test: + [md, ds, dq] = meandiffpermutation(x, y, nperm, alpha); + + %% (c) difference of means: + fprintf('\nmean x = %.1fmV, mean y = %.1fmV\n', mx, my); + fprintf(' difference of means = %.2fmV\n', md); + + %% (g) significance: + fprintf(' difference of means at 5%% significance = %.2fmV\n', dq); + if md >= dq + fprintf(' --> measured difference of means is significant\n'); + else + fprintf(' --> measured difference of means is not significant\n'); + end + + subplot(length(mys), 2, k*2-1); + title(sprintf('mx=%.1fmV, my=%.1fmV', mx, my)) + + %% (b), (f) plot histograms of data and pdf of differences: + meandiffplot(x, y, md, ds, dq, k, length(mys)); end -%% plot: -subplot(1, 2, 2) -bar(b, h, 'facecolor', 'b'); -hold on; -bar(b(b>=dq), h(b>=dq), 'facecolor', 'r'); -plot([md md], [0 4], 'r', 'linewidth', 2); -xlabel('Difference of means'); -ylabel('Probability density of H0'); -hold off; - -savefigpdf(gcf, 'meandiffsignificance.pdf', 12, 6); +savefigpdf(gcf, 'meandiffsignificance.pdf', 12, 10); diff --git a/bootstrap/exercises/savefigpdf.m b/bootstrap/exercises/savefigpdf.m index fbe2dc2..97a28a3 100644 --- a/bootstrap/exercises/savefigpdf.m +++ b/bootstrap/exercises/savefigpdf.m @@ -1,28 +1,28 @@ -function savefigpdf( fig, name, width, height ) +function savefigpdf(fig, name, width, height) % Saves figure fig in pdf file name.pdf with appropriately set page size % and fonts -% default width: -if nargin < 3 - width = 11.7; -end -% default height: -if nargin < 4 - height = 9.0; -end + % default width: + if nargin < 3 + width = 11.7; + end + % default height: + if nargin < 4 + height = 9.0; + end -% paper: -set( fig, 'PaperUnits', 'centimeters' ); -set( fig, 'PaperSize', [width height] ); -set( fig, 'PaperPosition', [0.0 0.0 width height] ); -set( fig, 'Color', 'white') + % paper: + set(fig, 'PaperUnits', 'centimeters'); + set(fig, 'PaperSize', [width height]); + set(fig, 'PaperPosition', [0.0 0.0 width height]); + set(fig, 'Color', 'white') -% font: -set( findall( fig, 'type', 'axes' ), 'FontSize', 12 ) -set( findall( fig, 'type', 'text' ), 'FontSize', 12 ) + % font: + set(findall(fig, 'type', 'axes'), 'FontSize', 12) + set(findall(fig, 'type', 'text'), 'FontSize', 12) -% save: -saveas( fig, name, 'pdf' ) + % save: + saveas(fig, name, 'pdf') end From bd261254a353b50909e2d0786508ca43a86996eb Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 14 Dec 2020 00:05:27 +0100 Subject: [PATCH 12/37] [bootstrap] improved latex and Makefile file structure --- bootstrap/exercises/Makefile | 36 +----- .../{exercises01.tex => resampling-1.tex} | 85 ++------------ exercises.mk | 33 ++++++ exercisesheader.tex | 108 ++++++++++++++++++ .../instructions.tex => exercisestitle.tex | 0 5 files changed, 151 insertions(+), 111 deletions(-) rename bootstrap/exercises/{exercises01.tex => resampling-1.tex} (77%) create mode 100644 exercises.mk create mode 100644 exercisesheader.tex rename bootstrap/exercises/instructions.tex => exercisestitle.tex (100%) diff --git a/bootstrap/exercises/Makefile b/bootstrap/exercises/Makefile index 27691d9..3f8d7db 100644 --- a/bootstrap/exercises/Makefile +++ b/bootstrap/exercises/Makefile @@ -1,34 +1,4 @@ -TEXFILES=$(wildcard exercises??.tex) -EXERCISES=$(TEXFILES:.tex=.pdf) -SOLUTIONS=$(EXERCISES:exercises%=solutions%) +TEXFILES=resampling-1.tex +# resampling2.tex -.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean - -pdf : $(SOLUTIONS) $(EXERCISES) - -exercises : $(EXERCISES) - -solutions : $(SOLUTIONS) - -$(SOLUTIONS) : solutions%.pdf : exercises%.tex instructions.tex - { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) - pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true - rm $(patsubst %.pdf,%,$@).[!p]* - -$(EXERCISES) : %.pdf : %.tex instructions.tex - pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true - -watch : - while true; do ! make -q pdf && make pdf; sleep 0.5; done - -watchexercises : - while true; do ! make -q exercises && make exercises; sleep 0.5; done - -watchsolutions : - while true; do ! make -q solutions && make solutions; sleep 0.5; done - -clean : - rm -f *~ *.aux *.log *.out - -cleanup : clean - rm -f $(SOLUTIONS) $(EXERCISES) +include ../../exercises.mk diff --git a/bootstrap/exercises/exercises01.tex b/bootstrap/exercises/resampling-1.tex similarity index 77% rename from bootstrap/exercises/exercises01.tex rename to bootstrap/exercises/resampling-1.tex index 12ffb94..326fbc6 100644 --- a/bootstrap/exercises/exercises01.tex +++ b/bootstrap/exercises/resampling-1.tex @@ -1,88 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[english]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 8\stitle}}{{\bfseries\large Resampling}}{{\bfseries\large December 14th, 2020}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - % columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\newcommand{\exercisetopic}{Resampling} +\newcommand{\exercisenum}{8} +\newcommand{\exercisedate}{December 14th, 2020} +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} +\input{../../exercisestitle} \begin{questions} diff --git a/exercises.mk b/exercises.mk new file mode 100644 index 0000000..f9d9cd8 --- /dev/null +++ b/exercises.mk @@ -0,0 +1,33 @@ +EXERCISES=$(TEXFILES:.tex=.pdf) +SOLUTIONS=$(EXERCISES:%.pdf=%-solutions.pdf) + +.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean + +pdf : $(SOLUTIONS) $(EXERCISES) + +exercises : $(EXERCISES) + +solutions : $(SOLUTIONS) + +$(SOLUTIONS) : %-solutions.pdf : %.tex ../../exercisesheader.tex ../../exercisestitle.tex + { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) + pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true + rm $(patsubst %.pdf,%,$@).[!p]* + +$(EXERCISES) : %.pdf : %.tex ../../exercisesheader.tex ../../exercisestitle.tex + pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true + +watch : + while true; do ! make -q pdf && make pdf; sleep 0.5; done + +watchexercises : + while true; do ! make -q exercises && make exercises; sleep 0.5; done + +watchsolutions : + while true; do ! make -q solutions && make solutions; sleep 0.5; done + +clean : + rm -f *~ *.aux *.log *.out + +cleanup : clean + rm -f $(SOLUTIONS) $(EXERCISES) diff --git a/exercisesheader.tex b/exercisesheader.tex new file mode 100644 index 0000000..321d22c --- /dev/null +++ b/exercisesheader.tex @@ -0,0 +1,108 @@ +\usepackage[english]{babel} +\usepackage{pslatex} +\usepackage{graphicx} +\usepackage{tikz} +\usepackage{xcolor} +\usepackage{amsmath} +\usepackage{amssymb} + +%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{listings} +\lstset{ + language=Matlab, + basicstyle=\ttfamily\footnotesize, + numbers=left, + numberstyle=\tiny, + title=\lstname, + showstringspaces=false, + commentstyle=\itshape\color{darkgray}, + breaklines=true, + breakautoindent=true, + % columns=flexible, + frame=single, + xleftmargin=1.5em, + xrightmargin=1em, + aboveskip=10pt +} + +%%%%% page style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage[left=20mm,right=20mm,top=25mm,bottom=19mm,headsep=2ex,headheight=3ex,footskip=3.5ex]{geometry} +\pagestyle{headandfoot} +\ifprintanswers +\newcommand{\stitle}{Solutions} +\else +\newcommand{\stitle}{} +\fi +\header{{\bfseries\large \exercisenum. \exercisetopic}}{{\bfseries\large\stitle}}{{\bfseries\large\exercisedate}} +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} +\runningfooter{}{\thepage}{} + +\shadedsolutions +\definecolor{SolutionColor}{gray}{0.9} + +\setlength{\baselineskip}{15pt} +\setlength{\parindent}{0.0cm} +\setlength{\parskip}{0.3cm} + +\usepackage{multicol} + +%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage[mediumspace,mediumqspace,Gray,squaren]{SIunits} % \ohm, \micro + +%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\cin}[1]{[{\rm #1}]_{\text{in}}} +\newcommand{\cout}[1]{[{\rm #1}]_{\text{out}}} +\newcommand{\units}[1]{\text{#1}} +\newcommand{\K}{\text{K$^+$}} +\newcommand{\Na}{\text{Na$^+$}} +\newcommand{\Cl}{\text{Cl$^-$}} +\newcommand{\Ca}{\text{Ca$^{2+}$}} +\newcommand{\water}{$\text{H}_2\text{O}$} + +\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}} +\newcommand{\RT}{{\rm Re\!\ }} +\newcommand{\IT}{{\rm Im\!\ }} +\newcommand{\arccot}{{\rm arccot}} +\newcommand{\sgn}{{\rm sgn}} +\newcommand{\im}{{\rm i}} +\newcommand{\drv}{\mathrm{d}} +\newcommand{\divis}[2]{$^{#1}\!\!/\!_{#2}$} +\newcommand{\vect}[2]{\left( \!\! \begin{array}{c} #1 \\ #2 \end{array} \!\! \right)} +\newcommand{\matt}[2]{\left( \!\! \begin{array}{cc} #1 \\ #2 \end{array} \!\! \right)} +\renewcommand{\Re}{\mathrm{Re}} +\renewcommand{\Im}{\mathrm{Im}} +\newcommand{\av}[1]{\left\langle #1 \right\rangle} + +\newcommand{\pref}[1]{(\ref{#1})} +\newcommand{\eqnref}[1]{(\ref{#1})} + +\newcommand{\hr}{\par\vspace{-5ex}\noindent\rule{\textwidth}{1pt}\par\vspace{-1ex}} + +\newcommand{\qt}[1]{\textbf{#1}\\} + +\newcommand{\code}[1]{\texttt{#1}} + +%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\continue}{\ifprintanswers% +\else +\vfill\hspace*{\fill}$\rightarrow$\newpage% +\fi} +\newcommand{\continuepage}{\ifprintanswers% +\newpage +\else +\vfill\hspace*{\fill}$\rightarrow$\newpage% +\fi} +\newcommand{\newsolutionpage}{\ifprintanswers% +\newpage% +\else +\fi} + +%%%%% hyperref %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue!50!black,linkcolor=blue!50!black,urlcolor=blue!50!black]{hyperref} diff --git a/bootstrap/exercises/instructions.tex b/exercisestitle.tex similarity index 100% rename from bootstrap/exercises/instructions.tex rename to exercisestitle.tex From 4357939cdbaf43fb7453b5adfe5bb36cea4e3874 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 14 Dec 2020 00:17:32 +0100 Subject: [PATCH 13/37] [statistics] improved latex and Makefile file structure --- exercisesheader.tex | 2 + exercisestitle.tex | 1 + statistics/exercises/Makefile | 35 +------- statistics/exercises/instructions.tex | 6 -- .../{exercises01.tex => statistics-1.tex} | 84 ++---------------- .../{exercises02.tex => statistics-2.tex} | 87 ++----------------- .../{exercises03.tex => statistics-3.tex} | 87 ++----------------- 7 files changed, 29 insertions(+), 273 deletions(-) delete mode 100644 statistics/exercises/instructions.tex rename statistics/exercises/{exercises01.tex => statistics-1.tex} (74%) rename statistics/exercises/{exercises02.tex => statistics-2.tex} (69%) rename statistics/exercises/{exercises03.tex => statistics-3.tex} (56%) diff --git a/exercisesheader.tex b/exercisesheader.tex index 321d22c..51a6258 100644 --- a/exercisesheader.tex +++ b/exercisesheader.tex @@ -87,6 +87,8 @@ \newcommand{\qt}[1]{\textbf{#1}\\} +\newcommand{\extra}{--- Optional ---\ \mbox{}} + \newcommand{\code}[1]{\texttt{#1}} %%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/exercisestitle.tex b/exercisestitle.tex index 3041d3e..b97b56b 100644 --- a/exercisestitle.tex +++ b/exercisestitle.tex @@ -4,3 +4,4 @@ {\large Jan Grewe, Jan Benda}\\[-3ex] Neuroethology Lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ \end{center} +\hr diff --git a/statistics/exercises/Makefile b/statistics/exercises/Makefile index 27691d9..fd49c98 100644 --- a/statistics/exercises/Makefile +++ b/statistics/exercises/Makefile @@ -1,34 +1,3 @@ -TEXFILES=$(wildcard exercises??.tex) -EXERCISES=$(TEXFILES:.tex=.pdf) -SOLUTIONS=$(EXERCISES:exercises%=solutions%) +TEXFILES=$(wildcard statistics-?.tex) -.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean - -pdf : $(SOLUTIONS) $(EXERCISES) - -exercises : $(EXERCISES) - -solutions : $(SOLUTIONS) - -$(SOLUTIONS) : solutions%.pdf : exercises%.tex instructions.tex - { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) - pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true - rm $(patsubst %.pdf,%,$@).[!p]* - -$(EXERCISES) : %.pdf : %.tex instructions.tex - pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true - -watch : - while true; do ! make -q pdf && make pdf; sleep 0.5; done - -watchexercises : - while true; do ! make -q exercises && make exercises; sleep 0.5; done - -watchsolutions : - while true; do ! make -q solutions && make solutions; sleep 0.5; done - -clean : - rm -f *~ *.aux *.log *.out - -cleanup : clean - rm -f $(SOLUTIONS) $(EXERCISES) +include ../../exercises.mk diff --git a/statistics/exercises/instructions.tex b/statistics/exercises/instructions.tex deleted file mode 100644 index 3041d3e..0000000 --- a/statistics/exercises/instructions.tex +++ /dev/null @@ -1,6 +0,0 @@ -\vspace*{-7.8ex} -\begin{center} -\textbf{\Large Introduction to Scientific Computing}\\[2.3ex] -{\large Jan Grewe, Jan Benda}\\[-3ex] -Neuroethology Lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} diff --git a/statistics/exercises/exercises01.tex b/statistics/exercises/statistics-1.tex similarity index 74% rename from statistics/exercises/exercises01.tex rename to statistics/exercises/statistics-1.tex index 22f1131..b7acb51 100644 --- a/statistics/exercises/exercises01.tex +++ b/statistics/exercises/statistics-1.tex @@ -1,88 +1,18 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[english]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 7\stitle}}{{\bfseries\large Statistics}}{{\bfseries\large December 8th, 2020}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} +\newcommand{\exercisetopic}{Statistics} +\newcommand{\exercisenum}{7} +\newcommand{\exercisedate}{December 8th, 2020} + +\input{../../exercisesheader} -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- bonus question ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} +\input{../../exercisestitle} \ifprintanswers% \else diff --git a/statistics/exercises/exercises02.tex b/statistics/exercises/statistics-2.tex similarity index 69% rename from statistics/exercises/exercises02.tex rename to statistics/exercises/statistics-2.tex index 4b1cc3c..e58f16b 100644 --- a/statistics/exercises/exercises02.tex +++ b/statistics/exercises/statistics-2.tex @@ -1,89 +1,18 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 7\stitle}}{{\bfseries\large Statistics}}{{\bfseries\large November 21st, 2017}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- bonus question ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\newcommand{\exercisetopic}{Statistics} +\newcommand{\exercisenum}{X2} +\newcommand{\exercisedate}{XXX} + +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} diff --git a/statistics/exercises/exercises03.tex b/statistics/exercises/statistics-3.tex similarity index 56% rename from statistics/exercises/exercises03.tex rename to statistics/exercises/statistics-3.tex index 11e4320..8456122 100644 --- a/statistics/exercises/exercises03.tex +++ b/statistics/exercises/statistics-3.tex @@ -1,89 +1,20 @@ \documentclass[12pt,a4paper,pdftex]{exam} +\newcommand{\exercisetopic}{Statistics -- Random Walk} +\newcommand{\exercisenum}{X3} +\newcommand{\exercisedate}{XXX} + +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} + \usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: L\"osungen} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large \"Ubung 8\stitle}}{{\bfseries\large Statistik}}{{\bfseries\large 29. November, 2016}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} From e37591d2743c8bf447f5c7abe44c8d3796691872 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 14 Dec 2020 10:48:37 +0100 Subject: [PATCH 14/37] renamed further-topics/ to replicability/ --- .../lectures/UT_WBMW_Rot_RGB.pdf | 0 .../lectures/beamercolorthemetuebingen.sty | 0 .../lectures/images/course_git.png | Bin .../lectures/images/git_logo.png | Bin .../lectures/images/git_pro_distributed.png | Bin .../lectures/images/git_pro_lifecycle.png | Bin .../lectures/images/git_pro_local.png | Bin .../lectures/images/github_logo.jpeg | Bin .../lectures/images/hines_etal_2014.png | Bin .../lectures/images/hines_etal_2014_grey.png | Bin .../lectures/images/phd092506s.gif | Bin .../lectures/images/pro_git-branches.png | Bin .../lectures/images/pro_git_commits.png | Bin .../lectures/images/project_end.png | Bin .../lectures/images/project_middle.png | Bin .../lectures/images/project_start.png | Bin .../lectures/images/rung_brazma_2013.png | Bin .../lectures/images/rung_brazma_2013_grey.png | Bin .../lectures/images/savage_vickers_2009.png | Bin .../lectures/images/savage_vickers_2009_title.png | Bin .../lectures/topics-chapter.tex | 0 .../lectures/topics-slides.tex | 0 scientificcomputing-script.tex | 8 +++++--- 23 files changed, 5 insertions(+), 3 deletions(-) rename {further_topics => replicability}/lectures/UT_WBMW_Rot_RGB.pdf (100%) rename {further_topics => replicability}/lectures/beamercolorthemetuebingen.sty (100%) rename {further_topics => replicability}/lectures/images/course_git.png (100%) rename {further_topics => replicability}/lectures/images/git_logo.png (100%) rename {further_topics => replicability}/lectures/images/git_pro_distributed.png (100%) rename {further_topics => replicability}/lectures/images/git_pro_lifecycle.png (100%) rename {further_topics => replicability}/lectures/images/git_pro_local.png (100%) rename {further_topics => replicability}/lectures/images/github_logo.jpeg (100%) rename {further_topics => replicability}/lectures/images/hines_etal_2014.png (100%) rename {further_topics => replicability}/lectures/images/hines_etal_2014_grey.png (100%) rename {further_topics => replicability}/lectures/images/phd092506s.gif (100%) rename {further_topics => replicability}/lectures/images/pro_git-branches.png (100%) rename {further_topics => replicability}/lectures/images/pro_git_commits.png (100%) rename {further_topics => replicability}/lectures/images/project_end.png (100%) rename {further_topics => replicability}/lectures/images/project_middle.png (100%) rename {further_topics => replicability}/lectures/images/project_start.png (100%) rename {further_topics => replicability}/lectures/images/rung_brazma_2013.png (100%) rename {further_topics => replicability}/lectures/images/rung_brazma_2013_grey.png (100%) rename {further_topics => replicability}/lectures/images/savage_vickers_2009.png (100%) rename {further_topics => replicability}/lectures/images/savage_vickers_2009_title.png (100%) rename {further_topics => replicability}/lectures/topics-chapter.tex (100%) rename {further_topics => replicability}/lectures/topics-slides.tex (100%) diff --git a/further_topics/lectures/UT_WBMW_Rot_RGB.pdf b/replicability/lectures/UT_WBMW_Rot_RGB.pdf similarity index 100% rename from further_topics/lectures/UT_WBMW_Rot_RGB.pdf rename to replicability/lectures/UT_WBMW_Rot_RGB.pdf diff --git a/further_topics/lectures/beamercolorthemetuebingen.sty b/replicability/lectures/beamercolorthemetuebingen.sty similarity index 100% rename from further_topics/lectures/beamercolorthemetuebingen.sty rename to replicability/lectures/beamercolorthemetuebingen.sty diff --git a/further_topics/lectures/images/course_git.png b/replicability/lectures/images/course_git.png similarity index 100% rename from further_topics/lectures/images/course_git.png rename to replicability/lectures/images/course_git.png diff --git a/further_topics/lectures/images/git_logo.png b/replicability/lectures/images/git_logo.png similarity index 100% rename from further_topics/lectures/images/git_logo.png rename to replicability/lectures/images/git_logo.png diff --git a/further_topics/lectures/images/git_pro_distributed.png b/replicability/lectures/images/git_pro_distributed.png similarity index 100% rename from further_topics/lectures/images/git_pro_distributed.png rename to replicability/lectures/images/git_pro_distributed.png diff --git a/further_topics/lectures/images/git_pro_lifecycle.png b/replicability/lectures/images/git_pro_lifecycle.png similarity index 100% rename from further_topics/lectures/images/git_pro_lifecycle.png rename to replicability/lectures/images/git_pro_lifecycle.png diff --git a/further_topics/lectures/images/git_pro_local.png b/replicability/lectures/images/git_pro_local.png similarity index 100% rename from further_topics/lectures/images/git_pro_local.png rename to replicability/lectures/images/git_pro_local.png diff --git a/further_topics/lectures/images/github_logo.jpeg b/replicability/lectures/images/github_logo.jpeg similarity index 100% rename from further_topics/lectures/images/github_logo.jpeg rename to replicability/lectures/images/github_logo.jpeg diff --git a/further_topics/lectures/images/hines_etal_2014.png b/replicability/lectures/images/hines_etal_2014.png similarity index 100% rename from further_topics/lectures/images/hines_etal_2014.png rename to replicability/lectures/images/hines_etal_2014.png diff --git a/further_topics/lectures/images/hines_etal_2014_grey.png b/replicability/lectures/images/hines_etal_2014_grey.png similarity index 100% rename from further_topics/lectures/images/hines_etal_2014_grey.png rename to replicability/lectures/images/hines_etal_2014_grey.png diff --git a/further_topics/lectures/images/phd092506s.gif b/replicability/lectures/images/phd092506s.gif similarity index 100% rename from further_topics/lectures/images/phd092506s.gif rename to replicability/lectures/images/phd092506s.gif diff --git a/further_topics/lectures/images/pro_git-branches.png b/replicability/lectures/images/pro_git-branches.png similarity index 100% rename from further_topics/lectures/images/pro_git-branches.png rename to replicability/lectures/images/pro_git-branches.png diff --git a/further_topics/lectures/images/pro_git_commits.png b/replicability/lectures/images/pro_git_commits.png similarity index 100% rename from further_topics/lectures/images/pro_git_commits.png rename to replicability/lectures/images/pro_git_commits.png diff --git a/further_topics/lectures/images/project_end.png b/replicability/lectures/images/project_end.png similarity index 100% rename from further_topics/lectures/images/project_end.png rename to replicability/lectures/images/project_end.png diff --git a/further_topics/lectures/images/project_middle.png b/replicability/lectures/images/project_middle.png similarity index 100% rename from further_topics/lectures/images/project_middle.png rename to replicability/lectures/images/project_middle.png diff --git a/further_topics/lectures/images/project_start.png b/replicability/lectures/images/project_start.png similarity index 100% rename from further_topics/lectures/images/project_start.png rename to replicability/lectures/images/project_start.png diff --git a/further_topics/lectures/images/rung_brazma_2013.png b/replicability/lectures/images/rung_brazma_2013.png similarity index 100% rename from further_topics/lectures/images/rung_brazma_2013.png rename to replicability/lectures/images/rung_brazma_2013.png diff --git a/further_topics/lectures/images/rung_brazma_2013_grey.png b/replicability/lectures/images/rung_brazma_2013_grey.png similarity index 100% rename from further_topics/lectures/images/rung_brazma_2013_grey.png rename to replicability/lectures/images/rung_brazma_2013_grey.png diff --git a/further_topics/lectures/images/savage_vickers_2009.png b/replicability/lectures/images/savage_vickers_2009.png similarity index 100% rename from further_topics/lectures/images/savage_vickers_2009.png rename to replicability/lectures/images/savage_vickers_2009.png diff --git a/further_topics/lectures/images/savage_vickers_2009_title.png b/replicability/lectures/images/savage_vickers_2009_title.png similarity index 100% rename from further_topics/lectures/images/savage_vickers_2009_title.png rename to replicability/lectures/images/savage_vickers_2009_title.png diff --git a/further_topics/lectures/topics-chapter.tex b/replicability/lectures/topics-chapter.tex similarity index 100% rename from further_topics/lectures/topics-chapter.tex rename to replicability/lectures/topics-chapter.tex diff --git a/further_topics/lectures/topics-slides.tex b/replicability/lectures/topics-slides.tex similarity index 100% rename from further_topics/lectures/topics-slides.tex rename to replicability/lectures/topics-slides.tex diff --git a/scientificcomputing-script.tex b/scientificcomputing-script.tex index 21daaba..5bacd1b 100644 --- a/scientificcomputing-script.tex +++ b/scientificcomputing-script.tex @@ -88,18 +88,20 @@ % add chapter on mutual information -% add chapters on linear algebra, PCA, clustering +% add chapters on linear algebra, PCA, clustering, see linearalgebra/ % add chapter on simple machine learning %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\part{Tools} -% Latex +% Latex -> see latex/ % markdown, html % Makefile -% version control (git and github) only put source files into repository! % distributed computing (ssh and grid engines) +% +% see replicability/ : +% version control (git and github) only put source files into repository! % data handling (structure, storage (rsync), backup, data bases) % data annotation, meta data From acc63490f4ac5225b0c4581f2cf2324ab98bdaf6 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 14 Dec 2020 20:21:37 +0100 Subject: [PATCH 15/37] [bootstrap] added matplotlib figure for meandiff --- bootstrap/exercises/meandiffplot.m | 12 +- bootstrap/exercises/meandiffsignificance.m | 6 +- bootstrap/exercises/meandiffsignificance.pdf | Bin 0 -> 8988 bytes .../lecture/pointprocessscetchA.eps | 120 ++++-- .../lecture/pointprocessscetchA.pdf | Bin 2786 -> 2924 bytes .../lecture/pointprocessscetchB.eps | 389 ++++++++++++------ .../lecture/pointprocessscetchB.pdf | Bin 4694 -> 4877 bytes 7 files changed, 365 insertions(+), 162 deletions(-) create mode 100644 bootstrap/exercises/meandiffsignificance.pdf diff --git a/bootstrap/exercises/meandiffplot.m b/bootstrap/exercises/meandiffplot.m index 24fd625..47e8d86 100644 --- a/bootstrap/exercises/meandiffplot.m +++ b/bootstrap/exercises/meandiffplot.m @@ -17,10 +17,12 @@ function meandiffplot(x, y, md, ds, dq, k, nrows) bmin = min([x; y]); bmax = max([x; y]); bins = bmin:(bmax-bmin)/20.0:bmax; - hist(x, bins, 'facecolor', 'b'); + [xh, b] = hist(x, bins); + [yh, b] = hist(y, bins); + bar(bins, xh, 'facecolor', 'b') hold on - hist(y, bins, 'facecolor', 'r'); - xlabel('x and y') + bar(bins, yh, 'facecolor', 'r'); + xlabel('x and y [mV]') ylabel('counts') hold off @@ -34,7 +36,7 @@ function meandiffplot(x, y, md, ds, dq, k, nrows) hold on; bar(b(b>=dq), h(b>=dq), 'facecolor', 'r'); plot([md md], [0 4], 'r', 'linewidth', 2); - xlabel('Difference of means'); - ylabel('Probability density of H0'); + xlabel('Difference of means [mV]'); + ylabel('pdf of H0'); hold off; end diff --git a/bootstrap/exercises/meandiffsignificance.m b/bootstrap/exercises/meandiffsignificance.m index e234270..b5de2fd 100644 --- a/bootstrap/exercises/meandiffsignificance.m +++ b/bootstrap/exercises/meandiffsignificance.m @@ -27,11 +27,11 @@ for k=1:length(mys) fprintf(' --> measured difference of means is not significant\n'); end - subplot(length(mys), 2, k*2-1); - title(sprintf('mx=%.1fmV, my=%.1fmV', mx, my)) - %% (b), (f) plot histograms of data and pdf of differences: meandiffplot(x, y, md, ds, dq, k, length(mys)); + + subplot(length(mys), 2, k*2-1); + title(sprintf('mx=%.1fmV, my=%.1fmV', mx, my)) end savefigpdf(gcf, 'meandiffsignificance.pdf', 12, 10); diff --git a/bootstrap/exercises/meandiffsignificance.pdf b/bootstrap/exercises/meandiffsignificance.pdf new file mode 100644 index 0000000000000000000000000000000000000000..70944210b2825f12b41d8097060dbf4ff8ab15fd GIT binary patch literal 8988 zcmbt)bySq?y7y4R(518v9g+h>cQ;5$!w5q&LpMl?bPk9#3X;+#f>P3Wc2DNd3fs}Q0K}IkSPe%kC1m+du<>%4YmebW&)iDqUq17lNY`k4z za4!`PsGEbMjVD-<6Q57P0|xa%3n)UpU?2`faWFraUjQs1g#Hy15_`-qz|POl&WSHA zjSqv{-dP6!(*qEnCJb)xT~^cP@QRmsknD}Bf3t`qHPVrWe@it_2Oq~*Tzhzp9em>y-J?6fGGVYEV1`> zvR|nrJpaM!tLozoxk$EHzrIn*r@TIReBH+qc=@TVREf^2Y%4$X`ikoFx{IfqfFbQo zR>IS{Mw!m%gK;OS=Vdp}D~RWq0asMpw>QTKKADKcrLKcpW5+$d+rzc(p`q#|hk)Ud zU};v82Xya`UgqzR5W8Y0nz<^ad_FIh+O8>`n6{E_3)iuFnqpw-b^N4rkml_x`h+7( z-0xSuR{5{49usLkzZ}f{#9M;6Ex+DIeD-j9vXT8+EL~-T4yQu)6L|NOi=J{ z>#`v4wBg0xQ1cST9`5<{~+F$b4GTvv3 zc5H)uluP6>3(ce9CJJSF&9#y=GbZZ$Zv-(*1`^`JZ{yXp_GP2bMQGq5*v>iNz%DkW z$7Zbduv4xm-Q|ECDet-Etxh&lfNw7_hmB@m*a=Hb>sYmOQtG+oW0I@EqGV*6v4v0N zWxR7>oGzw`#QPOsShj0B0eQuMaMjKbm&h#h7gx-9d_!4NH>LYGTs2uP73I?Tl}ols zlx!X6Upn8Cf?Zs~CSiT$V=W6X5;T~F)1XZEUHf;xQ(dlE*4IlLZ}YiLC8hJ{`KvhU zSC!L-4;Q{_b;%xPl=|FUa}ZSWiWLgmhmUCek_8%sik!MPeWQz+w2gSF+MURYByalh zsJ;Rd+?rO9(}Z@a*WP~S+Y3F+n{?vB0ALHLXV^Gv@lKznrfYQ~*diZ{MQb)St9Bu)>gM zTr{ya%Z;2Ai{@VHJ}&&(5Er#0FJ#MDqWWz+Kym0}$+8=vlr1ZPwNkA2^cpi!F-4_I zuWJQh$DLE(32v|A*MP$fqGI&1N;)H?m0VPRa5#jcT7yMIX{1>bBmaV_03RdPZQR+~$KXE-aN)&sHt%f1TAIqjM>#tEiwV~lIPBFS#OSkE}T zSR9TKw==YKBJZo3-w%@nhow7tqdMaVXK*rgJi}=+^x~~}H!!Zu!!{@=cAs6yk);6{ zaiAB2*cv8HPu9OHsyaCQKJn8?&~q-rscbYnqTXOH@H5|FL@ntP&o@5cYc^e~%%ayI z!Dme#3FYifbStV;d8nSsV7@_LzMG;$A^AMrvvP{+=N7I(NUmqi)Rr&nCx#7cSW*-O z)3drh(eQT=D9i!-9VW^cHZ}ngkyi`zuB_XVs-D~9oZj)7* zg`vXd#}D>7bjrxUhb*#HXu8QyO29(Bb0pym(Cu&*(nZ9#FR+pJID9wCQoeGm0zC<| z>yh>b*kTU%t$(3$dQ2FqLru>`J9om%_g3)%DG(AtZy<$<7)lCnp1viueU%AH9?XqC^dy$I+>E3Zn6Tf*_ z6k&ogx?x7n?yRT@h_P%16tN)(cKXt*&az2CufabHen@Z!Pik}4PbLwxm$M^tFRiZi zlKOHg*tSdSo8h%4fsdH1?*XirN%Xyz<$UaOc|dY|({D$u#1zILOH)Yt9*pR>;1scqHohcEqe_3hbF~!Yi9N(kF2yk$^@wyxtlgYUWx@-zM`7uxO z@{#xOcgNA0iiOk9Nj96)G@yxT5N}iLqCxr^#-sA=hksr>^#c-$Yp?9Ntl?)&$J4K!vPW>+D=>75nZ=eo7KvbB?io#yTuL5Grej@ph zQK!wG(m0?^O#TpOZv37;5GVE5Pbko(2EB#q#RAVRy|vQ_w>dL2p=0oHTuioGY197E zof3+wDttLy=Gs=9^(!N7vmk5aD&c|w9xf^ZN+imH<3}l++~ZWoV3~C!Ud|R+#jgp8 zvF6wX^VGJw%)FU3t4M{{;l}zJ_Xy2?r*`TzY8m2M4S8U!)r6}TI!?cX)88!=>OJSEO00Taz$aW`;)OCYQ7y2a zc#GeROOqNKB^H@3Yjg{03xhTccajWMi|L$3G^*WQ9I7*;n1tP;?kA+l?=9E)MJ(uD z7*Czi0I_81BtX<7P(+=Rc)t|LWxYMV*@jKv_*~C&by!rmgV}_vJCBsx#5Pw~($>AU zU(NupT}XSZ1{pcaq-4t&U!N({sr{faj(W9v4HKV{ZDxR9HU*>G8z~1ESle5VeiQw3 zP5fEmPrImG%3MmaK|DZoVKFcRT&b^U&C@y%>ayYq-H}ozd)6+T`|Ag zw77*A6HeYI!^H1MDI7)%#2eena(3v(n%Enwli8E4lmVP*F!QWA6>5~^KTeZ@6(%Tl zZ5>+rznTCRD06jckl`q%RX2<_{UVue?bz>ec&Hb)p)g|f@zno0+Og|&A^aU9#qO{j zdgnEMwLs3GF2_v%u%N%QS$!z)*zco5h<>E`&w!gA&-c?!gu$DA`4>kezPG>j^B4c{ z4Su{G`a-2?_v!(Lt|ovYIPi-+2XFqnHpk#o=l54$-%lWaw0>YS9J-jo7$p!X;d*TO zZ|m6jmbZhZnzkC4VNC&US;_FC98+J8Vof8Ri~uQNRgN?gkCfu79Zp!&rF+@a(?}1w zKVhCm7?Pz^ayEc=_ff7K9h0(+{dya5m6?a%!UDUyUK9)y6t<#Cv&sXm;d?p=+{TSlH)Z*$j#b%gzb;3 z-){+$mh!45tLy@nLKxGW=_7<<5x2$98RtAYBM=Y^+`@pT8 zZwn^0MV?6YhUei)k6sbzoD}rQY<^D>bPpQ}zke(z?PELEmw1DE$#-skn-;J!z&zt4 zKAq;~rgT0bPGS<+Gt*xw)8@nE@wHKh_RvwC3{$!3Oh-}pfS>F`6Yg*C(zBk6%qATF zk=Lc~Uy02Xh;$;uUzQ5uORfOY8f`ej#xg{=g$TvU7{n@U)x$X2Ey<-vog)OT_vm3$ zY=L{UQAJ!rv&=ZWjLQfN)UDZ5a2{>@=*&9Y_0u<&EwnP^uhgchGJQG+%#W;&DU(Hr zkyhSpA1Y2qSDLxGkVb-irZNpPI;Xee7BjLjc0wMbUseV zsZQ`P5SvWs7PCxk{!+5NsY;ExsGxUbNnB;6T*>IwCt>@kj0Uz~mTzC^=ww-q(xinA z;Nw7G@)^e)Vb`jW0rCp9r7X~7O(8HQc7~S6rgw% zb}K(Q#KGCI^1b(868CTsW2$ctTwSAy-I|7-#wYxda%tMCJ%5_u@-woV_Ymoy8@FWIJYv9(UW3aWqQyGOa{ASJ4`sMt^j>Z0$@p>r}gmNxNLUhFt)79x1|PmE|y+3QJv72gc{lpOUIXYyuWhDY7uLeBp5Ir zosm`X-w$(nC+T(bZ%2XsQNtPwz zSIjP;r0E~27*k?+5>@*vvUH(8zo;#)*zx3E-7oBl{_V`Z&! z>?xvG(DoM{L`F~xd!P)C2Z@AqGJ>^|vALnRO@;eB1(zTZcdh9|pOzsNC7C-#gy zbZP>XKpASG;yP9>4CZEsc97^I*86qkkz>`e;2h4CiIQoSr@sO)Rzr+H2j#Nhr!0&| zB)SpixmP%%w>J=#d&k8&%NLNo20ji;kW^W(svsF>#6=}|(F{f(C7y&6(QI)4AYbGn z^KE*y0l|~7iuYm9x`v^Ln;3Z?i7SAN%lzFri~?D2%q3*oOfD(|i;*dIbbzFoso74h zB%M*&ESHX!xzl$P;bz%}=6f``?bn7<%p<~~m8VVs);+?Oz}@;7jk?*Lf)z$^FE4(H z9;e%CQvMa8A6MW8j~(q`S8FXyY18u2`WK zw)y?ute#EGtc55Om$QEYgLds#DS=JVBhdl>ABR;U1|Jr6Va6(xYb9cyKMIqn4me3!CaJ(jM880Ml>CfrlX3%2yenK zIEYE`d*E+z!>>_2@JP+tCN!8RM#Un+-8#SD`M3}0hmH@Qlyrq+pvW6#%LQKr>RU{TsuP^VJcdQH7FVL~l&A#WIgaPR6RlODqbf*OKwC z=$=@~6A+pY*JQj2XOhPQ`nwf?JB^41V&hd=Sh~Z;u${$hIYmel0r4EMS^O{Ky7N7- zc+@!J!s=+I!2E``yR1-Q;v+WWp+b|Cl$=O_n01ad4{pH5JznG?OGLh4C9I~lpF>~1 zgnn4NCL`i2lZ_D&<>4UNX-e!kM1;-FXn(K4-gpS$k#f`!*)8UhZ_V>^UP*b2ynIWo z18v-oPo(A(k{SJZzK@*9Fu;q6Kq6{>*&Y{7*zKMwDymxf)d~7fIS!RXwkfN=G~O5T zUvwPGFQQi)d~eJp?2qqM|2v?U73TD@XTQ6{c(m$1P=m`@J*!fJe5vgECg zfkqqebJzY~qvcKAK%kZSy|?m-<)gNOpMFzM?R&=fW>}eVOdHj*JqNA$`i4pf5P$Z6 zGqxR_oI8M)a}H=&#zUKmtggT^lJfpDI51^q@-c_S^3~@i-YO!6?CX>sSNb_doGFvb zITwfUy$YFBqv~;5np(3x@-mJ2EDYw1F%d`Rfn_?;HtT9sh-D!0w555>^ag?`xUtX! zy(t_ve!xGJ-OLJY;FW73eeIj^S$Lxud1*1q8%H}g%O5%X@oxO6vF?4*Xvi~Hp!Z59we-Z9 z!5yPYd(-u}*+(!t*veH|kKofn(mQQQ7b%xhx<%W(*SZ>T$_55&DFN;ohdnRZ4M+bz0asG8wAjsh$mdw(>;yDQDWdNDh=pJvD|4 zp7)<;yN3v!*Mb!5@%FLUAuPiU5ymI)!oA!KY`IyX{KT`HBfxFliUnCa@;5dBx5c7l z;)U4w6PBRSKV$R}enTgEgYXSo%Q=&RiwI}t&{`C31g%%duyxVfC4Vg4ul~{aus@nvuCka##Q7{LpWwmen>~IadzHh92 zv(*YxA%4y(PDHR3utm?h{bf>m{nP-zz<_{y;4&z#*_$u2&GsNDysvbKoh3mb7gI67 z3MT8551MV@Tv&EJ#z^={S|3~6zVVL5Pd6f|b6(t@z}~$#o;A$$HJP79h-s*6N8~5z z$Vdp;9uMhG=z(MOq7JUBa?XuiTzz*%2gcO~3uVV^%_0SkCf7KN4iwsq=)K0a8sqm-sY(C1y z9ysI;!xBShah)mt%QPRa!y*ruf+B}{JFigjBb3}B2kBJ)_7}_j7V(RlpQM?AI%}&% zf(Z^(Fu+aHJSAPs^txGpImr6)jDc$~9?<-ID)dSEd&Hz0CL1?_pB9DEqDe@ljYRPN zeXxAj%MriOF;_Oxsa-~a+L=_o!`2`oF+!KJnQ~<;3=wQeRPStn4_VUu3YEL~`}lr| zAz}h^gD4{J4C!Pyh2?81hG2&32v0%xP^CI>^^gc&rqhdxY9dC?Lo4ZS2&(myc=&B& zC(fF!<*S1SZd4f7vQ#p-Qt-iwo-s2B^#4jq)ZF&!Dkmx(8km#Pao$-*YQi?!yq=o4B*8=ae z<&Yj&-&9qjF-p+4xek5XAeI#_;%>X)2lj_$3$kY9>NW-Ns7Av0bh;U>t{_6D(M;aa z0*en}*sRzCfGt928eMJ?x8g_@nxI@LPeh)Qa{2TT&xMh&)yNV`Ylap34_H%cUPBFsV7O5FRn;OkKH^6Z%d$LK81^ z!OhT;4wKkfLNKvv2`|&jP37BJ9kjHf{=kX`?6>-N;P-ULZL#Kj;B;5vtym>PsrUrf zKkJ|T?%l3yCYqg^;^7qAm1_wWM^M)V!^o=(25{muR#ucFC3w|7yJj^9neQ`eo-A^O z{!#69dBiURPd=K{$5I`1yUOfJ7ZtI4^5O(BAD9EL2(&TNRT)bjG5y;4l>9|^_@Y#O z&>|G_&OxFN=gElOlW#xzGGD&|UP`L5_JA|e3!M*&*sZ_Mnj60K+P4;b<{jINA>Kzw>IPlUIJ4a^fH ze8+VM8Th-wKzzDTd)VDb3ufyGl}Gr2%=pm^f^7KF!ckKdy&%D6hwEXXkC_ufSE(rTO z>v!|$`F|3t2}Os^;m6|*cZMT;;s4sOaQ6cI!-v0;CMk*TQ4j##rTngIK@fD86FszT zv{nylx-A|{A_DgGy)h#2HQU?S+O{!czph`_(`i3*CM7s&tO6A=D) zS+K~z^9iBX!#`!cJfMy)Fps;Q6LjMB5D4_d-ObKlt4a-ShXCDmrTq6u5o9JQC#onY zq9BNNN>ENjL`+#!Kwel-49qVluPmno7EzD}{oh&sT8a9O0kFH|{?$YR_3-*D-J-($ N5PVivB^_n_{{n6+@Ld1^ literal 0 HcmV?d00001 diff --git a/pointprocesses/lecture/pointprocessscetchA.eps b/pointprocesses/lecture/pointprocessscetchA.eps index 5a4bb00..7234511 100644 --- a/pointprocesses/lecture/pointprocessscetchA.eps +++ b/pointprocesses/lecture/pointprocessscetchA.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchA.tex -%%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Sun Dec 13 09:18:35 2020 +%%Creator: gnuplot 5.2 patchlevel 8 +%%CreationDate: Mon Dec 14 20:03:21 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 135 %%EndComments @@ -18,6 +18,7 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def +/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -29,11 +30,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -47,7 +48,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 4.6 (September 2012) +% Gnuplot Prolog Version 5.2 (Dec 2017) % %/SuppressPDFMark true def % @@ -64,11 +65,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -82,7 +83,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Default Line colors +% Classic Line colors (version 5.0) /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -95,19 +96,21 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default Line Types +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def /LTw {PL [] 1 setgray} def -/LTb {BL [] LCb DL} def +/LTb {PL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [4 dl1 2 dl2] LC1 DL} def -/LT2 {PL [2 dl1 3 dl2] LC2 DL} def -/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def -/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def -/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def -/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -302,7 +305,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -329,9 +332,14 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse - 2 lt - {/InterpretLevel1 true def} - {/InterpretLevel1 Level1 def} +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } ifelse % % PostScript level 2 pattern fill definitions @@ -420,6 +428,7 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop +% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -429,14 +438,39 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchA.tex) /Subject (gnuplot plot) - /Creator (gnuplot 4.6 patchlevel 4) - /Author (jan) + /Creator (gnuplot 5.2 patchlevel 8) % /Producer (gnuplot) % /Keywords () - /CreationDate (Sun Dec 13 09:18:35 2020) + /CreationDate (Mon Dec 14 20:03:21 2020) /DOCINFO pdfmark end } ifelse +% +% Support for boxed text - Ethan A Merritt Sep 2016 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { dup type /stringtype eq + { Boxing { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } + {} ifelse} def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% end %%EndProlog %%Page: 1 1 @@ -450,27 +484,33 @@ newpath 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 824 M +stroke +6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V +Z stroke 528 824 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 573 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 573 M 0 503 V 1412 573 M 0 503 V @@ -488,12 +528,18 @@ LC0 setrgbcolor 0 503 V 5685 573 M 0 503 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C stroke +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchA.pdf b/pointprocesses/lecture/pointprocessscetchA.pdf index b06226f27816fe77a57084746e940457f8cc9dc1..ebfae3dc92ebd0a8d91c320dc094c2eb487b3b9b 100644 GIT binary patch delta 1089 zcma)+e@GKi9Kf0R11}W`N-2m78(DPv?%mz)TyC)+cQ#Eo+$<`Tw!1f-%-!0(`76qh zq9Ckf5JhAVQCL*e@UQ;!4lQ^ElN+gPGd&x?Y*DnXO zfTyLwUsW4VATkV+PiqeL`;#F9VV{a^EC2-kepd7tHf%VNB)e&HPY7v_X!IZGNMgNJ z$3cvI!A@jU)wbv{B9E5s87j-$Rw945$=*}b&LZ#8P-gOK)fH*##qPIfW-Ge5%uM;@ z^76!uqQQ#kS@jD#^FdnpIea-|6qeaTC8zH-&abbL8}azZ^CP}_t?A*VrP4(>MlU>? zdopq1?D7#En4Z0UFuY-QIn=oCP~-FWICB{Ezk736DD4>japBr7LFpL0JyUsSj+>Zj z{WLb-rr5t-509|PTbrL7w@xb+!gKQfZc_|I|hTnDv@)|F^%d6+StLMb8vy7SO|1j~a)P*;0Sjbv7+;smAe3@F5#}(F z=d*14--&@J2|1#~@+l8h-wp(q^?WXW$r_A1mbh4D-u delta 949 zcmaDO_DGaZHNeG9*HF)#OZE7h{zVfXTi0_j8S=P(w{-OjxV_}$6=9Ah?&HcFd?(I0 z#a7fV_my}Z=JoRbf7Si`J&K8Ij^BUHw7c-YOIF>Z&spXq9h<`;K6y|0obZ*F9;egg z7j8N^?ViI2UKy@=3J(kSmgmdz|KC38-yoOQtPo;oY^7je1(vijo&1DVN5DkSOrapLBsn7|wJbG9!DO-mn;UU9b+Ne< zr;up3+p%x9P6mcuNq&)?O;JjkRd8w{gpreJmz9`jqYn}UvLOtxtbR(e6;#jWH|+V0 zszzp-T>8!+Q!?}OToOxCH9-D%NljKTG**CzO9Q7QyRm_#p#?CE7I0dbpa%ocjNsCw ztkmQZjr6?If}H#k1rPxgb}TK)$S=|WI%hH?mwvs8nW+LO)(jN#6u7_)10y2?V5Fmp z8JJ)ZGcw0iXJCk7o`I36Ifi+rMwTEk6=aJIOwA226tt$aYHI3gVPbCR zX6a(=Vqs|EYU$=^?&#uZX=r5XW@kfCMJ$({9anKlVo^y&QED2Ok%_S}m#V6(zZ(|- D)m9wr diff --git a/pointprocesses/lecture/pointprocessscetchB.eps b/pointprocesses/lecture/pointprocessscetchB.eps index a0b1ee2..f5df3c9 100644 --- a/pointprocesses/lecture/pointprocessscetchB.eps +++ b/pointprocesses/lecture/pointprocessscetchB.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchB.tex -%%Creator: gnuplot 4.6 patchlevel 4 -%%CreationDate: Sun Dec 13 09:18:35 2020 +%%Creator: gnuplot 5.2 patchlevel 8 +%%CreationDate: Mon Dec 14 20:03:21 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 237 %%EndComments @@ -18,6 +18,7 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def +/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -29,11 +30,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength mul mul + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -47,7 +48,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 4.6 (September 2012) +% Gnuplot Prolog Version 5.2 (Dec 2017) % %/SuppressPDFMark true def % @@ -64,11 +65,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray show grestore} {show} ifelse} def + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -82,7 +83,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Default Line colors +% Classic Line colors (version 5.0) /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -95,19 +96,21 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default Line Types +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def /LTw {PL [] 1 setgray} def -/LTb {BL [] LCb DL} def +/LTb {PL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [4 dl1 2 dl2] LC1 DL} def -/LT2 {PL [2 dl1 3 dl2] LC2 DL} def -/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def -/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def -/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def -/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -302,7 +305,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -329,9 +332,14 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse - 2 lt - {/InterpretLevel1 true def} - {/InterpretLevel1 Level1 def} +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } ifelse % % PostScript level 2 pattern fill definitions @@ -420,6 +428,7 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop +% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -429,14 +438,39 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchB.tex) /Subject (gnuplot plot) - /Creator (gnuplot 4.6 patchlevel 4) - /Author (jan) + /Creator (gnuplot 5.2 patchlevel 8) % /Producer (gnuplot) % /Keywords () - /CreationDate (Sun Dec 13 09:18:35 2020) + /CreationDate (Mon Dec 14 20:03:21 2020) /DOCINFO pdfmark end } ifelse +% +% Support for boxed text - Ethan A Merritt Sep 2016 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { dup type /stringtype eq + { Boxing { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } + {} ifelse} def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% end %%EndProlog %%Page: 1 1 @@ -450,27 +484,33 @@ newpath 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 3165 M +stroke +6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V --5680 0 R +Z stroke +528 3165 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 3029 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 3029 M 0 272 V 502 -272 R 0 272 V @@ -488,99 +528,167 @@ LC0 setrgbcolor 0 272 V 5685 3029 M 0 272 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +1.000 UP +2.000 UL LTb -LCb setrgbcolor -0.00 0.00 0.00 C 1.000 UP +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -LTb +[] 0 setdash +0.00 0.00 0.00 C +1.000 UP +LCb setrgbcolor 1.000 UL -LTb +[] 0 setdash gsave 6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 2043 M +stroke +6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V --5680 0 R +Z stroke +528 2043 M 5680 0 V +stroke +1.000 UL +[] 0 setdash 1291 1929 M +stroke +1291 1929 N 121 32 V -121 32 V --260 -64 R --121 32 V -121 32 V -910 1961 M +-260 0 R +stroke +1031 1993 N +910 1961 L +121 -32 V +-121 32 R 502 0 V -590 -32 R +stroke +1.000 UL +[] 0 setdash +2002 1929 M +stroke +2002 1929 N 121 32 V -121 32 V --469 -64 R --121 32 V -121 32 V --121 -32 R +-469 0 R +stroke +1533 1993 N +-121 -32 V +121 -32 V +-121 32 R 711 0 V -206 -22 R +stroke +1.000 UL +[] 0 setdash +2329 1939 M +stroke +2329 1939 N 84 22 V -84 22 V --122 -44 R --84 22 V -84 22 V --84 -22 R +-122 0 R +stroke +2207 1983 N +-84 -22 V +84 -22 V +-84 22 R 290 0 V -216 -23 R +stroke +1.000 UL +[] 0 setdash +2629 1938 M +stroke +2629 1938 N 88 23 V -88 23 V --128 -46 R --88 23 V -88 23 V --88 -23 R +-128 0 R +stroke +2501 1984 N +-88 -23 V +88 -23 V +-88 23 R 304 0 V -329 -32 R +stroke +1.000 UL +[] 0 setdash +3046 1929 M +stroke +3046 1929 N 121 32 V -121 32 V --208 -64 R --121 32 V -121 32 V --121 -32 R +-208 0 R +stroke +2838 1993 N +-121 -32 V +121 -32 V +-121 32 R 450 0 V -745 -32 R +stroke +1.000 UL +[] 0 setdash +3912 1929 M +stroke +3912 1929 N 121 32 V -121 32 V --624 -64 R --121 32 V -121 32 V --121 -32 R +-624 0 R +stroke +3288 1993 N +-121 -32 V +121 -32 V +-121 32 R 866 0 V -496 -32 R +stroke +1.000 UL +[] 0 setdash +4529 1929 M +stroke +4529 1929 N 121 32 V -121 32 V --375 -64 R --121 32 V -121 32 V --121 -32 R +-375 0 R +stroke +4154 1993 N +-121 -32 V +121 -32 V +-121 32 R 617 0 V -914 -32 R +stroke +1.000 UL +[] 0 setdash +5564 1929 M +stroke +5564 1929 N 121 32 V -121 32 V --793 -64 R --121 32 V -121 32 V --121 -32 R +-793 0 R +stroke +4771 1993 N +-121 -32 V +121 -32 V +-121 32 R 1035 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 10.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 1907 M +0.00 0.00 0.00 C +% Begin plot #1 +10.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 1907 M 0 272 V 502 -272 R 0 272 V @@ -598,74 +706,100 @@ LC0 setrgbcolor 0 272 V 5685 1907 M 0 272 V -1.000 UP stroke +LTw +% End plot #1 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 268 M +[] 0 setdash +0.00 0.00 0.00 C +528 268 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 460 M +[] 0 setdash +0.00 0.00 0.00 C +528 460 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 652 M +[] 0 setdash +0.00 0.00 0.00 C +528 652 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 844 M +[] 0 setdash +0.00 0.00 0.00 C +528 844 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1036 M +[] 0 setdash +0.00 0.00 0.00 C +528 1036 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1228 M +[] 0 setdash +0.00 0.00 0.00 C +528 1228 M -63 0 V stroke LTb LCb setrgbcolor -0.00 0.00 0.00 C 2.000 UL +[] 0 setdash +0.00 0.00 0.00 C +2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C 528 1276 M +[] 0 setdash +0.00 0.00 0.00 C +528 1276 M 528 220 L 5801 0 R 0 1056 R -5801 0 R 1.000 UP stroke -LTb LCb setrgbcolor -LTb 1.000 UL -LTb +[] 0 setdash gsave 6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 268 M +stroke +6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V +Z stroke 528 268 M 5680 0 V stroke -2.000 UL LTb -0.00 0.00 0.00 C 3.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 528 268 M +0.00 0.00 0.00 C +% Begin plot #1 +3.000 UL +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +528 268 M 382 0 V 0 96 R 502 0 V @@ -685,12 +819,17 @@ LC0 setrgbcolor 1035 0 V 0 96 R 533 0 V -1.500 UP stroke +LTw +% End plot #1 +% Begin plot #2 +1.500 UP 2.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 268 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -699,11 +838,16 @@ LC0 setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF +LTw +% End plot #2 +% Begin plot #3 1.000 UP 2.000 UL -LT0 -LC0 setrgbcolor -1.00 1.00 1.00 C 910 268 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +1.00 1.00 1.00 C +910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -712,11 +856,16 @@ LC0 setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF +LTw +% End plot #3 +% Begin plot #4 1.500 UP 2.000 UL -LT0 -LC0 setrgbcolor -0.00 0.00 0.00 C 910 364 CircleF +LTb +LCb setrgbcolor +[] 0 setdash +0.00 0.00 0.00 C +910 364 CircleF 1412 460 CircleF 2123 556 CircleF 2413 652 CircleF @@ -725,11 +874,17 @@ LC0 setrgbcolor 4033 940 CircleF 4650 1036 CircleF 5685 1132 CircleF -1.000 UP +LTw +% End plot #4 2.000 UL LTb LCb setrgbcolor -0.00 0.00 0.00 C stroke +[] 0 setdash +1.000 UP +2.000 UL +LTb +0.00 0.00 0.00 C +stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchB.pdf b/pointprocesses/lecture/pointprocessscetchB.pdf index 6d49213180fa4a5b33b784fef75bb8f5208c60a8..cc832083a74fc77f103c19c49584204a8fc72b5e 100644 GIT binary patch delta 3072 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 I)Y=UAFNvz-!vFvP From 475b3148c84565ebfd6f75be81d3fd667c52fc7f Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 14 Dec 2020 23:57:36 +0100 Subject: [PATCH 16/37] [bootstrap] split exercises --- bootstrap/exercises/Makefile | 3 +- bootstrap/exercises/resampling-1.tex | 66 +--------------------- bootstrap/exercises/resampling-2.tex | 84 ++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 66 deletions(-) create mode 100644 bootstrap/exercises/resampling-2.tex diff --git a/bootstrap/exercises/Makefile b/bootstrap/exercises/Makefile index 3f8d7db..c1e988e 100644 --- a/bootstrap/exercises/Makefile +++ b/bootstrap/exercises/Makefile @@ -1,4 +1,3 @@ -TEXFILES=resampling-1.tex -# resampling2.tex +TEXFILES=$(wildcard resampling-?.tex) include ../../exercises.mk diff --git a/bootstrap/exercises/resampling-1.tex b/bootstrap/exercises/resampling-1.tex index 326fbc6..75b8b81 100644 --- a/bootstrap/exercises/resampling-1.tex +++ b/bootstrap/exercises/resampling-1.tex @@ -18,69 +18,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \question \qt{Read chapter 7 of the script on ``resampling methods''!}\vspace{-3ex} -\question \qt{Bootstrap the standard error of the mean} -We want to compute the standard error of the mean of a data set by -means of the bootstrap method and compare the result with the formula -``standard deviation divided by the square-root of $n$''. -\begin{parts} - \part Download the file \code{thymusglandweights.dat} from Ilias. - This is a data set of the weights of the thymus glands of 14-day old chicken embryos - measured in milligram. - \part Load the data into Matlab (\code{load} function). - \part Compute histogram, mean, and standard error of the mean of the first 80 data points. - \part Compute the standard error of the mean of the first 80 data - points by bootstrapping the data 500 times. Write a function that - bootstraps the standard error of the mean of a given data set. The - function should also return a vector with the bootstrapped means. - \part Compute the 95\,\% confidence interval for the mean from the - bootstrap distribution (\code{quantile()} function) --- the - interval that contains the true mean with 95\,\% probability. - \part Use the whole data set and the bootstrap method for computing - the dependence of the standard error of the mean from the sample - size $n$. - \part Compare your result with the formula for the standard error - $\sigma/\sqrt{n}$. -\end{parts} -\begin{solution} - \lstinputlisting{bootstrapmean.m} - \lstinputlisting{bootstraptymus.m} - \includegraphics[width=0.5\textwidth]{bootstraptymus-datahist} - \includegraphics[width=0.5\textwidth]{bootstraptymus-meanhist} - \includegraphics[width=0.5\textwidth]{bootstraptymus-samples} -\end{solution} - - -\question \qt{Student t-distribution} -The distribution of Student's t, $t=\bar x/(\sigma_x/\sqrt{n})$, the -estimated mean $\bar x$ of a data set of size $n$ divided by the -estimated standard error of the mean $\sigma_x/\sqrt{n}$, where -$\sigma_x$ is the estimated standard deviation, is not a normal -distribution but a Student-t distribution. We want to compute the -Student-t distribution and compare it with the normal distribution. -\begin{parts} -\part Generate 100000 normally distributed random numbers. -\part Draw from these data 1000 samples of size $n=3$, 5, 10, and -50. For each sample size $n$ ... -\part ... compute the mean $\bar x$ of the samples and plot the -probability density of these means. -\part ... compare the resulting probability densities with corresponding -normal distributions. -\part ... compute Student's $t=\bar x/(\sigma_x/\sqrt{n})$ and compare its -distribution with the normal distribution with standard deviation of -one. Is $t$ normally distributed? Under which conditions is $t$ -normally distributed? -\end{parts} -\newsolutionpage -\begin{solution} - \lstinputlisting{tdistribution.m} - \includegraphics[width=1\textwidth]{tdistribution-n03}\\ - \includegraphics[width=1\textwidth]{tdistribution-n05}\\ - \includegraphics[width=1\textwidth]{tdistribution-n10}\\ - \includegraphics[width=1\textwidth]{tdistribution-n50} -\end{solution} - - -\continue \question \qt{Permutation test of correlations} \label{correlationtest} We want to compute the significance of a correlation by means of a permutation test. \begin{parts} @@ -109,6 +46,7 @@ y = randn(n, 1) + a*x; \includegraphics[width=1\textwidth]{correlationsignificance} \end{solution} +\newsolutionpage \question \qt{Bootstrap the correlation coefficient} The permutation test generates the distribution of the null hypothesis of uncorrelated data and we check whether the correlation coefficient @@ -137,7 +75,7 @@ We take the same data set that we have generated in exercise \end{solution} -\continuepage +\continue \question \qt{Permutation test of difference of means} We want to test whether two data sets come from distributions that differ in their mean by means of a permutation test. diff --git a/bootstrap/exercises/resampling-2.tex b/bootstrap/exercises/resampling-2.tex new file mode 100644 index 0000000..e27d1c0 --- /dev/null +++ b/bootstrap/exercises/resampling-2.tex @@ -0,0 +1,84 @@ +\documentclass[12pt,a4paper,pdftex]{exam} + +\newcommand{\exercisetopic}{Resampling} +\newcommand{\exercisenum}{X2} +\newcommand{\exercisedate}{December 14th, 2020} + +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{document} + +\input{../../exercisestitle} + +\begin{questions} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\question \qt{Read chapter 7 of the script on ``resampling methods''!}\vspace{-3ex} + +\question \qt{Bootstrap the standard error of the mean} +We want to compute the standard error of the mean of a data set by +means of the bootstrap method and compare the result with the formula +``standard deviation divided by the square-root of $n$''. +\begin{parts} + \part Download the file \code{thymusglandweights.dat} from Ilias. + This is a data set of the weights of the thymus glands of 14-day old chicken embryos + measured in milligram. + \part Load the data into Matlab (\code{load} function). + \part Compute histogram, mean, and standard error of the mean of the first 80 data points. + \part Compute the standard error of the mean of the first 80 data + points by bootstrapping the data 500 times. Write a function that + bootstraps the standard error of the mean of a given data set. The + function should also return a vector with the bootstrapped means. + \part Compute the 95\,\% confidence interval for the mean from the + bootstrap distribution (\code{quantile()} function) --- the + interval that contains the true mean with 95\,\% probability. + \part Use the whole data set and the bootstrap method for computing + the dependence of the standard error of the mean from the sample + size $n$. + \part Compare your result with the formula for the standard error + $\sigma/\sqrt{n}$. +\end{parts} +\begin{solution} + \lstinputlisting{bootstrapmean.m} + \lstinputlisting{bootstraptymus.m} + \includegraphics[width=0.5\textwidth]{bootstraptymus-datahist} + \includegraphics[width=0.5\textwidth]{bootstraptymus-meanhist} + \includegraphics[width=0.5\textwidth]{bootstraptymus-samples} +\end{solution} + + +\question \qt{Student t-distribution} +The distribution of Student's t, $t=\bar x/(\sigma_x/\sqrt{n})$, the +estimated mean $\bar x$ of a data set of size $n$ divided by the +estimated standard error of the mean $\sigma_x/\sqrt{n}$, where +$\sigma_x$ is the estimated standard deviation, is not a normal +distribution but a Student-t distribution. We want to compute the +Student-t distribution and compare it with the normal distribution. +\begin{parts} +\part Generate 100000 normally distributed random numbers. +\part Draw from these data 1000 samples of size $n=3$, 5, 10, and +50. For each sample size $n$ ... +\part ... compute the mean $\bar x$ of the samples and plot the +probability density of these means. +\part ... compare the resulting probability densities with corresponding +normal distributions. +\part ... compute Student's $t=\bar x/(\sigma_x/\sqrt{n})$ and compare its +distribution with the normal distribution with standard deviation of +one. Is $t$ normally distributed? Under which conditions is $t$ +normally distributed? +\end{parts} +\newsolutionpage +\begin{solution} + \lstinputlisting{tdistribution.m} + \includegraphics[width=1\textwidth]{tdistribution-n03}\\ + \includegraphics[width=1\textwidth]{tdistribution-n05}\\ + \includegraphics[width=1\textwidth]{tdistribution-n10}\\ + \includegraphics[width=1\textwidth]{tdistribution-n50} +\end{solution} + +\end{questions} + +\end{document} \ No newline at end of file From d6756d4975ec8c40ea4e5b7bd9ee3bac540c9fd5 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 08:29:29 +0100 Subject: [PATCH 17/37] [bootstrap] exercises here in chapter --- bootstrap/lecture/bootstrap-chapter.tex | 2 + .../lecture/pointprocessscetchA.eps | 120 ++---- .../lecture/pointprocessscetchA.pdf | Bin 2924 -> 2786 bytes .../lecture/pointprocessscetchB.eps | 389 ++++++------------ .../lecture/pointprocessscetchB.pdf | Bin 4877 -> 4694 bytes statistics/lecture/statistics-chapter.tex | 2 + 6 files changed, 158 insertions(+), 355 deletions(-) diff --git a/bootstrap/lecture/bootstrap-chapter.tex b/bootstrap/lecture/bootstrap-chapter.tex index 9009d78..60c2b5e 100644 --- a/bootstrap/lecture/bootstrap-chapter.tex +++ b/bootstrap/lecture/bootstrap-chapter.tex @@ -10,6 +10,8 @@ \setcounter{page}{\pagenumber} \setcounter{chapter}{\chapternumber} +\renewcommand{\exercisesolutions}{here} % 0: here, 1: chapter, 2: end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} diff --git a/pointprocesses/lecture/pointprocessscetchA.eps b/pointprocesses/lecture/pointprocessscetchA.eps index 7234511..59681c9 100644 --- a/pointprocesses/lecture/pointprocessscetchA.eps +++ b/pointprocesses/lecture/pointprocessscetchA.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchA.tex -%%Creator: gnuplot 5.2 patchlevel 8 -%%CreationDate: Mon Dec 14 20:03:21 2020 +%%Creator: gnuplot 4.6 patchlevel 4 +%%CreationDate: Mon Dec 14 23:59:13 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 135 %%EndComments @@ -18,7 +18,6 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def -/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -30,11 +29,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -48,7 +47,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 5.2 (Dec 2017) +% Gnuplot Prolog Version 4.6 (September 2012) % %/SuppressPDFMark true def % @@ -65,11 +64,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -83,7 +82,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Classic Line colors (version 5.0) +% Default Line colors /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -96,21 +95,19 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default dash patterns (version 5.0) -/LTB {BL [] LCb DL} def +% Default Line Types /LTw {PL [] 1 setgray} def -/LTb {PL [] LCb DL} def +/LTb {BL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [2 dl1 3 dl2] LC1 DL} def -/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def -/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def -/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [4 dl1 2 dl2] LC5 DL} def -/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def -/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def -/SL {[] 0 setdash} def +/LT1 {PL [4 dl1 2 dl2] LC1 DL} def +/LT2 {PL [2 dl1 3 dl2] LC2 DL} def +/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def +/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def +/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def +/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -305,7 +302,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -332,14 +329,9 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse -dup 2 lt - {/InterpretLevel1 true def - /InterpretLevel3 false def} - {/InterpretLevel1 Level1 def - 2 gt - {/InterpretLevel3 Level3 def} - {/InterpretLevel3 false def} - ifelse } + 2 lt + {/InterpretLevel1 true def} + {/InterpretLevel1 Level1 def} ifelse % % PostScript level 2 pattern fill definitions @@ -428,7 +420,6 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop -% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -438,39 +429,14 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchA.tex) /Subject (gnuplot plot) - /Creator (gnuplot 5.2 patchlevel 8) + /Creator (gnuplot 4.6 patchlevel 4) + /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Mon Dec 14 20:03:21 2020) + /CreationDate (Mon Dec 14 23:59:13 2020) /DOCINFO pdfmark end } ifelse -% -% Support for boxed text - Ethan A Merritt Sep 2016 -% -/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put - userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put - /Boxing true def } def -/ExtendTextBox { dup type /stringtype eq - { Boxing { gsave dup false charpath pathbbox - dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse - dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse - dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse - dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse - grestore } if } - {} ifelse} def -/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M - TBx1 TBxmargin sub TBy2 TBymargin add L - TBx2 TBxmargin add TBy2 TBymargin add L - TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def -/DrawTextBox { PopTextBox stroke /Boxing false def} def -/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def -0 0 0 0 InitTextBox -/TBxmargin 20 def -/TBymargin 20 def -/Boxing false def -/textshow { ExtendTextBox Gshow } def -% end %%EndProlog %%Page: 1 1 @@ -484,33 +450,27 @@ newpath 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 824 M -stroke -6208 824 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke 528 824 M 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 573 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 573 M 0 503 V 1412 573 M 0 503 V @@ -528,18 +488,12 @@ LCb setrgbcolor 0 503 V 5685 573 M 0 503 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -stroke +0.00 0.00 0.00 C stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchA.pdf b/pointprocesses/lecture/pointprocessscetchA.pdf index ebfae3dc92ebd0a8d91c320dc094c2eb487b3b9b..323c667bc81412dae3ddbd0efe2e4df66eacdacf 100644 GIT binary patch delta 904 zcmaDO_DGaZHNeG9*HF)#OZE7h{zVfXTi0_j8S=P(w{-OjxV_}$6=9Ah?&HcFd?(I0 z#a7fV_my}Z=JoRbf7Si`J&K8Ij^BUHw7c-YOIF>Z&spXq9h<`;K6y|0obZ*F9;egg z7j8N^?ViI2UKy@=3J(kSmgmdz|KC38-@)XoRO1SmYSnrGFgGmjW|=g*xZRzNVGfc*f(1z1H-8#zsSy}C?(A* zIJFSM$jP+JO3bs-2MGe%5C&LQKPA};s%P^X_IyTAz{GOO!2R36Da~qZY6AAUW~K_Dh%ivdQ{VzK z42+BnfbobbW?+Iv%*Y&5oq-{Sc?L$N<{0Lg8d-wGRFEw;Ff}*8RA^~A`7)PHtgESs zqoa|VlPNGE8JHWInOeHJx)@m+88{o68Jd_n+1U_O5zA#~$5mXCSX5F`l$yq6WMXX0 LrK;-c@5TiHAg&OQ delta 1047 zcmaDP`bMl?HNeG9*HF)tOZE7h{zY7>s-Age`N@eTnfZBE3hBiPx`hh5DZ!3zu0cTB z&p*I1G}sl$a&ioD_5jk(`MCu^#YvetnI)Azsb#4-wm`!abc&fp^ zTkl#t_|r7)Q862zT@p{rYOj0Tdahn2E1!1v2HZ>WUO(Xj?;E3e3J*5k*}b)|{eN`6 z0prQ@>zahF|4;Jri1a#rtK?CXLB-8Wt4w+0ntu1q)-rXAt6FwVV)-58t;d3%&087j zX7^=oTCZX05~zhjYFd)H(d3uR-b|(jljYb{iBn(C;?8bhWngS& zWH|XOizS3@WjL9aRY$;7&qx6nvB?=Zpg2{qnC!{wMx3deS>1_KNVGfC**0&EV$Wh! zH8s%W(swRO1*c9IU@U9+=I1H6q$VpEnkX2-yz-Jmn$^I-80aZZPAheEj{r>orlzda zcx|o5Pks*edi6y3(k&y+a zI&&ioF>@0WkeCXx#RldUrWgt>3{56`a@oWhm^xcHIk_2_S{RucShzX4I9VDP8#@^r p8n`(byIDBe*$`9_%VlTBRa}x-R8motn#N^hYHkS3{I33PTmYBnLQ((# diff --git a/pointprocesses/lecture/pointprocessscetchB.eps b/pointprocesses/lecture/pointprocessscetchB.eps index f5df3c9..8a1175f 100644 --- a/pointprocesses/lecture/pointprocessscetchB.eps +++ b/pointprocesses/lecture/pointprocessscetchB.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 %%Title: pointprocessscetchB.tex -%%Creator: gnuplot 5.2 patchlevel 8 -%%CreationDate: Mon Dec 14 20:03:21 2020 +%%Creator: gnuplot 4.6 patchlevel 4 +%%CreationDate: Mon Dec 14 23:59:13 2020 %%DocumentFonts: %%BoundingBox: 50 50 373 237 %%EndComments @@ -18,7 +18,6 @@ gnudict begin /Dashlength 1 def /Landscape false def /Level1 false def -/Level3 false def /Rounded true def /ClipToBoundingBox false def /SuppressPDFMark false def @@ -30,11 +29,11 @@ gnudict begin % /vshift -73 def /dl1 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if } def /dl2 { - 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + 10.0 Dashlength mul mul Rounded { currentlinewidth 0.75 mul add } if } def /hpt_ 31.5 def @@ -48,7 +47,7 @@ gnudict begin } if } def % -% Gnuplot Prolog Version 5.2 (Dec 2017) +% Gnuplot Prolog Version 4.6 (September 2012) % %/SuppressPDFMark true def % @@ -65,11 +64,11 @@ gnudict begin /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def /Lshow {currentpoint stroke M 0 vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Rshow {currentpoint stroke M dup stringwidth pop neg vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R - Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def + Blacktext {gsave 0 setgray show grestore} {show} ifelse} def /UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def /DL {Color {setrgbcolor Solid {pop []} if 0 setdash} @@ -83,7 +82,7 @@ gnudict begin /PL {stroke userlinewidth setlinewidth Rounded {1 setlinejoin 1 setlinecap} if} def 3.8 setmiterlimit -% Classic Line colors (version 5.0) +% Default Line colors /LCw {1 1 1} def /LCb {0 0 0} def /LCa {0 0 0} def @@ -96,21 +95,19 @@ gnudict begin /LC6 {0 0 0} def /LC7 {1 0.3 0} def /LC8 {0.5 0.5 0.5} def -% Default dash patterns (version 5.0) -/LTB {BL [] LCb DL} def +% Default Line Types /LTw {PL [] 1 setgray} def -/LTb {PL [] LCb DL} def +/LTb {BL [] LCb DL} def /LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def /LT0 {PL [] LC0 DL} def -/LT1 {PL [2 dl1 3 dl2] LC1 DL} def -/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def -/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def -/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def -/LT5 {PL [4 dl1 2 dl2] LC5 DL} def -/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def -/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def -/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def -/SL {[] 0 setdash} def +/LT1 {PL [4 dl1 2 dl2] LC1 DL} def +/LT2 {PL [2 dl1 3 dl2] LC2 DL} def +/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def +/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def +/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def +/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def /Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def /Dia {stroke [] 0 setdash 2 copy vpt add M hpt neg vpt neg V hpt vpt neg V @@ -305,7 +302,7 @@ gnudict begin ColR ColG ColB setrgbcolor} def /BoxColFill {gsave Rec PolyFill} def /PolyFill {gsave Density fill grestore grestore} def -/h {rlineto rlineto rlineto closepath gsave fill grestore stroke} bind def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def % % PostScript Level 1 Pattern Fill routine for rectangles % Usage: x y w h s a XX PatternFill @@ -332,14 +329,9 @@ gnudict begin % /languagelevel where {pop languagelevel} {1} ifelse -dup 2 lt - {/InterpretLevel1 true def - /InterpretLevel3 false def} - {/InterpretLevel1 Level1 def - 2 gt - {/InterpretLevel3 Level3 def} - {/InterpretLevel3 false def} - ifelse } + 2 lt + {/InterpretLevel1 true def} + {/InterpretLevel1 Level1 def} ifelse % % PostScript level 2 pattern fill definitions @@ -428,7 +420,6 @@ Level1 {Level1PatternFill} {Level2PatternFill} ifelse /Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall currentdict end definefont pop -% Level1 SuppressPDFMark or {} { /SDict 10 dict def @@ -438,39 +429,14 @@ systemdict /pdfmark known not { SDict begin [ /Title (pointprocessscetchB.tex) /Subject (gnuplot plot) - /Creator (gnuplot 5.2 patchlevel 8) + /Creator (gnuplot 4.6 patchlevel 4) + /Author (jan) % /Producer (gnuplot) % /Keywords () - /CreationDate (Mon Dec 14 20:03:21 2020) + /CreationDate (Mon Dec 14 23:59:13 2020) /DOCINFO pdfmark end } ifelse -% -% Support for boxed text - Ethan A Merritt Sep 2016 -% -/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put - userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put - /Boxing true def } def -/ExtendTextBox { dup type /stringtype eq - { Boxing { gsave dup false charpath pathbbox - dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse - dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse - dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse - dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse - grestore } if } - {} ifelse} def -/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M - TBx1 TBxmargin sub TBy2 TBymargin add L - TBx2 TBxmargin add TBy2 TBymargin add L - TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def -/DrawTextBox { PopTextBox stroke /Boxing false def} def -/FillTextBox { gsave PopTextBox fill grestore /Boxing false def} def -0 0 0 0 InitTextBox -/TBxmargin 20 def -/TBymargin 20 def -/Boxing false def -/textshow { ExtendTextBox Gshow } def -% end %%EndProlog %%Page: 1 1 @@ -484,33 +450,27 @@ newpath 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 3165 M -stroke -6208 3165 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke -528 3165 M +-5680 0 R 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 3029 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 3029 M 0 272 V 502 -272 R 0 272 V @@ -528,167 +488,99 @@ LCb setrgbcolor 0 272 V 5685 3029 M 0 272 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -1.000 UP +0.00 0.00 0.00 C 1.000 UP +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 2043 M -stroke -6208 2043 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke -528 2043 M +-5680 0 R 5680 0 V -stroke -1.000 UL -[] 0 setdash 1291 1929 M -stroke -1291 1929 N 121 32 V -121 32 V --260 0 R -stroke -1031 1993 N -910 1961 L -121 -32 V --121 32 R +-260 -64 R +-121 32 V +121 32 V +910 1961 M 502 0 V -stroke -1.000 UL -[] 0 setdash -2002 1929 M -stroke -2002 1929 N +590 -32 R 121 32 V -121 32 V --469 0 R -stroke -1533 1993 N --121 -32 V -121 -32 V --121 32 R +-469 -64 R +-121 32 V +121 32 V +-121 -32 R 711 0 V -stroke -1.000 UL -[] 0 setdash -2329 1939 M -stroke -2329 1939 N +206 -22 R 84 22 V -84 22 V --122 0 R -stroke -2207 1983 N --84 -22 V -84 -22 V --84 22 R +-122 -44 R +-84 22 V +84 22 V +-84 -22 R 290 0 V -stroke -1.000 UL -[] 0 setdash -2629 1938 M -stroke -2629 1938 N +216 -23 R 88 23 V -88 23 V --128 0 R -stroke -2501 1984 N --88 -23 V -88 -23 V --88 23 R +-128 -46 R +-88 23 V +88 23 V +-88 -23 R 304 0 V -stroke -1.000 UL -[] 0 setdash -3046 1929 M -stroke -3046 1929 N +329 -32 R 121 32 V -121 32 V --208 0 R -stroke -2838 1993 N --121 -32 V -121 -32 V --121 32 R +-208 -64 R +-121 32 V +121 32 V +-121 -32 R 450 0 V -stroke -1.000 UL -[] 0 setdash -3912 1929 M -stroke -3912 1929 N +745 -32 R 121 32 V -121 32 V --624 0 R -stroke -3288 1993 N --121 -32 V -121 -32 V --121 32 R +-624 -64 R +-121 32 V +121 32 V +-121 -32 R 866 0 V -stroke -1.000 UL -[] 0 setdash -4529 1929 M -stroke -4529 1929 N +496 -32 R 121 32 V -121 32 V --375 0 R -stroke -4154 1993 N --121 -32 V -121 -32 V --121 32 R +-375 -64 R +-121 32 V +121 32 V +-121 -32 R 617 0 V -stroke -1.000 UL -[] 0 setdash -5564 1929 M -stroke -5564 1929 N +914 -32 R 121 32 V -121 32 V --793 0 R -stroke -4771 1993 N --121 -32 V -121 -32 V --121 32 R +-793 -64 R +-121 32 V +121 32 V +-121 -32 R 1035 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -10.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 1907 M +0.00 0.00 0.00 C 10.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 1907 M 0 272 V 502 -272 R 0 272 V @@ -706,100 +598,74 @@ LCb setrgbcolor 0 272 V 5685 1907 M 0 272 V +1.000 UP stroke -LTw -% End plot #1 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -1.000 UP -2.000 UL -LTb -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 268 M +0.00 0.00 0.00 C 528 268 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 460 M +0.00 0.00 0.00 C 528 460 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 652 M +0.00 0.00 0.00 C 528 652 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 844 M +0.00 0.00 0.00 C 528 844 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1036 M +0.00 0.00 0.00 C 528 1036 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1228 M +0.00 0.00 0.00 C 528 1228 M -63 0 V stroke LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -2.000 UL +0.00 0.00 0.00 C 2.000 UL LTb LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 1276 M +0.00 0.00 0.00 C 528 1276 M 528 220 L 5801 0 R 0 1056 R -5801 0 R 1.000 UP stroke +LTb LCb setrgbcolor +LTb 1.000 UL -[] 0 setdash +LTb gsave 6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V 1 PolyFill 6208 268 M -stroke -6208 268 N 0 -32 V 121 32 V -121 32 V 0 -32 V -Z stroke 528 268 M 5680 0 V stroke +2.000 UL LTb -0.00 0.00 0.00 C -% Begin plot #1 -3.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -528 268 M +0.00 0.00 0.00 C 3.000 UL +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 528 268 M 382 0 V 0 96 R 502 0 V @@ -819,17 +685,12 @@ LCb setrgbcolor 1035 0 V 0 96 R 533 0 V -stroke -LTw -% End plot #1 -% Begin plot #2 1.500 UP +stroke 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 268 CircleF +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -838,16 +699,11 @@ LCb setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF -LTw -% End plot #2 -% Begin plot #3 1.000 UP 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -1.00 1.00 1.00 C -910 268 CircleF +LT0 +LC0 setrgbcolor +1.00 1.00 1.00 C 910 268 CircleF 1412 364 CircleF 2123 460 CircleF 2413 556 CircleF @@ -856,16 +712,11 @@ LCb setrgbcolor 4033 844 CircleF 4650 940 CircleF 5685 1036 CircleF -LTw -% End plot #3 -% Begin plot #4 1.500 UP 2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash -0.00 0.00 0.00 C -910 364 CircleF +LT0 +LC0 setrgbcolor +0.00 0.00 0.00 C 910 364 CircleF 1412 460 CircleF 2123 556 CircleF 2413 652 CircleF @@ -874,17 +725,11 @@ LCb setrgbcolor 4033 940 CircleF 4650 1036 CircleF 5685 1132 CircleF -LTw -% End plot #4 -2.000 UL -LTb -LCb setrgbcolor -[] 0 setdash 1.000 UP 2.000 UL LTb -0.00 0.00 0.00 C -stroke +LCb setrgbcolor +0.00 0.00 0.00 C stroke grestore end showpage diff --git a/pointprocesses/lecture/pointprocessscetchB.pdf b/pointprocesses/lecture/pointprocessscetchB.pdf index cc832083a74fc77f103c19c49584204a8fc72b5e..b7614482459574c083bebc72a2a943c2c623a83e 100644 GIT binary patch delta 2809 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 YDcFM;e2Iwj0m5N$C{R(+%+?(E7sZa)a{vGU delta 3027 zcmb7GdpK148rCS63EO3>9mz-oOt>)w{MU8v_^ zO@bnf&|tm#w<)<`Jw01?D9782@5f=|A-+5aG#CP9I1@-jCt#)8I}lu*i9lpYaIvxh zRx3^r7a-I90{!^m`)72$W|{bhEW0nsFIEM??JhOaQSL@VNp$$uE#;W&tRH zyv{@yhKntg?5qpphA@Gf2jpYed4)L(=sYIh!JBV}fWrak`#Xul=JU+>Ap&4G1~G`v zWDo)a{|h7t_#7t=-;2+5@bYEybYWBu8z7%m!V8;{p=gDH>{8re?o-nV*d9yznmKvh zV3mutQX7`dlWEMWzM*n7n%(}Lp_h`ij%Hb8Pn^s4TYWSnnN87-&T8QZE%@`Fdn(D# zu9@);zwXK&O8i54UWbJWms%n$9MlI%`tvMS!#jH-zAQg&$ri6_yNi3YS1XCp!n$VlUS zNz5vJ%}_U~JXqZe5(ys#?A6nTK?|aft^V;L=_=lSty285MfhCDvKTzy?_DuHuMvEx zrwkffZFn+5X`c3WCd^lA`axlRN?i3Zp-4Dt-@B1ybOxdh z@)oiso27BpFp5p$&x}WoON<7c6RBgnEvp{dM<-dyVP`s2M|?_DoBCgmu+v6A2nN@` z?|5Lw=PKw_!A@_MEOr%b6i}y5(Lp(tczGWz?$9JvS7I|tJ*shmps~NE1BY#|YO|fo zIzD!CreY=||K&Kc1vmMzQ*V187&jflsn);5Jq$c+tQlth3T{Yyi<0vZ(o5cw z#mY(zsgJ3NM-=)O3Q~^s2bJ^~WMyvmpF7tVdFR$VXU4gH+N$yQA?@PV8Dhpwblv3c z8;MUUo44<@Egrz@YwaHjOYil(V5pn-QAJXl|JX3Y%hVvZs3_wCY{f&I$4Hra|LXG! zq9oVc1Sy_!)IE9I`#rQgaoazFh{6C9s8*$YeV77Nph@w0Ff>1D#lz8={ zoPmtH#de4}9+%rQ=yG5W{PZt{BPXVsYchXTBhsWBLtO7W_M7C~(c*kh?LdlX!|SXJ zZ{cbliOP=oG(fN}t=;6e^UmpbmYsNt-8M2^);IQqf9q4h8_^%5YKsN$Yov#J`IuIl zyU6AmkMNEt-<74sOAmyf-V7&1&tA#D;`^jYwJ@|Zs!haxw)2w2cU0ZMsonFHP5Nx7 z7EB9gRJ%{B;NQ|GCCQ2Yd&Syn%Gss~Zvviw5X)=C-f zdnE((Z05(y1(Ep^znZ+;hu19hkgpY#t76BKura06C^~O0!SkrF%=-1y=P%M?uB&qo z+?$oOXR70tTt*cg((hJ4Kt@9*rA%6Q_f*lpAtN z?^}`d+tdq(jWvV?vAeFt?O3$avUMy!*E>3s+5x&5tFv9tP`;Q5YQDaKy#uE9Y-38T z1)a!EkWDAw=-xaYd4Lqa+jeklYXj+YMa>s{L`KeFO-*Ou%>`^=VlfQV@IeC?sMno0 zq0xS&a4MDP!q!B1Pz;HPgIilQHjo>lmQvfz@aa0!@jPMun$WtX@E59inxMpz%Daeu z$3t!Yu@&l*H4GK?pp^5)D%8PUnmP_o9J_T)(=ooj^_cUw;s?LD-ArAat5`?+X>Fqo zZ?ke(%_yvhMlozpu~S;&3}P?Mit|g)1!^TAF*Qz;`;5i_xn+!&-ksvBB|9 zS$d3C1#um7Y#I^(BdGDvVslF`k9236~H(nGB=aWtQ!4M!qa}*Y-P= z8Q9k3h_Q=e<+C27yWPWYZ@d^5#+>TPA2yuL?O8naMY^Kjey}dZbQkICmvN-`x``_6 zsw|p$mS#L!Swdrw?$|xq)#)MEa~N52E1{FoX=`^*$|9$5{8GWoJoK$YW677}EGZ=p zaV5Ey@g=ny`9MFoCR6N)J1!T3mOGp8->R2ZMEK2Nwyp2hp*P8wV=RRfrTuX^*_QFi znE-o}#7^;GIV5*ER)ZJLNSbK1Z{;D@M6_s0dDH`FFtnHL51$tmIa2pT&OmZ4x*&Zr zDzAU)g1lDgJn}~WI)NJVk|+DP+cd#I=t)U;R@}1K&}9Jh1)#3$t`Pzt)@c?l-f3i( zTTXW2cqC~4ccH1&9V1KY&sG7Ax>Y}|JpLF38sW*RtN^ah;lBGgarla-g=5Q;wH?P^ zNxhg?QxV&<8U)U9CE1oqC7Bw0S@Jv<&9Xb007~#b1Cm!X{Q2iD2+4EyVXXJ`nq-4m zPf9XiM5FPW5uj|c{m<0h2RVWWXREE-g+o$S1VYQYpa@uVY;lvaqf~WzV7!LHig<6@ zw-Q~xBJ(lchCEkO^iVL^IXt2`?BA-tXSP~;7(qq9XtGmWaHFDae({HYugTfLf3D=e284!- z@XDM2?V6^nxeg9D2K+}U4$yBpQqQ0YjmF(87U#@FNfT0}qKY!G7iG{%2w&*7!#;79+Z=Vn#zC zF<2A{ZDK_tk>GF?5`nP9!f}9CB-|QhLLi#&{+|pQ*xVe<<9mhh!$O!oU=$jO0tR=Y HJqi3z`?)s^ diff --git a/statistics/lecture/statistics-chapter.tex b/statistics/lecture/statistics-chapter.tex index 4331ed1..84833c0 100644 --- a/statistics/lecture/statistics-chapter.tex +++ b/statistics/lecture/statistics-chapter.tex @@ -10,6 +10,8 @@ \setcounter{page}{\pagenumber} \setcounter{chapter}{\chapternumber} +\renewcommand{\exercisesolutions}{here} % 0: here, 1: chapter, 2: end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} From 9db487fb253b7db18e9ac2df560872c8ccdc010b Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 13:50:42 +0100 Subject: [PATCH 18/37] [regression] updated exercise infrastructure --- regression/exercises/Makefile | 34 +-------- regression/{code => exercises}/checkdescent.m | 0 regression/{code => exercises}/descent.m | 0 regression/{code => exercises}/descentfit.m | 0 ...{exercises01.tex => gradientdescent-1.tex} | 71 ++++--------------- regression/{code => exercises}/linefit.m | 0 6 files changed, 16 insertions(+), 89 deletions(-) rename regression/{code => exercises}/checkdescent.m (100%) rename regression/{code => exercises}/descent.m (100%) rename regression/{code => exercises}/descentfit.m (100%) rename regression/exercises/{exercises01.tex => gradientdescent-1.tex} (64%) rename regression/{code => exercises}/linefit.m (100%) diff --git a/regression/exercises/Makefile b/regression/exercises/Makefile index 27691d9..ba0b38c 100644 --- a/regression/exercises/Makefile +++ b/regression/exercises/Makefile @@ -1,34 +1,4 @@ -TEXFILES=$(wildcard exercises??.tex) -EXERCISES=$(TEXFILES:.tex=.pdf) -SOLUTIONS=$(EXERCISES:exercises%=solutions%) +TEXFILES=$(wildcard gradientdescent-?.tex) -.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean +include ../../exercises.mk -pdf : $(SOLUTIONS) $(EXERCISES) - -exercises : $(EXERCISES) - -solutions : $(SOLUTIONS) - -$(SOLUTIONS) : solutions%.pdf : exercises%.tex instructions.tex - { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) - pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true - rm $(patsubst %.pdf,%,$@).[!p]* - -$(EXERCISES) : %.pdf : %.tex instructions.tex - pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true - -watch : - while true; do ! make -q pdf && make pdf; sleep 0.5; done - -watchexercises : - while true; do ! make -q exercises && make exercises; sleep 0.5; done - -watchsolutions : - while true; do ! make -q solutions && make solutions; sleep 0.5; done - -clean : - rm -f *~ *.aux *.log *.out - -cleanup : clean - rm -f $(SOLUTIONS) $(EXERCISES) diff --git a/regression/code/checkdescent.m b/regression/exercises/checkdescent.m similarity index 100% rename from regression/code/checkdescent.m rename to regression/exercises/checkdescent.m diff --git a/regression/code/descent.m b/regression/exercises/descent.m similarity index 100% rename from regression/code/descent.m rename to regression/exercises/descent.m diff --git a/regression/code/descentfit.m b/regression/exercises/descentfit.m similarity index 100% rename from regression/code/descentfit.m rename to regression/exercises/descentfit.m diff --git a/regression/exercises/exercises01.tex b/regression/exercises/gradientdescent-1.tex similarity index 64% rename from regression/exercises/exercises01.tex rename to regression/exercises/gradientdescent-1.tex index 9e7c5b3..8275723 100644 --- a/regression/exercises/exercises01.tex +++ b/regression/exercises/gradientdescent-1.tex @@ -1,60 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 10\stitle}}{{\bfseries\large Gradient descent}}{{\bfseries\large December 16th, 2019}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -\newcommand{\code}[1]{\texttt{#1}} -\renewcommand{\solutiontitle}{\noindent\textbf{Solution:}\par\noindent} -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\exercisetopic}{Resampling} +\newcommand{\exercisenum}{9} +\newcommand{\exercisedate}{December 21th, 2020} + +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} +\input{../../exercisestitle} \begin{questions} @@ -96,7 +53,7 @@ the parameter values at the minimum of the cost function and a vector with the value of the cost function at each step of the algorithm. \begin{solution} - \lstinputlisting{../code/descent.m} + \lstinputlisting{descent.m} \end{solution} \part Plot the data and the straight line with the parameter @@ -105,7 +62,7 @@ \part Plot the development of the costs as a function of the iteration step. \begin{solution} - \lstinputlisting{../code/descentfit.m} + \lstinputlisting{descentfit.m} \end{solution} \part For checking the gradient descend method from (a) compare @@ -116,7 +73,7 @@ minimum gradient. What are good values such that the gradient descent gets closest to the true minimum of the cost function? \begin{solution} - \lstinputlisting{../code/checkdescent.m} + \lstinputlisting{checkdescent.m} \end{solution} \part Use the functions \code{polyfit()} and \code{lsqcurvefit()} @@ -124,7 +81,7 @@ line that fits the data. Compare the resulting fit parameters of those functions with the ones of your gradient descent algorithm. \begin{solution} - \lstinputlisting{../code/linefit.m} + \lstinputlisting{linefit.m} \end{solution} \end{parts} diff --git a/regression/code/linefit.m b/regression/exercises/linefit.m similarity index 100% rename from regression/code/linefit.m rename to regression/exercises/linefit.m From 18da3117e5069cf2a15fbef8eb7cd5d2148ad6ed Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 13:56:24 +0100 Subject: [PATCH 19/37] [likelihood] updated exercise infrastructure --- likelihood/exercises/Makefile | 35 +------- likelihood/exercises/instructions.tex | 41 --------- .../{exercises01.tex => likelihood-1.tex} | 87 ++----------------- regression/exercises/gradientdescent-1.tex | 2 +- regression/exercises/instructions.tex | 6 -- 5 files changed, 10 insertions(+), 161 deletions(-) delete mode 100644 likelihood/exercises/instructions.tex rename likelihood/exercises/{exercises01.tex => likelihood-1.tex} (70%) delete mode 100644 regression/exercises/instructions.tex diff --git a/likelihood/exercises/Makefile b/likelihood/exercises/Makefile index 27691d9..cbfb17a 100644 --- a/likelihood/exercises/Makefile +++ b/likelihood/exercises/Makefile @@ -1,34 +1,3 @@ -TEXFILES=$(wildcard exercises??.tex) -EXERCISES=$(TEXFILES:.tex=.pdf) -SOLUTIONS=$(EXERCISES:exercises%=solutions%) +TEXFILES=$(wildcard likelihood-?.tex) -.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean - -pdf : $(SOLUTIONS) $(EXERCISES) - -exercises : $(EXERCISES) - -solutions : $(SOLUTIONS) - -$(SOLUTIONS) : solutions%.pdf : exercises%.tex instructions.tex - { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) - pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true - rm $(patsubst %.pdf,%,$@).[!p]* - -$(EXERCISES) : %.pdf : %.tex instructions.tex - pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true - -watch : - while true; do ! make -q pdf && make pdf; sleep 0.5; done - -watchexercises : - while true; do ! make -q exercises && make exercises; sleep 0.5; done - -watchsolutions : - while true; do ! make -q solutions && make solutions; sleep 0.5; done - -clean : - rm -f *~ *.aux *.log *.out - -cleanup : clean - rm -f $(SOLUTIONS) $(EXERCISES) +include ../../exercises.mk diff --git a/likelihood/exercises/instructions.tex b/likelihood/exercises/instructions.tex deleted file mode 100644 index 7fe599d..0000000 --- a/likelihood/exercises/instructions.tex +++ /dev/null @@ -1,41 +0,0 @@ -\vspace*{-8ex} -\begin{center} -\textbf{\Large Introduction to scientific computing}\\[1ex] -{\large Jan Grewe, Jan Benda}\\[-3ex] -Neuroethology lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} - -% \ifprintanswers% -% \else - -% % Die folgenden Aufgaben dienen der Wiederholung, \"Ubung und -% % Selbstkontrolle und sollten eigenst\"andig bearbeitet und gel\"ost -% % werden. Die L\"osung soll in Form eines einzelnen Skriptes (m-files) -% % im ILIAS hochgeladen werden. Jede Aufgabe sollte in einer eigenen -% % ``Zelle'' gel\"ost sein. Die Zellen \textbf{m\"ussen} unabh\"angig -% % voneinander ausf\"uhrbar sein. Das Skript sollte nach dem Muster: -% % ``variablen\_datentypen\_\{nachname\}.m'' benannt werden -% % (z.B. variablen\_datentypen\_mueller.m). - -% \begin{itemize} -% \item \"Uberzeuge dich von jeder einzelnen Zeile deines Codes, dass -% sie auch wirklich das macht, was sie machen soll! Teste dies mit -% kleinen Beispielen direkt in der Kommandozeile. -% \item Versuche die L\"osungen der Aufgaben m\"oglichst in -% sinnvolle kleine Funktionen herunterzubrechen. -% Sobald etwas \"ahnliches mehr als einmal berechnet werden soll, -% lohnt es sich eine Funktion daraus zu schreiben! -% \item Teste rechenintensive \code{for} Schleifen, Vektoren, Matrizen -% zuerst mit einer kleinen Anzahl von Wiederholungen oder kleiner -% Gr\"o{\ss}e, und benutze erst am Ende, wenn alles \"uberpr\"uft -% ist, eine gro{\ss}e Anzahl von Wiederholungen oder Elementen, um eine gute -% Statistik zu bekommen. -% \item Benutze die Hilfsfunktion von \code{matlab} (\code{help -% commando} oder \code{doc commando}) und das Internet, um -% herauszufinden, wie bestimmte \code{matlab} Funktionen zu verwenden -% sind und was f\"ur M\"oglichkeiten sie bieten. -% Auch zu inhaltlichen Konzepten bietet das Internet oft viele -% Antworten! -% \end{itemize} - -% \fi diff --git a/likelihood/exercises/exercises01.tex b/likelihood/exercises/likelihood-1.tex similarity index 70% rename from likelihood/exercises/exercises01.tex rename to likelihood/exercises/likelihood-1.tex index 4512e91..28b3946 100644 --- a/likelihood/exercises/exercises01.tex +++ b/likelihood/exercises/likelihood-1.tex @@ -1,90 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 11\stitle}}{{\bfseries\large Maximum likelihood}}{{\bfseries\large January 7th, 2020}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\newcommand{\exercisetopic}{Maximum Likelihood} +\newcommand{\exercisenum}{10} +\newcommand{\exercisedate}{January 12th, 2021} +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} diff --git a/regression/exercises/gradientdescent-1.tex b/regression/exercises/gradientdescent-1.tex index 8275723..7e25b0d 100644 --- a/regression/exercises/gradientdescent-1.tex +++ b/regression/exercises/gradientdescent-1.tex @@ -2,7 +2,7 @@ \newcommand{\exercisetopic}{Resampling} \newcommand{\exercisenum}{9} -\newcommand{\exercisedate}{December 21th, 2020} +\newcommand{\exercisedate}{December 22th, 2020} \input{../../exercisesheader} diff --git a/regression/exercises/instructions.tex b/regression/exercises/instructions.tex deleted file mode 100644 index 3041d3e..0000000 --- a/regression/exercises/instructions.tex +++ /dev/null @@ -1,6 +0,0 @@ -\vspace*{-7.8ex} -\begin{center} -\textbf{\Large Introduction to Scientific Computing}\\[2.3ex] -{\large Jan Grewe, Jan Benda}\\[-3ex] -Neuroethology Lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} From 88c6afac1c640b79e34a935d2a959ab88a569e2e Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 14:02:43 +0100 Subject: [PATCH 20/37] [pointprocesses] updated exercise infrastructure --- pointprocesses/exercises/Makefile | 36 +------- pointprocesses/exercises/instructions.tex | 6 -- ...ntprocesses01.tex => pointprocesses-1.tex} | 87 ++----------------- ...ntprocesses02.tex => pointprocesses-2.tex} | 85 ++---------------- ...ntprocesses03.tex => pointprocesses-3.tex} | 87 ++----------------- 5 files changed, 22 insertions(+), 279 deletions(-) delete mode 100644 pointprocesses/exercises/instructions.tex rename pointprocesses/exercises/{pointprocesses01.tex => pointprocesses-1.tex} (72%) rename pointprocesses/exercises/{pointprocesses02.tex => pointprocesses-2.tex} (68%) rename pointprocesses/exercises/{pointprocesses03.tex => pointprocesses-3.tex} (73%) diff --git a/pointprocesses/exercises/Makefile b/pointprocesses/exercises/Makefile index 0b63fb9..0d84b85 100644 --- a/pointprocesses/exercises/Makefile +++ b/pointprocesses/exercises/Makefile @@ -1,35 +1,3 @@ -BASENAME=pointprocesses -TEXFILES=$(wildcard $(BASENAME)??.tex) -EXERCISES=$(TEXFILES:.tex=.pdf) -SOLUTIONS=$(EXERCISES:pointprocesses%=pointprocesses-solutions%) +TEXFILES=$(wildcard pointprocesses-?.tex) -.PHONY: pdf exercises solutions watch watchexercises watchsolutions clean - -pdf : $(SOLUTIONS) $(EXERCISES) - -exercises : $(EXERCISES) - -solutions : $(SOLUTIONS) - -$(SOLUTIONS) : pointprocesses-solutions%.pdf : pointprocesses%.tex instructions.tex - { echo "\\documentclass[answers,12pt,a4paper,pdftex]{exam}"; sed -e '1d' $<; } > $(patsubst %.pdf,%.tex,$@) - pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $(patsubst %.pdf,%.tex,$@) || true - rm $(patsubst %.pdf,%,$@).[!p]* - -$(EXERCISES) : %.pdf : %.tex instructions.tex - pdflatex -interaction=scrollmode $< | tee /dev/stderr | fgrep -q "Rerun to get cross-references right" && pdflatex -interaction=scrollmode $< || true - -watch : - while true; do ! make -q pdf && make pdf; sleep 0.5; done - -watchexercises : - while true; do ! make -q exercises && make exercises; sleep 0.5; done - -watchsolutions : - while true; do ! make -q solutions && make solutions; sleep 0.5; done - -clean : - rm -f *~ *.aux *.log *.out - -cleanup : clean - rm -f $(SOLUTIONS) $(EXERCISES) +include ../../exercises.mk diff --git a/pointprocesses/exercises/instructions.tex b/pointprocesses/exercises/instructions.tex deleted file mode 100644 index 3041d3e..0000000 --- a/pointprocesses/exercises/instructions.tex +++ /dev/null @@ -1,6 +0,0 @@ -\vspace*{-7.8ex} -\begin{center} -\textbf{\Large Introduction to Scientific Computing}\\[2.3ex] -{\large Jan Grewe, Jan Benda}\\[-3ex] -Neuroethology Lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} diff --git a/pointprocesses/exercises/pointprocesses01.tex b/pointprocesses/exercises/pointprocesses-1.tex similarity index 72% rename from pointprocesses/exercises/pointprocesses01.tex rename to pointprocesses/exercises/pointprocesses-1.tex index eb78d42..eed6a5a 100644 --- a/pointprocesses/exercises/pointprocesses01.tex +++ b/pointprocesses/exercises/pointprocesses-1.tex @@ -1,90 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 12\stitle}}{{\bfseries\large Point processes}}{{\bfseries\large January 14th, 2020}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\newcommand{\exercisetopic}{Point Processes} +\newcommand{\exercisenum}{11} +\newcommand{\exercisedate}{January 19th, 2021} +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} diff --git a/pointprocesses/exercises/pointprocesses02.tex b/pointprocesses/exercises/pointprocesses-2.tex similarity index 68% rename from pointprocesses/exercises/pointprocesses02.tex rename to pointprocesses/exercises/pointprocesses-2.tex index c943457..883b0b2 100644 --- a/pointprocesses/exercises/pointprocesses02.tex +++ b/pointprocesses/exercises/pointprocesses-2.tex @@ -1,90 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Point Processes} +\newcommand{\exercisenum}{X2} +\newcommand{\exercisedate}{January 19th, 2021} -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{L\"osungen} -\else -\newcommand{\stitle}{\"Ubung} -\fi -\header{{\bfseries\large \stitle}}{{\bfseries\large Punktprozesse 2}}{{\bfseries\large 27. Oktober, 2015}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} diff --git a/pointprocesses/exercises/pointprocesses03.tex b/pointprocesses/exercises/pointprocesses-3.tex similarity index 73% rename from pointprocesses/exercises/pointprocesses03.tex rename to pointprocesses/exercises/pointprocesses-3.tex index 31bb760..1af6dc7 100644 --- a/pointprocesses/exercises/pointprocesses03.tex +++ b/pointprocesses/exercises/pointprocesses-3.tex @@ -1,90 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: L\"osungen} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large \"Ubung 8\stitle}}{{\bfseries\large Spiketrain Analyse}}{{\bfseries\large 6. Dezember, 2016}} -\firstpagefooter{Prof. Dr. Jan Benda}{Phone: 29 74573}{Email: -jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} +\newcommand{\exercisetopic}{Point Processes} +\newcommand{\exercisenum}{X3} +\newcommand{\exercisedate}{January 19th, 2021} +\input{../../exercisesheader} + +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\input{instructions} - +\input{../../exercisestitle} \begin{questions} From 18c53cb370be6afc7be96a6e4a44c5a5c6fd447d Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 18:55:20 +0100 Subject: [PATCH 21/37] [plotting] updated exercise infrastructure --- plotting/exercises/Makefile | 3 + plotting/exercises/instructions.tex | 12 +-- .../{exercises.tex => plotting-1.tex} | 84 ++----------------- 3 files changed, 13 insertions(+), 86 deletions(-) create mode 100644 plotting/exercises/Makefile rename plotting/exercises/{exercises.tex => plotting-1.tex} (54%) diff --git a/plotting/exercises/Makefile b/plotting/exercises/Makefile new file mode 100644 index 0000000..8e092f8 --- /dev/null +++ b/plotting/exercises/Makefile @@ -0,0 +1,3 @@ +TEXFILES=$(wildcard plotting-?.tex) + +include ../../exercises.mk diff --git a/plotting/exercises/instructions.tex b/plotting/exercises/instructions.tex index 37f737d..8f5d332 100644 --- a/plotting/exercises/instructions.tex +++ b/plotting/exercises/instructions.tex @@ -1,17 +1,11 @@ -\vspace*{-8ex} -\begin{center} -\textbf{\Large Introduction to scientific computing}\\[1ex] -{\large Jan Grewe, Jan Benda}\\[-3ex] -Neuroethology lab \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\ifprintanswers% +\else The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. In contrast to previous exercises, the solutions can not be saved in a single file. Combine the files into a single zip archive and submit it via ILIAS. Name the archive according to the pattern: ``plotting\_\{surname\}.zip''. -% \ifprintanswers% -% \else % % Die folgenden Aufgaben dienen der Wiederholung, \"Ubung und % % Selbstkontrolle und sollten eigenst\"andig bearbeitet und gel\"ost @@ -43,4 +37,4 @@ to the pattern: ``plotting\_\{surname\}.zip''. % Antworten! % \end{itemize} -% \fi +\fi diff --git a/plotting/exercises/exercises.tex b/plotting/exercises/plotting-1.tex similarity index 54% rename from plotting/exercises/exercises.tex rename to plotting/exercises/plotting-1.tex index f66c61c..48c0fd6 100644 --- a/plotting/exercises/exercises.tex +++ b/plotting/exercises/plotting-1.tex @@ -1,88 +1,18 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{pslatex} -\usepackage[mediumspace,mediumqspace]{SIunits} % \ohm, \micro -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Plotting} +\newcommand{\exercisenum}{X} +\newcommand{\exercisedate}{December 14th, 2020} -%%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\ifprintanswers -\newcommand{\stitle}{: Solutions} -\else -\newcommand{\stitle}{} -\fi -\header{{\bfseries\large Exercise 7\stitle}}{{\bfseries\large Plotting}}{{\bfseries\large November 20, 2019}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: -jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{amsmath} -\usepackage{amssymb} -\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}} - -%%%%% page breaks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\continue}{\ifprintanswers% -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\continuepage}{\ifprintanswers% -\newpage -\else -\vfill\hspace*{\fill}$\rightarrow$\newpage% -\fi} -\newcommand{\newsolutionpage}{\ifprintanswers% -\newpage% -\else -\fi} - -%%%%% new commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand{\qt}[1]{\textbf{#1}\\} -\newcommand{\pref}[1]{(\ref{#1})} -\newcommand{\extra}{--- Zusatzaufgabe ---\ \mbox{}} -\newcommand{\code}[1]{\texttt{#1}} - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} +\input{../../exercisestitle} + \input{instructions} \begin{questions} From 9a4100386b995311ebd80aedcc91208a0053d0ee Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 19:12:31 +0100 Subject: [PATCH 22/37] [programming] updated exercise infrastructure --- plotting/exercises/plotting-1.tex | 2 +- programming/exercises/Makefile | 11 +++ .../exercises/boolean_logical_indexing.tex | 46 ++++--------- programming/exercises/control_flow.tex | 39 +++-------- programming/exercises/matrices.tex | 45 +++---------- programming/exercises/scripts_functions.tex | 67 +++---------------- programming/exercises/structs_cells.tex | 37 ++-------- programming/exercises/variables_types.tex | 44 +++--------- programming/exercises/vectors.tex | 39 +++-------- programming/exercises/vectors_matrices.tex | 41 +++--------- 10 files changed, 88 insertions(+), 283 deletions(-) create mode 100644 programming/exercises/Makefile diff --git a/plotting/exercises/plotting-1.tex b/plotting/exercises/plotting-1.tex index 48c0fd6..381e43c 100644 --- a/plotting/exercises/plotting-1.tex +++ b/plotting/exercises/plotting-1.tex @@ -6,7 +6,7 @@ \input{../../exercisesheader} -\firstpagefooter{Prof. Dr. Jan Benda}{}{jan.benda@uni-tuebingen.de} +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} diff --git a/programming/exercises/Makefile b/programming/exercises/Makefile new file mode 100644 index 0000000..7f3247f --- /dev/null +++ b/programming/exercises/Makefile @@ -0,0 +1,11 @@ +TEXFILES= \ + boolean_logical_indexing.tex \ + control_flow.tex \ + matrices.tex \ + scripts_functions.tex \ + structs_cells.tex \ + variables_types.tex \ + vectors_matrices.tex \ + vectors.tex + +include ../../exercises.mk diff --git a/programming/exercises/boolean_logical_indexing.tex b/programming/exercises/boolean_logical_indexing.tex index f166f3d..b1d616d 100644 --- a/programming/exercises/boolean_logical_indexing.tex +++ b/programming/exercises/boolean_logical_indexing.tex @@ -1,39 +1,17 @@ -\documentclass[12pt,a4paper,pdftex, answers]{exam} - -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} \header{{\bfseries\large Exercise 4 - }}{{\bfseries\large Boolean expressions and logical indexing}}{{\bfseries\large 29. Oktober, 2019}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} \runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -\newcommand{\code}[1]{\texttt{#1}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\documentclass[12pt,a4paper,pdftex]{exam} + +\newcommand{\exercisetopic}{Logical indexing} +\newcommand{\exercisenum}{4} +\newcommand{\exercisedate}{29. Oktober, 2019} + +\input{../../exercisesheader} + +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to scientific computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. Your solution diff --git a/programming/exercises/control_flow.tex b/programming/exercises/control_flow.tex index 2dd88fd..55c448e 100644 --- a/programming/exercises/control_flow.tex +++ b/programming/exercises/control_flow.tex @@ -1,40 +1,17 @@ -\documentclass[12pt,a4paper,pdftex, answers]{exam} +\documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Control flow} +\newcommand{\exercisenum}{5} +\newcommand{\exercisedate}{5. November, 2019} -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 5}}{{\bfseries\large Control Flow}}{{\bfseries\large 05. November, 2019}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} -\newcommand{\code}[1]{\texttt{#1}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to scientific computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethologie \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. Your solution diff --git a/programming/exercises/matrices.tex b/programming/exercises/matrices.tex index 84127a4..3825486 100644 --- a/programming/exercises/matrices.tex +++ b/programming/exercises/matrices.tex @@ -1,40 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 3}}{{\bfseries\large Matrices}}{{\bfseries\large 22. Oktober, 2019}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -\newcommand{\code}[1]{\texttt{#1}} -\renewcommand{\solutiontitle}{\noindent\textbf{Solutions:}\par\noindent} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\exercisetopic}{Matrices} +\newcommand{\exercisenum}{3} +\newcommand{\exercisedate}{22. October, 2019} + +\input{../../exercisesheader} + +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to Scientific Computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} + +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. Your solution diff --git a/programming/exercises/scripts_functions.tex b/programming/exercises/scripts_functions.tex index 2b3282a..dcd919c 100644 --- a/programming/exercises/scripts_functions.tex +++ b/programming/exercises/scripts_functions.tex @@ -1,62 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -%\documentclass[answers,12pt,a4paper,pdftex]{exam} - -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{xcolor} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 6}}{{\bfseries\large Scripts and functions}}{{\bfseries\large 06. November, 2018}} -\firstpagefooter{Prof. Jan Benda}{Phone: 29 74 573}{Email: - jan.benda@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - - -%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage{listings} -\lstset{ - language=Matlab, - basicstyle=\ttfamily\footnotesize, - numbers=left, - numberstyle=\tiny, - title=\lstname, - showstringspaces=false, - commentstyle=\itshape\color{darkgray}, - breaklines=true, - breakautoindent=true, - columns=flexible, - frame=single, - xleftmargin=1em, - xrightmargin=1em, - aboveskip=10pt -} - -\newcommand{\code}[1]{\texttt{#1}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\exercisetopic}{Scripts and Functions} +\newcommand{\exercisenum}{6} +\newcommand{\exercisedate}{6. November, 2018} + +\input{../../exercisesheader} + +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to Scientific Computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. In contrast diff --git a/programming/exercises/structs_cells.tex b/programming/exercises/structs_cells.tex index a4431bc..b60a81d 100644 --- a/programming/exercises/structs_cells.tex +++ b/programming/exercises/structs_cells.tex @@ -1,40 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Structs and Cell Arrays} +\newcommand{\exercisenum}{6} +\newcommand{\exercisedate}{16. October, 2015} -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large \"Ubung 6}}{{\bfseries\large Strukturen und Cell Arrays}}{{\bfseries\large 16. Oktober, 2015}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} -\newcommand{\code}[1]{\texttt{#1}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Einf\"uhrung in die wissenschaftliche Datenverarbeitung}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\input{../../exercisestitle} Die folgenden Aufgaben dienen der Wiederholung, \"Ubung und Selbstkontrolle und sollten eigenst\"andig bearbeitet und gel\"ost diff --git a/programming/exercises/variables_types.tex b/programming/exercises/variables_types.tex index 3c4f017..89261c4 100644 --- a/programming/exercises/variables_types.tex +++ b/programming/exercises/variables_types.tex @@ -1,41 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[english]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\usepackage{lipsum} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} - -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 1}}{{\bfseries\large Variables und Datatypes}}{{\bfseries\large 03. November, 2020}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} - -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} - -\newcommand{\code}[1]{\texttt{#1}} -\renewcommand{\solutiontitle}{\noindent\textbf{Solutions:}\par\noindent} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\newcommand{\exercisetopic}{Variables und Datatypes} +\newcommand{\exercisenum}{1} +\newcommand{\exercisedate}{3. November, 2020} + +\input{../../exercisesheader} + +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to Scientific Computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. Your solution diff --git a/programming/exercises/vectors.tex b/programming/exercises/vectors.tex index 1ea0e8e..a870b39 100644 --- a/programming/exercises/vectors.tex +++ b/programming/exercises/vectors.tex @@ -1,40 +1,17 @@ \documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Vectors} +\newcommand{\exercisenum}{2} +\newcommand{\exercisedate}{3. November, 2020} -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 2}}{{\bfseries\large Vectors}}{{\bfseries\large 03. November, 2020}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} -\newcommand{\code}[1]{\texttt{#1}} -\renewcommand{\solutiontitle}{\noindent\textbf{Solutions:}\par\noindent} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to Scientific Computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} + +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture. You should try to solve them on your own. Your solution diff --git a/programming/exercises/vectors_matrices.tex b/programming/exercises/vectors_matrices.tex index 5726b64..d64c5fa 100644 --- a/programming/exercises/vectors_matrices.tex +++ b/programming/exercises/vectors_matrices.tex @@ -1,40 +1,17 @@ -\documentclass[12pt,a4paper,pdftex, answers]{exam} +\documentclass[12pt,a4paper,pdftex]{exam} -\usepackage[german]{babel} -\usepackage{natbib} -\usepackage{graphicx} -\usepackage[small]{caption} -\usepackage{sidecap} -\usepackage{pslatex} -\usepackage{amsmath} -\usepackage{amssymb} -\setlength{\marginparwidth}{2cm} -\usepackage[breaklinks=true,bookmarks=true,bookmarksopen=true,pdfpagemode=UseNone,pdfstartview=FitH,colorlinks=true,citecolor=blue]{hyperref} +\newcommand{\exercisetopic}{Vectors} +\newcommand{\exercisenum}{2} +\newcommand{\exercisedate}{3. November, 2020} -%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} -\pagestyle{headandfoot} -\header{{\bfseries\large Exercise 2}}{{\bfseries\large Vectors}}{{\bfseries\large 03. November, 2020}} -\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: - jan.grewe@uni-tuebingen.de} -\runningfooter{}{\thepage}{} +\input{../../exercisesheader} -\setlength{\baselineskip}{15pt} -\setlength{\parindent}{0.0cm} -\setlength{\parskip}{0.3cm} -\renewcommand{\baselinestretch}{1.15} +\firstpagefooter{Dr. Jan Grewe}{}{jan.grewe@uni-tuebingen.de} -\newcommand{\code}[1]{\texttt{#1}} -\renewcommand{\solutiontitle}{\noindent\textbf{Solutions:}\par\noindent} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} -\vspace*{-6.5ex} -\begin{center} - \textbf{\Large Introduction to Scientific Computing}\\[1ex] - {\large Jan Grewe, Jan Benda}\\[-3ex] - Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\ -\end{center} + +\input{../../exercisestitle} The exercises are meant for self-monitoring and revision of the lecture topic. You should try to solve them on your own. Your solution should From 9c6bb91de531393a556529b6e00a5b28b9792449 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 19:16:24 +0100 Subject: [PATCH 23/37] added exercise target to master Makefile --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b59d881..140f584 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BASENAME=scientificcomputing-script SUBDIRS=programming debugging plotting codestyle statistics bootstrap regression likelihood pointprocesses designpattern SUBTEXS=$(foreach subd, $(SUBDIRS), $(subd)/lecture/$(subd).tex) -all : plots chapters index script +all : plots chapters index script exercises chapters : for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture chapter; done @@ -37,6 +37,11 @@ watchpdf : watchscript : while true; do ! make -s -q script && make script; sleep 0.5; done + +exercises: + for sd in $(SUBDIRS); do if test -d $$sd/exercises; then $(MAKE) -C $$sd/exercises pdf; fi; done + + cleanplots: for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture cleanplots; done @@ -46,6 +51,7 @@ cleantex: clean : cleantex for sd in $(SUBDIRS); do $(MAKE) -C $$sd/lecture clean; done + for sd in $(SUBDIRS); do if test -d $$sd/exercises; then $(MAKE) -C $$sd/exercises clean; fi; done cleanall : clean rm -f $(BASENAME).pdf From a097b10024c0e766ba3173f3c50213e8006d5c9f Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 21:30:16 +0100 Subject: [PATCH 24/37] [programming] updated exercise headers --- programming/exercises/boolean_logical_indexing.tex | 2 +- programming/exercises/control_flow.tex | 2 +- programming/exercises/scripts_functions.tex | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/programming/exercises/boolean_logical_indexing.tex b/programming/exercises/boolean_logical_indexing.tex index b1d616d..c7a22dd 100644 --- a/programming/exercises/boolean_logical_indexing.tex +++ b/programming/exercises/boolean_logical_indexing.tex @@ -2,7 +2,7 @@ \newcommand{\exercisetopic}{Logical indexing} \newcommand{\exercisenum}{4} -\newcommand{\exercisedate}{29. Oktober, 2019} +\newcommand{\exercisedate}{17. November, 2020} \input{../../exercisesheader} diff --git a/programming/exercises/control_flow.tex b/programming/exercises/control_flow.tex index 55c448e..f6d8de7 100644 --- a/programming/exercises/control_flow.tex +++ b/programming/exercises/control_flow.tex @@ -2,7 +2,7 @@ \newcommand{\exercisetopic}{Control flow} \newcommand{\exercisenum}{5} -\newcommand{\exercisedate}{5. November, 2019} +\newcommand{\exercisedate}{24. November, 2020} \input{../../exercisesheader} diff --git a/programming/exercises/scripts_functions.tex b/programming/exercises/scripts_functions.tex index dcd919c..d02c5c9 100644 --- a/programming/exercises/scripts_functions.tex +++ b/programming/exercises/scripts_functions.tex @@ -2,7 +2,7 @@ \newcommand{\exercisetopic}{Scripts and Functions} \newcommand{\exercisenum}{6} -\newcommand{\exercisedate}{6. November, 2018} +\newcommand{\exercisedate}{1. December, 2020} \input{../../exercisesheader} From be79d450dfa62b1721125f604d7e15dec93d50be Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Tue, 15 Dec 2020 23:18:12 +0100 Subject: [PATCH 25/37] [regression] started to simplify chapter to a 1d problem --- regression/code/meanSquaredErrorLine.m | 1 - regression/code/meansquarederrorline.m | 15 ++ regression/lecture/cubicerrors.py | 36 ++--- regression/lecture/cubicfunc.py | 26 +++- regression/lecture/cubicmse.py | 7 +- regression/lecture/regression-chapter.tex | 111 +++++++++++++- regression/lecture/regression.tex | 167 +++++++++++----------- 7 files changed, 247 insertions(+), 116 deletions(-) delete mode 100644 regression/code/meanSquaredErrorLine.m create mode 100644 regression/code/meansquarederrorline.m diff --git a/regression/code/meanSquaredErrorLine.m b/regression/code/meanSquaredErrorLine.m deleted file mode 100644 index c395934..0000000 --- a/regression/code/meanSquaredErrorLine.m +++ /dev/null @@ -1 +0,0 @@ -mse = mean((y - y_est).^2); diff --git a/regression/code/meansquarederrorline.m b/regression/code/meansquarederrorline.m new file mode 100644 index 0000000..17f9d2f --- /dev/null +++ b/regression/code/meansquarederrorline.m @@ -0,0 +1,15 @@ +n = 40; +xmin = 2.2; +xmax = 3.9; +c = 6.0; +noise = 50.0; + +% generate data: +x = rand(n, 1) * (xmax-xmin) + xmin; +yest = c * x.^3; +y = yest + noise*randn(n, 1); + +% compute mean squared error: +mse = mean((y - y_est).^2); + +fprintf('the mean squared error is %g kg^2\n', mse)) diff --git a/regression/lecture/cubicerrors.py b/regression/lecture/cubicerrors.py index e072d9e..86e608f 100644 --- a/regression/lecture/cubicerrors.py +++ b/regression/lecture/cubicerrors.py @@ -15,28 +15,13 @@ def create_data(): return x, y, c -def plot_data(ax, x, y, c): - ax.plot(x, y, zorder=10, **psAm) - xx = np.linspace(2.1, 3.9, 100) - ax.plot(xx, c*xx**3.0, zorder=5, **lsBm) - for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]: - ax.plot(xx, cc*xx**3.0, zorder=5, **lsDm) - ax.set_xlabel('Size x', 'm') - ax.set_ylabel('Weight y', 'kg') - ax.set_xlim(2, 4) - ax.set_ylim(0, 400) - ax.set_xticks(np.arange(2.0, 4.1, 0.5)) - ax.set_yticks(np.arange(0, 401, 100)) - - def plot_data_errors(ax, x, y, c): ax.set_xlabel('Size x', 'm') - #ax.set_ylabel('Weight y', 'kg') + ax.set_ylabel('Weight y', 'kg') ax.set_xlim(2, 4) ax.set_ylim(0, 400) ax.set_xticks(np.arange(2.0, 4.1, 0.5)) ax.set_yticks(np.arange(0, 401, 100)) - ax.set_yticklabels([]) ax.annotate('Error', xy=(x[28]+0.05, y[28]+60), xycoords='data', xytext=(3.4, 70), textcoords='data', ha='left', @@ -52,31 +37,30 @@ def plot_data_errors(ax, x, y, c): yy = [c*x[i]**3.0, y[i]] ax.plot(xx, yy, zorder=5, **lsDm) + def plot_error_hist(ax, x, y, c): ax.set_xlabel('Squared error') ax.set_ylabel('Frequency') - bins = np.arange(0.0, 1250.0, 100) + bins = np.arange(0.0, 11000.0, 750) ax.set_xlim(bins[0], bins[-1]) - #ax.set_ylim(0, 35) - ax.set_xticks(np.arange(bins[0], bins[-1], 200)) - #ax.set_yticks(np.arange(0, 36, 10)) + ax.set_ylim(0, 15) + ax.set_xticks(np.arange(bins[0], bins[-1], 5000)) + ax.set_yticks(np.arange(0, 16, 5)) errors = (y-(c*x**3.0))**2.0 mls = np.mean(errors) ax.annotate('Mean\nsquared\nerror', xy=(mls, 0.5), xycoords='data', - xytext=(800, 3), textcoords='data', ha='left', + xytext=(4500, 6), textcoords='data', ha='left', arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2), connectionstyle="angle3,angleA=10,angleB=90") ) ax.hist(errors, bins, **fsC) - if __name__ == "__main__": x, y, c = create_data() fig, (ax1, ax2) = plt.subplots(1, 2) - fig.subplots_adjust(wspace=0.2, **adjust_fs(left=6.0, right=1.2)) - plot_data(ax1, x, y, c) - plot_data_errors(ax2, x, y, c) - #plot_error_hist(ax2, x, y, c) + fig.subplots_adjust(wspace=0.4, **adjust_fs(left=6.0, right=1.2)) + plot_data_errors(ax1, x, y, c) + plot_error_hist(ax2, x, y, c) fig.savefig("cubicerrors.pdf") plt.close() diff --git a/regression/lecture/cubicfunc.py b/regression/lecture/cubicfunc.py index e8c0565..45dd67b 100644 --- a/regression/lecture/cubicfunc.py +++ b/regression/lecture/cubicfunc.py @@ -2,7 +2,7 @@ import matplotlib.pyplot as plt import numpy as np from plotstyle import * -if __name__ == "__main__": +def create_data(): # wikipedia: # Generally, males vary in total length from 250 to 390 cm and # weigh between 90 and 306 kg @@ -12,10 +12,20 @@ if __name__ == "__main__": rng = np.random.RandomState(32281) noise = rng.randn(len(x))*50 y += noise + return x, y, c + - fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.4*figure_height)) - fig.subplots_adjust(**adjust_fs(left=6.0, right=1.2)) - +def plot_data(ax, x, y): + ax.plot(x, y, **psA) + ax.set_xlabel('Size x', 'm') + ax.set_ylabel('Weight y', 'kg') + ax.set_xlim(2, 4) + ax.set_ylim(0, 400) + ax.set_xticks(np.arange(2.0, 4.1, 0.5)) + ax.set_yticks(np.arange(0, 401, 100)) + + +def plot_data_fac(ax, x, y, c): ax.plot(x, y, zorder=10, **psA) xx = np.linspace(2.1, 3.9, 100) ax.plot(xx, c*xx**3.0, zorder=5, **lsB) @@ -27,6 +37,14 @@ if __name__ == "__main__": ax.set_ylim(0, 400) ax.set_xticks(np.arange(2.0, 4.1, 0.5)) ax.set_yticks(np.arange(0, 401, 100)) + +if __name__ == "__main__": + x, y, c = create_data() + print(len(x)) + fig, (ax1, ax2) = plt.subplots(1, 2) + fig.subplots_adjust(wspace=0.5, **adjust_fs(fig, left=6.0, right=1.5)) + plot_data(ax1, x, y) + plot_data_fac(ax2, x, y, c) fig.savefig("cubicfunc.pdf") plt.close() diff --git a/regression/lecture/cubicmse.py b/regression/lecture/cubicmse.py index f687885..55ac64b 100644 --- a/regression/lecture/cubicmse.py +++ b/regression/lecture/cubicmse.py @@ -14,6 +14,7 @@ def create_data(): y += noise return x, y, c + def gradient_descent(x, y): n = 20 dc = 0.01 @@ -29,6 +30,7 @@ def gradient_descent(x, y): mses.append(m0) cc -= eps*dmdc return cs, mses + def plot_mse(ax, x, y, c, cs): ms = np.zeros(len(cs)) @@ -54,7 +56,8 @@ def plot_mse(ax, x, y, c, cs): ax.set_ylim(0, 25000) ax.set_xticks(np.arange(0.0, 10.1, 2.0)) ax.set_yticks(np.arange(0, 30001, 10000)) - + + def plot_descent(ax, cs, mses): ax.plot(np.arange(len(mses))+1, mses, **lpsBm) ax.set_xlabel('Iteration') @@ -69,7 +72,7 @@ def plot_descent(ax, cs, mses): if __name__ == "__main__": x, y, c = create_data() cs, mses = gradient_descent(x, y) - fig, (ax1, ax2) = plt.subplots(1, 2) + fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 1.1*figure_height)) fig.subplots_adjust(wspace=0.2, **adjust_fs(left=8.0, right=0.5)) plot_mse(ax1, x, y, c, cs) plot_descent(ax2, cs, mses) diff --git a/regression/lecture/regression-chapter.tex b/regression/lecture/regression-chapter.tex index 792dfcd..2169854 100644 --- a/regression/lecture/regression-chapter.tex +++ b/regression/lecture/regression-chapter.tex @@ -40,6 +40,113 @@ \item Homework is to do the 2d problem with the straight line! \end{itemize} +\subsection{2D fit} + +\begin{exercise}{meanSquaredError.m}{} + Implement the objective function \eqref{mseline} as a function + \varcode{meanSquaredError()}. The function takes three + arguments. The first is a vector of $x$-values and the second + contains the measurements $y$ for each value of $x$. The third + argument is a 2-element vector that contains the values of + parameters \varcode{m} and \varcode{b}. The function returns the + mean square error. +\end{exercise} + + +\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} + Generate 20 data pairs $(x_i|y_i)$ that are linearly related with + slope $m=0.75$ and intercept $b=-40$, using \varcode{rand()} for + drawing $x$ values between 0 and 120 and \varcode{randn()} for + jittering the $y$ values with a standard deviation of 15. Then + calculate the mean squared error between the data and straight lines + for a range of slopes and intercepts using the + \varcode{meanSquaredError()} function from the previous exercise. + Illustrates the error surface using the \code{surface()} function. + Consult the documentation to find out how to use \code{surface()}. +\end{exercise} + +\begin{exercise}{meanSquaredGradient.m}{}\label{gradientexercise}% + Implement a function \varcode{meanSquaredGradient()}, that takes the + $x$- and $y$-data and the set of parameters $(m, b)$ of a straight + line as a two-element vector as input arguments. The function should + return the gradient at the position $(m, b)$ as a vector with two + elements. +\end{exercise} + +\begin{exercise}{errorGradient.m}{} + Extend the script of exercises~\ref{errorsurfaceexercise} to plot + both the error surface and gradients using the + \varcode{meanSquaredGradient()} function from + exercise~\ref{gradientexercise}. Vectors in space can be easily + plotted using the function \code{quiver()}. Use \code{contour()} + instead of \code{surface()} to plot the error surface. +\end{exercise} + + +\begin{exercise}{gradientDescent.m}{} + Implement the gradient descent for the problem of fitting a straight + line to some measured data. Reuse the data generated in + exercise~\ref{errorsurfaceexercise}. + \begin{enumerate} + \item Store for each iteration the error value. + \item Plot the error values as a function of the iterations, the + number of optimization steps. + \item Plot the measured data together with the best fitting straight line. + \end{enumerate}\vspace{-4.5ex} +\end{exercise} + + +\begin{figure}[t] + \includegraphics[width=1\textwidth]{lin_regress}\hfill + \titlecaption{Example data suggesting a linear relation.}{A set of + input signals $x$, e.g. stimulus intensities, were used to probe a + system. The system's output $y$ to the inputs are noted + (left). Assuming a linear relation between $x$ and $y$ leaves us + with 2 parameters, the slope (center) and the intercept with the + y-axis (right panel).}\label{linregressiondatafig} +\end{figure} + +\begin{figure}[t] + \includegraphics[width=1\textwidth]{linear_least_squares} + \titlecaption{Estimating the \emph{mean square error}.} {The + deviation error (orange) between the prediction (red line) and the + observations (blue dots) is calculated for each data point + (left). Then the deviations are squared and the average is + calculated (right).} + \label{leastsquareerrorfig} +\end{figure} + +\begin{figure}[t] + \includegraphics[width=0.75\textwidth]{error_surface} + \titlecaption{Error surface.}{The two model parameters $m$ and $b$ + define the base area of the surface plot. For each parameter + combination of slope and intercept the error is calculated. The + resulting surface has a minimum which indicates the parameter + combination that best fits the data.}\label{errorsurfacefig} +\end{figure} + + +\begin{figure}[t] + \includegraphics[width=0.75\textwidth]{error_gradient} + \titlecaption{Gradient of the error surface.} {Each arrow points + into the direction of the greatest ascend at different positions + of the error surface shown in \figref{errorsurfacefig}. The + contour lines in the background illustrate the error surface. Warm + colors indicate high errors, colder colors low error values. Each + contour line connects points of equal + error.}\label{gradientquiverfig} +\end{figure} + +\begin{figure}[t] + \includegraphics[width=0.45\textwidth]{gradient_descent} + \titlecaption{Gradient descent.}{The algorithm starts at an + arbitrary position. At each point the gradient is estimated and + the position is updated as long as the length of the gradient is + sufficiently large.The dots show the positions after each + iteration of the algorithm.} \label{gradientdescentfig} +\end{figure} + + \subsection{Linear fits} \begin{itemize} \item Polyfit is easy: unique solution! $c x^2$ is also a linear fit. @@ -54,8 +161,8 @@ Fit with matlab functions lsqcurvefit, polyfit \subsection{Non-linear fits} \begin{itemize} \item Example that illustrates the Nebenminima Problem (with error surface) -\item You need got initial values for the parameter! -\item Example that fitting gets harder the more parameter yuo have. +\item You need initial values for the parameter! +\item Example that fitting gets harder the more parameter you have. \item Try to fix as many parameter before doing the fit. \item How to test the quality of a fit? Residuals. $\chi^2$ test. Run-test. \end{itemize} diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index e63e3f9..779309b 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -2,99 +2,104 @@ \exercisechapter{Optimization and gradient descent} Optimization problems arise in many different contexts. For example, -to understand the behavior of a given system, the system is probed -with a range of input signals and then the resulting responses are -measured. This input-output relation can be described by a model. Such -a model can be a simple function that maps the input signals to -corresponding responses, it can be a filter, or a system of -differential equations. In any case, the model has some parameters that -specify how input and output signals are related. Which combination -of parameter values are best suited to describe the input-output -relation? The process of finding the best parameter values is an -optimization problem. For a simple parameterized function that maps -input to output values, this is the special case of a \enterm{curve - fitting} problem, where the average distance between the curve and -the response values is minimized. One basic numerical method used for -such optimization problems is the so called gradient descent, which is -introduced in this chapter. - -%%% Weiteres einfaches verbales Beispiel? Eventuell aus der Populationsoekologie? +to understand the behavior of a given neuronal system, the system is +probed with a range of input signals and then the resulting responses +are measured. This input-output relation can be described by a +model. Such a model can be a simple function that maps the input +signals to corresponding responses, it can be a filter, or a system of +differential equations. In any case, the model has some parameters +that specify how input and output signals are related. Which +combination of parameter values are best suited to describe the +input-output relation? The process of finding the best parameter +values is an optimization problem. For a simple parameterized function +that maps input to output values, this is the special case of a +\enterm{curve fitting} problem, where the average distance between the +curve and the response values is minimized. One basic numerical method +used for such optimization problems is the so called gradient descent, +which is introduced in this chapter. \begin{figure}[t] - \includegraphics[width=1\textwidth]{lin_regress}\hfill - \titlecaption{Example data suggesting a linear relation.}{A set of - input signals $x$, e.g. stimulus intensities, were used to probe a - system. The system's output $y$ to the inputs are noted - (left). Assuming a linear relation between $x$ and $y$ leaves us - with 2 parameters, the slope (center) and the intercept with the - y-axis (right panel).}\label{linregressiondatafig} + \includegraphics{cubicfunc} + \titlecaption{Example data suggesting a cubic relation.}{The length + $x$ and weight $y$ of $n=34$ male tigers (blue, left). Assuming a + cubic relation between size and weight leaves us with a single + free parameters, a scaling factor. The cubic relation is shown for + a few values of this scaling factor (orange and red, + right).}\label{cubicdatafig} \end{figure} -The data plotted in \figref{linregressiondatafig} suggest a linear -relation between input and output of the system. We thus assume that a -straight line +For demonstrating the curve-fitting problem let's take the simple +example of weights and sizes measured for a number of male tigers +(\figref{cubicdatafig}). Weight $y$ is proportional to volume +$V$ via the density $\rho$. The volume $V$ of any object is +proportional to its length $x$ cubed. The factor $\alpha$ relating +volume and size cubed depends on the shape of the object and we do not +know this factor for tigers. For the data set we thus expect a cubic +relation between weight and length \begin{equation} - \label{straightline} - y = f(x; m, b) = m\cdot x + b + \label{cubicfunc} + y = f(x; c) = c\cdot x^3 \end{equation} -is an appropriate model to describe the system. The line has two free -parameter, the slope $m$ and the $y$-intercept $b$. We need to find -values for the slope and the intercept that best describe the measured -data. In this chapter we use this example to illustrate the gradient -descent and how this methods can be used to find a combination of -slope and intercept that best describes the system. +where $c=\rho\alpha$, the product of a tiger's density and form +factor, is the only free parameter in the relation. We would like to +find out which value of $c$ best describes the measured data. In the +following we use this example to illustrate the gradient descent as a +basic method for finding such an optimal parameter. \section{The error function --- mean squared error} -Before the optimization can be done we need to specify what exactly is -considered an optimal fit. In our example we search the parameter -combination that describe the relation of $x$ and $y$ best. What is -meant by this? Each input $x_i$ leads to an measured output $y_i$ and -for each $x_i$ there is a \emph{prediction} or \emph{estimation} -$y^{est}(x_i)$ of the output value by the model. At each $x_i$ -estimation and measurement have a distance or error $y_i - -y^{est}(x_i)$. In our example the estimation is given by the equation -$y^{est}(x_i) = f(x_i;m,b)$. The best fitting model with parameters -$m$ and $b$ is the one that minimizes the distances between -observation $y_i$ and estimation $y^{est}(x_i)$ -(\figref{leastsquareerrorfig}). - -As a first guess we could simply minimize the sum $\sum_{i=1}^N y_i - -y^{est}(x_i)$. This approach, however, will not work since a minimal sum -can also be achieved if half of the measurements is above and the -other half below the predicted line. Positive and negative errors -would cancel out and then sum up to values close to zero. A better -approach is to sum over the absolute values of the distances: -$\sum_{i=1}^N |y_i - y^{est}(x_i)|$. This sum can only be small if all -deviations are indeed small no matter if they are above or below the -predicted line. Instead of the sum we could also take the average -\begin{equation} - \label{meanabserror} - f_{dist}(\{(x_i, y_i)\}|\{y^{est}(x_i)\}) = \frac{1}{N} \sum_{i=1}^N |y_i - y^{est}(x_i)| -\end{equation} -Instead of the averaged absolute errors, the \enterm[mean squared -error]{mean squared error} (\determ[quadratischer -Fehler!mittlerer]{mittlerer quadratischer Fehler}) +Before we go ahead finding the optimal parameter value we need to +specify what exactly we consider as an optimal fit. In our example we +search the parameter that describes the relation of $x$ and $y$ +best. What is meant by this? The length $x_i$ of each tiger is +associated with a weight $y_i$ and for each $x_i$ we have a +\emph{prediction} or \emph{estimation} $y^{est}(x_i)$ of the weight by +the model \eqnref{cubicfunc} for a specific value of the parameter +$c$. Prediction and actual data value ideally match (in a perfect +noise-free world), but in general the estimate and measurement are +separated by some distance or error $y_i - y^{est}(x_i)$. In our +example the estimate of the weight for the length $x_i$ is given by +equation \eqref{cubicfunc} $y^{est}(x_i) = f(x_i;c)$. The best fitting +model with parameter $c$ is the one that somehow minimizes the +distances between observations $y_i$ and corresponding estimations +$y^{est}(x_i)$ (\figref{cubicerrorsfig}). + +As a first guess we could simply minimize the sum of the distances, +$\sum_{i=1}^N y_i - y^{est}(x_i)$. This, however, does not work +because positive and negative errors would cancel out, no matter how +large they are, and sum up to values close to zero. Better is to sum +over absolute distances: $\sum_{i=1}^N |y_i - y^{est}(x_i)|$. This sum +can only be small if all deviations are indeed small no matter if they +are above or below the prediction. The sum of the squared distances, +$\sum_{i=1}^N (y_i - y^{est}(x_i))^2$, turns out to be an even better +choice. Instead of the sum we could also minimize the average distance \begin{equation} \label{meansquarederror} f_{mse}(\{(x_i, y_i)\}|\{y^{est}(x_i)\}) = \frac{1}{N} \sum_{i=1}^N (y_i - y^{est}(x_i))^2 \end{equation} -is commonly used (\figref{leastsquareerrorfig}). Similar to the -absolute distance, the square of the errors, $(y_i - y^{est}(x_i))^2$, is -always positive and thus positive and negative error values do not +This is known as the \enterm[mean squared error]{mean squared error} +(\determ[quadratischer Fehler!mittlerer]{mittlerer quadratischer + Fehler}). Similar to the absolute distance, the square of the errors +is always positive and thus positive and negative error values do not cancel each other out. In addition, the square punishes large deviations over small deviations. In chapter~\ref{maximumlikelihoodchapter} we show that minimizing the -mean square error is equivalent to maximizing the likelihood that the +mean squared error is equivalent to maximizing the likelihood that the observations originate from the model, if the data are normally distributed around the model prediction. -\begin{exercise}{meanSquaredErrorLine.m}{}\label{mseexercise}% - Given a vector of observations \varcode{y} and a vector with the - corresponding predictions \varcode{y\_est}, compute the \emph{mean - square error} between \varcode{y} and \varcode{y\_est} in a single - line of code. +\begin{exercise}{meansquarederrorline.m}{}\label{mseexercise} + Simulate $n=40$ tigers ranging from 2.2 to 3.9\,m in size and store + these sizes in a vector \varcode{x}. Compute the corresponding + predicted weights \varcode{yest} for each tiger according to + \eqnref{cubicfunc} with $c=6$\,\kilo\gram\per\meter\cubed. From the + predictions generate simulated measurements of the tiger's weights + \varcode{y}, by adding normally distributed random numbers to the + predictions scaled to a standard deviation of 50\,\kilo\gram. + + Compute the \emph{mean squared error} between \varcode{y} and + \varcode{yest} in a single line of code. \end{exercise} @@ -110,13 +115,13 @@ can be any function that describes the quality of the fit by mapping the data and the predictions to a single scalar value. \begin{figure}[t] - \includegraphics[width=1\textwidth]{linear_least_squares} - \titlecaption{Estimating the \emph{mean square error}.} {The - deviation error, orange) between the prediction (red - line) and the observations (blue dots) is calculated for each data - point (left). Then the deviations are squared and the aveage is + \includegraphics{cubicerrors} + \titlecaption{Estimating the \emph{mean squared error}.} {The + deviation error (orange) between the prediction (red line) and the + observations (blue dots) is calculated for each data point + (left). Then the deviations are squared and the average is calculated (right).} - \label{leastsquareerrorfig} + \label{cubicerrorsfig} \end{figure} Replacing $y^{est}$ in the mean squared error \eqref{meansquarederror} @@ -139,7 +144,7 @@ Fehler!kleinster]{Methode der kleinsten Quadrate}). contains the measurements $y$ for each value of $x$. The third argument is a 2-element vector that contains the values of parameters \varcode{m} and \varcode{b}. The function returns the - mean square error. + mean squared error. \end{exercise} @@ -359,7 +364,7 @@ distance between the red dots in \figref{gradientdescentfig}) is large. \begin{figure}[t] - \includegraphics[width=0.45\textwidth]{gradient_descent} + \includegraphics{cubicmse} \titlecaption{Gradient descent.}{The algorithm starts at an arbitrary position. At each point the gradient is estimated and the position is updated as long as the length of the gradient is From 1b14bca16419b8782b1af6e388b66168f0506676 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Wed, 16 Dec 2020 09:25:01 +0100 Subject: [PATCH 26/37] [regression] objective function section done --- chapter.mk | 4 +-- regression/code/meanSquaredError.m | 12 --------- regression/code/meanSquaredErrorCubic.m | 11 ++++++++ regression/code/meansquarederrorline.m | 4 +-- regression/lecture/cubicfunc.py | 2 +- regression/lecture/regression-chapter.tex | 11 -------- regression/lecture/regression.tex | 32 +++++++++++------------ 7 files changed, 31 insertions(+), 45 deletions(-) delete mode 100644 regression/code/meanSquaredError.m create mode 100644 regression/code/meanSquaredErrorCubic.m diff --git a/chapter.mk b/chapter.mk index 0482aed..f642e2e 100644 --- a/chapter.mk +++ b/chapter.mk @@ -10,8 +10,8 @@ pythonplots : $(PYPDFFILES) $(PYPDFFILES) : %.pdf: %.py ../../plotstyle.py PYTHONPATH="../../" python3 $< - #ps2pdf $@ $(@:.pdf=-temp.pdf) # strip fonts, saves only about 1.5MB - #mv $(@:.pdf=-temp.pdf) $@ +#ps2pdf $@ $(@:.pdf=-temp.pdf) # strip fonts, saves only about 1.5MB +#mv $(@:.pdf=-temp.pdf) $@ cleanpythonplots : rm -f $(PYPDFFILES) diff --git a/regression/code/meanSquaredError.m b/regression/code/meanSquaredError.m deleted file mode 100644 index 6eeea7b..0000000 --- a/regression/code/meanSquaredError.m +++ /dev/null @@ -1,12 +0,0 @@ -function mse = meanSquaredError(x, y, parameter) -% Mean squared error between a straight line and data pairs. -% -% Arguments: x, vector of the input values -% y, vector of the corresponding measured output values -% parameter, vector containing slope and intercept -% as the 1st and 2nd element, respectively. -% -% Returns: mse, the mean-squared-error. - - mse = mean((y - x * parameter(1) - parameter(2)).^2); -end diff --git a/regression/code/meanSquaredErrorCubic.m b/regression/code/meanSquaredErrorCubic.m new file mode 100644 index 0000000..bb17137 --- /dev/null +++ b/regression/code/meanSquaredErrorCubic.m @@ -0,0 +1,11 @@ +function mse = meanSquaredError(x, y, c) +% Mean squared error between data pairs and a cubic relation. +% +% Arguments: x, vector of the input values +% y, vector of the corresponding measured output values +% c, the factor for the cubic relation. +% +% Returns: mse, the mean-squared-error. + + mse = mean((y - c*x.^3).^2); +end diff --git a/regression/code/meansquarederrorline.m b/regression/code/meansquarederrorline.m index 17f9d2f..4eca4a3 100644 --- a/regression/code/meansquarederrorline.m +++ b/regression/code/meansquarederrorline.m @@ -10,6 +10,6 @@ yest = c * x.^3; y = yest + noise*randn(n, 1); % compute mean squared error: -mse = mean((y - y_est).^2); +mse = mean((y - yest).^2); -fprintf('the mean squared error is %g kg^2\n', mse)) +fprintf('the mean squared error is %.0f kg^2\n', mse) diff --git a/regression/lecture/cubicfunc.py b/regression/lecture/cubicfunc.py index 45dd67b..8b5b44a 100644 --- a/regression/lecture/cubicfunc.py +++ b/regression/lecture/cubicfunc.py @@ -41,7 +41,7 @@ def plot_data_fac(ax, x, y, c): if __name__ == "__main__": x, y, c = create_data() - print(len(x)) + print('n=%d' % len(x)) fig, (ax1, ax2) = plt.subplots(1, 2) fig.subplots_adjust(wspace=0.5, **adjust_fs(fig, left=6.0, right=1.5)) plot_data(ax1, x, y) diff --git a/regression/lecture/regression-chapter.tex b/regression/lecture/regression-chapter.tex index 2169854..8afed44 100644 --- a/regression/lecture/regression-chapter.tex +++ b/regression/lecture/regression-chapter.tex @@ -42,17 +42,6 @@ \subsection{2D fit} -\begin{exercise}{meanSquaredError.m}{} - Implement the objective function \eqref{mseline} as a function - \varcode{meanSquaredError()}. The function takes three - arguments. The first is a vector of $x$-values and the second - contains the measurements $y$ for each value of $x$. The third - argument is a 2-element vector that contains the values of - parameters \varcode{m} and \varcode{b}. The function returns the - mean square error. -\end{exercise} - - \begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} Generate 20 data pairs $(x_i|y_i)$ that are linearly related with slope $m=0.75$ and intercept $b=-40$, using \varcode{rand()} for diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 779309b..7fbffbf 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -109,10 +109,10 @@ The mean squared error is a so called \enterm{objective function} or \enterm{cost function} (\determ{Kostenfunktion}). A cost function assigns to a model prediction $\{y^{est}(x_i)\}$ for a given data set $\{(x_i, y_i)\}$ a single scalar value that we want to minimize. Here -we aim to adapt the model parameters to minimize the mean squared -error \eqref{meansquarederror}. In general, the \enterm{cost function} -can be any function that describes the quality of the fit by mapping -the data and the predictions to a single scalar value. +we aim to adapt the model parameter to minimize the mean squared error +\eqref{meansquarederror}. In general, the \enterm{cost function} can +be any function that describes the quality of a fit by mapping the +data and the predictions to a single scalar value. \begin{figure}[t] \includegraphics{cubicerrors} @@ -125,25 +125,23 @@ the data and the predictions to a single scalar value. \end{figure} Replacing $y^{est}$ in the mean squared error \eqref{meansquarederror} -with our model, the straight line \eqref{straightline}, the cost -function reads +with our cubic model \eqref{cubicfunc}, the cost function reads \begin{eqnarray} - f_{cost}(m,b|\{(x_i, y_i)\}) & = & \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;m,b))^2 \label{msefunc} \\ - & = & \frac{1}{N} \sum_{i=1}^N (y_i - m x_i - b)^2 \label{mseline} + f_{cost}(c|\{(x_i, y_i)\}) & = & \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;c))^2 \label{msefunc} \\ + & = & \frac{1}{N} \sum_{i=1}^N (y_i - c x_i^3)^2 \label{msecube} \end{eqnarray} -The optimization process tries to find the slope $m$ and the intercept -$b$ such that the cost function is minimized. With the mean squared -error as the cost function this optimization process is also called -method of the \enterm{least square error} (\determ[quadratischer +The optimization process tries to find a value for the factor $c$ such +that the cost function is minimized. With the mean squared error as +the cost function this optimization process is also called method of + \enterm{least squares} (\determ[quadratischer Fehler!kleinster]{Methode der kleinsten Quadrate}). -\begin{exercise}{meanSquaredError.m}{} - Implement the objective function \eqref{mseline} as a function - \varcode{meanSquaredError()}. The function takes three +\begin{exercise}{meanSquaredErrorCubic.m}{} + Implement the objective function \eqref{msecube} as a function + \varcode{meanSquaredErrorCubic()}. The function takes three arguments. The first is a vector of $x$-values and the second contains the measurements $y$ for each value of $x$. The third - argument is a 2-element vector that contains the values of - parameters \varcode{m} and \varcode{b}. The function returns the + argument is the value of the factor $c$. The function returns the mean squared error. \end{exercise} From 3541f30798c6d7722abc41f253112fe152968151 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Wed, 16 Dec 2020 15:14:57 +0100 Subject: [PATCH 27/37] [regression] new figure for minimum of a cost function --- regression/code/meanSquaredErrorCubic.m | 2 +- regression/lecture/cubiccost.py | 80 +++++++++++++++++++++++++ regression/lecture/regression.tex | 57 +++++++++--------- 3 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 regression/lecture/cubiccost.py diff --git a/regression/code/meanSquaredErrorCubic.m b/regression/code/meanSquaredErrorCubic.m index bb17137..44870a1 100644 --- a/regression/code/meanSquaredErrorCubic.m +++ b/regression/code/meanSquaredErrorCubic.m @@ -1,4 +1,4 @@ -function mse = meanSquaredError(x, y, c) +function mse = meanSquaredErrorCubic(x, y, c) % Mean squared error between data pairs and a cubic relation. % % Arguments: x, vector of the input values diff --git a/regression/lecture/cubiccost.py b/regression/lecture/cubiccost.py new file mode 100644 index 0000000..0b8d2dc --- /dev/null +++ b/regression/lecture/cubiccost.py @@ -0,0 +1,80 @@ +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.ticker as mt +from plotstyle import * + +def create_data(): + # wikipedia: + # Generally, males vary in total length from 250 to 390 cm and + # weigh between 90 and 306 kg + c = 6 + x = np.arange(2.2, 3.9, 0.05) + y = c * x**3.0 + rng = np.random.RandomState(32281) + noise = rng.randn(len(x))*50 + y += noise + return x, y, c + + +def plot_mse(ax, x, y, c): + ccs = np.linspace(0.5, 10.0, 200) + mses = np.zeros(len(ccs)) + for i, cc in enumerate(ccs): + mses[i] = np.mean((y-(cc*x**3.0))**2.0) + imin = np.argmin(mses) + + ax.plot(ccs, mses, **lsAm) + ax.plot(c, 500.0, **psB) + ax.plot(ccs[imin], mses[imin], **psC) + ax.annotate('Minimum of\ncost\nfunction', + xy=(ccs[imin], mses[imin]*1.2), xycoords='data', + xytext=(4, 7000), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(0.2,0.0), + connectionstyle="angle3,angleA=10,angleB=90") ) + ax.text(2.2, 500, 'True\nparameter\nvalue') + ax.annotate('', xy=(c-0.2, 500), xycoords='data', + xytext=(4.1, 700), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(1.0,0.0), + connectionstyle="angle3,angleA=-10,angleB=0") ) + ax.set_xlabel('c') + ax.set_ylabel('Mean squared error') + ax.set_xlim(2, 8.2) + ax.set_ylim(0, 10000) + ax.set_xticks(np.arange(2.0, 8.1, 2.0)) + ax.set_yticks(np.arange(0, 10001, 5000)) + + +def plot_mse_min(ax, x, y, c): + ccs = np.arange(0.5, 10.0, 0.05) + mses = np.zeros(len(ccs)) + for i, cc in enumerate(ccs): + mses[i] = np.mean((y-(cc*x**3.0))**2.0) + di = 20 + i0 = 14 + imin = np.argmin(mses[i0::di])*di + i0 + + ax.plot(c, 500.0, **psB) + ax.plot(ccs, mses, **lsAm) + ax.plot(ccs[i0::di], mses[i0::di], **psAm) + ax.plot(ccs[imin], mses[imin], **psC) + ax.annotate('Estimated\nminimum of\ncost\nfunction', + xy=(ccs[imin], mses[imin]*1.2), xycoords='data', + xytext=(4, 6700), textcoords='data', ha='left', + arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0), + connectionstyle="angle3,angleA=0,angleB=85") ) + ax.set_xlabel('c') + ax.set_xlim(2, 8.2) + ax.set_ylim(0, 10000) + ax.set_xticks(np.arange(2.0, 8.1, 2.0)) + ax.set_yticks(np.arange(0, 10001, 5000)) + ax.yaxis.set_major_formatter(mt.NullFormatter()) + + +if __name__ == "__main__": + x, y, c = create_data() + fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 1.1*figure_height)) + fig.subplots_adjust(**adjust_fs(left=8.0, right=1)) + plot_mse(ax1, x, y, c) + plot_mse_min(ax2, x, y, c) + fig.savefig("cubiccost.pdf") + plt.close() diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 7fbffbf..8867744 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -103,7 +103,7 @@ distributed around the model prediction. \end{exercise} -\section{Objective function} +\section{Cost function} The mean squared error is a so called \enterm{objective function} or \enterm{cost function} (\determ{Kostenfunktion}). A cost function @@ -146,42 +146,39 @@ Fehler!kleinster]{Methode der kleinsten Quadrate}). \end{exercise} -\section{Error surface} -For each combination of the two parameters $m$ and $b$ of the model we -can use \eqnref{mseline} to calculate the corresponding value of the -cost function. The cost function $f_{cost}(m,b|\{(x_i, y_i)\}|)$ is a -function $f_{cost}(m,b)$, that maps the parameter values $m$ and $b$ -to a scalar error value. The error values describe a landscape over the -$m$-$b$ plane, the error surface, that can be illustrated graphically -using a 3-d surface-plot. $m$ and $b$ are plotted on the $x$- and $y$- -axis while the third dimension indicates the error value -(\figref{errorsurfacefig}). +\section{Graph of the cost function} +For each value of the parameter $c$ of the model we can use +\eqnref{msecube} to calculate the corresponding value of the cost +function. The cost function $f_{cost}(c|\{(x_i, y_i)\}|)$ is a +function $f_{cost}(c)$ that maps the parameter value $c$ to a scalar +error value. For a given data set we thus can simply plot the cost +function as a function of $c$ (\figref{cubiccostfig}). \begin{figure}[t] - \includegraphics[width=0.75\textwidth]{error_surface} - \titlecaption{Error surface.}{The two model parameters $m$ and $b$ - define the base area of the surface plot. For each parameter - combination of slope and intercept the error is calculated. The - resulting surface has a minimum which indicates the parameter - combination that best fits the data.}\label{errorsurfacefig} + \includegraphics{cubiccost} + \titlecaption{Minimum of the cost function.}{For a given data set + the cost function, the mean squared error \eqnref{msecube}, as a + function of the unknown parameter $c$ has a minimum close to the + true value of $c$ that was used to generate the data + (left). Simply taking the absolute minimum of the cost function + computed for a pre-set range of values for the parameter $c$, has + the disadvantage to be limited in precision (right) and the + possibility to entirely miss the global minimum if it is outside + the computed range.}\label{cubiccostfig} \end{figure} \begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} - Generate 20 data pairs $(x_i|y_i)$ that are linearly related with - slope $m=0.75$ and intercept $b=-40$, using \varcode{rand()} for - drawing $x$ values between 0 and 120 and \varcode{randn()} for - jittering the $y$ values with a standard deviation of 15. Then - calculate the mean squared error between the data and straight lines - for a range of slopes and intercepts using the - \varcode{meanSquaredError()} function from the previous exercise. - Illustrates the error surface using the \code{surface()} function. - Consult the documentation to find out how to use \code{surface()}. + Then calculate the mean squared error between the data and straight + lines for a range of slopes and intercepts using the + \varcode{meanSquaredErrorCubic()} function from the previous + exercise. Illustrate the error surface using the \code{surface()} + function. \end{exercise} -By looking at the error surface we can directly see the position of -the minimum and thus estimate the optimal parameter combination. How -can we use the error surface to guide an automatic optimization -process? +By looking at the plot of the cost function we can visually identify +the position of the minimum and thus estimate the optimal value for +the parameter $c$. How can we use the error surface to guide an +automatic optimization process? The obvious approach would be to calculate the error surface for any combination of slope and intercept values and then find the position From 99a8a9d91e6e375c7824afefe6ca9e76c9f9a0f0 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Thu, 17 Dec 2020 22:38:07 +0100 Subject: [PATCH 28/37] [regression] improved cost function figure --- regression/lecture/cubiccost.py | 12 +++++++----- regression/lecture/regression.tex | 16 ++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/regression/lecture/cubiccost.py b/regression/lecture/cubiccost.py index 0b8d2dc..30d9575 100644 --- a/regression/lecture/cubiccost.py +++ b/regression/lecture/cubiccost.py @@ -49,16 +49,18 @@ def plot_mse_min(ax, x, y, c): mses = np.zeros(len(ccs)) for i, cc in enumerate(ccs): mses[i] = np.mean((y-(cc*x**3.0))**2.0) - di = 20 - i0 = 14 - imin = np.argmin(mses[i0::di])*di + i0 + imin = np.argmin(mses) + di = 25 + i0 = 16 + dimin = np.argmin(mses[i0::di])*di + i0 ax.plot(c, 500.0, **psB) ax.plot(ccs, mses, **lsAm) ax.plot(ccs[i0::di], mses[i0::di], **psAm) - ax.plot(ccs[imin], mses[imin], **psC) + ax.plot(ccs[dimin], mses[dimin], **psD) + #ax.plot(ccs[imin], mses[imin], **psCm) ax.annotate('Estimated\nminimum of\ncost\nfunction', - xy=(ccs[imin], mses[imin]*1.2), xycoords='data', + xy=(ccs[dimin], mses[dimin]*1.2), xycoords='data', xytext=(4, 6700), textcoords='data', ha='left', arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0), connectionstyle="angle3,angleA=0,angleB=85") ) diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 8867744..2990aef 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -154,6 +154,14 @@ function $f_{cost}(c)$ that maps the parameter value $c$ to a scalar error value. For a given data set we thus can simply plot the cost function as a function of $c$ (\figref{cubiccostfig}). +\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} + Then calculate the mean squared error between the data and straight + lines for a range of slopes and intercepts using the + \varcode{meanSquaredErrorCubic()} function from the previous + exercise. Illustrate the error surface using the \code{surface()} + function. +\end{exercise} + \begin{figure}[t] \includegraphics{cubiccost} \titlecaption{Minimum of the cost function.}{For a given data set @@ -167,14 +175,6 @@ function as a function of $c$ (\figref{cubiccostfig}). the computed range.}\label{cubiccostfig} \end{figure} -\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} - Then calculate the mean squared error between the data and straight - lines for a range of slopes and intercepts using the - \varcode{meanSquaredErrorCubic()} function from the previous - exercise. Illustrate the error surface using the \code{surface()} - function. -\end{exercise} - By looking at the plot of the cost function we can visually identify the position of the minimum and thus estimate the optimal value for the parameter $c$. How can we use the error surface to guide an From fefe1c3726a1ad784da789177b95bce2b465cc95 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Fri, 18 Dec 2020 13:10:53 +0100 Subject: [PATCH 29/37] [regression] text and example for cost function figure --- regression/code/plotcubiccosts.m | 9 ++++++ regression/lecture/regression.tex | 49 ++++++++++++++++--------------- 2 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 regression/code/plotcubiccosts.m diff --git a/regression/code/plotcubiccosts.m b/regression/code/plotcubiccosts.m new file mode 100644 index 0000000..6c90f03 --- /dev/null +++ b/regression/code/plotcubiccosts.m @@ -0,0 +1,9 @@ +cs = 2.0:0.1:8.0; +mses = zeros(length(cs)); +for i = 1:length(cs) + mses(i) = meanSquaredErrorCubic(x, y, cs(i)); +end + +plot(cs, mses) +xlabel('c') +ylabel('mean squared error') diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 2990aef..d903a0b 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -154,12 +154,11 @@ function $f_{cost}(c)$ that maps the parameter value $c$ to a scalar error value. For a given data set we thus can simply plot the cost function as a function of $c$ (\figref{cubiccostfig}). -\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} - Then calculate the mean squared error between the data and straight - lines for a range of slopes and intercepts using the +\begin{exercise}{plotcubiccosts.m}{} + Calculate the mean squared error between the data and the cubic + function for a range of values of the factor $c$ using the \varcode{meanSquaredErrorCubic()} function from the previous - exercise. Illustrate the error surface using the \code{surface()} - function. + exercise. Plot the graph of the cost function. \end{exercise} \begin{figure}[t] @@ -177,20 +176,22 @@ function as a function of $c$ (\figref{cubiccostfig}). By looking at the plot of the cost function we can visually identify the position of the minimum and thus estimate the optimal value for -the parameter $c$. How can we use the error surface to guide an +the parameter $c$. How can we use the cost function to guide an automatic optimization process? -The obvious approach would be to calculate the error surface for any -combination of slope and intercept values and then find the position -of the minimum using the \code{min} function. This approach, however -has several disadvantages: (i) it is computationally very expensive to -calculate the error for each parameter combination. The number of -combinations increases exponentially with the number of free -parameters (also known as the ``curse of dimensionality''). (ii) the -accuracy with which the best parameters can be estimated is limited by -the resolution used to sample the parameter space. The coarser the -parameters are sampled the less precise is the obtained position of -the minimum. +The obvious approach would be to calculate the mean squared error for +a range of parameter values and then find the position of the minimum +using the \code{min} function. This approach, however has several +disadvantages: (i) the accuracy of the estimation of the best +parameter is limited by the resolution used to sample the parameter +space. The coarser the parameters are sampled the less precise is the +obtained position of the minimum (\figref{cubiccostfig}, right). (ii) +the range of parameter values might not include the absolute minimum. +(iii) in particular for functions with more than a single free +parameter it is computationally expensive to calculate the cost +function for each parameter combination. The number of combinations +increases exponentially with the number of free parameters. This is +known as the \enterm{curse of dimensionality}. So we need a different approach. We want a procedure that finds the minimum of the cost function with a minimal number of computations and @@ -206,22 +207,22 @@ to arbitrary precision. m = \frac{f(x + \Delta x) - f(x)}{\Delta x} \end{equation} of a function $y = f(x)$ is the slope of the secant (red) defined - by the points $(x,f(x))$ and $(x+\Delta x,f(x+\Delta x))$ with the + by the points $(x,f(x))$ and $(x+\Delta x,f(x+\Delta x))$ at distance $\Delta x$. - The slope of the function $y=f(x)$ at the position $x$ (yellow) is + The slope of the function $y=f(x)$ at the position $x$ (orange) is given by the derivative $f'(x)$ of the function at that position. It is defined by the difference quotient in the limit of - infinitesimally (orange) small distances $\Delta x$: + infinitesimally (red and yellow) small distances $\Delta x$: \begin{equation} \label{derivative} f'(x) = \frac{{\rm d} f(x)}{{\rm d}x} = \lim\limits_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x} \end{equation} \end{minipage}\vspace{2ex} - It is not possible to calculate the derivative, \eqnref{derivative}, - numerically. The derivative can only be estimated using the - difference quotient, \eqnref{difffrac}, by using sufficiently small - $\Delta x$. + It is not possible to calculate the exact value of the derivative, + \eqnref{derivative}, numerically. The derivative can only be + estimated by computing the difference quotient, \eqnref{difffrac} + using sufficiently small $\Delta x$. \end{ibox} \begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} From ca5493624559b9a2efebe9ad79ea1023b49ca9a9 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Fri, 18 Dec 2020 23:37:17 +0100 Subject: [PATCH 30/37] [regression] finished gradient section --- regression/code/meanSquaredGradientCubic.m | 14 ++ regression/code/plotcubicgradient.m | 9 + regression/lecture/regression-chapter.tex | 12 +- regression/lecture/regression.tex | 191 ++++++++++----------- 4 files changed, 115 insertions(+), 111 deletions(-) create mode 100644 regression/code/meanSquaredGradientCubic.m create mode 100644 regression/code/plotcubicgradient.m diff --git a/regression/code/meanSquaredGradientCubic.m b/regression/code/meanSquaredGradientCubic.m new file mode 100644 index 0000000..a7ff6a2 --- /dev/null +++ b/regression/code/meanSquaredGradientCubic.m @@ -0,0 +1,14 @@ +function dmsedc = meanSquaredGradientCubic(x, y, c) +% The gradient of the mean squared error for a cubic relation. +% +% Arguments: x, vector of the x-data values +% y, vector of the corresponding y-data values +% c, the factor for the cubic relation. +% +% Returns: the derivative of the mean squared error at c. + + h = 1e-5; % stepsize for derivatives + mse = meanSquaredErrorCubic(x, y, c); + mseh = meanSquaredErrorCubic(x, y, c+h); + dmsedc = (mseh - mse)/h; +end diff --git a/regression/code/plotcubicgradient.m b/regression/code/plotcubicgradient.m new file mode 100644 index 0000000..0410b1f --- /dev/null +++ b/regression/code/plotcubicgradient.m @@ -0,0 +1,9 @@ +cs = 2.0:0.1:8.0; +mseg = zeros(length(cs)); +for i = 1:length(cs) + mseg(i) = meanSquaredGradientCubic(x, y, cs(i)); +end + +plot(cs, mseg) +xlabel('c') +ylabel('gradient') diff --git a/regression/lecture/regression-chapter.tex b/regression/lecture/regression-chapter.tex index 8afed44..3983848 100644 --- a/regression/lecture/regression-chapter.tex +++ b/regression/lecture/regression-chapter.tex @@ -25,19 +25,11 @@ \subsection{Start with one-dimensional problem!} \begin{itemize} -\item Let's fit a cubic function $y=cx^3$ (weight versus length of a tiger)\\ -\includegraphics[width=0.8\textwidth]{cubicfunc} -\item Introduce the problem, $c$ is density and form factor -\item How to generate an artificial data set (refer to simulation chapter) \item How to plot a function (do not use the data x values!) -\item Just the mean square error as a function of the factor c\\ -\includegraphics[width=0.8\textwidth]{cubicerrors} -\item Also mention the cost function for a straight line -\item 1-d gradient, NO quiver plot (it is a nightmare to get this right)\\ -\includegraphics[width=0.8\textwidth]{cubicmse} \item 1-d gradient descend -\item Describe in words the n-d problem. +\item Describe in words the n-d problem (boltzman as example?). \item Homework is to do the 2d problem with the straight line! +\item NO quiver plot (it is a nightmare to get this right) \end{itemize} \subsection{2D fit} diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index d903a0b..776f745 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -152,7 +152,7 @@ For each value of the parameter $c$ of the model we can use function. The cost function $f_{cost}(c|\{(x_i, y_i)\}|)$ is a function $f_{cost}(c)$ that maps the parameter value $c$ to a scalar error value. For a given data set we thus can simply plot the cost -function as a function of $c$ (\figref{cubiccostfig}). +function as a function of the parameter $c$ (\figref{cubiccostfig}). \begin{exercise}{plotcubiccosts.m}{} Calculate the mean squared error between the data and the cubic @@ -181,17 +181,18 @@ automatic optimization process? The obvious approach would be to calculate the mean squared error for a range of parameter values and then find the position of the minimum -using the \code{min} function. This approach, however has several -disadvantages: (i) the accuracy of the estimation of the best +using the \code{min()} function. This approach, however has several +disadvantages: (i) The accuracy of the estimation of the best parameter is limited by the resolution used to sample the parameter space. The coarser the parameters are sampled the less precise is the obtained position of the minimum (\figref{cubiccostfig}, right). (ii) -the range of parameter values might not include the absolute minimum. -(iii) in particular for functions with more than a single free +The range of parameter values might not include the absolute minimum. +(iii) In particular for functions with more than a single free parameter it is computationally expensive to calculate the cost -function for each parameter combination. The number of combinations -increases exponentially with the number of free parameters. This is -known as the \enterm{curse of dimensionality}. +function for each parameter combination at a sufficient +resolution. The number of combinations increases exponentially with +the number of free parameters. This is known as the \enterm{curse of + dimensionality}. So we need a different approach. We want a procedure that finds the minimum of the cost function with a minimal number of computations and @@ -219,110 +220,54 @@ to arbitrary precision. f'(x) = \frac{{\rm d} f(x)}{{\rm d}x} = \lim\limits_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x} \end{equation} \end{minipage}\vspace{2ex} - It is not possible to calculate the exact value of the derivative, - \eqnref{derivative}, numerically. The derivative can only be - estimated by computing the difference quotient, \eqnref{difffrac} - using sufficiently small $\Delta x$. + It is not possible to calculate the exact value of the derivative + \eqref{derivative} numerically. The derivative can only be estimated + by computing the difference quotient \eqref{difffrac} using + sufficiently small $\Delta x$. \end{ibox} -\begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} - Some functions that depend on more than a single variable: - \[ z = f(x,y) \] - for example depends on $x$ and $y$. Using the partial derivative - \[ \frac{\partial f(x,y)}{\partial x} = \lim\limits_{\Delta x \to 0} \frac{f(x + \Delta x,y) - f(x,y)}{\Delta x} \] - and - \[ \frac{\partial f(x,y)}{\partial y} = \lim\limits_{\Delta y \to 0} \frac{f(x, y + \Delta y) - f(x,y)}{\Delta y} \] - one can estimate the slope in the direction of the variables - individually by using the respective difference quotient - (Box~\ref{differentialquotientbox}). \vspace{1ex} - - \begin{minipage}[t]{0.5\textwidth} - \mbox{}\\[-2ex] - \includegraphics[width=1\textwidth]{gradient} - \end{minipage} - \hfill - \begin{minipage}[t]{0.46\textwidth} - For example, the partial derivatives of - \[ f(x,y) = x^2+y^2 \] are - \[ \frac{\partial f(x,y)}{\partial x} = 2x \; , \quad \frac{\partial f(x,y)}{\partial y} = 2y \; .\] - - The gradient is a vector that is constructed from the partial derivatives: - \[ \nabla f(x,y) = \left( \begin{array}{c} \frac{\partial f(x,y)}{\partial x} \\[1ex] \frac{\partial f(x,y)}{\partial y} \end{array} \right) \] - This vector points into the direction of the strongest ascend of - $f(x,y)$. - \end{minipage} - - \vspace{0.5ex} The figure shows the contour lines of a bi-variate - Gaussian $f(x,y) = \exp(-(x^2+y^2)/2)$ and the gradient (thick - arrows) and the corresponding two partial derivatives (thin arrows) - for three different locations. -\end{ibox} - - \section{Gradient} -Imagine to place a small ball at some point on the error surface -\figref{errorsurfacefig}. Naturally, it would roll down the steepest -slope and eventually stop at the minimum of the error surface (if it had no -inertia). We will use this picture to develop an algorithm to find our -way to the minimum of the objective function. The ball will always -follow the steepest slope. Thus we need to figure out the direction of -the steepest slope at the position of the ball. - -The \entermde{Gradient}{gradient} (Box~\ref{partialderivativebox}) of the -objective function is the vector +Imagine to place a ball at some point on the cost function +\figref{cubiccostfig}. Naturally, it would roll down the slope and +eventually stop at the minimum of the error surface (if it had no +inertia). We will use this analogy to develop an algorithm to find our +way to the minimum of the cost function. The ball always follows the +steepest slope. Thus we need to figure out the direction of the slope +at the position of the ball. + +In our one-dimensional example of a single free parameter the slope is +simply the derivative of the cost function with respect to the +parameter $c$. This derivative is called the +\entermde{Gradient}{gradient} of the cost function: \begin{equation} - \label{gradient} - \nabla f_{cost}(m,b) = \left( \frac{\partial f(m,b)}{\partial m}, - \frac{\partial f(m,b)}{\partial b} \right) + \label{costderivative} + \nabla f_{cost}(c) = \frac{{\rm d} f_{cost}(c)}{{\rm d} c} \end{equation} -that points to the strongest ascend of the objective function. The -gradient is given by partial derivatives -(Box~\ref{partialderivativebox}) of the mean squared error with -respect to the parameters $m$ and $b$ of the straight line. There is -no need to calculate it analytically because it can be estimated from -the partial derivatives using the difference quotient -(Box~\ref{differentialquotientbox}) for small steps $\Delta m$ and -$\Delta b$. For example, the partial derivative with respect to $m$ -can be computed as +There is no need to calculate this derivative analytically, because it +can be approximated numerically by the difference quotient +(Box~\ref{differentialquotientbox}) for small steps $\Delta c$: \begin{equation} - \frac{\partial f_{cost}(m,b)}{\partial m} = \lim\limits_{\Delta m \to - 0} \frac{f_{cost}(m + \Delta m, b) - f_{cost}(m,b)}{\Delta m} -\approx \frac{f_{cost}(m + \Delta m, b) - f_{cost}(m,b)}{\Delta m} \; . + \frac{{\rm d} f_{cost}(c)}{{\rm d} c} = + \lim\limits_{\Delta c \to 0} \frac{f_{cost}(c + \Delta c) - f_{cost}(c)}{\Delta c} + \approx \frac{f_{cost}(c + \Delta c) - f_{cost}(c)}{\Delta c} \end{equation} -The length of the gradient indicates the steepness of the slope -(\figref{gradientquiverfig}). Since want to go down the hill, we -choose the opposite direction. - - -\begin{figure}[t] - \includegraphics[width=0.75\textwidth]{error_gradient} - \titlecaption{Gradient of the error surface.} {Each arrow points - into the direction of the greatest ascend at different positions - of the error surface shown in \figref{errorsurfacefig}. The - contour lines in the background illustrate the error surface. Warm - colors indicate high errors, colder colors low error values. Each - contour line connects points of equal - error.}\label{gradientquiverfig} -\end{figure} - -\begin{exercise}{meanSquaredGradient.m}{}\label{gradientexercise}% - Implement a function \varcode{meanSquaredGradient()}, that takes the - $x$- and $y$-data and the set of parameters $(m, b)$ of a straight - line as a two-element vector as input arguments. The function should - return the gradient at the position $(m, b)$ as a vector with two - elements. +The derivative is positive for positive slopes. Since want to go down +the hill, we choose the opposite direction. + +\begin{exercise}{meanSquaredGradientCubic.m}{} + Implement a function \varcode{meanSquaredGradientCubic()}, that + takes the $x$- and $y$-data and the parameter $c$ as input + arguments. The function should return the derivative of the mean + squared error $f_{cost}(c)$ with respect to $c$ at the position + $c$. \end{exercise} -\begin{exercise}{errorGradient.m}{} - Extend the script of exercises~\ref{errorsurfaceexercise} to plot - both the error surface and gradients using the - \varcode{meanSquaredGradient()} function from - exercise~\ref{gradientexercise}. Vectors in space can be easily - plotted using the function \code{quiver()}. Use \code{contour()} - instead of \code{surface()} to plot the error surface. +\begin{exercise}{plotcubicgradient.m}{} + Using the \varcode{meanSquaredGradientCubic()} function from the + previous exercise, plot the derivative of the cost function as a + function of $c$. \end{exercise} - \section{Gradient descent} Finally, we are able to implement the optimization itself. By now it should be obvious why it is called the gradient descent method. All @@ -381,6 +326,50 @@ large. \end{exercise} +\begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} + Some functions that depend on more than a single variable: + \[ z = f(x,y) \] + for example depends on $x$ and $y$. Using the partial derivative + \[ \frac{\partial f(x,y)}{\partial x} = \lim\limits_{\Delta x \to 0} \frac{f(x + \Delta x,y) - f(x,y)}{\Delta x} \] + and + \[ \frac{\partial f(x,y)}{\partial y} = \lim\limits_{\Delta y \to 0} \frac{f(x, y + \Delta y) - f(x,y)}{\Delta y} \] + one can estimate the slope in the direction of the variables + individually by using the respective difference quotient + (Box~\ref{differentialquotientbox}). \vspace{1ex} + + \begin{minipage}[t]{0.5\textwidth} + \mbox{}\\[-2ex] + \includegraphics[width=1\textwidth]{gradient} + \end{minipage} + \hfill + \begin{minipage}[t]{0.46\textwidth} + For example, the partial derivatives of + \[ f(x,y) = x^2+y^2 \] are + \[ \frac{\partial f(x,y)}{\partial x} = 2x \; , \quad \frac{\partial f(x,y)}{\partial y} = 2y \; .\] + + The gradient is a vector that is constructed from the partial derivatives: + \[ \nabla f(x,y) = \left( \begin{array}{c} \frac{\partial f(x,y)}{\partial x} \\[1ex] \frac{\partial f(x,y)}{\partial y} \end{array} \right) \] + This vector points into the direction of the strongest ascend of + $f(x,y)$. + \end{minipage} + + \vspace{0.5ex} The figure shows the contour lines of a bi-variate + Gaussian $f(x,y) = \exp(-(x^2+y^2)/2)$ and the gradient (thick + arrows) and the corresponding two partial derivatives (thin arrows) + for three different locations. +\end{ibox} + +The \entermde{Gradient}{gradient} (Box~\ref{partialderivativebox}) of the +objective function is the vector +\begin{equation} + \label{gradient} + \nabla f_{cost}(m,b) = \left( \frac{\partial f(m,b)}{\partial m}, + \frac{\partial f(m,b)}{\partial b} \right) +\end{equation} +that points to the strongest ascend of the objective function. The +gradient is given by partial derivatives +(Box~\ref{partialderivativebox}) of the mean squared error with +respect to the parameters $m$ and $b$ of the straight line. \section{Summary} The gradient descent is an important numerical method for solving From 4b624fe9815f2d489ec72d9a9c3af0c494b63df4 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 19 Dec 2020 10:13:37 +0100 Subject: [PATCH 31/37] [regression] updated gradient descent seciotn text --- regression/lecture/regression.tex | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 776f745..3f8c045 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -272,24 +272,27 @@ the hill, we choose the opposite direction. Finally, we are able to implement the optimization itself. By now it should be obvious why it is called the gradient descent method. All ingredients are already there. We need: (i) the cost function -(\varcode{meanSquaredError()}), and (ii) the gradient -(\varcode{meanSquaredGradient()}). The algorithm of the gradient +(\varcode{meanSquaredErrorCubic()}), and (ii) the gradient +(\varcode{meanSquaredGradientCubic()}). The algorithm of the gradient descent works as follows: \begin{enumerate} -\item Start with some given combination of the parameters $m$ and $b$ - ($p_0 = (m_0, b_0)$). -\item \label{computegradient} Calculate the gradient at the current - position $p_i$. -\item If the length of the gradient falls below a certain value, we - assume to have reached the minimum and stop the search. We are - actually looking for the point at which the length of the gradient - is zero, but finding zero is impossible because of numerical - imprecision. We thus apply a threshold below which we are - sufficiently close to zero (e.g. \varcode{norm(gradient) < 0.1}). +\item Start with some arbitrary value $p_0$ for the parameter $c$. +\item \label{computegradient} Compute the gradient + \eqnref{costderivative} at the current position $p_i$. +\item If the length of the gradient, the absolute value of the + derivative \eqnref{costderivative}, is smaller than some threshold + value, we assume to have reached the minimum and stop the search. + We return the current parameter value $p_i$ as our best estimate of + the parameter $c$ that minimizes the cost function. + + We are actually looking for the point at which the derivative of the + cost function equals zero, but this is impossible because of + numerical imprecision. We thus apply a threshold below which we are + sufficiently close to zero. \item \label{gradientstep} If the length of the gradient exceeds the threshold we take a small step into the opposite direction: \begin{equation} - p_{i+1} = p_i - \epsilon \cdot \nabla f_{cost}(m_i, b_i) + p_{i+1} = p_i - \epsilon \cdot \nabla f_{cost}(p_i) \end{equation} where $\epsilon = 0.01$ is a factor linking the gradient to appropriate steps in the parameter space. @@ -298,11 +301,10 @@ descent works as follows: \Figref{gradientdescentfig} illustrates the gradient descent --- the path the imaginary ball has chosen to reach the minimum. Starting at -an arbitrary position on the error surface we change the position as -long as the gradient at that position is larger than a certain -threshold. If the slope is very steep, the change in the position (the -distance between the red dots in \figref{gradientdescentfig}) is -large. +an arbitrary position we change the position as long as the gradient +at that position is larger than a certain threshold. If the slope is +very steep, the change in the position (the distance between the red +dots in \figref{gradientdescentfig}) is large. \begin{figure}[t] \includegraphics{cubicmse} From 7518f9dd47483e71a3da605324e79942b5d7af2e Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 19 Dec 2020 12:20:18 +0100 Subject: [PATCH 32/37] [regression] gradient descent code --- regression/code/gradientDescentCubic.m | 25 ++++++++ regression/code/plotgradientdescentcubic.m | 29 +++++++++ regression/lecture/regression.tex | 74 +++++++++++++--------- 3 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 regression/code/gradientDescentCubic.m create mode 100644 regression/code/plotgradientdescentcubic.m diff --git a/regression/code/gradientDescentCubic.m b/regression/code/gradientDescentCubic.m new file mode 100644 index 0000000..a495221 --- /dev/null +++ b/regression/code/gradientDescentCubic.m @@ -0,0 +1,25 @@ +function [c, cs, mses] = gradientDescentCubic(x, y, c0, epsilon, threshold) +% Gradient descent for fitting a cubic relation. +% +% Arguments: x, vector of the x-data values. +% y, vector of the corresponding y-data values. +% c0, initial value for the parameter c. +% epsilon: factor multiplying the gradient. +% threshold: minimum value for gradient +% +% Returns: c, the final value of the c-parameter. +% cs: vector with all the c-values traversed. +% mses: vector with the corresponding mean squared errors + c = c0; + gradient = 1000.0; + cs = []; + mses = []; + count = 1; + while abs(gradient) > threshold + cs(count) = c; + mses(count) = meanSquaredErrorCubic(x, y, c); + gradient = meanSquaredGradientCubic(x, y, c); + c = c - epsilon * gradient; + count = count + 1; + end +end diff --git a/regression/code/plotgradientdescentcubic.m b/regression/code/plotgradientdescentcubic.m new file mode 100644 index 0000000..4972a92 --- /dev/null +++ b/regression/code/plotgradientdescentcubic.m @@ -0,0 +1,29 @@ +meansquarederrorline % generate data + +c0 = 2.0; +eps = 0.0001; +thresh = 0.1; +[cest, cs, mses] = gradientDescentCubic(x, y, c0, eps, thresh); + +subplot(2, 2, 1); % top left panel +hold on; +plot(cs, '-o'); +plot([1, length(cs)], [c, c], 'k'); % line indicating true c value +hold off; +xlabel('Iteration'); +ylabel('C'); +subplot(2, 2, 3); % bottom left panel +plot(mses, '-o'); +xlabel('Iteration steps'); +ylabel('MSE'); +subplot(1, 2, 2); % right panel +hold on; +% generate x-values for plottig the fit: +xx = min(x):0.01:max(x); +yy = cest * xx.^3; +plot(xx, yy, 'displayname', 'fit'); +plot(x, y, 'o', 'displayname', 'data'); % plot original data +xlabel('Size [m]'); +ylabel('Weight [kg]'); +legend("location", "northwest"); +pause diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 3f8c045..6e9c591 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -269,9 +269,21 @@ the hill, we choose the opposite direction. \end{exercise} \section{Gradient descent} + +\begin{figure}[t] + \includegraphics{cubicmse} + \titlecaption{Gradient descent.}{The algorithm starts at an + arbitrary position. At each point the gradient is estimated and + the position is updated as long as the length of the gradient is + sufficiently large.The dots show the positions after each + iteration of the algorithm.} \label{gradientdescentcubicfig} +\end{figure} + Finally, we are able to implement the optimization itself. By now it -should be obvious why it is called the gradient descent method. All -ingredients are already there. We need: (i) the cost function +should be obvious why it is called the gradient descent method. From a +starting position on we iteratively walk down the slope of the cost +function against its gradient. All ingredients necessary for this +algorithm are already there. We need: (i) the cost function (\varcode{meanSquaredErrorCubic()}), and (ii) the gradient (\varcode{meanSquaredGradientCubic()}). The algorithm of the gradient descent works as follows: @@ -292,41 +304,45 @@ descent works as follows: \item \label{gradientstep} If the length of the gradient exceeds the threshold we take a small step into the opposite direction: \begin{equation} + \label{gradientdescent} p_{i+1} = p_i - \epsilon \cdot \nabla f_{cost}(p_i) \end{equation} - where $\epsilon = 0.01$ is a factor linking the gradient to + where $\epsilon$ is a factor linking the gradient to appropriate steps in the parameter space. \item Repeat steps \ref{computegradient} -- \ref{gradientstep}. \end{enumerate} -\Figref{gradientdescentfig} illustrates the gradient descent --- the -path the imaginary ball has chosen to reach the minimum. Starting at -an arbitrary position we change the position as long as the gradient -at that position is larger than a certain threshold. If the slope is -very steep, the change in the position (the distance between the red -dots in \figref{gradientdescentfig}) is large. - -\begin{figure}[t] - \includegraphics{cubicmse} - \titlecaption{Gradient descent.}{The algorithm starts at an - arbitrary position. At each point the gradient is estimated and - the position is updated as long as the length of the gradient is - sufficiently large.The dots show the positions after each - iteration of the algorithm.} \label{gradientdescentfig} -\end{figure} - -\begin{exercise}{gradientDescent.m}{} - Implement the gradient descent for the problem of fitting a straight - line to some measured data. Reuse the data generated in - exercise~\ref{errorsurfaceexercise}. - \begin{enumerate} - \item Store for each iteration the error value. - \item Plot the error values as a function of the iterations, the - number of optimization steps. - \item Plot the measured data together with the best fitting straight line. - \end{enumerate}\vspace{-4.5ex} +\Figref{gradientdescentcubicfig} illustrates the gradient descent --- the +path the imaginary ball has chosen to reach the minimum. We walk along +the parameter axis against the gradient as long as the gradient +differs sufficiently from zero. At steep slopes we take large steps +(the distance between the red dots in \figref{gradientdescentcubicfig}) is +large. + +\begin{exercise}{gradientDescentCubic.m}{} + Implement the gradient descent algorithm for the problem of fitting + a cubic function \eqref{cubicfunc} to some measured data pairs $x$ + and $y$ as a function \varcode{gradientDescentCubic()} that returns + the estimated best fitting parameter value $c$ as well as two + vectors with all the parameter values and the corresponding values + of the cost function that the algorithm iterated trough. As + additional arguments that function takes the initial value for the + parameter $c$, the factor $\epsilon$ connecting the gradient with + iteration steps in \eqnref{gradientdescent}, and the threshold value + for the absolute value of the gradient terminating the algorithm. \end{exercise} +\begin{exercise}{plotgradientdescentcubic.m}{} + Use the function \varcode{gradientDescentCubic()} to fit the + simulated data from exercise~\ref{mseexercise}. Plot the returned + values of the parameter $c$ as as well as the corresponding mean + squared errors as a function of iteration step (two plots). Compare + the result of the gradient descent method with the true value of $c$ + used to simulate the data. Inspect the plots and adapt $\epsilon$ + and the threshold to make the algorithm behave as intended. Also + plot the data together with the best fitting cubic relation + \eqref{cubicfunc}. +\end{exercise} \begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} Some functions that depend on more than a single variable: From 891515caf86e1e6eb319bf0df5f28993ef6b18a9 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 19 Dec 2020 13:41:28 +0100 Subject: [PATCH 33/37] [regression] first part n-dim minimization --- regression/code/plotgradientdescentcubic.m | 9 +- regression/lecture/regression.tex | 96 ++++++++++++++++++++-- 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/regression/code/plotgradientdescentcubic.m b/regression/code/plotgradientdescentcubic.m index 4972a92..6ac54af 100644 --- a/regression/code/plotgradientdescentcubic.m +++ b/regression/code/plotgradientdescentcubic.m @@ -1,4 +1,4 @@ -meansquarederrorline % generate data +meansquarederrorline; % generate data c0 = 2.0; eps = 0.0001; @@ -21,9 +21,8 @@ hold on; % generate x-values for plottig the fit: xx = min(x):0.01:max(x); yy = cest * xx.^3; -plot(xx, yy, 'displayname', 'fit'); -plot(x, y, 'o', 'displayname', 'data'); % plot original data +plot(xx, yy); +plot(x, y, 'o'); % plot original data xlabel('Size [m]'); ylabel('Weight [kg]'); -legend("location", "northwest"); -pause +legend('fit', 'data', 'location', 'northwest'); diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 6e9c591..472f3c6 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -254,7 +254,7 @@ can be approximated numerically by the difference quotient The derivative is positive for positive slopes. Since want to go down the hill, we choose the opposite direction. -\begin{exercise}{meanSquaredGradientCubic.m}{} +\begin{exercise}{meanSquaredGradientCubic.m}{}\label{gradientcubic} Implement a function \varcode{meanSquaredGradientCubic()}, that takes the $x$- and $y$-data and the parameter $c$ as input arguments. The function should return the derivative of the mean @@ -312,12 +312,12 @@ descent works as follows: \item Repeat steps \ref{computegradient} -- \ref{gradientstep}. \end{enumerate} -\Figref{gradientdescentcubicfig} illustrates the gradient descent --- the -path the imaginary ball has chosen to reach the minimum. We walk along -the parameter axis against the gradient as long as the gradient +\Figref{gradientdescentcubicfig} illustrates the gradient descent --- +the path the imaginary ball has chosen to reach the minimum. We walk +along the parameter axis against the gradient as long as the gradient differs sufficiently from zero. At steep slopes we take large steps -(the distance between the red dots in \figref{gradientdescentcubicfig}) is -large. +(the distance between the red dots in \figref{gradientdescentcubicfig} +is large). \begin{exercise}{gradientDescentCubic.m}{} Implement the gradient descent algorithm for the problem of fitting @@ -339,11 +339,78 @@ large. squared errors as a function of iteration step (two plots). Compare the result of the gradient descent method with the true value of $c$ used to simulate the data. Inspect the plots and adapt $\epsilon$ - and the threshold to make the algorithm behave as intended. Also + and the threshold to make the algorithm behave as intended. Finally plot the data together with the best fitting cubic relation \eqref{cubicfunc}. \end{exercise} +The $\epsilon$ parameter in \eqnref{gradientdescent} is critical. If +too large, the algorithm does not converge to the minimum of the cost +function (try it!). At medium values it oscillates around the minimum +but might nevertheless converge. Only for sufficiently small values +(here $\epsilon = 0.0001$) does the algorithm follow the slope +downwards towards the minimum. + +The terminating condition on the absolute value of the gradient +influences how often the cost function is evaluated. The smaller the +threshold value the more often the cost is computed and the more +precisely the fit parameter is estimated. If it is too small, however, +the increase in precision is negligible, in particular in comparison +to the increased computational effort. Have a look at the derivatives +that we plotted in exercise~\ref{gradientcubic} and decide on a +sensible value for the threshold. Run the gradient descent algorithm +and check how the resulting $c$ parameter values converge and how many +iterations were needed. The reduce the threshold (by factors of ten) +and check how this changes the results. + +Many modern algorithms for finding the minimum of a function are based +on the basic idea of the gradient descent. Luckily these algorithms +choose $\epsilon$ in a smart adaptive way and they also come up with +sensible default values for the termination condition. On the other +hand, these algorithm often take optional arguments that let you +control how they behave. Now you know what this is all about. + +\section{N-dimensional minimization problems} + +So far we were concerned about finding the right value for a single +parameter that minimizes a cost function. The gradient descent method +for such one dimensional problems seems a bit like over kill. However, +often we deal with functions that have more than a single parameter, +in general $n$ parameter. We then need to find the minimum in an $n$ +dimensional parameter space. + +For our tiger problem, we could have also fitted the exponent $\alpha$ +of the power-law relation between size and weight, instead of assuming +a cubic relation: +\begin{equation} + \label{powerfunc} + y = f(x; c, \alpha) = f(x; \vec p) = c\cdot x^\alpha +\end{equation} +We then could check whether the resulting estimate of the exponent +$\alpha$ indeed is close to the expected power of three. The +power-law \eqref{powerfunc} has two free parameters $c$ and $\alpha$. +Instead of a single parameter we are now dealing with a vector $\vec +p$ containing $n$ parameter values. Here, $\vec p = (c, +\alpha)$. Luckily, all the concepts we introduced on the example of +the one dimensional problem of tiger weights generalize to +$n$-dimensional problems. We only need to adapt a few things. The cost +function for the mean squared error reads +\begin{equation} + \label{ndimcostfunc} + f_{cost}(\vec p|\{(x_i, y_i)\}) = \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;\vec p))^2 +\end{equation} + +For two-dimensional problems the graph of the cost function is an +\enterm{error surface} (\determ{{Fehlerfl\"ache}}). The two parameters +span a two-dimensional plane. The cost function assigns to each +parameter combination on this plane a single value. This results in a +landscape over the parameter plane with mountains and valleys and we +are searching for the bottom of the deepest valley. + +When we place a ball somewhere on the slopes of a hill it rolls +downwards and eventually stops at the bottom. The ball always rolls in +the direction of the steepest slope. + \begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} Some functions that depend on more than a single variable: \[ z = f(x,y) \] @@ -388,6 +455,21 @@ that points to the strongest ascend of the objective function. The gradient is given by partial derivatives (Box~\ref{partialderivativebox}) of the mean squared error with respect to the parameters $m$ and $b$ of the straight line. + + + +For example, you measure the response of a passive membrane to a +current step and you want to estimate membrane time constant. Then you +need to fit an exponential function +\begin{equation} + \label{expfunc} + V(t; \tau, \Delta V, V_{\infty}) = \Delta V e^{-t/\tau} + V_{\infty} +\end{equation} +with three free parameters $\tau$, $\Delta y$, $y_{\infty}$ to the +measured time course of the membrane potential $V(t)$. The $(x_i,y_i)$ +data pairs are the sampling times $t_i$ and the corresponding +measurements of the membrane potential $V_i$. + \section{Summary} The gradient descent is an important numerical method for solving From bfb2f66de2f7fab7cb5ad6ffbef83a1bfd52a1d7 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 19 Dec 2020 21:53:19 +0100 Subject: [PATCH 34/37] [regression] finished n-dim minimization --- designpattern/lecture/designpattern.tex | 8 +- regression/code/gradientDescentPower.m | 41 +++++++ regression/code/plotgradientdescentpower.m | 32 ++++++ regression/lecture/regression.tex | 127 +++++++++++++++------ 4 files changed, 166 insertions(+), 42 deletions(-) create mode 100644 regression/code/gradientDescentPower.m create mode 100644 regression/code/plotgradientdescentpower.m diff --git a/designpattern/lecture/designpattern.tex b/designpattern/lecture/designpattern.tex index 5baada5..05ee5ab 100644 --- a/designpattern/lecture/designpattern.tex +++ b/designpattern/lecture/designpattern.tex @@ -72,13 +72,13 @@ x = [2:3:20]; % Some vector. y = []; % Empty vector for storing the results. for i=1:length(x) % The function get_something() returns a vector of unspecified size: - z = get_somehow_more(x(i)); + z = get_something(x(i)); % The content of z is appended to the result vector y: - y = [y; z(:)]; + y = [y, z(:)]; % The z(:) syntax ensures that we append column-vectors. end -% Process the results stored in the vector z: -mean(y) +% Process the results stored in the vector y: +mean(y, 1) \end{pagelisting} diff --git a/regression/code/gradientDescentPower.m b/regression/code/gradientDescentPower.m new file mode 100644 index 0000000..31390eb --- /dev/null +++ b/regression/code/gradientDescentPower.m @@ -0,0 +1,41 @@ +function [p, ps, mses] = gradientDescentPower(x, y, p0, epsilon, threshold) +% Gradient descent for fitting a power-law. +% +% Arguments: x, vector of the x-data values. +% y, vector of the corresponding y-data values. +% p0, vector with initial values for c and alpha. +% epsilon: factor multiplying the gradient. +% threshold: minimum value for gradient +% +% Returns: p, vector with the final parameter values. +% ps: 2D-vector with all the parameter tuples traversed. +% mses: vector with the corresponding mean squared errors + + p = p0; + gradient = ones(1, length(p0)) * 1000.0; + ps = []; + mses = []; + while norm(gradient) > threshold + ps = [ps, p(:)]; + mses = [mses, meanSquaredErrorPower(x, y, p)]; + gradient = meanSquaredGradientPower(x, y, p); + p = p - epsilon * gradient; + end +end + +function mse = meanSquaredErrorPower(x, y, p) + mse = mean((y - p(1)*x.^p(2)).^2); +end + +function gradmse = meanSquaredGradientPower(x, y, p) + gradmse = zeros(size(p, 1), size(p, 2)); + h = 1e-5; % stepsize for derivatives + mse = meanSquaredErrorPower(x, y, p); + for i = 1:length(p) % for each coordinate ... + pi = p; + pi(i) = pi(i) + h; % displace i-th parameter + msepi = meanSquaredErrorPower(x, y, pi); + gradmse(i) = (msepi - mse)/h; + end +end + diff --git a/regression/code/plotgradientdescentpower.m b/regression/code/plotgradientdescentpower.m new file mode 100644 index 0000000..f52bfe7 --- /dev/null +++ b/regression/code/plotgradientdescentpower.m @@ -0,0 +1,32 @@ +meansquarederrorline; % generate data + +p0 = [2.0, 1.0]; +eps = 0.00001; +thresh = 50.0; +[pest, ps, mses] = gradientDescentPower(x, y, p0, eps, thresh); +pest + +subplot(2, 2, 1); % top left panel +hold on; +plot(ps(1,:), ps(2,:), '.'); +plot(ps(1,end), ps(2,end), 'og'); +plot(c, 3.0, 'or'); % dot indicating true parameter values +hold off; +xlabel('Iteration'); +ylabel('C'); +subplot(2, 2, 3); % bottom left panel +plot(mses, '-o'); +xlabel('Iteration steps'); +ylabel('MSE'); +subplot(1, 2, 2); % right panel +hold on; +% generate x-values for plottig the fit: +xx = min(x):0.01:max(x); +yy = pest(1) * xx.^pest(2); +plot(xx, yy); +plot(x, y, 'o'); % plot original data +xlabel('Size [m]'); +ylabel('Weight [kg]'); +legend('fit', 'data', 'location', 'northwest'); +pause + diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 472f3c6..69e7b05 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -319,7 +319,7 @@ differs sufficiently from zero. At steep slopes we take large steps (the distance between the red dots in \figref{gradientdescentcubicfig} is large). -\begin{exercise}{gradientDescentCubic.m}{} +\begin{exercise}{gradientDescentCubic.m}{}\label{gradientdescentexercise} Implement the gradient descent algorithm for the problem of fitting a cubic function \eqref{cubicfunc} to some measured data pairs $x$ and $y$ as a function \varcode{gradientDescentCubic()} that returns @@ -332,7 +332,7 @@ is large). for the absolute value of the gradient terminating the algorithm. \end{exercise} -\begin{exercise}{plotgradientdescentcubic.m}{} +\begin{exercise}{plotgradientdescentcubic.m}{}\label{plotgradientdescentexercise} Use the function \varcode{gradientDescentCubic()} to fit the simulated data from exercise~\ref{mseexercise}. Plot the returned values of the parameter $c$ as as well as the corresponding mean @@ -373,15 +373,14 @@ control how they behave. Now you know what this is all about. \section{N-dimensional minimization problems} So far we were concerned about finding the right value for a single -parameter that minimizes a cost function. The gradient descent method -for such one dimensional problems seems a bit like over kill. However, -often we deal with functions that have more than a single parameter, -in general $n$ parameter. We then need to find the minimum in an $n$ -dimensional parameter space. +parameter that minimizes a cost function. Often we deal with +functions that have more than a single parameter, in general $n$ +parameters. We then need to find the minimum in an $n$ dimensional +parameter space. For our tiger problem, we could have also fitted the exponent $\alpha$ of the power-law relation between size and weight, instead of assuming -a cubic relation: +a cubic relation with $\alpha=3$: \begin{equation} \label{powerfunc} y = f(x; c, \alpha) = f(x; \vec p) = c\cdot x^\alpha @@ -390,11 +389,11 @@ We then could check whether the resulting estimate of the exponent $\alpha$ indeed is close to the expected power of three. The power-law \eqref{powerfunc} has two free parameters $c$ and $\alpha$. Instead of a single parameter we are now dealing with a vector $\vec -p$ containing $n$ parameter values. Here, $\vec p = (c, -\alpha)$. Luckily, all the concepts we introduced on the example of -the one dimensional problem of tiger weights generalize to -$n$-dimensional problems. We only need to adapt a few things. The cost -function for the mean squared error reads +p$ containing $n$ parameter values. Here, $\vec p = (c, \alpha)$. All +the concepts we introduced on the example of the one dimensional +problem of tiger weights generalize to $n$-dimensional problems. We +only need to adapt a few things. The cost function for the mean +squared error reads \begin{equation} \label{ndimcostfunc} f_{cost}(\vec p|\{(x_i, y_i)\}) = \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;\vec p))^2 @@ -405,22 +404,18 @@ For two-dimensional problems the graph of the cost function is an span a two-dimensional plane. The cost function assigns to each parameter combination on this plane a single value. This results in a landscape over the parameter plane with mountains and valleys and we -are searching for the bottom of the deepest valley. +are searching for the position of the bottom of the deepest valley. -When we place a ball somewhere on the slopes of a hill it rolls -downwards and eventually stops at the bottom. The ball always rolls in -the direction of the steepest slope. - -\begin{ibox}[tp]{\label{partialderivativebox}Partial derivative and gradient} - Some functions that depend on more than a single variable: +\begin{ibox}[tp]{\label{partialderivativebox}Partial derivatives and gradient} + Some functions depend on more than a single variable. For example, the function \[ z = f(x,y) \] - for example depends on $x$ and $y$. Using the partial derivative + depends on both $x$ and $y$. Using the partial derivatives \[ \frac{\partial f(x,y)}{\partial x} = \lim\limits_{\Delta x \to 0} \frac{f(x + \Delta x,y) - f(x,y)}{\Delta x} \] and \[ \frac{\partial f(x,y)}{\partial y} = \lim\limits_{\Delta y \to 0} \frac{f(x, y + \Delta y) - f(x,y)}{\Delta y} \] - one can estimate the slope in the direction of the variables - individually by using the respective difference quotient - (Box~\ref{differentialquotientbox}). \vspace{1ex} + one can calculate the slopes in the directions of each of the + variables by means of the respective difference quotient + (see box~\ref{differentialquotientbox}). \vspace{1ex} \begin{minipage}[t]{0.5\textwidth} \mbox{}\\[-2ex] @@ -429,37 +424,93 @@ the direction of the steepest slope. \hfill \begin{minipage}[t]{0.46\textwidth} For example, the partial derivatives of - \[ f(x,y) = x^2+y^2 \] are + \[ f(x,y) = x^2+y^2 \vspace{-1ex} \] are \[ \frac{\partial f(x,y)}{\partial x} = 2x \; , \quad \frac{\partial f(x,y)}{\partial y} = 2y \; .\] - The gradient is a vector that is constructed from the partial derivatives: + The gradient is a vector with the partial derivatives as coordinates: \[ \nabla f(x,y) = \left( \begin{array}{c} \frac{\partial f(x,y)}{\partial x} \\[1ex] \frac{\partial f(x,y)}{\partial y} \end{array} \right) \] This vector points into the direction of the strongest ascend of $f(x,y)$. \end{minipage} - \vspace{0.5ex} The figure shows the contour lines of a bi-variate + \vspace{0.5ex} The figure shows the contour lines of a bivariate Gaussian $f(x,y) = \exp(-(x^2+y^2)/2)$ and the gradient (thick - arrows) and the corresponding two partial derivatives (thin arrows) - for three different locations. + arrows) together with the corresponding partial derivatives (thin + arrows) for three different locations. \end{ibox} -The \entermde{Gradient}{gradient} (Box~\ref{partialderivativebox}) of the -objective function is the vector +When we place a ball somewhere on the slopes of a hill, it rolls +downwards and eventually stops at the bottom. The ball always rolls in +the direction of the steepest slope. For a two-dimensional parameter +space of our example, the \entermde{Gradient}{gradient} +(box~\ref{partialderivativebox}) of the cost function is a vector +\begin{equation} + \label{gradientpowerlaw} + \nabla f_{cost}(c, \alpha) = \left( \frac{\partial f_{cost}(c, \alpha)}{\partial c}, + \frac{\partial f_{cost}(c, \alpha)}{\partial \alpha} \right) +\end{equation} +that points into the direction of the strongest ascend of the cost +function. The gradient is given by the partial derivatives +(box~\ref{partialderivativebox}) of the mean squared error with +respect to the parameters $c$ and $\alpha$ of the power law +relation. In general, for $n$-dimensional problems, the gradient is an +$n-$ dimensional vector containing for each of the $n$ parameters +$p_j$ the respective partial derivatives as coordinates: \begin{equation} \label{gradient} - \nabla f_{cost}(m,b) = \left( \frac{\partial f(m,b)}{\partial m}, - \frac{\partial f(m,b)}{\partial b} \right) + \nabla f_{cost}(\vec p) = \left( \frac{\partial f_{cost}(\vec p)}{\partial p_j} \right) +\end{equation} + +The iterative equation \eqref{gradientdescent} of the gradient descent +stays exactly the same, with the only difference that the current +parameter value $p_i$ becomes a vector $\vec p_i$ of parameter values: +\begin{equation} + \label{ndimgradientdescent} + \vec p_{i+1} = \vec p_i - \epsilon \cdot \nabla f_{cost}(\vec p_i) \end{equation} -that points to the strongest ascend of the objective function. The -gradient is given by partial derivatives -(Box~\ref{partialderivativebox}) of the mean squared error with -respect to the parameters $m$ and $b$ of the straight line. +For the termination condition we need the length of the gradient. In +one dimension it was just the absolute value of the derivative. For +$n$ dimensions this is according to the \enterm{Pythagorean theorem} +(\determ[Pythagoras!Satz des]{Satz des Pythagoras}) the square root of +the sum of the squared partial derivatives: +\begin{equation} + \label{ndimabsgradient} + |\nabla f_{cost}(\vec p_i)| = \sqrt{\sum_{i=1}^n \left(\frac{\partial f_{cost}(\vec p)}{\partial p_i}\right)^2} +\end{equation} +The \code{norm()} function implements this. + +\begin{exercise}{gradientDescentPower.m}{} + Adapt the function \varcode{gradientDescentCubic()} from + exercise~\ref{gradientdescentexercise} to implement the gradient + descent algorithm for the power law \eqref{powerfunc}. The new + function takes a two element vector $(c,\alpha)$ for the initial + parameter values and also returns the best parameter combination as + a two-element vector. Use a \varcode{for} loop over the two + dimensions for computing the gradient. +\end{exercise} + +\begin{exercise}{plotgradientdescentpower.m}{} + Use the function \varcode{gradientDescentPower()} to fit the + simulated data from exercise~\ref{mseexercise}. Plot the returned + values of the two parameters against each other. Compare the result + of the gradient descent method with the true values of $c$ and + $\alpha$ used to simulate the data. Observe the norm of the gradient + and inspect the plots to adapt $\epsilon$ (smaller than in + exercise~\ref{plotgradientdescentexercise}) and the threshold (much + larger) appropriately. Finally plot the data together with the best + fitting power-law \eqref{powerfunc}. +\end{exercise} + +\section{Curve fit for arbitrary functions} +So far, all our code for the gradient descent algorithm was tailored +to a specific function, the cubic relation \eqref{cubicfunc} or the +power law \eqref{powerfunc}. +\section{XXX} For example, you measure the response of a passive membrane to a -current step and you want to estimate membrane time constant. Then you +current step and you want to estimate membrane the time constant. Then you need to fit an exponential function \begin{equation} \label{expfunc} From 46affef86d61bd4ae301979bb46ba326a8e676c2 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sat, 19 Dec 2020 22:56:09 +0100 Subject: [PATCH 35/37] [regression] finished main text and exercises --- regression/code/gradientDescent.m | 66 ++++++---- regression/code/gradientDescentPower.m | 41 ------ regression/code/plotgradientdescentpower.m | 4 +- regression/lecture/regression-chapter.tex | 74 ----------- regression/lecture/regression.tex | 141 +++++++++++++-------- 5 files changed, 128 insertions(+), 198 deletions(-) delete mode 100644 regression/code/gradientDescentPower.m diff --git a/regression/code/gradientDescent.m b/regression/code/gradientDescent.m index 1919035..48b976c 100644 --- a/regression/code/gradientDescent.m +++ b/regression/code/gradientDescent.m @@ -1,32 +1,42 @@ -% x, y from exercise 8.3 +function [p, ps, mses] = gradientDescent(x, y, func, p0, epsilon, threshold) +% Gradient descent for fitting a function to data pairs. +% +% Arguments: x, vector of the x-data values. +% y, vector of the corresponding y-data values. +% func, function handle func(x, p) +% p0, vector with initial parameter values +% epsilon: factor multiplying the gradient. +% threshold: minimum value for gradient +% +% Returns: p, vector with the final parameter values. +% ps: 2D-vector with all the parameter vectors traversed. +% mses: vector with the corresponding mean squared errors -% some arbitrary values for the slope and the intercept to start with: -position = [-2.0, 10.0]; + p = p0; + gradient = ones(1, length(p0)) * 1000.0; + ps = []; + mses = []; + while norm(gradient) > threshold + ps = [ps, p(:)]; + mses = [mses, meanSquaredError(x, y, func, p)]; + gradient = meanSquaredGradient(x, y, func, p); + p = p - epsilon * gradient; + end +end + +function mse = meanSquaredError(x, y, func, p) + mse = mean((y - func(x, p)).^2); +end -% gradient descent: -gradient = []; -errors = []; -count = 1; -eps = 0.0001; -while isempty(gradient) || norm(gradient) > 0.1 - gradient = meanSquaredGradient(x, y, position); - errors(count) = meanSquaredError(x, y, position); - position = position - eps .* gradient; - count = count + 1; +function gradmse = meanSquaredGradient(x, y, func, p) + gradmse = zeros(size(p, 1), size(p, 2)); + h = 1e-5; % stepsize for derivatives + mse = meanSquaredError(x, y, func, p); + for i = 1:length(p) % for each coordinate ... + pi = p; + pi(i) = pi(i) + h; % displace i-th parameter + msepi = meanSquaredError(x, y, func, pi); + gradmse(i) = (msepi - mse)/h; + end end -figure() -subplot(2,1,1) -hold on -scatter(x, y, 'displayname', 'data') -xx = min(x):0.01:max(x); -yy = position(1).*xx + position(2); -plot(xx, yy, 'displayname', 'fit') -xlabel('Input') -ylabel('Output') -grid on -legend show -subplot(2,1,2) -plot(errors) -xlabel('optimization steps') -ylabel('error') diff --git a/regression/code/gradientDescentPower.m b/regression/code/gradientDescentPower.m deleted file mode 100644 index 31390eb..0000000 --- a/regression/code/gradientDescentPower.m +++ /dev/null @@ -1,41 +0,0 @@ -function [p, ps, mses] = gradientDescentPower(x, y, p0, epsilon, threshold) -% Gradient descent for fitting a power-law. -% -% Arguments: x, vector of the x-data values. -% y, vector of the corresponding y-data values. -% p0, vector with initial values for c and alpha. -% epsilon: factor multiplying the gradient. -% threshold: minimum value for gradient -% -% Returns: p, vector with the final parameter values. -% ps: 2D-vector with all the parameter tuples traversed. -% mses: vector with the corresponding mean squared errors - - p = p0; - gradient = ones(1, length(p0)) * 1000.0; - ps = []; - mses = []; - while norm(gradient) > threshold - ps = [ps, p(:)]; - mses = [mses, meanSquaredErrorPower(x, y, p)]; - gradient = meanSquaredGradientPower(x, y, p); - p = p - epsilon * gradient; - end -end - -function mse = meanSquaredErrorPower(x, y, p) - mse = mean((y - p(1)*x.^p(2)).^2); -end - -function gradmse = meanSquaredGradientPower(x, y, p) - gradmse = zeros(size(p, 1), size(p, 2)); - h = 1e-5; % stepsize for derivatives - mse = meanSquaredErrorPower(x, y, p); - for i = 1:length(p) % for each coordinate ... - pi = p; - pi(i) = pi(i) + h; % displace i-th parameter - msepi = meanSquaredErrorPower(x, y, pi); - gradmse(i) = (msepi - mse)/h; - end -end - diff --git a/regression/code/plotgradientdescentpower.m b/regression/code/plotgradientdescentpower.m index f52bfe7..206e2bb 100644 --- a/regression/code/plotgradientdescentpower.m +++ b/regression/code/plotgradientdescentpower.m @@ -3,7 +3,7 @@ meansquarederrorline; % generate data p0 = [2.0, 1.0]; eps = 0.00001; thresh = 50.0; -[pest, ps, mses] = gradientDescentPower(x, y, p0, eps, thresh); +[pest, ps, mses] = gradientDescent(x, y, @powerLaw, p0, eps, thresh); pest subplot(2, 2, 1); % top left panel @@ -22,7 +22,7 @@ subplot(1, 2, 2); % right panel hold on; % generate x-values for plottig the fit: xx = min(x):0.01:max(x); -yy = pest(1) * xx.^pest(2); +yy = powerLaw(xx, pest); plot(xx, yy); plot(x, y, 'o'); % plot original data xlabel('Size [m]'); diff --git a/regression/lecture/regression-chapter.tex b/regression/lecture/regression-chapter.tex index 3983848..2ca1ec2 100644 --- a/regression/lecture/regression-chapter.tex +++ b/regression/lecture/regression-chapter.tex @@ -23,80 +23,6 @@ \item Fig 8.2 right: this should be a chi-squared distribution with one degree of freedom! \end{itemize} -\subsection{Start with one-dimensional problem!} -\begin{itemize} -\item How to plot a function (do not use the data x values!) -\item 1-d gradient descend -\item Describe in words the n-d problem (boltzman as example?). -\item Homework is to do the 2d problem with the straight line! -\item NO quiver plot (it is a nightmare to get this right) -\end{itemize} - -\subsection{2D fit} - -\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise} - Generate 20 data pairs $(x_i|y_i)$ that are linearly related with - slope $m=0.75$ and intercept $b=-40$, using \varcode{rand()} for - drawing $x$ values between 0 and 120 and \varcode{randn()} for - jittering the $y$ values with a standard deviation of 15. Then - calculate the mean squared error between the data and straight lines - for a range of slopes and intercepts using the - \varcode{meanSquaredError()} function from the previous exercise. - Illustrates the error surface using the \code{surface()} function. - Consult the documentation to find out how to use \code{surface()}. -\end{exercise} - -\begin{exercise}{meanSquaredGradient.m}{}\label{gradientexercise}% - Implement a function \varcode{meanSquaredGradient()}, that takes the - $x$- and $y$-data and the set of parameters $(m, b)$ of a straight - line as a two-element vector as input arguments. The function should - return the gradient at the position $(m, b)$ as a vector with two - elements. -\end{exercise} - -\begin{exercise}{errorGradient.m}{} - Extend the script of exercises~\ref{errorsurfaceexercise} to plot - both the error surface and gradients using the - \varcode{meanSquaredGradient()} function from - exercise~\ref{gradientexercise}. Vectors in space can be easily - plotted using the function \code{quiver()}. Use \code{contour()} - instead of \code{surface()} to plot the error surface. -\end{exercise} - - -\begin{exercise}{gradientDescent.m}{} - Implement the gradient descent for the problem of fitting a straight - line to some measured data. Reuse the data generated in - exercise~\ref{errorsurfaceexercise}. - \begin{enumerate} - \item Store for each iteration the error value. - \item Plot the error values as a function of the iterations, the - number of optimization steps. - \item Plot the measured data together with the best fitting straight line. - \end{enumerate}\vspace{-4.5ex} -\end{exercise} - - -\begin{figure}[t] - \includegraphics[width=1\textwidth]{lin_regress}\hfill - \titlecaption{Example data suggesting a linear relation.}{A set of - input signals $x$, e.g. stimulus intensities, were used to probe a - system. The system's output $y$ to the inputs are noted - (left). Assuming a linear relation between $x$ and $y$ leaves us - with 2 parameters, the slope (center) and the intercept with the - y-axis (right panel).}\label{linregressiondatafig} -\end{figure} - -\begin{figure}[t] - \includegraphics[width=1\textwidth]{linear_least_squares} - \titlecaption{Estimating the \emph{mean square error}.} {The - deviation error (orange) between the prediction (red line) and the - observations (blue dots) is calculated for each data point - (left). Then the deviations are squared and the average is - calculated (right).} - \label{leastsquareerrorfig} -\end{figure} - \begin{figure}[t] \includegraphics[width=0.75\textwidth]{error_surface} \titlecaption{Error surface.}{The two model parameters $m$ and $b$ diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 69e7b05..36e1808 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -479,49 +479,73 @@ the sum of the squared partial derivatives: \end{equation} The \code{norm()} function implements this. -\begin{exercise}{gradientDescentPower.m}{} + +\section{Passing a function as an argument to another function} + +So far, all our code for the gradient descent algorithm was tailored +to a specific function, the cubic relation \eqref{cubicfunc}. It would +be much better if we could pass an arbitrary function to our gradient +algorithm. Then we would not need to rewrite it every time anew. + +This is possible. We can indeed pass a function as an argument to +another function. For this use the \code{@}-operator. As an example +let's define a function that produces a standard plot for a function: + +\pageinputlisting[caption={Example function taking a function as argument.}]{funcPlotter.m} + +This function can then be used as follows for plotting a sine wave. We +pass the built in \varcode{sin()} function as \varcode{@sin} as an +argument to our function: + +\pageinputlisting[caption={Passing a function handle as an argument to a function.}]{funcplotterexamples.m} + + +\section{Gradient descent algorithm for arbitrary functions} + +Now we are ready to adapt the gradient descent algorithm from +exercise~\ref{gradientdescentexercise} to arbitrary functions with $n$ +parameters that we want to fit to some data. + +\begin{exercise}{gradientDescent.m}{} Adapt the function \varcode{gradientDescentCubic()} from exercise~\ref{gradientdescentexercise} to implement the gradient - descent algorithm for the power law \eqref{powerfunc}. The new - function takes a two element vector $(c,\alpha)$ for the initial - parameter values and also returns the best parameter combination as - a two-element vector. Use a \varcode{for} loop over the two - dimensions for computing the gradient. + descent algorithm for any function \varcode{func(x, p)} that takes + as first argument the $x$-data values and as second argument a + vector with parameter values. The new function takes a vector $\vec + p_0$ for the initial parameter values and also returns the best + parameter combination as a vector. Use a \varcode{for} loop over the + two dimensions for computing the gradient. \end{exercise} +For testing our new function we need to implement the power law +\eqref{powerfunc}: + +\begin{exercise}{powerLaw.m}{} + Write a function that implements \eqref{powerfunc}. The function + gets as arguments a vector $x$ containing the $x$-data values and + another vector containing as elements the parameters for the power + law, i.e. the factor $c$ and the power $\alpha$. It returns a vector + with the computed $y$ values for each $x$ value. +\end{exercise} + +Now let's use the new gradient descent function to fit a power law to +our tiger data-set: + \begin{exercise}{plotgradientdescentpower.m}{} - Use the function \varcode{gradientDescentPower()} to fit the - simulated data from exercise~\ref{mseexercise}. Plot the returned - values of the two parameters against each other. Compare the result - of the gradient descent method with the true values of $c$ and - $\alpha$ used to simulate the data. Observe the norm of the gradient - and inspect the plots to adapt $\epsilon$ (smaller than in + Use the function \varcode{gradientDescent()} to fit the + \varcode{powerLaw()} function to the simulated data from + exercise~\ref{mseexercise}. Plot the returned values of the two + parameters against each other. Compare the result of the gradient + descent method with the true values of $c$ and $\alpha$ used to + simulate the data. Observe the norm of the gradient and inspect the + plots to adapt $\epsilon$ (smaller than in exercise~\ref{plotgradientdescentexercise}) and the threshold (much larger) appropriately. Finally plot the data together with the best fitting power-law \eqref{powerfunc}. \end{exercise} -\section{Curve fit for arbitrary functions} - -So far, all our code for the gradient descent algorithm was tailored -to a specific function, the cubic relation \eqref{cubicfunc} or the -power law \eqref{powerfunc}. - -\section{XXX} -For example, you measure the response of a passive membrane to a -current step and you want to estimate membrane the time constant. Then you -need to fit an exponential function -\begin{equation} - \label{expfunc} - V(t; \tau, \Delta V, V_{\infty}) = \Delta V e^{-t/\tau} + V_{\infty} -\end{equation} -with three free parameters $\tau$, $\Delta y$, $y_{\infty}$ to the -measured time course of the membrane potential $V(t)$. The $(x_i,y_i)$ -data pairs are the sampling times $t_i$ and the corresponding -measurements of the membrane potential $V_i$. - -\section{Summary} +\section{Fitting non-linear functions to data} The gradient descent is an important numerical method for solving optimization problems. It is used to find the global minimum of an @@ -530,33 +554,44 @@ objective function. Curve fitting is a common application for the gradient descent method. For the case of fitting straight lines to data pairs, the error surface (using the mean squared error) has exactly one clearly defined -global minimum. In fact, the position of the minimum can be analytically -calculated as shown in the next chapter. - -Problems that involve nonlinear computations on parameters, e.g. the -rate $\lambda$ in an exponential function $f(x;\lambda) = e^{\lambda - x}$, do not have an analytical solution for the least squares. To -find the least squares for such functions numerical methods such as -the gradient descent have to be applied. - -The suggested gradient descent algorithm can be improved in multiple -ways to converge faster. For example one could adapt the step size to -the length of the gradient. These numerical tricks have already been -implemented in pre-defined functions. Generic optimization functions -such as \matlabfun{fminsearch()} have been implemented for arbitrary -objective functions, while the more specialized function -\matlabfun{lsqcurvefit()} i specifically designed for optimizations in -the least square error sense. - -%\newpage +global minimum. In fact, the position of the minimum can be +analytically calculated as shown in the next chapter. For linear +fitting problems numerical methods like the gradient descent are not +needed. + +Fitting problems that involve nonlinear functions of the parameters, +e.g. the power law \eqref{powerfunc} or the exponential function +$f(x;\lambda) = e^{\lambda x}$, do not have an analytical solution for +the least squares. To find the least squares for such functions +numerical methods such as the gradient descent have to be applied. + +The suggested gradient descent algorithm is quite fragile and requires +manually tuned values for $\epsilon$ and the threshold for terminating +the iteration. The algorithm can be improved in multiple ways to +converge more robustly and faster. For example one could adapt the +step size to the length of the gradient. These numerical tricks have +already been implemented in pre-defined functions. Generic +optimization functions such as \mcode{fminsearch()} have been +implemented for arbitrary objective functions, while the more +specialized function \mcode{lsqcurvefit()} is specifically designed +for optimizations in the least square error sense. + +\begin{exercise}{plotlsqcurvefitpower.m}{} + Use the \matlab-function \varcode{lsqcurvefit()} instead of + \varcode{gradientDescent()} to fit the \varcode{powerLaw()} function + to the simulated data from exercise~\ref{mseexercise}. Plot the data + and the resulting best fitting power law function. +\end{exercise} + + \begin{important}[Beware of secondary minima!] Finding the absolute minimum is not always as easy as in the case of - fitting a straight line. Often, the error surface has secondary or + fitting a straight line. Often, the cost function has secondary or local minima in which the gradient descent stops even though there is a more optimal solution, a global minimum that is lower than the local minimum. Starting from good initial positions is a good approach to avoid getting stuck in local minima. Also keep in mind - that error surfaces tend to be simpler (less local minima) the fewer + that cost functions tend to be simpler (less local minima) the fewer parameters are fitted from the data. Each additional parameter increases complexity and is computationally more expensive. \end{important} From dea6319e7553d9b9f6b150938c825e5a69db1dc8 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 20 Dec 2020 01:05:02 +0100 Subject: [PATCH 36/37] [regression] finished chapter --- regression/code/meanSquaredErrorCubic.m | 4 +- regression/lecture/cubiccost.py | 2 +- regression/lecture/cubicerrors.py | 4 +- regression/lecture/cubicfunc.py | 4 +- regression/lecture/cubicmse.py | 2 +- regression/lecture/error_surface.py | 56 ---------------- regression/lecture/lin_regress.py | 60 ----------------- regression/lecture/linear_least_squares.py | 65 ------------------ regression/lecture/regression-chapter.tex | 35 ---------- regression/lecture/regression.tex | 76 +++++++++++++++------- 10 files changed, 61 insertions(+), 247 deletions(-) delete mode 100644 regression/lecture/error_surface.py delete mode 100644 regression/lecture/lin_regress.py delete mode 100644 regression/lecture/linear_least_squares.py diff --git a/regression/code/meanSquaredErrorCubic.m b/regression/code/meanSquaredErrorCubic.m index 44870a1..8953d50 100644 --- a/regression/code/meanSquaredErrorCubic.m +++ b/regression/code/meanSquaredErrorCubic.m @@ -1,8 +1,8 @@ function mse = meanSquaredErrorCubic(x, y, c) % Mean squared error between data pairs and a cubic relation. % -% Arguments: x, vector of the input values -% y, vector of the corresponding measured output values +% Arguments: x, vector of the x-data values +% y, vector of the corresponding y-data values % c, the factor for the cubic relation. % % Returns: mse, the mean-squared-error. diff --git a/regression/lecture/cubiccost.py b/regression/lecture/cubiccost.py index 30d9575..ac145fa 100644 --- a/regression/lecture/cubiccost.py +++ b/regression/lecture/cubiccost.py @@ -75,7 +75,7 @@ def plot_mse_min(ax, x, y, c): if __name__ == "__main__": x, y, c = create_data() fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 1.1*figure_height)) - fig.subplots_adjust(**adjust_fs(left=8.0, right=1)) + fig.subplots_adjust(**adjust_fs(left=8.0, right=1.2)) plot_mse(ax1, x, y, c) plot_mse_min(ax2, x, y, c) fig.savefig("cubiccost.pdf") diff --git a/regression/lecture/cubicerrors.py b/regression/lecture/cubicerrors.py index 86e608f..d74c3bf 100644 --- a/regression/lecture/cubicerrors.py +++ b/regression/lecture/cubicerrors.py @@ -58,8 +58,8 @@ def plot_error_hist(ax, x, y, c): if __name__ == "__main__": x, y, c = create_data() - fig, (ax1, ax2) = plt.subplots(1, 2) - fig.subplots_adjust(wspace=0.4, **adjust_fs(left=6.0, right=1.2)) + fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 0.9*figure_height)) + fig.subplots_adjust(wspace=0.5, **adjust_fs(left=6.0, right=1.2)) plot_data_errors(ax1, x, y, c) plot_error_hist(ax2, x, y, c) fig.savefig("cubicerrors.pdf") diff --git a/regression/lecture/cubicfunc.py b/regression/lecture/cubicfunc.py index 8b5b44a..3b34c03 100644 --- a/regression/lecture/cubicfunc.py +++ b/regression/lecture/cubicfunc.py @@ -42,8 +42,8 @@ def plot_data_fac(ax, x, y, c): if __name__ == "__main__": x, y, c = create_data() print('n=%d' % len(x)) - fig, (ax1, ax2) = plt.subplots(1, 2) - fig.subplots_adjust(wspace=0.5, **adjust_fs(fig, left=6.0, right=1.5)) + fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 0.9*figure_height)) + fig.subplots_adjust(wspace=0.5, **adjust_fs(fig, left=6.0, right=1.2)) plot_data(ax1, x, y) plot_data_fac(ax2, x, y, c) fig.savefig("cubicfunc.pdf") diff --git a/regression/lecture/cubicmse.py b/regression/lecture/cubicmse.py index 55ac64b..0d956c5 100644 --- a/regression/lecture/cubicmse.py +++ b/regression/lecture/cubicmse.py @@ -73,7 +73,7 @@ if __name__ == "__main__": x, y, c = create_data() cs, mses = gradient_descent(x, y) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 1.1*figure_height)) - fig.subplots_adjust(wspace=0.2, **adjust_fs(left=8.0, right=0.5)) + fig.subplots_adjust(**adjust_fs(left=8.0, right=1.2)) plot_mse(ax1, x, y, c, cs) plot_descent(ax2, cs, mses) fig.savefig("cubicmse.pdf") diff --git a/regression/lecture/error_surface.py b/regression/lecture/error_surface.py deleted file mode 100644 index da0d867..0000000 --- a/regression/lecture/error_surface.py +++ /dev/null @@ -1,56 +0,0 @@ -import numpy as np -from mpl_toolkits.mplot3d import Axes3D -import matplotlib.pyplot as plt -import matplotlib.cm as cm -from plotstyle import * - -def create_data(): - m = 0.75 - n= -40 - x = np.arange(10.,110., 2.5) - y = m * x + n; - rng = np.random.RandomState(37281) - noise = rng.randn(len(x))*15 - y += noise - return x, y, m, n - - -def plot_error_plane(ax, x, y, m, n): - ax.set_xlabel('Slope m') - ax.set_ylabel('Intercept b') - ax.set_zlabel('Mean squared error') - ax.set_xlim(-4.5, 5.0) - ax.set_ylim(-60.0, -20.0) - ax.set_zlim(0.0, 700.0) - ax.set_xticks(np.arange(-4, 5, 2)) - ax.set_yticks(np.arange(-60, -19, 10)) - ax.set_zticks(np.arange(0, 700, 200)) - ax.grid(True) - ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) - ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) - ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0)) - ax.invert_xaxis() - ax.view_init(25, 40) - slopes = np.linspace(-4.5, 5, 40) - intercepts = np.linspace(-60, -20, 40) - x, y = np.meshgrid(slopes, intercepts) - error_surf = np.zeros(x.shape) - for i, s in enumerate(slopes) : - for j, b in enumerate(intercepts) : - error_surf[j,i] = np.mean((y-s*x-b)**2.0) - ax.plot_surface(x, y, error_surf, rstride=1, cstride=1, cmap=cm.coolwarm, - linewidth=0, shade=True) - # Minimum: - mini = np.unravel_index(np.argmin(error_surf), error_surf.shape) - ax.scatter(slopes[mini[1]], intercepts[mini[0]], [0.0], color='#cc0000', s=60) - - -if __name__ == "__main__": - x, y, m, n = create_data() - fig = plt.figure() - ax = fig.add_subplot(1, 1, 1, projection='3d') - plot_error_plane(ax, x, y, m, n) - fig.set_size_inches(7., 5.) - fig.subplots_adjust(**adjust_fs(fig, 1.0, 0.0, 0.0, 0.0)) - fig.savefig("error_surface.pdf") - plt.close() diff --git a/regression/lecture/lin_regress.py b/regression/lecture/lin_regress.py deleted file mode 100644 index ae854d5..0000000 --- a/regression/lecture/lin_regress.py +++ /dev/null @@ -1,60 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from plotstyle import * - -def create_data(): - m = 0.75 - n= -40 - x = np.arange(10.,110., 2.5) - y = m * x + n; - rng = np.random.RandomState(37281) - noise = rng.randn(len(x))*15 - y += noise - return x, y, m, n - - -def plot_data(ax, x, y): - ax.plot(x, y, **psA) - ax.set_xlabel('Input x') - ax.set_ylabel('Output y') - ax.set_xlim(0, 120) - ax.set_ylim(-80, 80) - ax.set_xticks(np.arange(0,121, 40)) - ax.set_yticks(np.arange(-80,81, 40)) - - -def plot_data_slopes(ax, x, y, m, n): - ax.plot(x, y, **psA) - xx = np.asarray([2, 118]) - for i in np.linspace(0.3*m, 2.0*m, 5): - ax.plot(xx, i*xx+n, **lsBm) - ax.set_xlabel('Input x') - #ax.set_ylabel('Output y') - ax.set_xlim(0, 120) - ax.set_ylim(-80, 80) - ax.set_xticks(np.arange(0,121, 40)) - ax.set_yticks(np.arange(-80,81, 40)) - - -def plot_data_intercepts(ax, x, y, m, n): - ax.plot(x, y, **psA) - xx = np.asarray([2, 118]) - for i in np.linspace(n-1*n, n+1*n, 5): - ax.plot(xx, m*xx + i, **lsBm) - ax.set_xlabel('Input x') - #ax.set_ylabel('Output y') - ax.set_xlim(0, 120) - ax.set_ylim(-80, 80) - ax.set_xticks(np.arange(0,121, 40)) - ax.set_yticks(np.arange(-80,81, 40)) - - -if __name__ == "__main__": - x, y, m, n = create_data() - fig, axs = plt.subplots(1, 3) - fig.subplots_adjust(wspace=0.5, **adjust_fs(fig, left=6.0, right=1.5)) - plot_data(axs[0], x, y) - plot_data_slopes(axs[1], x, y, m, n) - plot_data_intercepts(axs[2], x, y, m, n) - fig.savefig("lin_regress.pdf") - plt.close() diff --git a/regression/lecture/linear_least_squares.py b/regression/lecture/linear_least_squares.py deleted file mode 100644 index d36fd32..0000000 --- a/regression/lecture/linear_least_squares.py +++ /dev/null @@ -1,65 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from plotstyle import * - -def create_data(): - m = 0.75 - n= -40 - x = np.concatenate( (np.arange(10.,110., 2.5), np.arange(0.,120., 2.0)) ) - y = m * x + n; - rng = np.random.RandomState(37281) - noise = rng.randn(len(x))*15 - y += noise - return x, y, m, n - - -def plot_data(ax, x, y, m, n): - ax.set_xlabel('Input x') - ax.set_ylabel('Output y') - ax.set_xlim(0, 120) - ax.set_ylim(-80, 80) - ax.set_xticks(np.arange(0,121, 40)) - ax.set_yticks(np.arange(-80,81, 40)) - ax.annotate('Error', - xy=(x[34]+1, y[34]+15), xycoords='data', - xytext=(80, -50), textcoords='data', ha='left', - arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0), - connectionstyle="angle3,angleA=50,angleB=-30") ) - ax.plot(x[:40], y[:40], zorder=0, **psAm) - inxs = [3, 13, 16, 19, 25, 34, 36] - ax.plot(x[inxs], y[inxs], zorder=10, **psA) - xx = np.asarray([2, 118]) - ax.plot(xx, m*xx+n, **lsBm) - for i in inxs : - xx = [x[i], x[i]] - yy = [m*x[i]+n, y[i]] - ax.plot(xx, yy, zorder=5, **lsDm) - - -def plot_error_hist(ax, x, y, m, n): - ax.set_xlabel('Squared error') - ax.set_ylabel('Frequency') - bins = np.arange(0.0, 602.0, 50.0) - ax.set_xlim(bins[0], bins[-1]) - ax.set_ylim(0, 35) - ax.set_xticks(np.arange(bins[0], bins[-1], 100)) - ax.set_yticks(np.arange(0, 36, 10)) - errors = (y-(m*x+n))**2.0 - mls = np.mean(errors) - ax.annotate('Mean\nsquared\nerror', - xy=(mls, 0.5), xycoords='data', - xytext=(350, 20), textcoords='data', ha='left', - arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2), - connectionstyle="angle3,angleA=10,angleB=90") ) - ax.hist(errors, bins, **fsD) - - - -if __name__ == "__main__": - x, y, m, n = create_data() - fig, axs = plt.subplots(1, 2) - fig.subplots_adjust(**adjust_fs(fig, left=6.0)) - plot_data(axs[0], x, y, m, n) - plot_error_hist(axs[1], x, y, m, n) - fig.savefig("linear_least_squares.pdf") - plt.close() diff --git a/regression/lecture/regression-chapter.tex b/regression/lecture/regression-chapter.tex index 2ca1ec2..45fdfda 100644 --- a/regression/lecture/regression-chapter.tex +++ b/regression/lecture/regression-chapter.tex @@ -23,47 +23,12 @@ \item Fig 8.2 right: this should be a chi-squared distribution with one degree of freedom! \end{itemize} -\begin{figure}[t] - \includegraphics[width=0.75\textwidth]{error_surface} - \titlecaption{Error surface.}{The two model parameters $m$ and $b$ - define the base area of the surface plot. For each parameter - combination of slope and intercept the error is calculated. The - resulting surface has a minimum which indicates the parameter - combination that best fits the data.}\label{errorsurfacefig} -\end{figure} - - -\begin{figure}[t] - \includegraphics[width=0.75\textwidth]{error_gradient} - \titlecaption{Gradient of the error surface.} {Each arrow points - into the direction of the greatest ascend at different positions - of the error surface shown in \figref{errorsurfacefig}. The - contour lines in the background illustrate the error surface. Warm - colors indicate high errors, colder colors low error values. Each - contour line connects points of equal - error.}\label{gradientquiverfig} -\end{figure} - -\begin{figure}[t] - \includegraphics[width=0.45\textwidth]{gradient_descent} - \titlecaption{Gradient descent.}{The algorithm starts at an - arbitrary position. At each point the gradient is estimated and - the position is updated as long as the length of the gradient is - sufficiently large.The dots show the positions after each - iteration of the algorithm.} \label{gradientdescentfig} -\end{figure} - - \subsection{Linear fits} \begin{itemize} \item Polyfit is easy: unique solution! $c x^2$ is also a linear fit. \item Example for overfitting with polyfit of a high order (=number of data points) \end{itemize} -\section{Fitting in practice} - -Fit with matlab functions lsqcurvefit, polyfit - \subsection{Non-linear fits} \begin{itemize} diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 36e1808..2db6a31 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -227,6 +227,7 @@ to arbitrary precision. \end{ibox} \section{Gradient} + Imagine to place a ball at some point on the cost function \figref{cubiccostfig}. Naturally, it would roll down the slope and eventually stop at the minimum of the error surface (if it had no @@ -235,10 +236,21 @@ way to the minimum of the cost function. The ball always follows the steepest slope. Thus we need to figure out the direction of the slope at the position of the ball. +\begin{figure}[t] + \includegraphics{cubicgradient} + \titlecaption{Derivative of the cost function.}{The gradient, the + derivative \eqref{costderivative} of the cost function, is + negative to the left of the minimum of the cost function, zero at, + and positive to the right of the minimum (left). For each value of + the parameter $c$ the negative gradient (arrows) points towards + the minimum of the cost function + (right).} \label{gradientcubicfig} +\end{figure} + In our one-dimensional example of a single free parameter the slope is simply the derivative of the cost function with respect to the -parameter $c$. This derivative is called the -\entermde{Gradient}{gradient} of the cost function: +parameter $c$ (\figref{gradientcubicfig}, left). This derivative is called +the \entermde{Gradient}{gradient} of the cost function: \begin{equation} \label{costderivative} \nabla f_{cost}(c) = \frac{{\rm d} f_{cost}(c)}{{\rm d} c} @@ -252,7 +264,8 @@ can be approximated numerically by the difference quotient \approx \frac{f_{cost}(c + \Delta c) - f_{cost}(c)}{\Delta c} \end{equation} The derivative is positive for positive slopes. Since want to go down -the hill, we choose the opposite direction. +the hill, we choose the opposite direction (\figref{gradientcubicfig}, +right). \begin{exercise}{meanSquaredGradientCubic.m}{}\label{gradientcubic} Implement a function \varcode{meanSquaredGradientCubic()}, that @@ -275,7 +288,7 @@ the hill, we choose the opposite direction. \titlecaption{Gradient descent.}{The algorithm starts at an arbitrary position. At each point the gradient is estimated and the position is updated as long as the length of the gradient is - sufficiently large.The dots show the positions after each + sufficiently large. The dots show the positions after each iteration of the algorithm.} \label{gradientdescentcubicfig} \end{figure} @@ -378,18 +391,18 @@ functions that have more than a single parameter, in general $n$ parameters. We then need to find the minimum in an $n$ dimensional parameter space. -For our tiger problem, we could have also fitted the exponent $\alpha$ -of the power-law relation between size and weight, instead of assuming -a cubic relation with $\alpha=3$: +For our tiger problem, we could have also fitted the exponent $a$ of +the power-law relation between size and weight, instead of assuming a +cubic relation with $a=3$: \begin{equation} \label{powerfunc} - y = f(x; c, \alpha) = f(x; \vec p) = c\cdot x^\alpha + y = f(x; c, a) = f(x; \vec p) = c\cdot x^a \end{equation} We then could check whether the resulting estimate of the exponent -$\alpha$ indeed is close to the expected power of three. The -power-law \eqref{powerfunc} has two free parameters $c$ and $\alpha$. +$a$ indeed is close to the expected power of three. The +power-law \eqref{powerfunc} has two free parameters $c$ and $a$. Instead of a single parameter we are now dealing with a vector $\vec -p$ containing $n$ parameter values. Here, $\vec p = (c, \alpha)$. All +p$ containing $n$ parameter values. Here, $\vec p = (c, a)$. All the concepts we introduced on the example of the one dimensional problem of tiger weights generalize to $n$-dimensional problems. We only need to adapt a few things. The cost function for the mean @@ -399,12 +412,27 @@ squared error reads f_{cost}(\vec p|\{(x_i, y_i)\}) = \frac{1}{N} \sum_{i=1}^N (y_i - f(x_i;\vec p))^2 \end{equation} +\begin{figure}[t] + \includegraphics{powergradientdescent} + \titlecaption{Gradient descent on an error surface.}{Contour plot of + the cost function \eqref{ndimcostfunc} for the fit of a power law + \eqref{powerfunc} to some data. Here the cost function is a long + and narrow valley on the plane spanned by the two parameters $c$ + and $a$ of the power law. The red line marks the path of the + gradient descent algorithm. The gradient is always perpendicular + to the contour lines. The algorithm quickly descends into the + valley and then slowly creeps on the shallow bottom of the valley + towards the global minimum where it terminates (yellow circle). + } \label{powergradientdescentfig} +\end{figure} + For two-dimensional problems the graph of the cost function is an \enterm{error surface} (\determ{{Fehlerfl\"ache}}). The two parameters span a two-dimensional plane. The cost function assigns to each parameter combination on this plane a single value. This results in a landscape over the parameter plane with mountains and valleys and we -are searching for the position of the bottom of the deepest valley. +are searching for the position of the bottom of the deepest valley +(\figref{powergradientdescentfig}). \begin{ibox}[tp]{\label{partialderivativebox}Partial derivatives and gradient} Some functions depend on more than a single variable. For example, the function @@ -446,13 +474,13 @@ space of our example, the \entermde{Gradient}{gradient} (box~\ref{partialderivativebox}) of the cost function is a vector \begin{equation} \label{gradientpowerlaw} - \nabla f_{cost}(c, \alpha) = \left( \frac{\partial f_{cost}(c, \alpha)}{\partial c}, - \frac{\partial f_{cost}(c, \alpha)}{\partial \alpha} \right) + \nabla f_{cost}(c, a) = \left( \frac{\partial f_{cost}(c, a)}{\partial c}, + \frac{\partial f_{cost}(c, a)}{\partial a} \right) \end{equation} that points into the direction of the strongest ascend of the cost function. The gradient is given by the partial derivatives (box~\ref{partialderivativebox}) of the mean squared error with -respect to the parameters $c$ and $\alpha$ of the power law +respect to the parameters $c$ and $a$ of the power law relation. In general, for $n$-dimensional problems, the gradient is an $n-$ dimensional vector containing for each of the $n$ parameters $p_j$ the respective partial derivatives as coordinates: @@ -468,6 +496,9 @@ parameter value $p_i$ becomes a vector $\vec p_i$ of parameter values: \label{ndimgradientdescent} \vec p_{i+1} = \vec p_i - \epsilon \cdot \nabla f_{cost}(\vec p_i) \end{equation} +The algorithm proceeds along the negative gradient +(\figref{powergradientdescentfig}). + For the termination condition we need the length of the gradient. In one dimension it was just the absolute value of the derivative. For $n$ dimensions this is according to the \enterm{Pythagorean theorem} @@ -479,8 +510,7 @@ the sum of the squared partial derivatives: \end{equation} The \code{norm()} function implements this. - -\section{Passing a function as an argument to another function} +\subsection{Passing a function as an argument to another function} So far, all our code for the gradient descent algorithm was tailored to a specific function, the cubic relation \eqref{cubicfunc}. It would @@ -500,7 +530,7 @@ argument to our function: \pageinputlisting[caption={Passing a function handle as an argument to a function.}]{funcplotterexamples.m} -\section{Gradient descent algorithm for arbitrary functions} +\subsection{Gradient descent algorithm for arbitrary functions} Now we are ready to adapt the gradient descent algorithm from exercise~\ref{gradientdescentexercise} to arbitrary functions with $n$ @@ -524,21 +554,21 @@ For testing our new function we need to implement the power law Write a function that implements \eqref{powerfunc}. The function gets as arguments a vector $x$ containing the $x$-data values and another vector containing as elements the parameters for the power - law, i.e. the factor $c$ and the power $\alpha$. It returns a vector + law, i.e. the factor $c$ and the power $a$. It returns a vector with the computed $y$ values for each $x$ value. \end{exercise} Now let's use the new gradient descent function to fit a power law to -our tiger data-set: +our tiger data-set (\figref{powergradientdescentfig}): \begin{exercise}{plotgradientdescentpower.m}{} Use the function \varcode{gradientDescent()} to fit the \varcode{powerLaw()} function to the simulated data from exercise~\ref{mseexercise}. Plot the returned values of the two parameters against each other. Compare the result of the gradient - descent method with the true values of $c$ and $\alpha$ used to - simulate the data. Observe the norm of the gradient and inspect the - plots to adapt $\epsilon$ (smaller than in + descent method with the true values of $c$ and $a$ used to simulate + the data. Observe the norm of the gradient and inspect the plots to + adapt $\epsilon$ (smaller than in exercise~\ref{plotgradientdescentexercise}) and the threshold (much larger) appropriately. Finally plot the data together with the best fitting power-law \eqref{powerfunc}. From 17bf940101e651cb235be5baa513d09f75723067 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Sun, 20 Dec 2020 13:15:40 +0100 Subject: [PATCH 37/37] [regression] smaller steps for derivative --- regression/code/gradientDescent.m | 2 +- regression/code/meanSquaredGradientCubic.m | 2 +- regression/code/plotcubicgradient.m | 2 ++ regression/code/plotgradientdescentcubic.m | 4 +-- regression/code/plotgradientdescentpower.m | 4 +-- regression/lecture/regression.tex | 29 +++++++++++----------- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/regression/code/gradientDescent.m b/regression/code/gradientDescent.m index 48b976c..20e0b90 100644 --- a/regression/code/gradientDescent.m +++ b/regression/code/gradientDescent.m @@ -30,7 +30,7 @@ end function gradmse = meanSquaredGradient(x, y, func, p) gradmse = zeros(size(p, 1), size(p, 2)); - h = 1e-5; % stepsize for derivatives + h = 1e-7; % stepsize for derivatives mse = meanSquaredError(x, y, func, p); for i = 1:length(p) % for each coordinate ... pi = p; diff --git a/regression/code/meanSquaredGradientCubic.m b/regression/code/meanSquaredGradientCubic.m index a7ff6a2..99d5b3b 100644 --- a/regression/code/meanSquaredGradientCubic.m +++ b/regression/code/meanSquaredGradientCubic.m @@ -7,7 +7,7 @@ function dmsedc = meanSquaredGradientCubic(x, y, c) % % Returns: the derivative of the mean squared error at c. - h = 1e-5; % stepsize for derivatives + h = 1e-7; % stepsize for derivatives mse = meanSquaredErrorCubic(x, y, c); mseh = meanSquaredErrorCubic(x, y, c+h); dmsedc = (mseh - mse)/h; diff --git a/regression/code/plotcubicgradient.m b/regression/code/plotcubicgradient.m index 0410b1f..d00bf6e 100644 --- a/regression/code/plotcubicgradient.m +++ b/regression/code/plotcubicgradient.m @@ -1,3 +1,5 @@ +meansquarederrorline; % generate data + cs = 2.0:0.1:8.0; mseg = zeros(length(cs)); for i = 1:length(cs) diff --git a/regression/code/plotgradientdescentcubic.m b/regression/code/plotgradientdescentcubic.m index 6ac54af..6aadc12 100644 --- a/regression/code/plotgradientdescentcubic.m +++ b/regression/code/plotgradientdescentcubic.m @@ -1,8 +1,8 @@ meansquarederrorline; % generate data c0 = 2.0; -eps = 0.0001; -thresh = 0.1; +eps = 0.00001; +thresh = 1.0; [cest, cs, mses] = gradientDescentCubic(x, y, c0, eps, thresh); subplot(2, 2, 1); % top left panel diff --git a/regression/code/plotgradientdescentpower.m b/regression/code/plotgradientdescentpower.m index 206e2bb..2d2a08f 100644 --- a/regression/code/plotgradientdescentpower.m +++ b/regression/code/plotgradientdescentpower.m @@ -2,7 +2,7 @@ meansquarederrorline; % generate data p0 = [2.0, 1.0]; eps = 0.00001; -thresh = 50.0; +thresh = 1.0; [pest, ps, mses] = gradientDescent(x, y, @powerLaw, p0, eps, thresh); pest @@ -28,5 +28,3 @@ plot(x, y, 'o'); % plot original data xlabel('Size [m]'); ylabel('Weight [kg]'); legend('fit', 'data', 'location', 'northwest'); -pause - diff --git a/regression/lecture/regression.tex b/regression/lecture/regression.tex index 2db6a31..bfff7bb 100644 --- a/regression/lecture/regression.tex +++ b/regression/lecture/regression.tex @@ -240,11 +240,11 @@ at the position of the ball. \includegraphics{cubicgradient} \titlecaption{Derivative of the cost function.}{The gradient, the derivative \eqref{costderivative} of the cost function, is - negative to the left of the minimum of the cost function, zero at, - and positive to the right of the minimum (left). For each value of - the parameter $c$ the negative gradient (arrows) points towards - the minimum of the cost function - (right).} \label{gradientcubicfig} + negative to the left of the minimum (vertical line) of the cost + function, zero (horizontal line) at, and positive to the right of + the minimum (left). For each value of the parameter $c$ the + negative gradient (arrows) points towards the minimum of the cost + function (right).} \label{gradientcubicfig} \end{figure} In our one-dimensional example of a single free parameter the slope is @@ -263,9 +263,9 @@ can be approximated numerically by the difference quotient \lim\limits_{\Delta c \to 0} \frac{f_{cost}(c + \Delta c) - f_{cost}(c)}{\Delta c} \approx \frac{f_{cost}(c + \Delta c) - f_{cost}(c)}{\Delta c} \end{equation} -The derivative is positive for positive slopes. Since want to go down -the hill, we choose the opposite direction (\figref{gradientcubicfig}, -right). +Choose, for example, $\Delta c = 10^{-7}$. The derivative is positive +for positive slopes. Since want to go down the hill, we choose the +opposite direction (\figref{gradientcubicfig}, right). \begin{exercise}{meanSquaredGradientCubic.m}{}\label{gradientcubic} Implement a function \varcode{meanSquaredGradientCubic()}, that @@ -361,7 +361,7 @@ The $\epsilon$ parameter in \eqnref{gradientdescent} is critical. If too large, the algorithm does not converge to the minimum of the cost function (try it!). At medium values it oscillates around the minimum but might nevertheless converge. Only for sufficiently small values -(here $\epsilon = 0.0001$) does the algorithm follow the slope +(here $\epsilon = 0.00001$) does the algorithm follow the slope downwards towards the minimum. The terminating condition on the absolute value of the gradient @@ -373,7 +373,7 @@ to the increased computational effort. Have a look at the derivatives that we plotted in exercise~\ref{gradientcubic} and decide on a sensible value for the threshold. Run the gradient descent algorithm and check how the resulting $c$ parameter values converge and how many -iterations were needed. The reduce the threshold (by factors of ten) +iterations were needed. Then reduce the threshold (by factors of ten) and check how this changes the results. Many modern algorithms for finding the minimum of a function are based @@ -508,7 +508,8 @@ the sum of the squared partial derivatives: \label{ndimabsgradient} |\nabla f_{cost}(\vec p_i)| = \sqrt{\sum_{i=1}^n \left(\frac{\partial f_{cost}(\vec p)}{\partial p_i}\right)^2} \end{equation} -The \code{norm()} function implements this. +The \code{norm()} function implements this given a vector with the +partial derivatives. \subsection{Passing a function as an argument to another function} @@ -568,10 +569,8 @@ our tiger data-set (\figref{powergradientdescentfig}): parameters against each other. Compare the result of the gradient descent method with the true values of $c$ and $a$ used to simulate the data. Observe the norm of the gradient and inspect the plots to - adapt $\epsilon$ (smaller than in - exercise~\ref{plotgradientdescentexercise}) and the threshold (much - larger) appropriately. Finally plot the data together with the best - fitting power-law \eqref{powerfunc}. + adapt $\epsilon$ and the threshold if necessary. Finally plot the + data together with the best fitting power-law \eqref{powerfunc}. \end{exercise}