computational methods (phys 2030)

69
Computational Methods (PHYS 2030) York University Winter 2018 Lecture 1 Instructors: Prof. Christopher Bergevin ([email protected]) Schedule: Lecture: MWF 11:30-12:30 (CLH M) Website: http://www.yorku.ca/cberge/2030W2018.html

Upload: others

Post on 06-Jan-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computational Methods (PHYS 2030)

Computational Methods (PHYS 2030)

York UniversityWinter 2018Lecture 1

Instructors: Prof. Christopher Bergevin ([email protected])

Schedule: Lecture: MWF 11:30-12:30 (CLH M)

Website: http://www.yorku.ca/cberge/2030W2018.html

Page 2: Computational Methods (PHYS 2030)

à Nowthatyouhave(orhavenot)figuredthisout,determinehowtowriteacomputercodeto“solve”thisproblem(e.g.,computervision”)

Ex. 1

Page 3: Computational Methods (PHYS 2030)

http://www.slate.com/blogs/quora/2015/12/28/will_coding_still_be_relevant_in_a_decade.html

“Absolutely.Notonlywillcodingberelevantin10years,itwillbemore relevantthanitistoday.However,thesyntaxofcodinglanguageswillcontinuebecomingeasier.Whenitstarted,codingwasaboutholesinpiecesofcardboard.Thenitlookedlikethis:00101010101.ItnowlooksalotmorelikeEnglish.AscodinglanguagesbecomemoreEnglish-like,theywillbeeasiertolearn,lessarcane,andthusmorepopular.Andascomputingsystemspermeateourlives,tellingthesedeviceswhatwewantthemtodo,andinventingnewusesforthem,willcontinuetobemorepopular.”

Page 4: Computational Methods (PHYS 2030)

http://www.slate.com/blogs/quora/2015/12/28/will_coding_still_be_relevant_in_a_decade.html

“Buttoteachacomputertodosomethingitneverhasbeforewillstillrequirespecializedunderstandingofhowtocommunicatewiththespecificityofacomputerprogrammer,aswellasthecomputationalthinkingneededtodescribeanalgorithm.Thesyntaxofhowtodesignalooporaconditionalforacomputertodosomethingormakeadecision—thatsyntaxmaychange,butthefundamentalconceptsunderneathareunlikelytogoawayformanymanydecades.”

à Somekeyconceptualideasarepresenthere.Notonlywewillbuildoffofsuch,butPHYS2030willallowthesetobecomeakeyfoundationalcomponentinyourscientificthinking....

Page 5: Computational Methods (PHYS 2030)

Tangent (redownstream“jobqualifications”)

https://www.facebook.com/careers/resume?req=a0I1200000JXrgMEAT

Page 6: Computational Methods (PHYS 2030)

Tangent (redownstream“jobqualifications”)

https://www.facebook.com/careers/resume?req=a0I1200000JXrgMEAT

Page 7: Computational Methods (PHYS 2030)

Tangent (redownstream“jobqualifications”)

https://www.facebook.com/careers/resume?req=a0I1200000JXdHzEAL

“Strongmathskillsareahugeplus”

Page 8: Computational Methods (PHYS 2030)

Tangent (redownstream“jobqualifications”)

https://www.facebook.com/careers/resume?req=a0I1200000JXdHzEAL

à PHYS2030isprovidingyouw/someoftheskillstopaythebills!

Page 9: Computational Methods (PHYS 2030)

Ex. 2

Ø Howmanybirdsarethere?Ø Whichwayaretheyflying?Ø Couldweinferhowfast?

Page 10: Computational Methods (PHYS 2030)

Heuristicstartingpoint:Alwaysagoodideatohavethree independentwaystobackupideas/thoughts

Considera(seeminglytrivial)example:

Whatistheareaofacircle?

Ex. 3

Page 11: Computational Methods (PHYS 2030)

Whatistheareaofacircle?

Approach1

Area=p r2r

Begsthequestionthough:Whatintheworldisthismysteriousnumberp?

Page 12: Computational Methods (PHYS 2030)

Whatistheareaofacircle?

Approach2

Riemannsums

Page 13: Computational Methods (PHYS 2030)
Page 14: Computational Methods (PHYS 2030)

Trapezoid method (Method B)np= 25

0 0.5 1 1.5 2 2.5 30

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

x

F(x)

area calculated by trapz.m for 25 points =1.9971

INTexample1.m

Candothis(i.e.,Approach2)“computationally”too…

Page 15: Computational Methods (PHYS 2030)

Whatistheareaofacircle?

Approach3

Computational“Montecarlo”approach

à Turntheproblemintoadifferentone(e.g.,whatisthatmysterynumberp?)

Page 16: Computational Methods (PHYS 2030)

Ex. Estimating p EXestimatePI.m

