├── 0point4.png ├── Console.png ├── Spanner.png ├── L5testfig.pdf ├── WAfricanEVD.pdf ├── WAfricanEVD.png ├── wkpda_EVDtableofcases.png ├── Week1_Lecture2_1-JuliaBox.png ├── Week1_Lecture2_2-Notebook.png ├── WAfricanEVD_noformatspecified.png ├── Week2_Lecture2_1-Wikipedia-EVD-cases.png ├── Week2_Lecture2_2-Wikipedia-EVD-data.png ├── .gitattributes ├── .gitignore ├── README.md ├── style.css ├── wikipediaEVDdatesconverted.csv ├── wikipediaEVDraw.csv ├── GadflyTutorialData.csv ├── Week 3_Peer graded quiz on Types.ipynb ├── .ipynb_checkpoints ├── Week 3_Peer graded quiz on Types-checkpoint.ipynb ├── Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb └── Week 4_Peer graded quiz on data-checkpoint.ipynb ├── Week 4_Peer graded quiz on Gadfly.ipynb ├── CCS.csv ├── Week2_2_2_CreateCSV.ipynb ├── Week1_1-WhySpecial.ipynb ├── Week 4_Peer graded quiz on data.ipynb ├── Week2_2_1-LoadingData.ipynb ├── Week1_4-ArithmeticalExp.ipynb ├── Week2_1-EbolaExample.ipynb ├── Week1_2-JuliaBox.ipynb ├── Functions.ipynb ├── Week1_3-REPL.ipynb └── Week1_9-Functions2.ipynb /0point4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/0point4.png -------------------------------------------------------------------------------- /Console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Console.png -------------------------------------------------------------------------------- /Spanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Spanner.png -------------------------------------------------------------------------------- /L5testfig.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/L5testfig.pdf -------------------------------------------------------------------------------- /WAfricanEVD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/WAfricanEVD.pdf -------------------------------------------------------------------------------- /WAfricanEVD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/WAfricanEVD.png -------------------------------------------------------------------------------- /wkpda_EVDtableofcases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/wkpda_EVDtableofcases.png -------------------------------------------------------------------------------- /Week1_Lecture2_1-JuliaBox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Week1_Lecture2_1-JuliaBox.png -------------------------------------------------------------------------------- /Week1_Lecture2_2-Notebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Week1_Lecture2_2-Notebook.png -------------------------------------------------------------------------------- /WAfricanEVD_noformatspecified.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/WAfricanEVD_noformatspecified.png -------------------------------------------------------------------------------- /Week2_Lecture2_1-Wikipedia-EVD-cases.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Week2_Lecture2_1-Wikipedia-EVD-cases.png -------------------------------------------------------------------------------- /Week2_Lecture2_2-Wikipedia-EVD-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juanklopper/JuliaCourseNotebooks/HEAD/Week2_Lecture2_2-Wikipedia-EVD-data.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JuliaCourseNotebooks 2 | 3 | Jupyter notebooks and Juno .jl files for the Julia Scientific Programming course on Coursera 4 | 5 | The recently released version 1.0 of Julia marked a milestone in the development of the language. Julia has been a rapidly evolving language. This creates challenges when teaching Julia. Over the next few weeks and month the course code will be adapted to comply with the changes introduced in Julia 1.0 (0.7). 6 | 7 | **Juno** is the integrated development environment (IDE) choice for Julia. It is built on the Atom IDE. As of the time of writing of this README file, Julia Computing still releases version 0.6.4 of Julia. To use Julia 1.0, dowload it from https://julialang.org. Also dowload Atom from https://atom.io In Atom hit the CONTROL key (or COMMAND key on a Mac) and the comma key. This brings up the settings. Under the Install tab search for *uber-juno* which will install the Julia interface for Atom. When this is done, also add the address to the julia 1.0 executable on your computer. Restart ATOM. 8 | 9 | When creating a new file, save it first, explicitely using the .jl extension. This will tell Atom to use the Julia interface. Have a look at some of the new .jl files added to this repository. 10 | 11 | Julia Computing ( https://www.juliacomputing.com ) releases of Julia contains the Juno interface. We will let you know when the 1.0 release goes live. 12 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 81 | 82 | -------------------------------------------------------------------------------- /wikipediaEVDdatesconverted.csv: -------------------------------------------------------------------------------- 1 | 613,28637,11314,3804,2536,10675,4808,14122,3955 2 | 606,28634,11314,3804,2536,10672,4808,14122,3955 3 | 599,28635,11314,3805,2536,10672,4808,14122,3955 4 | 592,28607,11314,3810,2536,10672,4808,14089,3955 5 | 582,28539,11298,3806,2535,10672,4808,14061,3955 6 | 575,28476,11298,3803,2535,10672,4808,14001,3955 7 | 568,28454,11297,3800,2534,10672,4808,13982,3955 8 | 554,28388,11296,3805,2533,10672,4808,13911,3955 9 | 547,28295,11295,3800,2532,10672,4808,13823,3955 10 | 540,28220,11291,3792,2530,10672,4808,13756,3953 11 | 533,28147,11291,3792,2530,10672,4808,13683,3953 12 | 526,28073,11290,3792,2529,10672,4808,13609,3953 13 | 512,27952,11284,3786,2524,10672,4808,13494,3952 14 | 505,27929,11283,3787,2524,10672,4808,13470,3951 15 | 491,27748,11279,3786,2520,10672,4808,13290,3951 16 | 477,27642,11261,3760,2506,10673,4808,13209,3947 17 | 470,27573,11246,3748,2499,10670,4807,13155,3940 18 | 463,27514,11220,3729,2482,10666,4806,13119,3932 19 | 456,27443,11207,3718,2473,10666,4806,13059,3924 20 | 449,27305,11169,3674,2444,10666,4806,12965,3919 21 | 435,27110,11132,3652,2429,10666,4806,12827,3912 22 | 421,26898,11105,3635,2407,10666,4806,12632,3907 23 | 407,26558,10990,3589,2386,10564,4716,12440,3903 24 | 393,26009,10793,3565,2358,10212,4573,12267,3877 25 | 379,25480,10557,3515,2333,9862,4408,12138,3831 26 | 365,24837,10296,3429,2263,9602,4301,11841,3747 27 | 351,24282,9976,3285,2170,9343,4162,11619,3629 28 | 337,23659,9574,3155,2091,9238,4037,11301,3461 29 | 323,22824,9147,3044,1995,8881,3826,10934,3341 30 | 309,22022,8780,2917,1910,8622,3686,10518,3199 31 | 295,21226,8399,2806,1814,8331,3538,10124,3062 32 | 281,20171,7890,2707,1709,8018,3423,9446,2758 33 | 267,18565,7273,2415,1525,7819,3346,8356,2417 34 | 253,17110,6397,2164,1325,7653,3157,7312,1915 35 | 241,15291,5765,2047,1214,7082,2963,6190,1598 36 | 225,13015,5188,1731,1041,6525,2697,4759,1450 37 | 211,9911,4890,1540,926,4665,2705,3706,1259 38 | 204,8950,4476,1472,843,4249,2458,3252,1183 39 | 190,7169,3278,1157,710,3696,1998,2317,570 40 | 176,5327,2578,942,601,2720,1461,1655,516 41 | 162,3664,1794,771,494,1698,871,1216,436 42 | 147,2225,1225,543,394,834,466,848,365 43 | 140,1835,1011,506,373,599,323,730,315 44 | 130,1437,825,472,346,391,227,574,252 45 | 123,1201,672,427,319,249,129,525,224 46 | 114,982,613,411,310,174,106,397,197 47 | 102,779,481,412,305,115,75,252,101 48 | 87,528,337,398,264,33,24,97,49 49 | 66,309,202,281,186,12,11,16,5 50 | 51,260,182,248,171,12,11,–,– 51 | 40,239,160,226,149,13,11,-,- 52 | 23,176,110,168,108,8,2,–,– 53 | 9,130,82,122,80,8,2,–,– 54 | 0,49,29,49,29,–,–,–,– 55 | -------------------------------------------------------------------------------- /wikipediaEVDraw.csv: -------------------------------------------------------------------------------- 1 | 25 Nov 2015,28637,11314,3804,2536,10675,4808,14122,3955 2 | 18 Nov 2015,28634,11314,3804,2536,10672,4808,14122,3955 3 | 11 Nov 2015,28635,11314,3805,2536,10672,4808,14122,3955 4 | 4 Nov 2015,28607,11314,3810,2536,10672,4808,14089,3955 5 | 25 Oct 2015,28539,11298,3806,2535,10672,4808,14061,3955 6 | 18 Oct 2015,28476,11298,3803,2535,10672,4808,14001,3955 7 | 11 Oct 2015,28454,11297,3800,2534,10672,4808,13982,3955 8 | 27 Sep 2015,28388,11296,3805,2533,10672,4808,13911,3955 9 | 20 Sep 2015,28295,11295,3800,2532,10672,4808,13823,3955 10 | 13 Sep 2015,28220,11291,3792,2530,10672,4808,13756,3953 11 | 6 Sep 2015,28147,11291,3792,2530,10672,4808,13683,3953 12 | 30 Aug 2015,28073,11290,3792,2529,10672,4808,13609,3953 13 | 16 Aug 2015,27952,11284,3786,2524,10672,4808,13494,3952 14 | 9 Aug 2015,27929,11283,3787,2524,10672,4808,13470,3951 15 | 26 Jul 2015,27748,11279,3786,2520,10672,4808,13290,3951 16 | 12 Jul 2015,27642,11261,3760,2506,10673,4808,13209,3947 17 | 5 Jul 2015,27573,11246,3748,2499,10670,4807,13155,3940 18 | 28 Jun 2015,27514,11220,3729,2482,10666,4806,13119,3932 19 | 21 Jun 2015,27443,11207,3718,2473,10666,4806,13059,3924 20 | 14 Jun 2015,27305,11169,3674,2444,10666,4806,12965,3919 21 | 31 May 2015,27110,11132,3652,2429,10666,4806,12827,3912 22 | 17 May 2015,26898,11105,3635,2407,10666,4806,12632,3907 23 | 3 May 2015,26558,10990,3589,2386,10564,4716,12440,3903 24 | 19 Apr 2015,26009,10793,3565,2358,10212,4573,12267,3877 25 | 5 Apr 2015,25480,10557,3515,2333,9862,4408,12138,3831 26 | 22 Mar 2015,24837,10296,3429,2263,9602,4301,11841,3747 27 | 8 Mar 2015,24282,9976,3285,2170,9343,4162,11619,3629 28 | 22 Feb 2015,23659,9574,3155,2091,9238,4037,11301,3461 29 | 8 Feb 2015,22824,9147,3044,1995,8881,3826,10934,3341 30 | 25 Jan 2015,22022,8780,2917,1910,8622,3686,10518,3199 31 | 11 Jan 2015,21226,8399,2806,1814,8331,3538,10124,3062 32 | 28 Dec 2014,20171,7890,2707,1709,8018,3423,9446,2758 33 | 14 Dec 2014,18565,7273,2415,1525,7819,3346,8356,2417 34 | 30 Nov 2014,17110,6397,2164,1325,7653,3157,7312,1915 35 | 18 Nov 2014,15291,5765,2047,1214,7082,2963,6190,1598 36 | 2 Nov 2014,13015,5188,1731,1041,6525,2697,4759,1450 37 | 19 Oct 2014,9911,4890,1540,926,4665,2705,3706,1259 38 | 12 Oct 2014,8950,4476,1472,843,4249,2458,3252,1183 39 | 28 Sep 2014,7169,3278,1157,710,3696,1998,2317,570 40 | 14 Sep 2014,5327,2578,942,601,2720,1461,1655,516 41 | 31 Aug 2014,3664,1794,771,494,1698,871,1216,436 42 | 16 Aug 2014,2225,1225,543,394,834,466,848,365 43 | 9 Aug 2014,1835,1011,506,373,599,323,730,315 44 | 30 Jul 2014,1437,825,472,346,391,227,574,252 45 | 23 Jul 2014,1201,672,427,319,249,129,525,224 46 | 14 Jul 2014,982,613,411,310,174,106,397,197 47 | 2 Jul 2014,779,481,412,305,115,75,252,101 48 | 17 Jun 2014,528,337,398,264,33,24,97,49 49 | 27 May 2014,309,202,281,186,12,11,16,5 50 | 12 May 2014,260,182,248,171,12,11,–,– 51 | 1 May 2014,239,160,226,149,13,11,-,- 52 | 14 Apr 2014,176,110,168,108,8,2,–,– 53 | 31 Mar 2014,130,82,122,80,8,2,–,– 54 | 22 Mar 2014,49,29,49,29,–,–,–,– 55 | -------------------------------------------------------------------------------- /GadflyTutorialData.csv: -------------------------------------------------------------------------------- 1 | Patient,Gender,Age,Variable1,Variable2,Variable3,Variable4,Category1,Category2,Category3 1,F,37,22.3,104,5.3,64,A,C,P 2,F,55,12.1,84,12.7,58,B,X,Q 3,M,44,15.6,101,6.9,68,A,R,Q 4,F,54,20.8,111,14.8,54,B,C,R 5,M,41,21.5,106,25.1,50,A,X,P 6,F,51,14.7,112,14.1,70,B,R,R 7,M,42,18.7,99,0.3,63,A,C,P 8,M,50,22.1,102,5.7,62,B,X,R 9,M,50,11.6,114,12,64,A,R,P 10,F,55,18.9,107,7.8,54,B,C,P 11,F,37,9.5,109,12.8,58,A,X,Q 12,F,36,11.1,102,0.5,53,B,R,Q 13,M,45,13.4,95,6.7,62,A,C,R 14,F,54,9.1,69,11.2,50,B,X,P 15,M,38,16,105,4.9,62,A,R,R 16,F,35,14.7,106,3.8,56,B,C,P 17,M,44,10.4,102,8.3,50,A,X,R 18,M,47,23.6,100,23.6,65,B,R,P 19,M,55,8.6,109,9.2,66,A,C,P 20,F,46,10.4,86,4.9,66,B,X,Q 21,F,38,11.8,91,5.9,55,A,R,Q 22,F,51,16.5,106,5,62,B,C,R 23,M,36,20,103,8.1,70,A,X,P 24,F,55,23.8,95,3.2,64,B,R,R 25,M,48,14.4,101,3.3,67,A,C,P 26,F,51,11.7,93,11.9,67,B,X,R 27,M,37,18.5,99,9.8,55,A,R,P 28,M,40,14.9,94,9.2,53,B,C,P 29,M,51,19.8,97,57.9,63,A,X,Q 30,F,35,10.6,97,3.9,60,B,R,Q 31,F,43,23.6,99,3.4,60,A,C,R 32,F,53,21.1,92,22,66,B,X,P 33,M,45,13.9,119,18.4,51,A,R,R 34,F,42,15.7,101,20.7,64,B,C,P 35,M,52,24.7,84,19.8,68,A,X,R 36,F,35,12.6,95,1.3,55,B,R,P 37,M,42,16.4,106,18.1,59,A,C,P 38,M,49,18.4,120,5.9,54,B,X,Q 39,M,47,13.4,98,19.6,61,A,R,Q 40,F,55,20.5,88,0.3,68,B,C,R 41,F,38,13.8,101,11.5,61,A,X,P 42,F,54,10.3,110,17.2,50,B,R,R 43,M,39,22.5,116,14.4,51,A,C,P 44,F,44,16.2,98,1.9,54,B,X,R 45,M,37,15.5,102,6.3,55,A,R,P 46,F,47,18.7,96,5.4,57,B,C,P 47,M,53,8.8,92,6.3,50,A,X,Q 48,M,54,13.2,90,18.3,62,B,R,Q 49,M,42,17.2,86,0.2,52,A,C,R 50,F,52,12.7,104,26.4,53,B,X,P 51,F,36,9.1,97,14.5,64,A,R,R 52,F,53,14.5,101,13.9,50,B,C,P 53,M,44,12.2,111,14.7,60,A,X,R 54,F,35,20.1,84,7.5,53,B,R,P 55,M,48,15.4,92,11.3,54,A,C,P 56,F,41,18.8,96,10,65,B,X,Q 57,M,53,23.3,104,3.2,69,A,R,Q 58,M,46,21.3,101,3.5,60,B,C,R 59,M,55,16.3,100,2.1,58,A,X,P 60,F,54,14.8,110,8.3,61,B,R,R 61,F,41,17,111,4.6,50,A,C,P 62,F,50,11.5,93,4.8,53,B,X,R 63,M,48,12.1,106,0.8,63,A,R,P 64,F,47,8.5,110,32.4,50,B,C,P 65,M,35,12.3,90,11.2,70,A,X,Q 66,F,49,23.8,105,4.9,68,B,R,Q 67,M,45,16.7,108,9.7,58,A,C,R 68,M,48,14,93,8.7,68,B,X,P 69,M,52,24.8,103,0.2,60,A,R,R 70,F,51,24.9,119,7.6,54,B,C,P 71,F,37,12.9,94,2.4,69,A,X,R 72,F,40,24.4,84,3.2,61,B,R,P 73,M,44,14.3,78,1.5,53,A,C,P 74,F,42,16.6,108,19.5,66,B,X,Q 75,M,49,24.3,114,11.5,62,A,R,Q 76,F,54,17.9,90,3.9,54,B,C,R 77,M,43,21.2,99,3.9,61,A,X,P 78,M,41,11.3,97,17.7,70,B,R,R 79,M,45,22.4,106,0.8,62,A,C,P 80,F,39,19.3,103,10.7,57,B,X,R 81,F,39,15.1,90,3.1,61,A,R,P 82,F,42,23,97,14.3,64,B,C,P 83,M,40,19.5,103,27.3,65,A,X,Q 84,F,42,22.5,98,7.7,51,B,R,Q 85,M,50,8.8,103,1.7,59,A,C,R 86,F,45,14.4,99,7.4,63,B,X,P 87,M,37,8.6,93,21.7,58,A,R,R 88,M,50,12.8,97,0.6,50,B,C,P 89,M,52,14.3,91,7.6,70,A,X,R 90,F,52,19.9,105,14.6,53,B,R,P 91,F,53,19.7,118,2.7,59,A,C,P 92,F,50,10,102,0.6,54,B,X,Q 93,M,54,22.8,108,17.4,51,A,R,Q 94,F,41,24.7,91,16.2,64,B,C,R 95,M,54,9.4,108,1.5,58,A,X,P 96,F,39,22.4,99,4.1,50,B,R,R 97,M,46,21.1,84,8.8,65,A,C,P 98,M,43,19.1,99,13.4,65,B,X,R 99,M,53,15.7,93,0.5,51,A,R,P 100,F,38,24.8,99,5.1,57,B,C,P 101,F,55,18.6,95,23.3,53,A,C,P 102,F,52,24.8,106,7.2,52,B,X,Q 103,M,53,15,91,7.9,50,A,R,Q 104,F,46,11.6,114,0.5,57,B,C,R 105,M,43,12.9,106,7.5,64,A,X,P 106,F,53,22.8,106,8.6,51,B,R,R 107,M,38,17.7,123,0.1,69,A,C,P 108,M,52,19.3,93,25,67,B,X,R 109,M,44,12.3,87,24.6,50,A,R,P 110,F,40,13.7,112,3.2,50,B,C,P 111,F,49,16.6,104,5.4,68,A,X,Q 112,F,44,23.7,88,18.3,55,B,R,Q 113,M,40,22.5,101,7.4,53,A,C,R 114,F,43,14.9,85,53.9,66,B,X,P 115,M,52,23.8,111,2.1,68,A,R,R 116,F,42,21.4,107,2.1,67,B,C,P 117,M,53,11.6,100,4.6,56,A,X,R 118,M,37,20.9,105,1.3,64,B,R,P 119,M,53,17.3,104,11.8,67,A,C,P 120,F,37,15.3,98,4.4,50,B,X,Q 121,F,47,16.8,90,0.7,62,A,R,Q 122,F,37,23.2,112,1.1,51,B,C,R 123,M,42,19.2,106,12.3,69,A,X,P 124,F,55,21.7,98,9.3,70,B,R,R 125,M,53,16.8,101,1.4,56,A,C,P 126,F,52,24.4,107,5.5,60,B,X,R 127,M,46,13.1,115,5.6,69,A,R,P 128,M,45,23,101,5.7,70,B,C,P 129,M,53,12,101,22.7,55,A,X,Q 130,F,44,24.5,87,8.8,58,B,R,Q 131,F,40,17.7,93,5.6,54,A,C,R 132,F,40,10.5,100,10.3,50,B,X,P 133,M,50,16.2,98,4.2,66,A,R,R 134,F,37,22.7,117,0.3,52,B,C,P 135,M,40,23.5,84,2.9,67,A,X,R 136,F,47,18.3,104,17.8,57,B,R,P 137,M,54,15.5,74,12.8,58,A,C,P 138,M,41,24.1,117,24.5,59,B,X,Q 139,M,47,10.6,110,19.4,61,A,R,Q 140,F,50,13.9,104,8,55,B,C,R 141,F,48,19.3,97,5.6,68,A,X,P 142,F,47,17.3,108,11.7,69,B,R,R 143,M,51,24.6,111,2,64,A,C,P 144,F,38,24.7,111,7.3,54,B,X,R 145,M,36,22.4,95,7.7,58,A,R,P 146,F,52,24.5,93,5,69,B,C,P 147,M,36,11.4,103,2.2,63,A,X,Q 148,M,41,24.3,93,0.5,57,B,R,Q 149,M,36,18.1,98,10.6,69,A,C,R 150,F,53,24.5,87,10.9,51,B,X,P 151,F,39,23.3,90,1,56,A,R,R 152,F,55,23.7,118,27,66,B,C,P 153,M,37,20.4,104,20.8,65,A,X,R 154,F,42,21.6,95,24.2,70,B,R,P 155,M,44,15.1,95,77.9,64,A,C,P 156,F,53,12.3,105,17.9,65,B,X,Q 157,M,39,10.2,104,22.7,62,A,R,Q 158,M,50,18.2,102,8.3,57,B,C,R 159,M,48,20.1,91,1.1,62,A,X,P 160,F,54,15,98,2.4,69,B,R,R 161,F,52,9.7,104,1.3,50,A,C,P 162,F,46,21.3,105,6.8,68,B,X,R 163,M,36,15.2,96,18.7,51,A,R,P 164,F,40,12.5,96,8.9,52,B,C,P 165,M,48,10.4,105,5.1,60,A,X,Q 166,F,36,20,105,27.2,62,B,R,Q 167,M,37,17.2,98,7.1,67,A,C,R 168,M,54,19.7,109,3.9,70,B,X,P 169,M,47,19.9,93,13.8,51,A,R,R 170,F,55,9.3,111,20.5,62,B,C,P 171,F,41,16,90,51.1,55,A,X,R 172,F,50,14.5,89,1.5,70,B,R,P 173,M,42,12.3,64,12.6,70,A,C,P 174,F,52,8.9,103,12.8,58,B,X,Q 175,M,43,21.1,112,13.8,65,A,R,Q 176,F,47,21.4,125,0.5,50,B,C,R 177,M,50,10.2,101,9.9,70,A,X,P 178,M,52,23.9,73,7.1,58,B,R,R 179,M,49,17.4,93,4.1,62,A,C,P 180,F,47,10.3,111,10,55,B,X,R 181,F,40,8.9,88,29.6,55,A,R,P 182,F,51,22.6,86,17.7,61,B,C,P 183,M,37,22.8,102,6.4,58,A,X,Q 184,F,52,23.4,107,30.1,65,B,R,Q 185,M,39,21,98,5,65,A,C,R 186,F,53,24.3,105,1.3,62,B,X,P 187,M,45,11,94,7.6,50,A,R,R 188,M,53,14.1,99,46.1,53,B,C,P 189,M,37,17.8,104,2.1,52,A,X,R 190,F,54,11.8,92,0.6,66,B,R,P 191,F,54,23.6,93,6.3,51,A,C,P 192,F,47,13.5,99,0.1,70,B,X,Q 193,M,42,16,108,1.7,51,A,R,Q 194,F,53,14.3,96,7.7,58,B,C,R 195,M,54,9.7,100,1.3,55,A,X,P 196,F,40,9.6,103,12.1,56,B,R,R 197,M,42,12.6,109,3.6,68,A,C,P 198,M,49,11.2,95,1.8,53,B,X,R 199,M,36,24.2,97,8.2,58,A,R,P 200,F,48,10.3,114,20.4,63,B,C,P 2 | -------------------------------------------------------------------------------- /Week 3_Peer graded quiz on Types.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz for `Types`" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### Answer the following questions by creating the appropriate code." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "### Question 1\n", 29 | "\n", 30 | "List the subtypes of the `Real` type." 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 16, 36 | "metadata": { 37 | "collapsed": false 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Subtypes of Real\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "### Question 2\n", 49 | "\n", 50 | "Create a user-defined type called `MyFloat` with a single field called `x` that is of type `Float64`." 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 17, 56 | "metadata": { 57 | "collapsed": false 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "# Create a user-defined type called MyFloat with a single field called x of type Float64\n" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "### Question 3\n", 69 | "\n", 70 | "Instantiate the `MyFloat` type with a field values of $ 3 $." 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 18, 76 | "metadata": { 77 | "collapsed": false 78 | }, 79 | "outputs": [], 80 | "source": [ 81 | "# Instantiate the MyFloat type with a field value of 3\n" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "### Question 4\n", 89 | "\n", 90 | "Create a user-defined parametrized type called `MyCube` with $ 3 $ fields called `h`, `w`, and `l`." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 19, 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "outputs": [], 100 | "source": [ 101 | "# Create a user-defined parametrized type called MyCube with $ 3 $ fields called h, w, and l.\n" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### Question 5\n", 109 | "\n", 110 | "Instantiate the type `MyCube` with $ 2 $ variables called `cube1` and `cube2`, i.e. `cube1 = MyCube(...`. Pass the field values $ 2 $, $ 3 $, and $ 2 $ to `cube1` and $ 4 $, $ 3 $, and $ 2 $ to `cube2`." 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 20, 116 | "metadata": { 117 | "collapsed": false 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "# Create 2 instances of the MyCube type\n" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Question 6\n", 129 | "\n", 130 | "Change the `h` field value of `cube1` to $ 3 $." 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 21, 136 | "metadata": { 137 | "collapsed": false 138 | }, 139 | "outputs": [], 140 | "source": [ 141 | "# Change the h filed value of cube1 to 3\n" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "### Question 7\n", 149 | "\n", 150 | "Import the `Base.log` function." 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 22, 156 | "metadata": { 157 | "collapsed": true 158 | }, 159 | "outputs": [], 160 | "source": [ 161 | "# Import the Base.log function\n" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "### Question 8\n", 169 | "\n", 170 | "Create and external constructor that will specify the `log()` function for an instance of the `MyCube` type as the natural logarithm of the product of the values held in the fields `h`, `w`, and `l`." 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 23, 176 | "metadata": { 177 | "collapsed": false 178 | }, 179 | "outputs": [], 180 | "source": [ 181 | "# Create and external constructor for the natural logarithm of the volume of an instance of MyCube\n" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "### Question 9\n", 189 | "\n", 190 | "Calculate the `log()` of `cube1`." 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 24, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [], 200 | "source": [ 201 | "# The natural log of cube1\n" 202 | ] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "metadata": {}, 207 | "source": [ 208 | "### Question 10\n", 209 | "\n", 210 | "Overload the methods of the `+()` function to add the individual field values of $ 2 $ instances of the `MyCube` type." 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 25, 216 | "metadata": { 217 | "collapsed": false 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "# Overload the methods of the +() functions for the MyCube type\n" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "### Question 11\n", 229 | "\n", 230 | "Add `cube1` and `cube2`." 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 26, 236 | "metadata": { 237 | "collapsed": false 238 | }, 239 | "outputs": [], 240 | "source": [ 241 | "# Add cube1 and cube2\n" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": null, 247 | "metadata": { 248 | "collapsed": true 249 | }, 250 | "outputs": [], 251 | "source": [] 252 | } 253 | ], 254 | "metadata": { 255 | "anaconda-cloud": {}, 256 | "kernelspec": { 257 | "display_name": "Julia 0.4.6", 258 | "language": "julia", 259 | "name": "julia-0.4" 260 | }, 261 | "language_info": { 262 | "file_extension": ".jl", 263 | "mimetype": "application/julia", 264 | "name": "julia", 265 | "version": "0.4.6" 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 0 270 | } 271 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Week 3_Peer graded quiz on Types-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz for `Types`" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### Answer the following questions by creating the appropriate code." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "### Question 1\n", 29 | "\n", 30 | "List the subtypes of the `Real` type." 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 16, 36 | "metadata": { 37 | "collapsed": false 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Subtypes of Real\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "### Question 2\n", 49 | "\n", 50 | "Create a user-defined type called `MyFloat` with a single field called `x` that is of type `Float64`." 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 17, 56 | "metadata": { 57 | "collapsed": false 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "# Create a user-defined type called MyFloat with a single field called x of type Float64\n" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "### Question 3\n", 69 | "\n", 70 | "Instantiate the `MyFloat` type with a field values of $ 3 $." 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 18, 76 | "metadata": { 77 | "collapsed": false 78 | }, 79 | "outputs": [], 80 | "source": [ 81 | "# Instantiate the MyFloat type with a field value of 3\n" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "### Question 4\n", 89 | "\n", 90 | "Create a user-defined parametrized type called `MyCube` with $ 3 $ fields called `h`, `w`, and `l`." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 19, 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "outputs": [], 100 | "source": [ 101 | "# Create a user-defined parametrized type called MyCube with $ 3 $ fields called h, w, and l.\n" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### Question 5\n", 109 | "\n", 110 | "Instantiate the type `MyCube` with $ 2 $ variables called `cube1` and `cube2`, i.e. `cube1 = MyCube(...`. Pass the field values $ 2 $, $ 3 $, and $ 2 $ to `cube1` and $ 4 $, $ 3 $, and $ 2 $ to `cube2`." 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 20, 116 | "metadata": { 117 | "collapsed": false 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "# Create 2 instances of the MyCube type\n" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Question 6\n", 129 | "\n", 130 | "Change the `h` field value of `cube1` to $ 3 $." 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 21, 136 | "metadata": { 137 | "collapsed": false 138 | }, 139 | "outputs": [], 140 | "source": [ 141 | "# Change the h filed value of cube1 to 3\n" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "### Question 7\n", 149 | "\n", 150 | "Import the `Base.log` function." 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 22, 156 | "metadata": { 157 | "collapsed": true 158 | }, 159 | "outputs": [], 160 | "source": [ 161 | "# Import the Base.log function\n" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "### Question 8\n", 169 | "\n", 170 | "Create and external constructor that will specify the `log()` function for an instance of the `MyCube` type as the natural logarithm of the product of the values held in the fields `h`, `w`, and `l`." 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 23, 176 | "metadata": { 177 | "collapsed": false 178 | }, 179 | "outputs": [], 180 | "source": [ 181 | "# Create and external constructor for the natural logarithm of the volume of an instance of MyCube\n" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "### Question 9\n", 189 | "\n", 190 | "Calculate the `log()` of `cube1`." 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 24, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [], 200 | "source": [ 201 | "# The natural log of cube1\n" 202 | ] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "metadata": {}, 207 | "source": [ 208 | "### Question 10\n", 209 | "\n", 210 | "Overload the methods of the `+()` function to add the individual field values of $ 2 $ instances of the `MyCube` type." 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 25, 216 | "metadata": { 217 | "collapsed": false 218 | }, 219 | "outputs": [], 220 | "source": [ 221 | "# Overload the methods of the +() functions for the MyCube type\n" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "### Question 11\n", 229 | "\n", 230 | "Add `cube1` and `cube2`." 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 26, 236 | "metadata": { 237 | "collapsed": false 238 | }, 239 | "outputs": [], 240 | "source": [ 241 | "# Add cube1 and cube2\n" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": null, 247 | "metadata": { 248 | "collapsed": true 249 | }, 250 | "outputs": [], 251 | "source": [] 252 | } 253 | ], 254 | "metadata": { 255 | "anaconda-cloud": {}, 256 | "kernelspec": { 257 | "display_name": "Julia 0.4.6", 258 | "language": "julia", 259 | "name": "julia-0.4" 260 | }, 261 | "language_info": { 262 | "file_extension": ".jl", 263 | "mimetype": "application/julia", 264 | "name": "julia", 265 | "version": "0.4.6" 266 | } 267 | }, 268 | "nbformat": 4, 269 | "nbformat_minor": 0 270 | } 271 | -------------------------------------------------------------------------------- /Week 4_Peer graded quiz on Gadfly.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz on Gadfly" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### After importing `Gadfly` and `DataFrames`, answer the following questions by creating the appropriate code." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 25, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "# using Gadfly, DataFrames;" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "### Question 1\n", 40 | "\n", 41 | "Create a DataFrame called `data` with column names `A`, `B`, `C`, and `D`. Each column should have $ 30 $ values.\n", 42 | "\n", 43 | "- For column `A` generate $ 30 $ random values in the range $ 1 : 10 $\n", 44 | "- For column `B` generate $ 30 $ random values in the range $ 1 : 10 $\n", 45 | "- For column `C` generate $ 30 $ random values from the choices `P` and `Q`\n", 46 | "- For column `D` generate $ 30 $ random values from the choices `X`, `Y`, and `Z`" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 26, 52 | "metadata": { 53 | "collapsed": false 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "# Create the DataFrame called data\n" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "### Question 2\n", 65 | "\n", 66 | "Create a scatter plot from columns `A` and `B` using the point geometry." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 27, 72 | "metadata": { 73 | "collapsed": false 74 | }, 75 | "outputs": [], 76 | "source": [ 77 | "# Create a scatter plot using the point geometry\n" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "### Question 3\n", 85 | "\n", 86 | "Change the point marker color to `gray` and increase the size to `5px`." 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 28, 92 | "metadata": { 93 | "collapsed": false 94 | }, 95 | "outputs": [], 96 | "source": [ 97 | "# Change the point marker color to gray and the size to 5px\n" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### Question 4\n", 105 | "\n", 106 | "Create a (simple) scatter plot using point geometry using values in columns `A` and `B`, but grouped by the unique elements found in column `C`. Leave all other elements at their default values." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 29, 112 | "metadata": { 113 | "collapsed": false 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "# Create a scatter plot using point geometry from the values in columns A and B, grouped by column C\n" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "### Question 5\n", 125 | "\n", 126 | "Receate the plot in *Question 4*, but change the point marker size to `10px`, with colors `#AAAAAA` and `#777777`." 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 30, 132 | "metadata": { 133 | "collapsed": false 134 | }, 135 | "outputs": [], 136 | "source": [ 137 | "# Recreate the plot in Question 4 with point marker size 10px and colors #AAAAAA and #777777\n" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "### Question 6\n", 145 | "\n", 146 | "Create a box plot of the values in column `A` based on the unique values in column `D`. Render the plot in `grey`." 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 31, 152 | "metadata": { 153 | "collapsed": false 154 | }, 155 | "outputs": [], 156 | "source": [ 157 | "# Create a grey box plot of the values in column A based on the unique values in columns D\n" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "### Question 7\n", 165 | "\n", 166 | "Recreate the plot in Question 6. Increase the spacing to `50px` and add the plot title \"`My plot`\"." 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 32, 172 | "metadata": { 173 | "collapsed": false 174 | }, 175 | "outputs": [], 176 | "source": [ 177 | "# Recreate the plot in Question 6 with increased spacing (50px) and add the title My plot\n" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "### Question 8\n", 185 | "\n", 186 | "Recreate the plot in Question 7 but add a `ygroup` based on the unqiue values in column C." 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 33, 192 | "metadata": { 193 | "collapsed": false 194 | }, 195 | "outputs": [], 196 | "source": [ 197 | "# Recreate the plot in Question 7 but add a ygroup based on the unique values in column C\n" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": {}, 203 | "source": [ 204 | "### Question 9\n", 205 | "\n", 206 | "Add a new column called `E` and add $ 30 $ values from the standard normal distribution." 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 34, 212 | "metadata": { 213 | "collapsed": false 214 | }, 215 | "outputs": [], 216 | "source": [ 217 | "# Add column E with 30 values form the standard normal distribution\n" 218 | ] 219 | }, 220 | { 221 | "cell_type": "markdown", 222 | "metadata": {}, 223 | "source": [ 224 | "### Question 10\n", 225 | "\n", 226 | "Create a density plot using the values in column `E` and draw a vertical line in `red` with size `2px` though the actual mean of the values in column `E`." 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 35, 232 | "metadata": { 233 | "collapsed": false 234 | }, 235 | "outputs": [], 236 | "source": [ 237 | "# Create a density plot from the values in column E and draw a 2px red vertical line through the actual mean\n" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": { 244 | "collapsed": true 245 | }, 246 | "outputs": [], 247 | "source": [] 248 | } 249 | ], 250 | "metadata": { 251 | "anaconda-cloud": {}, 252 | "kernelspec": { 253 | "display_name": "Julia 0.4.6", 254 | "language": "julia", 255 | "name": "julia-0.4" 256 | }, 257 | "language_info": { 258 | "file_extension": ".jl", 259 | "mimetype": "application/julia", 260 | "name": "julia", 261 | "version": "0.4.6" 262 | } 263 | }, 264 | "nbformat": 4, 265 | "nbformat_minor": 0 266 | } 267 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Week 4_Peer graded quiz on Gadfly-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz on Gadfly" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### After importing `Gadfly` and `DataFrames`, answer the following questions by creating the appropriate code." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 25, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "# using Gadfly, DataFrames;" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "### Question 1\n", 40 | "\n", 41 | "Create a DataFrame called `data` with column names `A`, `B`, `C`, and `D`. Each column should have $ 30 $ values.\n", 42 | "\n", 43 | "- For column `A` generate $ 30 $ random values in the range $ 1 : 10 $\n", 44 | "- For column `B` generate $ 30 $ random values in the range $ 1 : 10 $\n", 45 | "- For column `C` generate $ 30 $ random values from the choices `P` and `Q`\n", 46 | "- For column `D` generate $ 30 $ random values from the choices `X`, `Y`, and `Z`" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 26, 52 | "metadata": { 53 | "collapsed": false 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "# Create the DataFrame called data\n" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "### Question 2\n", 65 | "\n", 66 | "Create a scatter plot from columns `A` and `B` using the point geometry." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 27, 72 | "metadata": { 73 | "collapsed": false 74 | }, 75 | "outputs": [], 76 | "source": [ 77 | "# Create a scatter plot using the point geometry\n" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "### Question 3\n", 85 | "\n", 86 | "Change the point marker color to `gray` and increase the size to `5px`." 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 28, 92 | "metadata": { 93 | "collapsed": false 94 | }, 95 | "outputs": [], 96 | "source": [ 97 | "# Change the point marker color to gray and the size to 5px\n" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### Question 4\n", 105 | "\n", 106 | "Create a (simple) scatter plot using point geometry using values in columns `A` and `B`, but grouped by the unique elements found in column `C`. Leave all other elements at their default values." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 29, 112 | "metadata": { 113 | "collapsed": false 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "# Create a scatter plot using point geometry from the values in columns A and B, grouped by column C\n" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "### Question 5\n", 125 | "\n", 126 | "Receate the plot in *Question 4*, but change the point marker size to `10px`, with colors `#AAAAAA` and `#777777`." 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 30, 132 | "metadata": { 133 | "collapsed": false 134 | }, 135 | "outputs": [], 136 | "source": [ 137 | "# Recreate the plot in Question 4 with point marker size 10px and colors #AAAAAA and #777777\n" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "### Question 6\n", 145 | "\n", 146 | "Create a box plot of the values in column `A` based on the unique values in column `D`. Render the plot in `grey`." 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 31, 152 | "metadata": { 153 | "collapsed": false 154 | }, 155 | "outputs": [], 156 | "source": [ 157 | "# Create a grey box plot of the values in column A based on the unique values in columns D\n" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "### Question 7\n", 165 | "\n", 166 | "Recreate the plot in Question 6. Increase the spacing to `50px` and add the plot title \"`My plot`\"." 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 32, 172 | "metadata": { 173 | "collapsed": false 174 | }, 175 | "outputs": [], 176 | "source": [ 177 | "# Recreate the plot in Question 6 with increased spacing (50px) and add the title My plot\n" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "### Question 8\n", 185 | "\n", 186 | "Recreate the plot in Question 7 but add a `ygroup` based on the unqiue values in column C." 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 33, 192 | "metadata": { 193 | "collapsed": false 194 | }, 195 | "outputs": [], 196 | "source": [ 197 | "# Recreate the plot in Question 7 but add a ygroup based on the unique values in column C\n" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": {}, 203 | "source": [ 204 | "### Question 9\n", 205 | "\n", 206 | "Add a new column called `E` and add $ 30 $ values from the standard normal distribution." 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 34, 212 | "metadata": { 213 | "collapsed": false 214 | }, 215 | "outputs": [], 216 | "source": [ 217 | "# Add column E with 30 values form the standard normal distribution\n" 218 | ] 219 | }, 220 | { 221 | "cell_type": "markdown", 222 | "metadata": {}, 223 | "source": [ 224 | "### Question 10\n", 225 | "\n", 226 | "Create a density plot using the values in column `E` and draw a vertical line in `red` with size `2px` though the actual mean of the values in column `E`." 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 35, 232 | "metadata": { 233 | "collapsed": false 234 | }, 235 | "outputs": [], 236 | "source": [ 237 | "# Create a density plot from the values in column E and draw a 2px red vertical line through the actual mean\n" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": { 244 | "collapsed": true 245 | }, 246 | "outputs": [], 247 | "source": [] 248 | } 249 | ], 250 | "metadata": { 251 | "anaconda-cloud": {}, 252 | "kernelspec": { 253 | "display_name": "Julia 0.4.6", 254 | "language": "julia", 255 | "name": "julia-0.4" 256 | }, 257 | "language_info": { 258 | "file_extension": ".jl", 259 | "mimetype": "application/julia", 260 | "name": "julia", 261 | "version": "0.4.6" 262 | } 263 | }, 264 | "nbformat": 4, 265 | "nbformat_minor": 0 266 | } 267 | -------------------------------------------------------------------------------- /CCS.csv: -------------------------------------------------------------------------------- 1 | "PatientID","Cat1","Cat2","Var1","Var2","Var3" 2 | 1,"A","C",38.25682170735211,5.939131803063266,35.05790787394423 3 | 2,"A","C",17.831672926455425,5.3475437647467015,21.130960534087748 4 | 8,"A","B",16.021847362622296,6.60708739107548,60.94357572800236 5 | 9,"A","C",45.11578946046756,6.007331523437179,21.879716257527214 6 | 16,"A","C",20.448024664719128,8.548191553013755,20.662273742223093 7 | 18,"A","B",28.354866592358434,7.956423420109708,33.180721180524046 8 | 25,"A","C",22.449698055243154,6.346176553966556,40.23647859806062 9 | 28,"A","B",48.41249747282861,5.325830066483782,28.89558282117991 10 | 29,"A","C",40.00749019795842,11.418946000149159,71.59107138476448 11 | 33,"A","C",20.718078088759942,5.3776825349838875,27.421634761166143 12 | 37,"A","B",17.039552902790813,5.341678126021321,24.350125791798412 13 | 38,"A","B",42.668677048130725,5.822836826149952,52.361023970347645 14 | 41,"A","B",19.954005492731604,5.139109665644092,93.1999049245544 15 | 42,"A","B",20.616861807456626,5.373775257683365,22.956316044932706 16 | 45,"A","B",31.96943333536114,7.03175222186184,32.4353920798117 17 | 48,"A","C",15.896503262657347,6.816307422196048,56.91791495074396 18 | 50,"A","B",34.12637671623271,10.132043236302893,95.0800494348705 19 | 54,"A","C",17.266696029416444,6.232851527491789,30.592429272236995 20 | 56,"A","B",17.65139392415621,6.482234591532695,30.411111164705403 21 | 57,"A","C",19.411007643097165,6.7381729160524415,51.404061512592136 22 | 58,"A","B",20.72167664093812,12.544965670716241,23.516481089946932 23 | 72,"A","C",41.067434948202134,6.790353447911059,25.463601202747274 24 | 77,"A","C",21.748637652644852,5.331207233871429,53.37901535144456 25 | 79,"A","B",24.795379875133985,6.421028372159899,67.80454363409564 26 | 81,"A","C",19.455898596105506,15.58264883701855,42.09359631060543 27 | 87,"A","B",20.42366215424995,6.0313350908620045,20.315296150337286 28 | 90,"A","B",32.12531899176456,7.5079670766812505,30.041428426466076 29 | 91,"A","C",27.80314774867038,5.569594345445192,20.873838118661297 30 | 93,"A","B",22.519476318918194,8.263168140286755,38.939609071578595 31 | 96,"A","C",52.42066995572101,10.589195161626716,22.849503575655408 32 | 97,"A","B",17.86580280548761,5.655153490926597,24.834925736117476 33 | 98,"A","C",18.304614879706364,5.206774148431451,60.24118038143812 34 | 99,"A","B",34.7957739318938,5.216771110070992,59.17313599632728 35 | 106,"A","C",17.990856155662172,5.805746954705914,22.986199725703937 36 | 107,"A","B",39.836469762383274,6.022064589307947,113.15915549478461 37 | 109,"A","C",17.89733059230163,9.017338715515097,39.73978608265236 38 | 114,"A","B",24.85255007423403,9.605542413410712,27.385339755186326 39 | 116,"A","B",17.997482304579076,8.204854456465476,23.41802059390876 40 | 117,"A","C",18.126071048122057,5.861439897610202,33.45755944581491 41 | 118,"A","B",17.575316399030562,8.71839481538569,56.086741718272286 42 | 4,"A","R",15.235601323477356,6.215777958365601,52.76976082287107 43 | 5,"A","R",25.15592340019337,7.490853667122982,33.99205373814725 44 | 6,"A","L",20.374496641186234,8.042691101281173,36.737306584027735 45 | 7,"A","L",43.5454122027658,5.299561550914789,75.76065870686222 46 | 11,"A","L",27.00543246299954,7.33753361967878,51.95612370492146 47 | 13,"A","L",17.735061128409228,5.251731495227136,25.925747015591718 48 | 14,"A","R",35.64113423781144,5.611566778966378,22.31970427696362 49 | 15,"A","R",16.48124586197382,8.144386537580985,44.26031952257776 50 | 20,"A","R",27.678888117250423,5.007772798459267,48.91881800373497 51 | 24,"A","R",20.290681944092228,7.885401148400058,32.836306424266965 52 | 26,"A","R",17.505164918032847,6.240301965190178,35.342960208912075 53 | 27,"A","R",27.823738893199685,7.101351572945177,102.85932501129798 54 | 30,"A","L",23.417627180715208,5.759435713338087,37.780811668758844 55 | 31,"A","L",17.416035856675663,5.7669808788855415,72.7943296690139 56 | 34,"A","L",34.72990536077704,5.445868658294521,58.065830110339235 57 | 40,"A","R",16.61883230435811,11.990779570002214,75.98733027504302 58 | 43,"A","L",36.13353019343677,9.397166165878637,50.02309957641912 59 | 44,"A","L",24.809298589357333,5.488379786878529,32.86894571765556 60 | 46,"A","L",38.30912284860666,6.233737160602212,21.21064844444261 61 | 47,"A","R",17.295927130680944,5.837944799072202,21.8276428223884 62 | 3,"B","X",24.06717700015676,3.0953199839743557,112.89374831207112 63 | 10,"B","F",16.589170569532676,7.1961316954933165,64.60108919251198 64 | 12,"B","F",40.10862142125212,4.098132961724937,31.34378123959812 65 | 17,"B","X",15.64473700818153,4.398113164328716,90.43175254860111 66 | 19,"B","X",39.368824847370625,6.393289044425163,54.47765539222189 67 | 21,"B","X",19.75510302623217,6.67391560088026,65.63213195508845 68 | 22,"B","X",46.448031059566205,7.751223293581221,41.80920515708942 69 | 23,"B","F",20.110684991712837,6.010929352119751,30.54343507281063 70 | 32,"B","X",30.549244560679348,3.709026551771673,94.08221057281018 71 | 35,"B","X",40.342410369530434,5.802418229901492,32.431285425829245 72 | 36,"B","F",17.61996478246801,3.272834021856402,45.279244306347266 73 | 39,"B","F",16.733111232009126,6.61873179993091,136.54780501476213 74 | 49,"B","X",34.171806783254596,3.750692428586434,32.270046028269256 75 | 51,"B","X",22.66461295251438,5.434594856859489,46.391239612707636 76 | 53,"B","F",30.135912277898576,3.76523838506742,30.321857770813068 77 | 59,"B","F",46.669586712038395,7.434769526485639,119.21343212403997 78 | 60,"B","X",43.32784943607196,3.9676916323091,78.8563412369135 79 | 63,"B","X",37.769606895027124,4.683753740577215,62.531800530107404 80 | 64,"B","F",31.74416965486681,3.5353814489730864,37.02352631086494 81 | 66,"B","X",21.384324733014576,4.743470890116747,49.275427145539155 82 | 67,"B","F",50.314538396562334,3.900974215467013,44.348033258162914 83 | 70,"B","X",62.371171183468505,3.018192374313788,147.39740194224694 84 | 71,"B","F",21.34654236894925,5.593431828293242,42.86011283343048 85 | 74,"B","F",15.820464572624056,3.2672668036815287,81.89634808229764 86 | 75,"B","X",84.23781038235661,5.6973824946641525,33.62948279937371 87 | 82,"B","X",41.73087408600318,3.454628386262769,65.72050426362536 88 | 85,"B","X",20.47493230602923,3.0117329341084575,67.70290091219718 89 | 88,"B","F",18.820495284292548,3.350410136146232,63.12557433232596 90 | 89,"B","F",26.73651845631796,3.8857375757598116,32.131917472465275 91 | 94,"B","F",22.69554494043684,3.913500381488114,49.53126214241773 92 | 100,"B","F",22.85363951467999,3.4813819703202014,34.7470936977334 93 | 102,"B","F",26.168582545839982,7.8584928331483646,99.3884671188813 94 | 103,"B","X",25.189755052026534,3.95881641016381,37.58826724970993 95 | 104,"B","F",37.018649921471,3.2954579895322436,110.74930744994928 96 | 105,"B","F",16.001958073218425,3.597589178824381,33.509407699797606 97 | 108,"B","X",19.765408611319234,3.4852524696675835,82.22448707504337 98 | 110,"B","X",19.578361699219148,11.917936789833698,44.043972351378805 99 | 111,"B","F",51.47410177495646,7.390867958250017,54.05613535009404 100 | 112,"B","F",22.58171946648838,5.629658117233228,39.46161322194196 101 | 120,"B","F",18.915525082842635,4.655106220303599,43.02578086404075 102 | 52,"B","R",29.982079670804236,6.90968000880066,57.51301755799257 103 | 55,"B","L",17.638581517150232,3.22905408396069,91.98045477526048 104 | 61,"B","L",25.46667156604546,8.555814504073485,88.77349639506795 105 | 62,"B","R",17.790822188585835,3.8816708712371217,106.08580109774431 106 | 65,"B","R",68.88733313061795,5.759272330342896,31.936985641936744 107 | 68,"B","L",29.06522838659918,4.684200064538992,77.62150616089157 108 | 69,"B","R",29.646945148445013,4.638146015092245,67.20166997221638 109 | 73,"B","R",23.26159974788763,3.0325095342576898,34.19143854116885 110 | 76,"B","R",17.002920887616682,5.394773109501809,31.129698423073002 111 | 78,"B","L",55.3878765748924,4.153035018201736,40.08457579332007 112 | 80,"B","R",20.220543535369945,6.36441733413244,45.43500515886002 113 | 83,"B","L",16.41724330342222,3.8416674717599735,89.69686766584209 114 | 84,"B","R",47.62237187470963,5.400323458550362,47.45407464660502 115 | 86,"B","L",73.02293637462614,3.3834931659546856,55.1737331680735 116 | 92,"B","R",16.410649941738182,4.303512135274212,87.73566030225827 117 | 95,"B","R",16.280064844736785,3.3725173889152478,52.60176250341807 118 | 101,"B","L",16.888304208704465,3.1959840213773445,60.18825331103146 119 | 113,"B","R",32.353749277992264,3.386772487438742,30.01573902344151 120 | 115,"B","R",20.13788637918843,3.4273072950030423,44.68926075087645 121 | 119,"B","L",17.61437635438921,3.4511600360326606,40.694652906806695 122 | -------------------------------------------------------------------------------- /Week2_2_2_CreateCSV.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 1, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "

Creating .csv from data tables on the web

" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "Suppose you have found data in a table on the web. Here's how to extract the data save it as a .csv file to be used in Julia. We start with the Ebola data that are used in this course, which can be found on Wikipedia. \n", 123 | "\n", 124 | "
\n", 125 | "\n", 126 | "

Important information:

\n", 127 | "We will use a spreadsheet, namely LibreOffice Calc, to do the work. Note that the date information on the Wikipedia site is not handled by all spreadsheets in the same way. If you use a different spreadsheet, you may find your results differ from ours.\n", 128 | "\n", 129 | "LibreOffice Calc is available for Windows, iOS and Linux, whereas most other spreadsheets are limited to one or two of these platforms.\n", 130 | "\n" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "

Wikipedia data on the West African EVD epidemic

\n", 138 | "\n", 139 | "These data are on the webpage https://en.wikipedia.org/wiki/West_African_Ebola_virus_epidemic_timeline_of_reported_cases_and_deaths\n", 140 | "\n", 141 | "Go there now, please, and navigate until you see a table that looks like this:\n", 142 | "\n", 143 | "\"(Screenshot" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "

Using a spreadsheet to save a website table as a .csv file

\n", 151 | "\n", 152 | "Highlight the entire table, starting with the date \"25 Nov 2015\" all the way to the last row, which has the date \"22 Mar 2014\". Make sure you highlight exactly these rows, and every one of these rows completely.\n", 153 | "\n", 154 | "Use your browser's \"Copy\" feature. This is different for different browsers, but in many cases you can simply right-click and then click on \"Copy\".\n", 155 | "\n", 156 | "Now open a spreadsheet (we used LibreOffice Calc), and paste the table. Again, different spreadsheets give different options. Make sure you select the option the puts the column of dates in the first column.\n", 157 | "\n", 158 | "Now save the spreadsheet, taking care to save it as a text file with .csv format. I will refer to this file as \"wikipediaEVDraw.csv\" but you may of course choose your own name. If you open the file with a text editor, you should see that the first few lines of the file look like this:\n", 159 | "\n", 160 | "\"(Screenshot\n", 161 | "\n", 162 | "\n", 163 | "Notice in particular that\n", 164 | "- Every row in the table is a new line in the file\n", 165 | "- The first comma is AFTER the first date\n", 166 | "- To be exact, the columns in the table are separated by commas in the file. This is what comma-separated-value files look like, no more and no less. This is the .csv format." 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "Julia 0.4.6", 173 | "language": "julia", 174 | "name": "julia-0.4" 175 | }, 176 | "language_info": { 177 | "file_extension": ".jl", 178 | "mimetype": "application/julia", 179 | "name": "julia", 180 | "version": "0.4.6" 181 | } 182 | }, 183 | "nbformat": 4, 184 | "nbformat_minor": 0 185 | } 186 | -------------------------------------------------------------------------------- /Week1_1-WhySpecial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 1, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "# PROGRAMMING LANGUAGES AND WHY JULIA IS SPECIAL " 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lesson