% ### EXestimatePI.m ### 04.22.11 {C. Bergevin}% Use a random # generator to estimate pi by considering the ratio of areas% of a circle to a square

clear% -----------N=1000; % # of points to use% -----------figure(1); clf; hold on; grid on; % +++% generate array of (uniformly distributed) x and y valuesA= 2*rand(N,1)-1; % x coord.B= 2*rand(N,1)-1; % y coord.% +++% loop thru to test if each coordinate pair is inside or outAc= 0; % indexerfor nn=1:N

x= A(nn); y= B(nn);% test to see if the point falls within the unit circle (i.e., within% it area); if so, update indexerif (sqrt(x^2+y^2) <= 1), Ac= Ac+1; endplot(x,y,'kx'); % also plot for visual purposes

end% +++% estimate pi as the ratio of the areaspiEST= 4*(Ac/N); fprintf('\n estimate for pi = %g (using %g points) \n\n',piEST, N);% +++axis([-1 1 -1 1]); xlabel('x'); ylabel('y')% also draw a unit circletheta= linspace(0,2*pi,100); xC= cos(theta); yC= sin(theta); plot(xC,yC,'r-');

Page 17: Computational Methods (PHYS 2030)

Ex. Estimating p

−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

x

y

N=1000; % # of points to use

estimate for pi = 3.12 (using 1000 points)

à Simplyjustusingrandomnumbersandratiosofareas

Page 18: Computational Methods (PHYS 2030)

Ex. Estimating p

wikipedia (MonteCarlomethod)

EXestimatePI.m

−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

x

y

Page 19: Computational Methods (PHYS 2030)

PHYS 2030: Course philosophy

"WhatIcannotcreate,Idonotunderstand.”- R.Feynman

à Ourfocusisonconceptualunderstanding,notoptimizationperse.That’snottosaythatefficiencyisnotimportant!

“Programmingisasciencebasedonlimitedresources;onecanprogramonlywithintherangeofpoweravailableinacomputer’shardwareandsoftware.”

- D.Kushner(MastersofDoom:HowTwoGuysCreatedanEmpireandTransformedPopCulture)

Page 20: Computational Methods (PHYS 2030)

PHYS 2030 Overview

§ Numeric differentiation

§ Numeric integration

§ ODEs

§ DAQ

§ Data visualization

§ Linear systems theory

§ Regression

§ Nonlinear system

§ Fourier/spectral analysis

§ Linear systems (revisited)

§ Monte Carlo methods

Page 21: Computational Methods (PHYS 2030)

PHYS 2030 Overview: Course themes

1.Programming/computingskillsoknowledgeofsyntax&capabilitiesocomfortabilityodebugging(payattentiontoerrormessages)ostyle:modularversuscomprehensiveprogrammingofindingonlineresources(incl.scientificjournals)

2.Numericalmethodsosolvingdifferentialequations—>harmonicoscillatoroeigenvalueproblems—>PrinciplecomponentanalysisoMonteCarlooregressionocomplexnumbers—>fractalsoFouriertransformsobifurcationanalysis(perioddoublingcascadeandchaos)

3.Dataacquisition/analysisomeasuringdataovisualizingdataoanalyzingdata&signalprocessingostatistics—>Anscombe’s dataocompressedsensing

Caveat:Astimepermits(i.e.,wemightnotgettoallthis)

Page 22: Computational Methods (PHYS 2030)

http://www.yorku.ca/cberge/2030W2018.html

à This is the course website and will be the main “go to” place for all course-related info (e.g., syllabus, slides, chapters for reading, exam info, etc…)

Page 23: Computational Methods (PHYS 2030)

‘Golden rules’ of (2030) computing

1.Thecomputeronlydoeswhatyoutellittodo

2.Thinkaheadwhenwritingcode:trytominimizefuturework(e.g.,evenremotelyarchaiccodenowwillcertainlyequalheadachelateron)

4.Comment.Comment.Comment.[clearlyandefficiently]

Othertips:Ø 'Preserveall'versions'ofworkablecode.'

[Caveat:Don'tmodifysomeoneelse'scode!Copyandmakeyourownversion.]

Ø Whenusingexternalroutines(i.e.,codeyoudidn'twriteyourself),keepthespectre ofthe'blackbox'inmindatalltime.

3.Stayorganized.Findastyle thatworksforyou

Page 24: Computational Methods (PHYS 2030)

Ø Wantsomesortofprogrammableinterface

Ø Matlab iswhatwewillusehere,but....

Ø ...therearemanyoptionsforscientificcomputing/codingavailable(e.g.,Mathematica,Maple,Python,Octave,C,Java,etc....)

PHYS 2030 Logistics

Importantmessagehere!à ThetruevalueofPHYS2030liesnotinanyMatlab syntaxyou’llpickup,butinthebasic/coreprogrammingconcepts,practiceinsuch,andanew“attitude”recomputing

Page 25: Computational Methods (PHYS 2030)

Ø Thinkof“computercoding”aslearningtoread&write

§ First,youpickalanguage(e.g.,Matlab)

§ Second,youlearnbasicgrammar(“syntax”à CSE1541)

§ NextyoulearnlanguageandreadShakespeare(PHYS2030)

§ Eventuallyyougetonwithyourlifeandactuallydosomething,likewriteanoveloraFAQpageforavideogame(thoughyouneverstoplearningalongtheway!)

PHYS 2030 Logistics

Page 26: Computational Methods (PHYS 2030)

Accessing Matlab

Twopossibleoptions:

§ Purchase(or‘rent’)astudentversion viaMathworks

§ Accessremotelyviasecurelogin(webfas)toYorkserver(abitslow/clunky)

1.GotothisURLandandclickontheinstallbuttonforthecitrix receiver:https://webfas.yorku.ca/Citrix/WEBFASWeb/

2.Downloadthecitrix reciever andinstalltheexecutable

3.Afterinstallationcontinuetotheloginanduseyourpassportyorkusernameandpassword

4.Ontheleftshouldbeatabwitha"+"sign,openitandclickAllAppsandaddthematlab app

5.Clickthematlab appandadownloadwillbegin.Oncefinishedloading,doubleclick thedownloadandfromthereitshouldtakecareoftherest

Page 27: Computational Methods (PHYS 2030)

à Youcan(legitimately!)geta“softcopy”ofthebook

Coursetext(whichwewillonlylooselyfollow;thebulkofthecontentwillbecontainedinthecoursenotes/codes)

Page 28: Computational Methods (PHYS 2030)
Page 29: Computational Methods (PHYS 2030)
Page 30: Computational Methods (PHYS 2030)
Page 31: Computational Methods (PHYS 2030)

àWewillcoversomeofthesetopics,plus(plentyof)othersnotlistedhere

Page 32: Computational Methods (PHYS 2030)

Review (re CSE 1541)

u basicsofcomputing:digitalversusanalog,binaryu overviewofMatlab andbasicformat/syntaxu numbersversusstringsu logicals &relationaloperatorsu vectors,arrays,structures,etc….(+indicies)u basicprogramming,includingloopsandconditionalsu basicetiquette(e.g.,namingvariable,commentingcode)u datatypesu datafileinput/outputu basicstatisticsu plottingdatau user-definedfunctionsu Scriptsu matrixmanipulations(e.g.,Gaussianelimination)u randomnumbersu (basic)curvefittingu recursiverelations,bisectionu numericaldifferentiation,integrationu solvingODEs

àWearegoingtostarthereandtrytoensureeveryonegetsuptospeed (butit’sgoingtobehard!)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 33: Computational Methods (PHYS 2030)

Post-class exercises

Ø MakesureyouhaveacomfortablemeanstorunMatlab

Ø Writeacodetoreadinanimage.HowdoesMatlab storethenumbers?

Course website: http://www.yorku.ca/cberge/2030W2018.html

Ø Outlineameansastohowyoumighttacklethisproblemposedearlier....

Ø Writeyourown“estimatep”code

Page 34: Computational Methods (PHYS 2030)
Page 35: Computational Methods (PHYS 2030)
Page 36: Computational Methods (PHYS 2030)
Page 37: Computational Methods (PHYS 2030)

http://www.polygon.com/2016/12/9/13902832/you-can-play-atari-games-inside-minecraft

Page 38: Computational Methods (PHYS 2030)

http://www.polygon.com/2016/12/9/13902832/you-can-play-atari-games-inside-minecraft

Page 39: Computational Methods (PHYS 2030)

Let’scookupafew(moreoddball)examplestomotivatehowwemightwanttouseacomputerinaprogrammablefashiontoaddressaquestion....

Forsimplicity,we’llconfineourselvestothetopicof“imageanalysis”

Note:Thissortofthingisarelative“hottopic”(e.g.,thisisthesortofthingGooglehashiredextensivelyin)andleadsnicelyintootherareassuchasdeeplearning

Page 40: Computational Methods (PHYS 2030)

Ex. 2

Howmany“bifurcations”(i.e.,branchingpoints)arethere?

Page 41: Computational Methods (PHYS 2030)

Keepinmindthatthereisanissueof“resolution”herethatcomplicatesmatters...

Ex. 2

Page 42: Computational Methods (PHYS 2030)

Ex. 3

http://www.biometricupdate.com/201612/eyelock-intros-iris-authentication-reference-designs-for-iot-device-integration

Page 43: Computational Methods (PHYS 2030)

Ex. 3

Page 44: Computational Methods (PHYS 2030)

Ex. 3

Page 45: Computational Methods (PHYS 2030)

Ex. 3

Page 46: Computational Methods (PHYS 2030)

Ex. 3

Page 47: Computational Methods (PHYS 2030)

Ex. 3

Page 48: Computational Methods (PHYS 2030)

à Essentiallyaprobleminpatternrecognition(e.g.,computervision)

Ex. 3 (cont. re “Search & Find”)

Page 49: Computational Methods (PHYS 2030)

Ex. 3 (cont. re “Search & Find”)

Page 50: Computational Methods (PHYS 2030)

'#ffir#Y. -.;-'&,,#|m,:lL*"*d ",*^-,';*n;:!.f,

.*\oY,* .{i(e-J."ilt_l_a"la.'.fu: Wl---l|-V,. .?.L_;:.;-zf,ir;".--r, r , --";F'KY"

i*,ffi*:ss#-::ffi

olh\:

"L':;rffi':;iIs"+. \v'1. lt

Ex. 3 (cont. re “Search & Find”)

Page 51: Computational Methods (PHYS 2030)

'#ffir#Y. -.;-'&,,#|m,:lL*"*d ",*^-,';*n;:!.f,

.*\oY,* .{i(e-J."ilt_l_a"la.'.fu: Wl---l|-V,. .?.L_;:.;-zf,ir;".--r, r , --";F'KY"

i*,ffi*:ss#-::ffi

olh\:

"L':;rffi':;iIs"+. \v'1. lt

à Desireditemisdifferentthanthe‘template’(orkernel)

Ex. 3 (cont. re “Search & Find”)

Page 52: Computational Methods (PHYS 2030)

Ex. 3 (cont. re “Search & Find”)

Tofurtherillustratehowhardthissortof“problem”is...

“This,beingquiteatask(andnotoneeasilydelegatedtoautomaticoptical-recognitionsystems),wascarriedoutinpartbyabunchof120,000enthusiasticamateurs.”

“Anatlasofwhereproteinsarefoundincellswillhelpworkoutwhattheydo”

Page 53: Computational Methods (PHYS 2030)

Aside: Deep Learning

ThecoveroftheJanuary28,2016issueofNature,whichfeaturesGoogle’sgroundbreakingAIresearch.

Ø MachinelearningØ NeuralnetworksØ “Deeplearning”

http://neuralnetworksanddeeplearning.com/chap6.html

Note:ThisstuffisbeyondthescopeofPHYS2030

Page 54: Computational Methods (PHYS 2030)

à Emptybulletinboard

Ex. 4

“thestapleproblem”à Aneasierchallenge?

Page 55: Computational Methods (PHYS 2030)

Ø Howmanystaplearethere?

Ø Distributionofangles?

Ø Howtowriteacodetoobjectivelymeasuresuch?

Ex. 4

Page 56: Computational Methods (PHYS 2030)
Page 57: Computational Methods (PHYS 2030)

Aside

àMoredetailslaterinwhenwedealw/“DAQ”

Page 58: Computational Methods (PHYS 2030)

http://interface.khm.de/index.php/lab/interfaces-advanced/theremin-as-a-capacitive-sensing-device/

Page 59: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

u basicsofcomputing:digitalversusanalog,binaryu overviewofMatlab andbasicformat/syntaxu numbersversusstringsu logicals &relationaloperatorsu vectors,arrays,structures,etc….(+indicies)u basicprogramming,includingloopsandconditionalsu basicetiquette(e.g.,namingvariable,commentingcode)u datatypesu datafileinput/outputu basicstatisticsu plottingdatau user-definedfunctionsu Scriptsu matrixmanipulations(e.g.,Gaussianelimination)u randomnumbersu (basic)curvefittingu recursiverelations,bisectionu (basic)numericaldifferentiation,integrationu (basic)solvingODEs

Page 60: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 61: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 62: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 63: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 64: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 65: Computational Methods (PHYS 2030)

Review (re CSE 1541)

http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml

Page 66: Computational Methods (PHYS 2030)

Ex. 4 “staple problem” REDUX

à Asanaside,we’lloutlinea“blackbox”methodthatmakesuseofMatlab’s“toolboxes” (somethingyoumayormaynothaveaccessto)

ImageProcessingToolboxhttps://www.mathworks.com/help/images/examples.html

Page 67: Computational Methods (PHYS 2030)

Ex. 4 “staple problem” REDUX

https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html

Page 68: Computational Methods (PHYS 2030)

Ex. 4 “staple problem” REDUX

https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html

à Nowuptothispoint,theunderlying“computations”arerelativelystraight-forward.Butthingsareabouttogetmysterious...

Page 69: Computational Methods (PHYS 2030)

Ex. 4 “staple problem” REDUX

https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html

à Bewarethemysterious“blackbox”atworkhere!!