\n", 123 | "\n", 124 | "- [Outcome](#Outcome)\n", 125 | "- [Comparison with other programming languages](#Comparison-with-other-programming-languages)\n", 126 | "- [Why Julia is easy to learn](#Why-Julia-is-easy-to-learn)\n", 127 | "- [Some technical aspects of Julia](#Some-technical-aspects-of-Julia)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "
\n", 135 | "

Outcome

\n", 136 | "\n", 137 | "After this lesson, you will be able to: \n", 138 | "\n", 139 | "- Say how Julia compares to Python, Matlab, C and Fortran\n", 140 | "- Say why Julia is easy to learn\n", 141 | "- List some technical aspects of Julia" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "[Back to the top](#In-this-lesson)" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "
\n", 156 | "

Comparison with other programming languages

\n", 157 | "\n", 158 | "#### Julia is easy to learn -- but so are many other languages, for example Python and Matlab\n", 159 | "\n", 160 | "#### Julia is fast -- but so are some other languages, notably C and Fortran (terms and condition apply)\n", 161 | "\n", 162 | "#### Julia is free -- but so are Python, R and Octave\n", 163 | "\n", 164 | "\n", 165 | ".\n", 166 | "### But Julia is unique in that it is all three: free, fast AND easy to learn\n", 167 | "\n", 168 | "[Back to the top](#In-this-lesson)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "
\n", 176 | "

Why Julia is easy to learn

\n", 177 | "\n", 178 | "Basically, Julia is easy to learn because Julia programs are quick to write. The main reason concerns the number of lines of code:\n", 179 | "\n", 180 | "***IN JULIA, ONE WRITES ONLY A FEW LINES PER TASK***\n", 181 | "\n", 182 | "\n", 183 | "Computer programs are written to perform tasks. These can be simple, such as computing interest earned, or complex, such as converting speech to text.\n", 184 | "\n", 185 | "Julia programs tend to be short. For example, a C program for opening a file and reading its data into computer memory, converting the data to a different format along the way, can be expected to be far longer in C than in Julia.\n", 186 | "\n", 187 | "In this it is similar to Python and Matlab.\n", 188 | "\n", 189 | "\n", 190 | "## Speed of execution\n", 191 | "\n", 192 | "The speed of a program is quite a tricky thing to measure, what with computers varying a lot in basic processor speed, available memory, coprocessors and other multitasking tricks.\n", 193 | "\n", 194 | "Nevertheless, if a task in Python or Matlab is consuming a lot of time (that is, if it runs in minutes or hours rather than milliseconds and seconds), it often runs a lot faster in Julia. There are some benchmark tests to confirm this****. \n", 195 | "\n", 196 | "In this it is similar to C and Fortran (see also the remarks below on Julias *type system*).\n", 197 | "\n", 198 | "\n", 199 | "****To be fair, there are Python enthusiasts who declare those tests unreliable and biased.\n", 200 | "\n", 201 | "\n", 202 | "#### It should also be said that slow programs can be written in languages thath are supposed to be fast, and this is true for Julia as well. In this course, we will pay some attention to Julia's type system, which is the heart of most performance issues in Julia. However, the principles and techniques for making the most of Julia's capacity for speed is a subject for a more advanced course than this one.\n" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": {}, 208 | "source": [ 209 | "[Back to the top](#In-this-lesson)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "metadata": {}, 215 | "source": [ 216 | "
\n", 217 | "

Some technical aspects of Julia

\n", 218 | "\n", 219 | "### Julia is strongly typed and dynamic\n", 220 | "\n", 221 | "This combination is unique to Julia. Dynamic languages like Python and Matlab tend to be easy to learn and the programs written in them tend to quite short. Up to now, such languages have only used fairly simple type systems, which meant the programs could not be optimised to make the best possible use of processor capacity.\n", 222 | "\n", 223 | "It is the strong and very detailed type system that allows Julia code to run (almost) as fast as C. \n", 224 | "\n", 225 | "You will learn about Julia's type system in Lecture 6; we plunge into Julia's dynamic aspect in Lecture 3.\n", 226 | "\n", 227 | "### Julia functions have multiple dispatch\n", 228 | "\n", 229 | "This is linked to the type system. You will learn about functions in Lectures 8 and 9.\n", 230 | "\n", 231 | "### Julia supports parallel programming, is concurrent, and has a data model suitable for huge data sets.\n", 232 | "\n", 233 | "All these things means that Julia is especially suitable for distributed and networked computing and data management, and that it scales really well.\n", 234 | "\n", 235 | "### Julia interfaces particularly well with other languages\n", 236 | "\n", 237 | "These include a nearly-native way of using Python code in Julia and vice versa, a very powerful way of linking Julia with C code, and very natural integration of R and Julia. Other language interfaces are in development." 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": {}, 243 | "source": [ 244 | "[Back to the top](#In-this-lesson)" 245 | ] 246 | } 247 | ], 248 | "metadata": { 249 | "kernelspec": { 250 | "display_name": "Julia 0.4.6", 251 | "language": "julia", 252 | "name": "julia-0.4" 253 | }, 254 | "language_info": { 255 | "file_extension": ".jl", 256 | "mimetype": "application/julia", 257 | "name": "julia", 258 | "version": "0.4.6" 259 | } 260 | }, 261 | "nbformat": 4, 262 | "nbformat_minor": 0 263 | } 264 | -------------------------------------------------------------------------------- /Week 4_Peer graded quiz on data.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz for data" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### Import the following packages and create the DataFrame as indicated." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [ 31 | { 32 | "name": "stderr", 33 | "output_type": "stream", 34 | "text": [ 35 | "WARNING: Method definition combinations(Any, Integer) in module Base at combinatorics.jl:182 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/combinations.jl:42.\n", 36 | "WARNING: Method definition permutations(Any) in module Base at combinatorics.jl:219 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:24.\n", 37 | "WARNING: Method definition partitions(Integer) in module Base at combinatorics.jl:252 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:26.\n", 38 | "WARNING: Method definition partitions(Integer, Integer) in module Base at combinatorics.jl:318 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:93.\n", 39 | "WARNING: Method definition partitions(AbstractArray{T<:Any, 1}) in module Base at combinatorics.jl:380 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:158.\n", 40 | "WARNING: Method definition partitions(AbstractArray{T<:Any, 1}, Int64) in module Base at combinatorics.jl:447 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:228.\n", 41 | "WARNING: Method definition factorial(#T<:Integer, #T<:Integer) in module Base at combinatorics.jl:56 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:18.\n", 42 | "WARNING: Method definition factorial(Integer, Integer) in module Base at combinatorics.jl:66 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:28.\n", 43 | "WARNING: Method definition parity(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:642 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:221.\n", 44 | "WARNING: Method definition nthperm(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:92 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:161.\n", 45 | "WARNING: Method definition nthperm(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:89 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:157.\n", 46 | "WARNING: Method definition nthperm!(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:70 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:136.\n", 47 | "WARNING: Method definition prevprod(Array{Int64, 1}, Any) in module Base at combinatorics.jl:565 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:354.\n", 48 | "WARNING: Method definition levicivita(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:611 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:188.\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "using DataFrames, Distributions, HypothesisTests;" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": { 60 | "collapsed": false 61 | }, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "Plots.PlotlyJSBackend()" 67 | ] 68 | }, 69 | "execution_count": 2, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "using Plots\n", 76 | "plotlyjs()" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "outputs": [ 86 | { 87 | "name": "stderr", 88 | "output_type": "stream", 89 | "text": [ 90 | "WARNING: New definition \n", 91 | " +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n", 92 | "is ambiguous with: \n", 93 | " +(DataArrays.DataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:276.\n", 94 | "To fix, define \n", 95 | " +(DataArrays.DataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n", 96 | "before the new definition.\n", 97 | "WARNING: New definition \n", 98 | " +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n", 99 | "is ambiguous with: \n", 100 | " +(DataArrays.AbstractDataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:300.\n", 101 | "To fix, define \n", 102 | " +(DataArrays.AbstractDataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n", 103 | "before the new definition.\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "using StatPlots;" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 4, 114 | "metadata": { 115 | "collapsed": false 116 | }, 117 | "outputs": [], 118 | "source": [ 119 | "data = DataFrame(Subject = collect(1:90), Age = rand(18:60, 90), Variable1 = rand(Normal(100, 10), 90),\n", 120 | "Variable2 = rand(Chisq(5), 90), Variable3 = rand(Exponential(4), 90), Category1 = rand([\"X\", \"R\"], 90),\n", 121 | "Category2 = rand([\"I\", \"II\", \"III\", \"IV\"], 90),\n", 122 | "Category3 = rand([\"Improved\", \"Static\", \"Worsened\"], 90));" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "#### Answer the following questions by creating the appropriate code." 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "### Question 1\n", 137 | "\n", 138 | "Use the appropriate function from the `DataFrames` to describe the `Variable1` column." 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 5, 144 | "metadata": { 145 | "collapsed": false 146 | }, 147 | "outputs": [], 148 | "source": [ 149 | "# Describe the values in Variable1\n" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "### Question 2\n", 157 | "\n", 158 | "Use the appropriate function from the `DataFrames` package to list how many unique values there are in the `Category1` column." 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 6, 164 | "metadata": { 165 | "collapsed": false 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "# How many unique value are there in the Category1 column?\n" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "### Question 3\n", 177 | "\n", 178 | "Plot a histogram of the values in `Variable3` using 10 bins." 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 7, 184 | "metadata": { 185 | "collapsed": false 186 | }, 187 | "outputs": [], 188 | "source": [ 189 | "# Histogram of Variable3\n" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "### Question 4\n", 197 | "\n", 198 | "Create two new DataFrames named `X` and `R` such that each of these sub-DataFrames only have the corresponding data point values in the `Category1` column, i.e. `X = ...`." 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 8, 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "outputs": [], 208 | "source": [ 209 | "# Create three new sub-DataFrames based on the unique values in Category1\n" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "metadata": {}, 215 | "source": [ 216 | "### Question 5\n", 217 | "\n", 218 | "Use the `EqualVarianceTTest()` from the `HypothesisTests` package to perform a *t*-test comparing the values in `Variable1` for the null hypothesis stating that there is no difference between the two groups." 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 9, 224 | "metadata": { 225 | "collapsed": false 226 | }, 227 | "outputs": [], 228 | "source": [ 229 | "# t-Test comparing Variable1 values between groups X and R\n" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "### Question 6\n", 237 | "\n", 238 | "Create a scatter plot for `Variable1` and `Variable2` values grouped by `Category1`. Make the title of the plot *My scatter plot*. The markers should be of opacity $ 0.5 $ and size $ 10 $." 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 10, 244 | "metadata": { 245 | "collapsed": false 246 | }, 247 | "outputs": [], 248 | "source": [ 249 | "# Scatter plot of Variable1 against Variable2 grouped by Category1 with maker opacity 0.5 and size 10\n" 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "metadata": {}, 255 | "source": [ 256 | "### Question 7\n", 257 | "\n", 258 | "Create a sub-DataFrame called `worsened` including only rows indicating `Worsened` in the `Category3` column, i.e. `worsened = ...`." 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 11, 264 | "metadata": { 265 | "collapsed": false 266 | }, 267 | "outputs": [], 268 | "source": [ 269 | "# Create a sub-DataFrame for patients that have worsened according to Category3 values\n" 270 | ] 271 | }, 272 | { 273 | "cell_type": "markdown", 274 | "metadata": {}, 275 | "source": [ 276 | "### Question 8\n", 277 | "\n", 278 | "Calculate the mean and standard deviation of `Variable1` values for patients who have `Worsened` as computer variables `meanw` and `stdw`, i.e. `meanw = ....`." 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 12, 284 | "metadata": { 285 | "collapsed": false 286 | }, 287 | "outputs": [], 288 | "source": [ 289 | "# Mean of Variable1 for patients that have worsened\n" 290 | ] 291 | }, 292 | { 293 | "cell_type": "markdown", 294 | "metadata": {}, 295 | "source": [ 296 | "### Question 9\n", 297 | "\n", 298 | "Create a plot of the theoretical distribution using the values for `meanw` and `stdw`. State the `label` value as *Distribution* and provide a unique title to you plot." 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 13, 304 | "metadata": { 305 | "collapsed": false 306 | }, 307 | "outputs": [], 308 | "source": [ 309 | "# Create a theoretical distribution plot with meanw and stdw\n" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "metadata": {}, 315 | "source": [ 316 | "### Question 10\n", 317 | "\n", 318 | "Create a **Plotly** account and sign in. Return to your notebook and upload the image in *Question 10* to the **Plotly** cloud for editing. Save the plot by hitting the *Save* button. Share the link to the plot by copying the *share link* in a Markdown cell." 319 | ] 320 | }, 321 | { 322 | "cell_type": "markdown", 323 | "metadata": {}, 324 | "source": [] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": null, 329 | "metadata": { 330 | "collapsed": true 331 | }, 332 | "outputs": [], 333 | "source": [] 334 | } 335 | ], 336 | "metadata": { 337 | "anaconda-cloud": {}, 338 | "kernelspec": { 339 | "display_name": "Julia 0.4.6", 340 | "language": "julia", 341 | "name": "julia-0.4" 342 | }, 343 | "language_info": { 344 | "file_extension": ".jl", 345 | "mimetype": "application/julia", 346 | "name": "julia", 347 | "version": "0.4.6" 348 | } 349 | }, 350 | "nbformat": 4, 351 | "nbformat_minor": 0 352 | } 353 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/Week 4_Peer graded quiz on data-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Peer-graded quiz for data" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Please note that this notebook was created in Julia version 0.4.6." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### Import the following packages and create the DataFrame as indicated." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [ 31 | { 32 | "name": "stderr", 33 | "output_type": "stream", 34 | "text": [ 35 | "WARNING: Method definition combinations(Any, Integer) in module Base at combinatorics.jl:182 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/combinations.jl:42.\n", 36 | "WARNING: Method definition permutations(Any) in module Base at combinatorics.jl:219 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:24.\n", 37 | "WARNING: Method definition partitions(Integer) in module Base at combinatorics.jl:252 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:26.\n", 38 | "WARNING: Method definition partitions(Integer, Integer) in module Base at combinatorics.jl:318 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:93.\n", 39 | "WARNING: Method definition partitions(AbstractArray{T<:Any, 1}) in module Base at combinatorics.jl:380 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:158.\n", 40 | "WARNING: Method definition partitions(AbstractArray{T<:Any, 1}, Int64) in module Base at combinatorics.jl:447 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:228.\n", 41 | "WARNING: Method definition factorial(#T<:Integer, #T<:Integer) in module Base at combinatorics.jl:56 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:18.\n", 42 | "WARNING: Method definition factorial(Integer, Integer) in module Base at combinatorics.jl:66 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/factorials.jl:28.\n", 43 | "WARNING: Method definition parity(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:642 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:221.\n", 44 | "WARNING: Method definition nthperm(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:92 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:161.\n", 45 | "WARNING: Method definition nthperm(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:89 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:157.\n", 46 | "WARNING: Method definition nthperm!(AbstractArray{T<:Any, 1}, Integer) in module Base at combinatorics.jl:70 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:136.\n", 47 | "WARNING: Method definition prevprod(Array{Int64, 1}, Any) in module Base at combinatorics.jl:565 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/partitions.jl:354.\n", 48 | "WARNING: Method definition levicivita(AbstractArray{#T<:Integer, 1}) in module Base at combinatorics.jl:611 overwritten in module Combinatorics at /Users/juanklopper/.julia/v0.4/Combinatorics/src/permutations.jl:188.\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "using DataFrames, Distributions, HypothesisTests;" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": { 60 | "collapsed": false 61 | }, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "Plots.PlotlyJSBackend()" 67 | ] 68 | }, 69 | "execution_count": 2, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "using Plots\n", 76 | "plotlyjs()" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "outputs": [ 86 | { 87 | "name": "stderr", 88 | "output_type": "stream", 89 | "text": [ 90 | "WARNING: New definition \n", 91 | " +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n", 92 | "is ambiguous with: \n", 93 | " +(DataArrays.DataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:276.\n", 94 | "To fix, define \n", 95 | " +(DataArrays.DataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n", 96 | "before the new definition.\n", 97 | "WARNING: New definition \n", 98 | " +(AbstractArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury) at /Users/juanklopper/.julia/v0.4/WoodburyMatrices/src/SymWoodburyMatrices.jl:106\n", 99 | "is ambiguous with: \n", 100 | " +(DataArrays.AbstractDataArray, AbstractArray) at /Users/juanklopper/.julia/v0.4/DataArrays/src/operators.jl:300.\n", 101 | "To fix, define \n", 102 | " +(DataArrays.AbstractDataArray{T<:Any, 2}, WoodburyMatrices.SymWoodbury)\n", 103 | "before the new definition.\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "using StatPlots;" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 4, 114 | "metadata": { 115 | "collapsed": false 116 | }, 117 | "outputs": [], 118 | "source": [ 119 | "data = DataFrame(Subject = collect(1:90), Age = rand(18:60, 90), Variable1 = rand(Normal(100, 10), 90),\n", 120 | "Variable2 = rand(Chisq(5), 90), Variable3 = rand(Exponential(4), 90), Category1 = rand([\"X\", \"R\"], 90),\n", 121 | "Category2 = rand([\"I\", \"II\", \"III\", \"IV\"], 90),\n", 122 | "Category3 = rand([\"Improved\", \"Static\", \"Worsened\"], 90));" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "#### Answer the following questions by creating the appropriate code." 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "### Question 1\n", 137 | "\n", 138 | "Use the appropriate function from the `DataFrames` to describe the `Variable1` column." 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 5, 144 | "metadata": { 145 | "collapsed": false 146 | }, 147 | "outputs": [], 148 | "source": [ 149 | "# Describe the values in Variable1\n" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "### Question 2\n", 157 | "\n", 158 | "Use the appropriate function from the `DataFrames` package to list how many unique values there are in the `Category1` column." 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 6, 164 | "metadata": { 165 | "collapsed": false 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "# How many unique value are there in the Category1 column?\n" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "### Question 3\n", 177 | "\n", 178 | "Plot a histogram of the values in `Variable3` using 10 bins." 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 7, 184 | "metadata": { 185 | "collapsed": false 186 | }, 187 | "outputs": [], 188 | "source": [ 189 | "# Histogram of Variable3\n" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "### Question 4\n", 197 | "\n", 198 | "Create two new DataFrames named `X` and `R` such that each of these sub-DataFrames only have the corresponding data point values in the `Category1` column, i.e. `X = ...`." 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 8, 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "outputs": [], 208 | "source": [ 209 | "# Create three new sub-DataFrames based on the unique values in Category1\n" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "metadata": {}, 215 | "source": [ 216 | "### Question 5\n", 217 | "\n", 218 | "Use the `EqualVarianceTTest()` from the `HypothesisTests` package to perform a *t*-test comparing the values in `Variable1` for the null hypothesis stating that there is no difference between the two groups." 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 9, 224 | "metadata": { 225 | "collapsed": false 226 | }, 227 | "outputs": [], 228 | "source": [ 229 | "# t-Test comparing Variable1 values between groups X and R\n" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "### Question 6\n", 237 | "\n", 238 | "Create a scatter plot for `Variable1` and `Variable2` values grouped by `Category1`. Make the title of the plot *My scatter plot*. The markers should be of opacity $ 0.5 $ and size $ 10 $." 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 10, 244 | "metadata": { 245 | "collapsed": false 246 | }, 247 | "outputs": [], 248 | "source": [ 249 | "# Scatter plot of Variable1 against Variable2 grouped by Category1 with maker opacity 0.5 and size 10\n" 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "metadata": {}, 255 | "source": [ 256 | "### Question 7\n", 257 | "\n", 258 | "Create a sub-DataFrame called `worsened` including only rows indicating `Worsened` in the `Category3` column, i.e. `worsened = ...`." 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 11, 264 | "metadata": { 265 | "collapsed": false 266 | }, 267 | "outputs": [], 268 | "source": [ 269 | "# Create a sub-DataFrame for patients that have worsened according to Category3 values\n" 270 | ] 271 | }, 272 | { 273 | "cell_type": "markdown", 274 | "metadata": {}, 275 | "source": [ 276 | "### Question 8\n", 277 | "\n", 278 | "Calculate the mean and standard deviation of `Variable1` values for patients who have `Worsened` as computer variables `meanw` and `stdw`, i.e. `meanw = ....`." 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 12, 284 | "metadata": { 285 | "collapsed": false 286 | }, 287 | "outputs": [], 288 | "source": [ 289 | "# Mean of Variable1 for patients that have worsened\n" 290 | ] 291 | }, 292 | { 293 | "cell_type": "markdown", 294 | "metadata": {}, 295 | "source": [ 296 | "### Question 9\n", 297 | "\n", 298 | "Create a plot of the theoretical distribution using the values for `meanw` and `stdw`. State the `label` value as *Distribution* and provide a unique title to you plot." 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 13, 304 | "metadata": { 305 | "collapsed": false 306 | }, 307 | "outputs": [], 308 | "source": [ 309 | "# Create a theoretical distribution plot with meanw and stdw\n" 310 | ] 311 | }, 312 | { 313 | "cell_type": "markdown", 314 | "metadata": {}, 315 | "source": [ 316 | "### Question 10\n", 317 | "\n", 318 | "Create a **Plotly** account and sign in. Return to your notebook and upload the image in *Question 10* to the **Plotly** cloud for editing. Save the plot by hitting the *Save* button. Share the link to the plot by copying the *share link* in a Markdown cell." 319 | ] 320 | }, 321 | { 322 | "cell_type": "markdown", 323 | "metadata": {}, 324 | "source": [] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": null, 329 | "metadata": { 330 | "collapsed": true 331 | }, 332 | "outputs": [], 333 | "source": [] 334 | } 335 | ], 336 | "metadata": { 337 | "anaconda-cloud": {}, 338 | "kernelspec": { 339 | "display_name": "Julia 0.4.6", 340 | "language": "julia", 341 | "name": "julia-0.4" 342 | }, 343 | "language_info": { 344 | "file_extension": ".jl", 345 | "mimetype": "application/julia", 346 | "name": "julia", 347 | "version": "0.4.6" 348 | } 349 | }, 350 | "nbformat": 4, 351 | "nbformat_minor": 0 352 | } 353 | -------------------------------------------------------------------------------- /Week2_2_1-LoadingData.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 1, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "

Ebola and Wikipedia: Loading publicly available data using Julia

" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lecture

\n", 123 | "\n", 124 | "- [Outcome](#Outcome)\n", 125 | "- [Wikipedia data on the West African EVD epidemic](#Wikipedia-data-on-the-West-African-EVD-epidemic)\n", 126 | "- [Using readdlm() to load a .csv file](#Using-readdlm-to-load-a-.csv-file)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "[Back to the top](#In-this-lecture)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "

Outcome

\n", 141 | "\n", 142 | "After this lecture, you will be able to\n", 143 | "- Find data on the West African EVD epidemic online\n", 144 | "- Use readdlm() to load data from a .csv file containing this data\n", 145 | "\n", 146 | "[Back to the top](#In-this-lecture)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "

Wikipedia data on the West African EVD epidemic

\n", 154 | "\n", 155 | "Wikipedia has many excellent articles on Ebola. We will be using one with fairly complete data on the timeline of cases: https://en.wikipedia.org/wiki/West_African_Ebola_virus_epidemic_timeline_of_reported_cases_and_deaths\n", 156 | "\n", 157 | "Go there now, please, and navigate until you see a table that looks like this:\n", 158 | "\n", 159 | "\"(Screenshot\n" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "[Back to the top](#In-this-lecture)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "We have provided the data as a file named wikipediaEVDraw.csv. The \".csv\" extension indicates that it is a comma-separated file, and the \"raw\" in the filename indicates that the data are imported as is, without any changes.\n", 174 | "\n", 175 | "If you would like to learn how to create .csv files from tables on the web, please go the optional lecture \"How to export web tables to .csv files\"." 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "[Back to the top](#In-this-lecture)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "

Using readdlm to load a .csv file

\n", 190 | "\n", 191 | "Now we can start using Julia again. In a new notebook for you Week 2 Julia code, enter and execute the line below:" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 3, 197 | "metadata": { 198 | "collapsed": false 199 | }, 200 | "outputs": [ 201 | { 202 | "data": { 203 | "text/plain": [ 204 | "54x9 Array{Any,2}:\n", 205 | " \"25 Nov 2015\" 28637 11314 3804 2536 … 4808 14122 3955 \n", 206 | " \"18 Nov 2015\" 28634 11314 3804 2536 4808 14122 3955 \n", 207 | " \"11 Nov 2015\" 28635 11314 3805 2536 4808 14122 3955 \n", 208 | " \"4 Nov 2015\" 28607 11314 3810 2536 4808 14089 3955 \n", 209 | " \"25 Oct 2015\" 28539 11298 3806 2535 4808 14061 3955 \n", 210 | " \"18 Oct 2015\" 28476 11298 3803 2535 … 4808 14001 3955 \n", 211 | " \"11 Oct 2015\" 28454 11297 3800 2534 4808 13982 3955 \n", 212 | " \"27 Sep 2015\" 28388 11296 3805 2533 4808 13911 3955 \n", 213 | " \"20 Sep 2015\" 28295 11295 3800 2532 4808 13823 3955 \n", 214 | " \"13 Sep 2015\" 28220 11291 3792 2530 4808 13756 3953 \n", 215 | " \"6 Sep 2015\" 28147 11291 3792 2530 … 4808 13683 3953 \n", 216 | " \"30 Aug 2015\" 28073 11290 3792 2529 4808 13609 3953 \n", 217 | " \"16 Aug 2015\" 27952 11284 3786 2524 4808 13494 3952 \n", 218 | " ⋮ ⋱ \n", 219 | " \"9 Aug 2014\" 1835 1011 506 373 323 730 315 \n", 220 | " \"30 Jul 2014\" 1437 825 472 346 227 574 252 \n", 221 | " \"23 Jul 2014\" 1201 672 427 319 129 525 224 \n", 222 | " \"14 Jul 2014\" 982 613 411 310 … 106 397 197 \n", 223 | " \"2 Jul 2014\" 779 481 412 305 75 252 101 \n", 224 | " \"17 Jun 2014\" 528 337 398 264 24 97 49 \n", 225 | " \"27 May 2014\" 309 202 281 186 11 16 5 \n", 226 | " \"12 May 2014\" 260 182 248 171 11 \"–\" \"–\"\n", 227 | " \"1 May 2014\" 239 160 226 149 … 11 \"-\" \"-\"\n", 228 | " \"14 Apr 2014\" 176 110 168 108 2 \"–\" \"–\"\n", 229 | " \"31 Mar 2014\" 130 82 122 80 2 \"–\" \"–\"\n", 230 | " \"22 Mar 2014\" 49 29 49 29 \"–\" \"–\" \"–\"" 231 | ] 232 | }, 233 | "execution_count": 3, 234 | "metadata": {}, 235 | "output_type": "execute_result" 236 | } 237 | ], 238 | "source": [ 239 | "wikiEVDraw = readdlm(\"wikipediaEVDraw.csv\", ',') # getting quotes right is important!" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "metadata": {}, 245 | "source": [ 246 | "The readdlm() function is Julia's way to read any file that consists of lines separated into data items with a delimeter of some sort. In fact, the very word \"readdlm\" is an abbreviation of \"read-with-a-delimiter\". \n", 247 | "\n", 248 | "Notice three things\n", 249 | "- We have used a variable to contain the data from the file (you could change the name, though, if you like)\n", 250 | "- The file name is given as a string, using double quotes\n", 251 | "- The delimeter is given as a character, using single quotes\n", 252 | "\n", 253 | "Finally, we see that the type of the data, after it has been stored in the variable is an array, the elements of which are of Any type. This is not good for computation---in particular, for modelling we need the data in terms of days since the start of the epidemic. Our next job is to convert the strings in columnn one into integers which give number of days since 22 March 2014." 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": {}, 259 | "source": [ 260 | "[Back to the top](#In-this-lecture)" 261 | ] 262 | } 263 | ], 264 | "metadata": { 265 | "kernelspec": { 266 | "display_name": "Julia 0.4.6", 267 | "language": "julia", 268 | "name": "julia-0.4" 269 | }, 270 | "language_info": { 271 | "file_extension": ".jl", 272 | "mimetype": "application/julia", 273 | "name": "julia", 274 | "version": "0.4.6" 275 | } 276 | }, 277 | "nbformat": 4, 278 | "nbformat_minor": 0 279 | } 280 | -------------------------------------------------------------------------------- /Week1_4-ArithmeticalExp.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "# Arithmetical expressions " 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lecture

\n", 123 | "\n", 124 | "- [Outcome](#Outcome)\n", 125 | "- [A really simple example](#A-really-simple-example)\n", 126 | "- [Operator Precedence in Julia](#Operator-Precedence-in-Julia)\n" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "
\n", 134 | "

Outcome

\n", 135 | "\n", 136 | "After this lecture, you will be able to: \n", 137 | "\n", 138 | "- Form arithmetical expressions using numbers and operators\n", 139 | "- State the order of preference of Julia's elementary arithmetical operators\n", 140 | "- Work out exactly how Julia would evalutate an arithmetical expression" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "[Back to the top](#In-this-lecture)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "

A really simple example

" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 9, 160 | "metadata": { 161 | "collapsed": false 162 | }, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "-2" 168 | ] 169 | }, 170 | "execution_count": 9, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "1 - 2 + 3 - 4" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 10, 182 | "metadata": { 183 | "collapsed": false 184 | }, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "1.25" 190 | ] 191 | }, 192 | "execution_count": 10, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "1 / 2 + 3 / 4" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 11, 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "outputs": [ 208 | { 209 | "data": { 210 | "text/plain": [ 211 | "0.05" 212 | ] 213 | }, 214 | "execution_count": 11, 215 | "metadata": {}, 216 | "output_type": "execute_result" 217 | } 218 | ], 219 | "source": [ 220 | "1 / (2 + 3) / 4" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 12, 226 | "metadata": { 227 | "collapsed": false 228 | }, 229 | "outputs": [ 230 | { 231 | "data": { 232 | "text/plain": [ 233 | "0.36363636363636365" 234 | ] 235 | }, 236 | "execution_count": 12, 237 | "metadata": {}, 238 | "output_type": "execute_result" 239 | } 240 | ], 241 | "source": [ 242 | "1 / (2 + 3 / 4)" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 13, 248 | "metadata": { 249 | "collapsed": false 250 | }, 251 | "outputs": [ 252 | { 253 | "data": { 254 | "text/plain": [ 255 | "0.875" 256 | ] 257 | }, 258 | "execution_count": 13, 259 | "metadata": {}, 260 | "output_type": "execute_result" 261 | } 262 | ], 263 | "source": [ 264 | "(1 / 2 + 3 ) / 4" 265 | ] 266 | }, 267 | { 268 | "cell_type": "markdown", 269 | "metadata": {}, 270 | "source": [ 271 | "[Back to the top](#In-this-lecture)" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "metadata": {}, 277 | "source": [ 278 | "

Operator Precedence in Julia

\n", 279 | "\n", 280 | "The plus, minus, multiply and divide operators in Julia are, of course, + - / and *.\n", 281 | "\n", 282 | "When several of them occur, it can be ambiguous to the human eye, for example 1 / 2 / 3. From the left, it is a third of one half. From the right, it is one divided by two thirds. So from the left it is 1/6, and from the right it is 3/2.\n", 283 | "\n", 284 | "In Julia, though, there is only one way to read it: from the left.\n", 285 | "\n", 286 | "Likewise, from the left, 2 - 3 + 4 is 3, from the right it is -5, and in Julia it can only be 3.\n", 287 | "\n", 288 | "Similarly, 2^3/2 is read as follows: first the ^ operator makes 2^3 into 8, and then division by 2 makes it 4. To get the other possibility, you have to use parentheses, namely 2^(3/2)." 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 14, 294 | "metadata": { 295 | "collapsed": false 296 | }, 297 | "outputs": [ 298 | { 299 | "name": "stdout", 300 | "output_type": "stream", 301 | "text": [ 302 | "0.16666666666666666\n", 303 | "3\n", 304 | "4.0\n", 305 | "2.82842712474619\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "println(1/2/3) # remember that println can do simple arithmetic!\n", 311 | "println(2-3+4)\n", 312 | "println(2^3/2) # although both inputs are Int64, and the output could be Int64, it is in fact Float64\n", 313 | "println( 2^(3/2) ) # the extra spaces inside the parenthesis help the human reader" 314 | ] 315 | }, 316 | { 317 | "cell_type": "markdown", 318 | "metadata": {}, 319 | "source": [ 320 | "\n", 321 | "\n", 322 | "In Julia, as in many other languages (in particular Matlab and Python), the order of arithmetical operations is as follows:\n", 323 | "\n", 324 | "--- do the insides of parentheses first\n", 325 | "\n", 326 | "--- then do exponentiation\n", 327 | "\n", 328 | "--- then do multiplication and division, from left to right\n", 329 | "\n", 330 | "--- finally, do addition and subtraction, from left to right" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 15, 336 | "metadata": { 337 | "collapsed": false 338 | }, 339 | "outputs": [ 340 | { 341 | "data": { 342 | "text/plain": [ 343 | "-11.725000000000001" 344 | ] 345 | }, 346 | "execution_count": 15, 347 | "metadata": {}, 348 | "output_type": "execute_result" 349 | } 350 | ], 351 | "source": [ 352 | "# Let's do some exercises in this. Predict the output of, then run these expressions\n", 353 | "0.2 + 0.1 - 3 * 6.7 / 4 - 1 - 2 * 3 #BAD CODE! It mixes types: some Int64, some Float64!!" 354 | ] 355 | }, 356 | { 357 | "cell_type": "markdown", 358 | "metadata": {}, 359 | "source": [ 360 | "You can really go to town, Julia allows extremely long arithmetical expressions:" 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "execution_count": 17, 366 | "metadata": { 367 | "collapsed": false 368 | }, 369 | "outputs": [ 370 | { 371 | "data": { 372 | "text/plain": [ 373 | "1.4290565829566904" 374 | ] 375 | }, 376 | "execution_count": 17, 377 | "metadata": {}, 378 | "output_type": "execute_result" 379 | } 380 | ], 381 | "source": [ 382 | ".1010101 ^ 2.33333333 - (17/18/19/20/20) + 1. / (1. + 2. / (1. + 3. / (1. + 5.)))^.1010101 ^ 2.33333333 - (17/18/19/20/20) + 1. / (1. + 2. / (1. + 3. / (1. + 5.)))" 383 | ] 384 | }, 385 | { 386 | "cell_type": "markdown", 387 | "metadata": {}, 388 | "source": [ 389 | "[Back to the top](#In-this-lecture)" 390 | ] 391 | } 392 | ], 393 | "metadata": { 394 | "kernelspec": { 395 | "display_name": "Julia 0.4.6", 396 | "language": "julia", 397 | "name": "julia-0.4" 398 | }, 399 | "language_info": { 400 | "file_extension": ".jl", 401 | "mimetype": "application/julia", 402 | "name": "julia", 403 | "version": "0.4.6" 404 | } 405 | }, 406 | "nbformat": 4, 407 | "nbformat_minor": 0 408 | } 409 | -------------------------------------------------------------------------------- /Week2_1-EbolaExample.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 1, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "

The Ebola epidemic of 2014

" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lecture

\n", 123 | "\n", 124 | "- [Outcome](#Outcome)\n", 125 | "- [Ebola Virus Disease (EVD)](#Ebola-Virus-Disease)\n", 126 | "- [The West African EVD epidemic](#The-West-African-EVD-epidemic)\n", 127 | "- [Models vs data vs reality: the case of West African EVD](#Models-vs-data-vs-reality:-the-case-of-West-African-EVD)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "[Back to the top](#In-this-lecture)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "

Outcome

\n", 142 | "\n", 143 | "After this lecture, you will be able to\n", 144 | "- Describe Ebola Virus Disease \n", 145 | "- Outline the time course of the West African EVD epidemic \n", 146 | "- Distinguish the reality of EVD from two related things: models of the disease and the available data on the disease\n", 147 | "\n", 148 | "[Back to the top](#In-this-lecture)" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "

Ebola Virus Disease

\n", 156 | "\n", 157 | "\n", 158 | "Ebola Virus Disease (EVD) is spread by direct contact with body fluids. Unlike flu and colds, airborne particles do not spread the disease.\n", 159 | "\n", 160 | "An infected person is likely to get very ill (symptoms include pain, fever, diarrhea and vomiting) and also quite likely to die---in the epidemic we'll consider, up to 7 out of every 10 untreated cases died, and overall approximately 1 out of 3 known cases died.\n", 161 | "\n", 162 | "It is not entirely clear how infectious the disease really is. People in daily contact with an ill person, in particular those who frequently touch them and/or their clothing and bedclothes seem to be at high risk unless special precautions are taken. At one stage of the epidemic, it was said that 1 in every 10 cases were medical personnel involved in caring for the sick. On the other hand, merely being in the presence of ill people seems not to be a big risk.\n", 163 | "\n", 164 | "The disease lasts about three weeks in most people, after which they are either dead or the virus is no longer active in their bodies. The infectious period seems to be concentrated around the third week, which is when the disease is most acute.\n", 165 | "\n", 166 | "However, in some cases it appears that the virus may persist in an inactive form in the bodies of survivors. It is not clear how long this lasts nor how likely survivors are to become infectious again. Sadly, it is true that many survivors continue to experience health problems due to EVD." 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "[Back to the top](#In-this-lecture)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "

The West African EVD epidemic

\n", 181 | "\n", 182 | "Up to 2013, all known cases of EVD were in Central Africa. But in 2014, several cases were reported from Guinea in West Africa, and these were eventually traced back to a child who became ill and died in December 2013.\n", 183 | "\n", 184 | "This child infected three family members who subsequently also died. The social context is one of small villages fairly near each other, and the disease spread into neighbouring villages. From there it rapidly spread into other areas of Guinea, and also to the neighbouring countries Liberia and Sierra Leone (but not to other neighbouring countries, except briefly into Mali). In all three countries, it spread not only through small villages but also through towns and cities.\n", 185 | "\n", 186 | "Because a single case of EVD can potentially infect many others in a short time, and because it kills so many who get ill, it represents a very serious health threat anywhere that it appears. In Guinea it was at first not recognised, because many diseases have similar symptoms and it was unknown in West Africa. Moreover, Guinea, Liberia and Sierra Leone are countries that have suffered extensive disruption through civil war and consequently have weak health systems and there is much mistrust of government. The initial response to EVD in these countries could not contain it, and it became widespread within months. Throughout much of 2014, the number of new cases per week seemed to be increasing.\n", 187 | "\n", 188 | "While in many ways one would wish that the world responded more rapidly and fully, eventually there was a strong effort, particularly by Doctors Without Borders and the World Health Organisation. They, together with local health authorities and the government, were able eventually to provided effective treatment and prevention measures. By late 2014, the number of new cases per week was not growing and throughout 2015 the new cases per week became fewer and fewer.\n", 189 | "\n", 190 | "In most of 2016, there were no new cases in the three worst-affected countries. The international emergency is over. However, the health systems in all three countries remain on the alert for possible flare-ups. And of course, the survivors are still living with the severe consequences of the epidemic.\n", 191 | "\n" 192 | ] 193 | }, 194 | { 195 | "cell_type": "markdown", 196 | "metadata": {}, 197 | "source": [ 198 | "[Back to the top](#In-this-lecture)" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "

Models vs data vs reality: the case of West African EVD

\n", 206 | "\n", 207 | "So what does this have to do with writing Julia code? \n", 208 | "\n", 209 | "Answer: Julia can be used to explore the EVD epidemic, and this process of exploring will illustrate many of the features of the language.\n", 210 | "\n", 211 | "In the lectures of Week 2, you will explore publicly available data, in the process learning about the following aspects of Julia:\n", 212 | "- handling date-time data\n", 213 | "- \"for\" loops\n", 214 | "- making plots\n", 215 | "- \"if\" statements\n", 216 | "as well as getting practice with array slicing and user-defined functions.\n", 217 | "\n", 218 | "In the lectures of Week 3, you will study one particular way of modelling the epidemic. In the process, you will \n", 219 | "- extend your familiarity with for loops\n", 220 | "- learn how to pass parameters to functions\n", 221 | "- learn how to use a Julia notebook for hand-fitting a curve to data\n", 222 | "\n", 223 | "You might be tempted to think that the model of the epidemic is really how it spread. Please resist that! A model is *ALWAYS* far simpler than the real thing. In fact, a model is simpler than the data it is fitted to. This is the whole point of the model: it is fairly simple and can be completely understood. The real world is hugely more intricate than is captured in the data (for example, the actual social relations, the actual contacts between people, the role of travelling from place to place, the role of animals, etc., etc., are not part of the data at all).\n", 224 | "\n", 225 | "The hope is that by measuring relevant things (in this case, keeping count of how many people have got ill), one can understand enough to be able to do something useful. The most important thing in the case of the EVD epidemic was to realise that it *was* an epidemic, and could potentially spread through the entire country, possibly the entire region, and possibly even the whole world.\n", 226 | "\n", 227 | "Note that a serious viral epidemic spread in 1918 through the whole world (in that case, though, infection was through air-borne particles, greatly increasing the number of people that one ill person could infect).\n", 228 | "\n", 229 | "It is this that EVD modelling hopes to understand, and eventually to help to contain." 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "[Back to the top](#In-this-lecture)" 237 | ] 238 | } 239 | ], 240 | "metadata": { 241 | "kernelspec": { 242 | "display_name": "Julia 0.4.5", 243 | "language": "julia", 244 | "name": "julia-0.4" 245 | }, 246 | "language_info": { 247 | "file_extension": ".jl", 248 | "mimetype": "application/julia", 249 | "name": "julia", 250 | "version": "0.4.5" 251 | } 252 | }, 253 | "nbformat": 4, 254 | "nbformat_minor": 0 255 | } 256 | -------------------------------------------------------------------------------- /Week1_2-JuliaBox.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "# Getting ready---JuliaBox (live programming using a website)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lecture

" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "- [Outcome](#Outcome)\n", 130 | "- [The JuliaBox website](#The-JuliaBox-website)\n", 131 | "- [Naming, saving, opening JuliaBox notebooks](#Naming,-saving,-opening-JuliaBox-notebooks)\n", 132 | "- [A Few More Comments](#A-Few-More-Comments)\n", 133 | "- [IJulia](#IJulia)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "

Outcome

\n", 141 | "\n", 142 | "After this lecture, you will be able to\n", 143 | "- Login to JuliaBox.com\n", 144 | "- Start a new notebook on JuliaBox.com\n", 145 | "- Do elementary arithmetic in a JuliaBox.com notebook code cell\n", 146 | "- Name, save and rename notebooks on JuliaBox.com\n", 147 | "- Open an existing notebook on JuliaBox.com\n", 148 | "- (optionally) Install IJulia and run interactive notebooks on your own computer" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "[Back to the top](#In-this-lecture)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "

The JuliaBox website

\n", 163 | "\n", 164 | "If you don't have a GMail account, please create one now. Then login to www.juliabox.com (via GMail). You should see something like this:\n", 165 | "\n", 166 | "\"(Screenshot\n", 167 | "\n", 168 | "\n", 169 | "\n", 170 | "\n", 171 | "Click on the New button (near the top right), selecting Julia 0.4.6 as your kernel. It opens a new tab in your browser, using the name Untitled. It should look like this:\n", 172 | "\n", 173 | "\"(Screenshot\n", 174 | "\n", 175 | "\n", 176 | "What you see is an empty notebook, with a cell ready to receive input. Note that it is a code cell, indicated by a message in the toolbar at the top of your browser page, and also by the \"In [ ]:\" to the left of the cell.\n", 177 | "\n", 178 | "You will need to ensure that cells with code in them are always code cells. Otherwise they will not do any programming tasks for you.\n", 179 | "\n", 180 | "Let's try it out! We'll enter some very elementary arithmetic expressions, and get the notebook to evaluate them by pressing Shift-Enter\n" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 5, 186 | "metadata": { 187 | "collapsed": false 188 | }, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "2" 194 | ] 195 | }, 196 | "execution_count": 5, 197 | "metadata": {}, 198 | "output_type": "execute_result" 199 | } 200 | ], 201 | "source": [ 202 | "1+1" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 6, 208 | "metadata": { 209 | "collapsed": false 210 | }, 211 | "outputs": [ 212 | { 213 | "data": { 214 | "text/plain": [ 215 | "-31" 216 | ] 217 | }, 218 | "execution_count": 6, 219 | "metadata": {}, 220 | "output_type": "execute_result" 221 | } 222 | ], 223 | "source": [ 224 | "2003 * 2016\n", 225 | "45 - 76\n" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "Note that the elementary arithmetic operators are + - * \\ ^ \n", 233 | "\n", 234 | "Parentheses should be used when there is any possibility of more than one interpretation." 235 | ] 236 | }, 237 | { 238 | "cell_type": "markdown", 239 | "metadata": {}, 240 | "source": [ 241 | "[Back to the top](#In-this-lecture)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "metadata": {}, 247 | "source": [ 248 | "

Naming, saving, opening JuliaBox notebooks

\n", 249 | "\n", 250 | "One often wants to save a notebook for future use. JuliaBox gives it the unhelpful name \"Untitled\", so the first step is to rename your current notebook.\n", 251 | "\n", 252 | "To do so, click on File (near the top left), a menu opens, click Rename... and type the name of your choice in the box that opens. Click OK or just hit Enter.\n", 253 | "\n", 254 | "Every once in a while you should save the notebook you are currently working on, and also just before closing the notebook and leaving. \n", 255 | "\n", 256 | "To save, click on File and in the menu click the Save and Checkpoint option.\n", 257 | "\n", 258 | "One should always leave gracefully, if you can. So when done with a notebook, click on File, click on Save and Checkpoint, and then click the Close and Halt option.\n", 259 | "\n", 260 | "At any time you wish to, you can open the notebook again. Just go the directory page, which is the very first one that JuliaBox opened for you. It will be there under you name you saved it as. Just click on it, and it opens in its own tab." 261 | ] 262 | }, 263 | { 264 | "cell_type": "markdown", 265 | "metadata": {}, 266 | "source": [ 267 | "[Back to the top](#In-this-lecture)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "metadata": {}, 273 | "source": [ 274 | "

A Few More Comments

\n", 275 | "\n", 276 | "### Julia is an interpreted language\n", 277 | "\n", 278 | "What you have just seen is a demonstration of how interpreted languages work: the moment they get a complete line of code, they execute it. Python and Matlab are also interpreted languages.\n", 279 | "\n", 280 | "This is the opposite of compiled languages like C and Fortran. There, the code has to be compiled before it is run." 281 | ] 282 | }, 283 | { 284 | "cell_type": "markdown", 285 | "metadata": {}, 286 | "source": [ 287 | "### Julia as a command line interpreter\n", 288 | "\n", 289 | "Actually, the situation here in a notebook is a bit of a luxury: one can put several lines in cell and execute them all at once. From the command line, really one can only execute one line at a time****. In this, it is quite similar to Python and Matlab.\n", 290 | "\n", 291 | "****Terms and conditions apply: a single command line entry can look as if it contains several lines. And one can chain several (usually very short) commands on one line." 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "metadata": {}, 297 | "source": [ 298 | "### Code files in Julia\n", 299 | "\n", 300 | "Although JuliaBox (equivalently IJulia) is a wonderful environment in which to explore the pleasures of coding in Julia, you should know that many Julia projects consists purely of files that contain lines of Julia code.\n", 301 | "\n", 302 | "This of course is how most computer programs are organised.\n", 303 | "\n", 304 | "In particular, Julia itself consists of a very basic core, written in C, the Base package, mostly written in Julia, and many extensions, some of them written in other languages but mostly written in Julia. This adds up to many thousands of lines of code, organised in hundreds of files.\n", 305 | "\n", 306 | "In this course, we will not require you to write files of Julia code." 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "metadata": {}, 312 | "source": [ 313 | "### The Base package\n", 314 | "\n", 315 | "When you start a new notebook on JuliaBox, you have available to you the Base package. But often one wants to do things that are available only in extensions. They then have to be added to your JuliaBox session. We will cover that in Lesson 3, and use several of the extension packages in Lesson 3 and in Lesson 4." 316 | ] 317 | }, 318 | { 319 | "cell_type": "markdown", 320 | "metadata": {}, 321 | "source": [ 322 | "[Back to the top](#In-this-lecture)" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "metadata": {}, 328 | "source": [ 329 | "

IJulia

\n", 330 | "\n", 331 | "\n", 332 | "For those of you who have installed Julia on your own local computer, here's how to get interactive notebooks running\n", 333 | "\n", 334 | "Step 1: Start Julia, and go to the command line.\n", 335 | "\n", 336 | "Step 2: Install IJulia by typing and entering \"Pkg.add(\"IJulia\")\".\n", 337 | "\n", 338 | "Step 3: Activate IJulia by typing and entering \"using IJulia\".\n", 339 | "\n", 340 | "Step 4: Start up IJulia by typing and entering \"notebook()\". It opens in a browser (if necessary, starting up the browser).\n", 341 | "\n", 342 | "It can be a little unclear how to shut it down. I generally first close the browser window, then return to the Julia terminal and press Ctrl-C. The other way round also works. " 343 | ] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "metadata": {}, 348 | "source": [ 349 | "[Back to the top](#In-this-lecture)" 350 | ] 351 | } 352 | ], 353 | "metadata": { 354 | "kernelspec": { 355 | "display_name": "Julia 0.4.7", 356 | "language": "julia", 357 | "name": "julia-0.4" 358 | }, 359 | "language_info": { 360 | "file_extension": ".jl", 361 | "mimetype": "application/julia", 362 | "name": "julia", 363 | "version": "0.4.7" 364 | } 365 | }, 366 | "nbformat": 4, 367 | "nbformat_minor": 0 368 | } 369 | -------------------------------------------------------------------------------- /Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Julia Version 1.0.3\n", 13 | "Commit 099e826241 (2018-12-18 01:34 UTC)\n", 14 | "Platform Info:\n", 15 | " OS: Linux (x86_64-pc-linux-gnu)\n", 16 | " CPU: Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz\n", 17 | " WORD_SIZE: 64\n", 18 | " LIBM: libopenlibm\n", 19 | " LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)\n", 20 | "Environment:\n", 21 | " JULIABOX = true\n", 22 | " JULIA_PKG_SERVER = https://pkg.juliacomputing.com\n", 23 | " JULIA = /opt/julia-0.6/bin/julia\n", 24 | " JULIA_KERNELS = ['julia-0.6', 'julia-1.0', 'julia-1.0k']\n", 25 | " JULIA_PKG_TOKEN_PATH = /mnt/juliabox/.julia/token.toml\n", 26 | " JULIABOX_ROLE = \n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "versioninfo()" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "# Functions" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "* A function maps a tuple of arguments to a return value" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## I Creating basic Functions" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 2, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "my_addition (generic function with 1 method)" 64 | ] 65 | }, 66 | "execution_count": 2, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "# 1 using the function keyword\n", 73 | "#Create a function named my_addition\n", 74 | "#Takes two arguments\n", 75 | "#Return the addition of the two values\n", 76 | "function my_addition(x, y)\n", 77 | " return x + y\n", 78 | "end" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 3, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "7" 90 | ] 91 | }, 92 | "execution_count": 3, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "# 2 Calling a function\n", 99 | "#Call the function with two argument values\n", 100 | "my_addition(3, 4)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 4, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "data": { 110 | "text/plain": [ 111 | "7" 112 | ] 113 | }, 114 | "execution_count": 4, 115 | "metadata": {}, 116 | "output_type": "execute_result" 117 | } 118 | ], 119 | "source": [ 120 | "# 3 Built-in functions\n", 121 | "#The plus, +, symbol (as other arithmetical symbols) are built-in functions\n", 122 | "+(3, 4)" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 5, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/plain": [ 133 | "Σ (generic function with 1 method)" 134 | ] 135 | }, 136 | "execution_count": 5, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "# 4 Using a Unicode symbol as a function name (done by typing \\Sigma and hitting the Tab key)\n", 143 | "function Σ(x, y)\n", 144 | " return x + y\n", 145 | "end" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 6, 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "7" 157 | ] 158 | }, 159 | "execution_count": 6, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "Σ(3, 4)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "## II Anonymous functions" 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": {}, 178 | "source": [ 179 | "* Functions can be assigned to variables\n", 180 | "* Functions can be used as arguments\n", 181 | "* Functions can be returned as values" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 7, 187 | "metadata": {}, 188 | "outputs": [ 189 | { 190 | "data": { 191 | "text/plain": [ 192 | "#3 (generic function with 1 method)" 193 | ] 194 | }, 195 | "execution_count": 7, 196 | "metadata": {}, 197 | "output_type": "execute_result" 198 | } 199 | ], 200 | "source": [ 201 | "# 1 An anonymous function\n", 202 | "x -> x^2 + 3" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 8, 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "data": { 212 | "text/plain": [ 213 | "3-element Array{Float64,1}:\n", 214 | " 2.0\n", 215 | " 3.0\n", 216 | " 8.0" 217 | ] 218 | }, 219 | "execution_count": 8, 220 | "metadata": {}, 221 | "output_type": "execute_result" 222 | } 223 | ], 224 | "source": [ 225 | "# 2 A function as an argument\n", 226 | "#Passing the round() function as argument to the map() function\n", 227 | "map(round, [2.1, 3.4, 7.9])" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 9, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "3-element Array{Int64,1}:\n", 239 | " 4\n", 240 | " 9\n", 241 | " 16" 242 | ] 243 | }, 244 | "execution_count": 9, 245 | "metadata": {}, 246 | "output_type": "execute_result" 247 | } 248 | ], 249 | "source": [ 250 | "#Passing an anonymous function as an arguemt to the map() function\n", 251 | "map(x -> x^2, [2, 3, 4])" 252 | ] 253 | }, 254 | { 255 | "cell_type": "markdown", 256 | "metadata": {}, 257 | "source": [ 258 | "## III Tuples and functions" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "* Tuples are immutable collections" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 10, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/plain": [ 276 | "(1, \"Julia\", 7)" 277 | ] 278 | }, 279 | "execution_count": 10, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "# 1 Examples of tuples\n", 286 | "my_tuple = (1, \"Julia\", 7)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 11, 292 | "metadata": {}, 293 | "outputs": [ 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "Tuple{Int64,String,Int64}" 298 | ] 299 | }, 300 | "execution_count": 11, 301 | "metadata": {}, 302 | "output_type": "execute_result" 303 | } 304 | ], 305 | "source": [ 306 | "typeof(my_tuple)" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 12, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "data": { 316 | "text/plain": [ 317 | "(4,)" 318 | ] 319 | }, 320 | "execution_count": 12, 321 | "metadata": {}, 322 | "output_type": "execute_result" 323 | } 324 | ], 325 | "source": [ 326 | "# * Single value tuple must have a comma\n", 327 | "my_second_tuple = (4,)" 328 | ] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": 13, 333 | "metadata": {}, 334 | "outputs": [ 335 | { 336 | "data": { 337 | "text/plain": [ 338 | "Tuple{Int64}" 339 | ] 340 | }, 341 | "execution_count": 13, 342 | "metadata": {}, 343 | "output_type": "execute_result" 344 | } 345 | ], 346 | "source": [ 347 | "typeof(my_second_tuple)" 348 | ] 349 | }, 350 | { 351 | "cell_type": "code", 352 | "execution_count": 14, 353 | "metadata": {}, 354 | "outputs": [ 355 | { 356 | "data": { 357 | "text/plain": [ 358 | "3" 359 | ] 360 | }, 361 | "execution_count": 14, 362 | "metadata": {}, 363 | "output_type": "execute_result" 364 | } 365 | ], 366 | "source": [ 367 | "# 2 Indexing a tuple\n", 368 | "length(my_tuple)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 15, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "\"Julia\"" 380 | ] 381 | }, 382 | "execution_count": 15, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "my_tuple[2]" 389 | ] 390 | }, 391 | { 392 | "cell_type": "code", 393 | "execution_count": 16, 394 | "metadata": {}, 395 | "outputs": [ 396 | { 397 | "data": { 398 | "text/plain": [ 399 | "(a = 4, b = \"Julia\", c = 3)" 400 | ] 401 | }, 402 | "execution_count": 16, 403 | "metadata": {}, 404 | "output_type": "execute_result" 405 | } 406 | ], 407 | "source": [ 408 | "# 3 Tuple indexing\n", 409 | "# * Named tuple creates a name for each element\n", 410 | "my_other_tuple = (a = 4, b = \"Julia\", c = 3)" 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "execution_count": 17, 416 | "metadata": {}, 417 | "outputs": [ 418 | { 419 | "data": { 420 | "text/plain": [ 421 | "\"Julia\"" 422 | ] 423 | }, 424 | "execution_count": 17, 425 | "metadata": {}, 426 | "output_type": "execute_result" 427 | } 428 | ], 429 | "source": [ 430 | "#Indexing tuple by name\n", 431 | "my_other_tuple.b" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": 18, 437 | "metadata": {}, 438 | "outputs": [ 439 | { 440 | "data": { 441 | "text/plain": [ 442 | "my_function (generic function with 1 method)" 443 | ] 444 | }, 445 | "execution_count": 18, 446 | "metadata": {}, 447 | "output_type": "execute_result" 448 | } 449 | ], 450 | "source": [ 451 | "# 4 Function returns\n", 452 | "# * Multiple return values of a function are tuples\n", 453 | "function my_function(a, b)\n", 454 | " return a + b, a - b\n", 455 | "end" 456 | ] 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": 19, 461 | "metadata": {}, 462 | "outputs": [ 463 | { 464 | "data": { 465 | "text/plain": [ 466 | "(15, 5)" 467 | ] 468 | }, 469 | "execution_count": 19, 470 | "metadata": {}, 471 | "output_type": "execute_result" 472 | } 473 | ], 474 | "source": [ 475 | "#Calling the function\n", 476 | "my_function(10, 5)" 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 20, 482 | "metadata": {}, 483 | "outputs": [ 484 | { 485 | "data": { 486 | "text/plain": [ 487 | "Tuple{Int64,Int64}" 488 | ] 489 | }, 490 | "execution_count": 20, 491 | "metadata": {}, 492 | "output_type": "execute_result" 493 | } 494 | ], 495 | "source": [ 496 | "#Looking up the type of the function return\n", 497 | "typeof(my_function(10, 5))" 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 21, 503 | "metadata": {}, 504 | "outputs": [ 505 | { 506 | "data": { 507 | "text/plain": [ 508 | "(15, 5)" 509 | ] 510 | }, 511 | "execution_count": 21, 512 | "metadata": {}, 513 | "output_type": "execute_result" 514 | } 515 | ], 516 | "source": [ 517 | "#This allows for each element to be given a variable name\n", 518 | "r, s = my_function(10, 5)" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": 22, 524 | "metadata": {}, 525 | "outputs": [ 526 | { 527 | "data": { 528 | "text/plain": [ 529 | "15" 530 | ] 531 | }, 532 | "execution_count": 22, 533 | "metadata": {}, 534 | "output_type": "execute_result" 535 | } 536 | ], 537 | "source": [ 538 | "r" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 23, 544 | "metadata": {}, 545 | "outputs": [ 546 | { 547 | "data": { 548 | "text/plain": [ 549 | "5" 550 | ] 551 | }, 552 | "execution_count": 23, 553 | "metadata": {}, 554 | "output_type": "execute_result" 555 | } 556 | ], 557 | "source": [ 558 | "s" 559 | ] 560 | }, 561 | { 562 | "cell_type": "markdown", 563 | "metadata": {}, 564 | "source": [ 565 | "## IV Functions with keyword arguments" 566 | ] 567 | }, 568 | { 569 | "cell_type": "markdown", 570 | "metadata": {}, 571 | "source": [ 572 | "* Keyword arguments are added after semi-colon\n", 573 | "* Their order is not explicit\n", 574 | "* Default values are addded" 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "execution_count": 24, 580 | "metadata": {}, 581 | "outputs": [ 582 | { 583 | "data": { 584 | "text/plain": [ 585 | "my_keyword_function (generic function with 1 method)" 586 | ] 587 | }, 588 | "execution_count": 24, 589 | "metadata": {}, 590 | "output_type": "execute_result" 591 | } 592 | ], 593 | "source": [ 594 | "# 1 Creating a function with a keyword argument\n", 595 | "function my_keyword_function(x, y; z = 3)\n", 596 | " return x + y + z\n", 597 | "end" 598 | ] 599 | }, 600 | { 601 | "cell_type": "code", 602 | "execution_count": 25, 603 | "metadata": {}, 604 | "outputs": [ 605 | { 606 | "data": { 607 | "text/plain": [ 608 | "6" 609 | ] 610 | }, 611 | "execution_count": 25, 612 | "metadata": {}, 613 | "output_type": "execute_result" 614 | } 615 | ], 616 | "source": [ 617 | "# 2 Omission of keyword argument uses default\n", 618 | "my_keyword_function(1, 2)" 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "execution_count": 26, 624 | "metadata": {}, 625 | "outputs": [ 626 | { 627 | "data": { 628 | "text/plain": [ 629 | "13" 630 | ] 631 | }, 632 | "execution_count": 26, 633 | "metadata": {}, 634 | "output_type": "execute_result" 635 | } 636 | ], 637 | "source": [ 638 | "# 3 Keyword argument names must be used\n", 639 | "my_keyword_function(1, 2, z = 10)" 640 | ] 641 | }, 642 | { 643 | "cell_type": "code", 644 | "execution_count": 27, 645 | "metadata": {}, 646 | "outputs": [ 647 | { 648 | "data": { 649 | "text/plain": [ 650 | "5-element Array{Float64,1}:\n", 651 | " 0.0 \n", 652 | " 1.0 \n", 653 | " 1.2246467991473532e-16\n", 654 | " -1.0 \n", 655 | " 1.2246467991473532e-16" 656 | ] 657 | }, 658 | "execution_count": 27, 659 | "metadata": {}, 660 | "output_type": "execute_result" 661 | } 662 | ], 663 | "source": [ 664 | "# 4 Use of dot notation for functions\n", 665 | "#Passes a collection elementwise to a function\n", 666 | "#Use instead of map()\n", 667 | "sin.([0., π/2., π, 3/2. * π, π])" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": null, 673 | "metadata": {}, 674 | "outputs": [], 675 | "source": [] 676 | } 677 | ], 678 | "metadata": { 679 | "kernelspec": { 680 | "display_name": "Julia 1.0.3", 681 | "language": "julia", 682 | "name": "julia-1.0" 683 | }, 684 | "language_info": { 685 | "file_extension": ".jl", 686 | "mimetype": "application/julia", 687 | "name": "julia", 688 | "version": "1.0.3" 689 | } 690 | }, 691 | "nbformat": 4, 692 | "nbformat_minor": 2 693 | } 694 | -------------------------------------------------------------------------------- /Week1_3-REPL.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 2, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "

The Julia REPL: strings, arithmetic

" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "

In this lecture

\n", 123 | "\n", 124 | "- [Outcome](#Outcome)\n", 125 | "- [The REPL](#The-REPL)\n", 126 | "- [Further REPL examples](#Further-REPL-examples)\n", 127 | "- [Points of note](#Points-of-note)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "[Back to the top](#In-this-lecture)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "

Outcome

\n", 142 | "\n", 143 | "After this lecture, you will be able to\n", 144 | "- Say what the Julia REPL is and what it does \n", 145 | "- Understand and use println()\n", 146 | "- Make strings, and combine them using * and ^\n", 147 | "- Say what is special about the characters \"\\\" and \"$\"\n", 148 | "\n", 149 | "[Back to the top](#In-this-lecture)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "

The REPL

\n", 157 | "\n", 158 | "The basic process in Julia is the REPL, which stands for \"Read-Evaluate-Print Loop\".\n", 159 | "\n", 160 | "Every time you take a step in Julia (hitting Shift-Enter in JuliaBox, for instance), you run through this loop.\n", 161 | "\n", 162 | "Try it: open a new notebook in JuliaBox (just click on New towards the top right), and in the cell (NB! leave it in code mode!) type the line below, then press Shift-Enter." 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 1, 168 | "metadata": { 169 | "collapsed": false 170 | }, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "Hello, world!\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "println(\"Hello, world!\")" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "Famously, the first program in any language. A one-liner. Let's see how it works." 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": {}, 194 | "source": [ 195 | "#### The \"println()\" part\n", 196 | "\n", 197 | "This is one of Julia's built-in functions. The word \"println\" is the name of the function, and it points to the code that the function uses to do its work.\n", 198 | "\n", 199 | "The parentheses \"( )\" is how Julia knows that it is dealing with a function. You need to watch carefully for the different kinds of delimiters in Julia. Here, it is \"()\", which we will call parentheses. Julia also uses \"[ ]\" which we will call brackets, and \"{ }\", which we will call braces.\n", 200 | "\n", 201 | "If you hadn't noticed, please now realise that the quotation marks in the previous paragraph are NOT part of the delimeters we are talking about, they are just there to indicate that we are talking about the actual signs between the quotation marks. \n", 202 | "\n", 203 | "That is, on this course we use quotation marks to show we are not concerned with what the signs between the quotation marks mean, we are just talking about those signs themselves. " 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "metadata": {}, 209 | "source": [ 210 | "#### The \"Hello, World!\" part\n", 211 | "\n", 212 | "Whatever is inside the parentheses of a function, is called the *argument* of that function. In this case, you see that the argument is inside quotation marks, and guess what? Yes---the function println() does not care about what the message means, it just puts whatever is inside the quotation marks on the screen.\n", 213 | "\n", 214 | "More or less in the way that a telephone needs to be indifferent to what human beings are actually saying ...\n", 215 | "\n", 216 | "In particular, println() must treat the argument purely as signs to be printed. By enclosing the message in double quotation marks, you turn it into a string which println() then displays without paying any attention to its contents.\n", 217 | "\n", 218 | "In Julia, strings are *immutable*. You can, if you like, use some part of a string, you can put strings together---but you can't actually change a string." 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "[Back to the top](#In-this-lecture)" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "

Further REPL examples

" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 2, 238 | "metadata": { 239 | "collapsed": false 240 | }, 241 | "outputs": [ 242 | { 243 | "data": { 244 | "text/plain": [ 245 | "5" 246 | ] 247 | }, 248 | "execution_count": 2, 249 | "metadata": {}, 250 | "output_type": "execute_result" 251 | } 252 | ], 253 | "source": [ 254 | "5 # this is a comment: the value 5 is entered ... and echoed" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 3, 260 | "metadata": { 261 | "collapsed": false 262 | }, 263 | "outputs": [ 264 | { 265 | "data": { 266 | "text/plain": [ 267 | "10" 268 | ] 269 | }, 270 | "execution_count": 3, 271 | "metadata": {}, 272 | "output_type": "execute_result" 273 | } 274 | ], 275 | "source": [ 276 | "5+5 # 5+5 is entered, evaluated, and the result is echoed" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": 4, 282 | "metadata": { 283 | "collapsed": false 284 | }, 285 | "outputs": [ 286 | { 287 | "name": "stdout", 288 | "output_type": "stream", 289 | "text": [ 290 | "1.2000000000000002\n", 291 | "16.8 ... evaluated!\n" 292 | ] 293 | } 294 | ], 295 | "source": [ 296 | "println(5-3.8) # println() treats numbers intelligently ... more or less\n", 297 | "\n", 298 | "println(5+15-3.2, \" ... evaluated!\" ) \n", 299 | " # one can mix numbers and strings in println() " 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 5, 305 | "metadata": { 306 | "collapsed": false 307 | }, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "Hello! My word!\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "println(\"Hello!\" * \" My word!\") # strings are combined using *" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 6, 324 | "metadata": { 325 | "collapsed": false 326 | }, 327 | "outputs": [ 328 | { 329 | "name": "stdout", 330 | "output_type": "stream", 331 | "text": [ 332 | "Hello! My word! My word! My word!\n" 333 | ] 334 | } 335 | ], 336 | "source": [ 337 | "println(\"Hello!\" * \" My word!\"^3) # strings are repeated using ^" 338 | ] 339 | }, 340 | { 341 | "cell_type": "markdown", 342 | "metadata": {}, 343 | "source": [ 344 | "[Back to the top](#In-this-lecture)" 345 | ] 346 | }, 347 | { 348 | "cell_type": "markdown", 349 | "metadata": {}, 350 | "source": [ 351 | "

Points of note

\n", 352 | "\n", 353 | "As I said, REPL stands for \"Read-Evaluate-Print Loop\". It is a feature of dynamic languages such as Julia, Python, and Matlab. \n", 354 | "\n", 355 | "Using the acronym REPL just emphasises that a dynamic language continually stands ready to execute one more line of code." 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "metadata": {}, 361 | "source": [ 362 | "### Strings\n", 363 | "\n", 364 | "Anything included in double quotes is a string in Julia. Of course, the only things you can include are items you can type out. These include ALMOST all the characters on your keyboard---letters, numbers, quotation marks.\n", 365 | "\n", 366 | "For example" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": 7, 372 | "metadata": { 373 | "collapsed": false 374 | }, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "\"abc!@#%^ .. kyking:;'<,>.?/\"" 380 | ] 381 | }, 382 | "execution_count": 7, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "\"abc!@#%^ .. kyking:;'<,>.?/\" # string of odd characters ..." 389 | ] 390 | }, 391 | { 392 | "cell_type": "markdown", 393 | "metadata": {}, 394 | "source": [ 395 | "The exceptions are the *escape* characters like \"\\\" and \"$\" (the most important ones for Julia). As follows:" 396 | ] 397 | }, 398 | { 399 | "cell_type": "code", 400 | "execution_count": 9, 401 | "metadata": { 402 | "collapsed": false 403 | }, 404 | "outputs": [ 405 | { 406 | "ename": "LoadError", 407 | "evalue": "LoadError: syntax: incomplete: invalid string syntax\nwhile loading In[9], in expression starting on line 1", 408 | "output_type": "error", 409 | "traceback": [ 410 | "LoadError: syntax: incomplete: invalid string syntax\nwhile loading In[9], in expression starting on line 1", 411 | "" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "\"\\\" " 417 | ] 418 | }, 419 | { 420 | "cell_type": "markdown", 421 | "metadata": {}, 422 | "source": [ 423 | "Our first bug! It is also a bug if the you try \"$\". But try \"\\$\" and println(\"\\$\") ... they don't throw any error message, but that doesn't mean they're doing what you want them to!\n", 424 | "\n", 425 | "Bugs are a big deal in programming --- some would say the main difference between expert and lay programmers is in how they deal with bugs.\n", 426 | "\n", 427 | "Learn to read bug reports, learn to love them. You will certainly see a great many if you carry on programming!\n", 428 | "\n", 429 | "The truth is, the error messages that tell you about bugs aren't always that helpful. This is one is not too bad, at least it talks about string syntax, so you know where to look.\n", 430 | "\n", 431 | "Incidentally, the interactive notebook can warn you about this particular bug" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": 24, 437 | "metadata": { 438 | "collapsed": true 439 | }, 440 | "outputs": [ 441 | { 442 | "ename": "LoadError", 443 | "evalue": "LoadError: syntax: incomplete: invalid string syntax\nwhile loading In[24], in expression starting on line 1", 444 | "output_type": "error", 445 | "traceback": [ 446 | "LoadError: syntax: incomplete: invalid string syntax\nwhile loading In[24], in expression starting on line 1", 447 | "" 448 | ] 449 | } 450 | ], 451 | "source": [ 452 | "println(\"\\\") #note the colour of the closing parenthesis---the argument is not a string" 453 | ] 454 | }, 455 | { 456 | "cell_type": "markdown", 457 | "metadata": {}, 458 | "source": [ 459 | "[Back to the top](#In-this-lecture)" 460 | ] 461 | } 462 | ], 463 | "metadata": { 464 | "kernelspec": { 465 | "display_name": "Julia 0.4.6", 466 | "language": "julia", 467 | "name": "julia-0.4" 468 | }, 469 | "language_info": { 470 | "file_extension": ".jl", 471 | "mimetype": "application/julia", 472 | "name": "julia", 473 | "version": "0.4.6" 474 | } 475 | }, 476 | "nbformat": 4, 477 | "nbformat_minor": 0 478 | } 479 | -------------------------------------------------------------------------------- /Week1_9-Functions2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 11, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/html": [ 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "\n", 18 | "\n", 19 | "\n", 93 | "\n" 94 | ], 95 | "text/plain": [ 96 | "HTML{ASCIIString}(\"\\n\\n\\n\\n\\n\\n\\n\\n\")" 97 | ] 98 | }, 99 | "execution_count": 11, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "# Setting up a custom stylesheet in IJulia\n", 106 | "file = open(\"style.css\") # A .css file in the same folder as this notebook file\n", 107 | "styl = readall(file) # Read the file\n", 108 | "HTML(\"$styl\") # Output as HTML" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "# Functions in Julia II" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": { 121 | "collapsed": true 122 | }, 123 | "source": [ 124 | "

In this lecture

\n", 125 | "\n", 126 | "- [Outcome](#Outcome)\n", 127 | "- [One-line function definition](#One-line-function-definition)\n", 128 | "- [Multi-line function definition](#Multi-line-function-definition)\n", 129 | "- [Functions with multiple methods](#Functions-with-multiple-methods)\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "
\n", 137 | "

Outcome

\n", 138 | "\n", 139 | "After this lecture, you will be able to: \n", 140 | "\n", 141 | "- Define a function using the \"functionname(varlist) = ...\" one-line syntax\n", 142 | "- Define a function using the \"function name(varlist) ... end\" multiline syntax\n", 143 | "- Define an additional method for an existing user-defined function\n", 144 | "- Specify types for input values in a user-defined function\n", 145 | "- Use workspace() to clear the notebook of all values so that function signatures can be redefined." 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "[Back to the top](#In-this-lecture)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "

One-line function definition

\n", 160 | "\n", 161 | "This has an extremely simple form. For example:" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 1, 167 | "metadata": { 168 | "collapsed": false 169 | }, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/plain": [ 174 | "myfunc (generic function with 1 method)" 175 | ] 176 | }, 177 | "execution_count": 1, 178 | "metadata": {}, 179 | "output_type": "execute_result" 180 | } 181 | ], 182 | "source": [ 183 | "myfunc(firstvar) = 20*firstvar " 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "The rules are for defining one-line function are: \n", 191 | "- the name of the function must be a valid variable name (in this case \"myfunc\" is the name)\n", 192 | "- the arguments of the function must be valid variable names\n", 193 | "- the argument must be in parentheses (and as we'll see, multiple arguments must be separated by values)\n", 194 | "- the name, with arguments in parentheses goes on the left of an assignment\n", 195 | "- the code for evaluating the function goes on the right.\n", 196 | "\n", 197 | "By the way, it's not quite accurate that the code must always fit on one line---it must be a single statement, but so-called compound statements are often written with line breaks, to help the human reader. We will not be using compound statements in one-line functions in this course." 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 2, 203 | "metadata": { 204 | "collapsed": false 205 | }, 206 | "outputs": [ 207 | { 208 | "data": { 209 | "text/plain": [ 210 | "6664.4439999999995" 211 | ] 212 | }, 213 | "execution_count": 2, 214 | "metadata": {}, 215 | "output_type": "execute_result" 216 | } 217 | ], 218 | "source": [ 219 | "myfunc(333.2222) # then we just call it like any other function" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "metadata": {}, 225 | "source": [ 226 | "Here is an illustration of a two-argument function:" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 3, 232 | "metadata": { 233 | "collapsed": false 234 | }, 235 | "outputs": [ 236 | { 237 | "data": { 238 | "text/plain": [ 239 | "addxtoy (generic function with 1 method)" 240 | ] 241 | }, 242 | "execution_count": 3, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "addxtoy(x,y) = x + y # not supposed to be useful! it just shows how the job is done" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 4, 254 | "metadata": { 255 | "collapsed": false 256 | }, 257 | "outputs": [ 258 | { 259 | "data": { 260 | "text/plain": [ 261 | "10.8" 262 | ] 263 | }, 264 | "execution_count": 4, 265 | "metadata": {}, 266 | "output_type": "execute_result" 267 | } 268 | ], 269 | "source": [ 270 | "addxtoy(33, -22.2) # mixed types: illustrates that for quick and dirty code, we can (mostly) ignore types" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "metadata": {}, 276 | "source": [ 277 | "[Back to the top](#In-this-lecture)" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "

Multi-line function definition

\n", 285 | "\n", 286 | "Let's face it, computing should not be all be done with one-liners. Julia supplies the following syntax for functions that take up multiple lines:" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 6, 292 | "metadata": { 293 | "collapsed": false 294 | }, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "nextfunc (generic function with 1 method)" 300 | ] 301 | }, 302 | "execution_count": 6, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "function nextfunc(a, b, c) # this line names your function and specifies the inputs\n", 309 | " a*b + c # here go your (usually quite a few) lines\n", 310 | "\n", 311 | " # ... just illustrating the possiblity of using white space and additional comments \n", 312 | "end\n" 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": 7, 318 | "metadata": { 319 | "collapsed": false 320 | }, 321 | "outputs": [ 322 | { 323 | "data": { 324 | "text/plain": [ 325 | "38" 326 | ] 327 | }, 328 | "execution_count": 7, 329 | "metadata": {}, 330 | "output_type": "execute_result" 331 | } 332 | ], 333 | "source": [ 334 | "nextfunc(7,5,3) # again, just call it like any other function" 335 | ] 336 | }, 337 | { 338 | "cell_type": "markdown", 339 | "metadata": {}, 340 | "source": [ 341 | "To illustrate multi-line functions a bit more, here's a useful device for debugging: a line inside a function that gives you the value and the type of a variable. \n", 342 | "\n", 343 | "It relies on the escape character \"$\" in strings, which you recall DOESN'T create a dollar sign, but instead modifies how the string is built.\n" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 8, 349 | "metadata": { 350 | "collapsed": false 351 | }, 352 | "outputs": [ 353 | { 354 | "data": { 355 | "text/plain": [ 356 | "showdebugprintln (generic function with 1 method)" 357 | ] 358 | }, 359 | "execution_count": 8, 360 | "metadata": {}, 361 | "output_type": "execute_result" 362 | } 363 | ], 364 | "source": [ 365 | "function showdebugprintln(testvar)\n", 366 | " println(\"inside the showdebubprint() now\") #this line announces where the report is coming from\n", 367 | " println(\"The type of testvar is $(typeof(testvar)) and the value of testvar is $testvar\")\n", 368 | " # and this line reports what value, and hence what type, testvar actually has here\n", 369 | "end\n", 370 | " " 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": 9, 376 | "metadata": { 377 | "collapsed": false 378 | }, 379 | "outputs": [ 380 | { 381 | "name": "stdout", 382 | "output_type": "stream", 383 | "text": [ 384 | "inside the showdebubprint() now\n", 385 | "The type of testvar is Array{Any,1} and the value of testvar is Any['1',2.0]\n" 386 | ] 387 | } 388 | ], 389 | "source": [ 390 | "a = ['1',2.]\n", 391 | "showdebugprintln(a)" 392 | ] 393 | }, 394 | { 395 | "cell_type": "markdown", 396 | "metadata": {}, 397 | "source": [ 398 | "[Back to the top](#In-this-lecture)" 399 | ] 400 | }, 401 | { 402 | "cell_type": "markdown", 403 | "metadata": {}, 404 | "source": [ 405 | "

Functions with multiple methods

\n", 406 | "\n", 407 | "As we saw in Lecture 8, many code bodies can share one function name. Julia knows which of them is relevant via the type signature. The type signature is simply the list of types of all the variables that are used to call the function. \n", 408 | "\n", 409 | "Here is a function that basically parallels the cos function." 410 | ] 411 | }, 412 | { 413 | "cell_type": "code", 414 | "execution_count": 11, 415 | "metadata": { 416 | "collapsed": true 417 | }, 418 | "outputs": [ 419 | { 420 | "data": { 421 | "text/plain": [ 422 | "mycos (generic function with 1 method)" 423 | ] 424 | }, 425 | "execution_count": 11, 426 | "metadata": {}, 427 | "output_type": "execute_result" 428 | } 429 | ], 430 | "source": [ 431 | "mycos(x) = cos(x)" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": null, 437 | "metadata": { 438 | "collapsed": true 439 | }, 440 | "outputs": [], 441 | "source": [ 442 | "mycos(.7) # standard value of cos (angle in radians, of course)" 443 | ] 444 | }, 445 | { 446 | "cell_type": "markdown", 447 | "metadata": {}, 448 | "source": [ 449 | "Now we extend mycos() by providing a function for computing the cosine from the hypotenuse and adjacent side: " 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": null, 455 | "metadata": { 456 | "collapsed": true 457 | }, 458 | "outputs": [], 459 | "source": [ 460 | "mycos(adj, hyp) = adj/hyp" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 24, 466 | "metadata": { 467 | "collapsed": true 468 | }, 469 | "outputs": [ 470 | { 471 | "data": { 472 | "text/plain": [ 473 | "0.9230769230769231" 474 | ] 475 | }, 476 | "execution_count": 24, 477 | "metadata": {}, 478 | "output_type": "execute_result" 479 | } 480 | ], 481 | "source": [ 482 | "mycos(12, 13) # the cosine of the larger angle in a standard 5, 12, 13 triangle" 483 | ] 484 | }, 485 | { 486 | "cell_type": "code", 487 | "execution_count": 25, 488 | "metadata": { 489 | "collapsed": true 490 | }, 491 | "outputs": [ 492 | { 493 | "data": { 494 | "text/html": [ 495 | "2 methods for generic function mycos:" 496 | ], 497 | "text/plain": [ 498 | "# 2 methods for generic function \"mycos\":\n", 499 | "mycos(x) at In[11]:1\n", 500 | "mycos(hyp, adj) at In[23]:1" 501 | ] 502 | }, 503 | "execution_count": 25, 504 | "metadata": {}, 505 | "output_type": "execute_result" 506 | } 507 | ], 508 | "source": [ 509 | "methods(mycos) #Check this carefully!" 510 | ] 511 | }, 512 | { 513 | "cell_type": "markdown", 514 | "metadata": {}, 515 | "source": [ 516 | "Again, methods() is your friend. Note especially that each method is given in terms of its input variables." 517 | ] 518 | }, 519 | { 520 | "cell_type": "markdown", 521 | "metadata": {}, 522 | "source": [ 523 | "As with every user-defined function, it is easy for these to go wrong. Suppose we want to make sure the mycos(x) is never called for integer values. We can require the input to be Float64 as follows:" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 26, 529 | "metadata": { 530 | "collapsed": true 531 | }, 532 | "outputs": [ 533 | { 534 | "data": { 535 | "text/plain": [ 536 | "mycos (generic function with 3 methods)" 537 | ] 538 | }, 539 | "execution_count": 26, 540 | "metadata": {}, 541 | "output_type": "execute_result" 542 | } 543 | ], 544 | "source": [ 545 | "mycos(thet::Float64) = cos(thet) # note the use of :: to force Julia to check the type " 546 | ] 547 | }, 548 | { 549 | "cell_type": "markdown", 550 | "metadata": {}, 551 | "source": [ 552 | "However, there are now three methods, and integers can still be passed (check this for yourself). We actually intended to replace mycos(x) with mycos(thet::Float64). To do so, first we must clear the old version. Unfortunately, the only way to clear a notebook is to clear everything, by using workspace(). \n", 553 | "\n", 554 | "Everything is cleared, so we have to redefine not only mycos(x) but also mycos(adj, hyp):" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": 45, 560 | "metadata": { 561 | "collapsed": true 562 | }, 563 | "outputs": [ 564 | { 565 | "data": { 566 | "text/plain": [ 567 | "mycos (generic function with 1 method)" 568 | ] 569 | }, 570 | "execution_count": 45, 571 | "metadata": {}, 572 | "output_type": "execute_result" 573 | } 574 | ], 575 | "source": [ 576 | "workspace() # no argument, please! \n", 577 | "# ... clears all the results\n", 578 | "mycos(thet::Float64) = cos(thet) # so passing mycos() an integer will now cause Julia to throw an error\n", 579 | "mycos(hyp, adj) = adj/hyp" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 47, 585 | "metadata": { 586 | "collapsed": true 587 | }, 588 | "outputs": [ 589 | { 590 | "ename": "LoadError", 591 | "evalue": "LoadError: MethodError: `mycos` has no method matching mycos(::Int64)\nwhile loading In[47], in expression starting on line 1", 592 | "output_type": "error", 593 | "traceback": [ 594 | "LoadError: MethodError: `mycos` has no method matching mycos(::Int64)\nwhile loading In[47], in expression starting on line 1", 595 | "" 596 | ] 597 | } 598 | ], 599 | "source": [ 600 | "mycos(1) # ... this shouldn't work now ..." 601 | ] 602 | }, 603 | { 604 | "cell_type": "markdown", 605 | "metadata": {}, 606 | "source": [ 607 | "[Back to the top](#In-this-lecture)" 608 | ] 609 | } 610 | ], 611 | "metadata": { 612 | "kernelspec": { 613 | "display_name": "Julia 0.4.5", 614 | "language": "julia", 615 | "name": "julia-0.4" 616 | }, 617 | "language_info": { 618 | "file_extension": ".jl", 619 | "mimetype": "application/julia", 620 | "name": "julia", 621 | "version": "0.4.5" 622 | } 623 | }, 624 | "nbformat": 4, 625 | "nbformat_minor": 0 626 | } 627 | --------------------------------------------------------------------------------