computational methods (phys 2030)
TRANSCRIPT
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
à Nowthatyouhave(orhavenot)figuredthisout,determinehowtowriteacomputercodeto“solve”thisproblem(e.g.,computervision”)
Ex. 1
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.”
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....
Tangent (redownstream“jobqualifications”)
https://www.facebook.com/careers/resume?req=a0I1200000JXrgMEAT
Tangent (redownstream“jobqualifications”)
https://www.facebook.com/careers/resume?req=a0I1200000JXrgMEAT
Tangent (redownstream“jobqualifications”)
https://www.facebook.com/careers/resume?req=a0I1200000JXdHzEAL
“Strongmathskillsareahugeplus”
Tangent (redownstream“jobqualifications”)
https://www.facebook.com/careers/resume?req=a0I1200000JXdHzEAL
à PHYS2030isprovidingyouw/someoftheskillstopaythebills!
Ex. 2
Ø Howmanybirdsarethere?Ø Whichwayaretheyflying?Ø Couldweinferhowfast?
Heuristicstartingpoint:Alwaysagoodideatohavethree independentwaystobackupideas/thoughts
Considera(seeminglytrivial)example:
Whatistheareaofacircle?
Ex. 3
Whatistheareaofacircle?
Approach1
Area=p r2r
Begsthequestionthough:Whatintheworldisthismysteriousnumberp?
Whatistheareaofacircle?
Approach2
Riemannsums
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…
Whatistheareaofacircle?
Approach3
Computational“Montecarlo”approach
à Turntheproblemintoadifferentone(e.g.,whatisthatmysterynumberp?)
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-');
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
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
PHYS 2030: Course philosophy
"WhatIcannotcreate,Idonotunderstand.”- R.Feynman
à Ourfocusisonconceptualunderstanding,notoptimizationperse.That’snottosaythatefficiencyisnotimportant!
“Programmingisasciencebasedonlimitedresources;onecanprogramonlywithintherangeofpoweravailableinacomputer’shardwareandsoftware.”
- D.Kushner(MastersofDoom:HowTwoGuysCreatedanEmpireandTransformedPopCulture)
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
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)
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…)
‘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
Ø 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
Ø Thinkof“computercoding”aslearningtoread&write
§ First,youpickalanguage(e.g.,Matlab)
§ Second,youlearnbasicgrammar(“syntax”à CSE1541)
§ NextyoulearnlanguageandreadShakespeare(PHYS2030)
§ Eventuallyyougetonwithyourlifeandactuallydosomething,likewriteanoveloraFAQpageforavideogame(thoughyouneverstoplearningalongtheway!)
PHYS 2030 Logistics
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
à Youcan(legitimately!)geta“softcopy”ofthebook
Coursetext(whichwewillonlylooselyfollow;thebulkofthecontentwillbecontainedinthecoursenotes/codes)
àWewillcoversomeofthesetopics,plus(plentyof)othersnotlistedhere
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
Post-class exercises
Ø MakesureyouhaveacomfortablemeanstorunMatlab
Ø Writeacodetoreadinanimage.HowdoesMatlab storethenumbers?
Course website: http://www.yorku.ca/cberge/2030W2018.html
Ø Outlineameansastohowyoumighttacklethisproblemposedearlier....
Ø Writeyourown“estimatep”code
http://www.polygon.com/2016/12/9/13902832/you-can-play-atari-games-inside-minecraft
http://www.polygon.com/2016/12/9/13902832/you-can-play-atari-games-inside-minecraft
Let’scookupafew(moreoddball)examplestomotivatehowwemightwanttouseacomputerinaprogrammablefashiontoaddressaquestion....
Forsimplicity,we’llconfineourselvestothetopicof“imageanalysis”
Note:Thissortofthingisarelative“hottopic”(e.g.,thisisthesortofthingGooglehashiredextensivelyin)andleadsnicelyintootherareassuchasdeeplearning
Ex. 2
Howmany“bifurcations”(i.e.,branchingpoints)arethere?
Keepinmindthatthereisanissueof“resolution”herethatcomplicatesmatters...
Ex. 2
Ex. 3
http://www.biometricupdate.com/201612/eyelock-intros-iris-authentication-reference-designs-for-iot-device-integration
Ex. 3
Ex. 3
Ex. 3
Ex. 3
Ex. 3
à Essentiallyaprobleminpatternrecognition(e.g.,computervision)
Ex. 3 (cont. re “Search & Find”)
Ex. 3 (cont. re “Search & Find”)
'#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”)
'#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”)
Ex. 3 (cont. re “Search & Find”)
Tofurtherillustratehowhardthissortof“problem”is...
“This,beingquiteatask(andnotoneeasilydelegatedtoautomaticoptical-recognitionsystems),wascarriedoutinpartbyabunchof120,000enthusiasticamateurs.”
“Anatlasofwhereproteinsarefoundincellswillhelpworkoutwhattheydo”
Aside: Deep Learning
ThecoveroftheJanuary28,2016issueofNature,whichfeaturesGoogle’sgroundbreakingAIresearch.
Ø MachinelearningØ NeuralnetworksØ “Deeplearning”
http://neuralnetworksanddeeplearning.com/chap6.html
Note:ThisstuffisbeyondthescopeofPHYS2030
à Emptybulletinboard
Ex. 4
“thestapleproblem”à Aneasierchallenge?
Ø Howmanystaplearethere?
Ø Distributionofangles?
Ø Howtowriteacodetoobjectivelymeasuresuch?
Ex. 4
Aside
àMoredetailslaterinwhenwedealw/“DAQ”
http://interface.khm.de/index.php/lab/interfaces-advanced/theremin-as-a-capacitive-sensing-device/
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
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Review (re CSE 1541)
http://www.eecs.yorku.ca/course_archive/2013-14/W/1541/calendar.shtml
Ex. 4 “staple problem” REDUX
à Asanaside,we’lloutlinea“blackbox”methodthatmakesuseofMatlab’s“toolboxes” (somethingyoumayormaynothaveaccessto)
ImageProcessingToolboxhttps://www.mathworks.com/help/images/examples.html
Ex. 4 “staple problem” REDUX
https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html
Ex. 4 “staple problem” REDUX
https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html
à Nowuptothispoint,theunderlying“computations”arerelativelystraight-forward.Butthingsareabouttogetmysterious...
Ex. 4 “staple problem” REDUX
https://www.mathworks.com/help/images/examples/correcting-nonuniform-illumination.html
à Bewarethemysterious“blackbox”atworkhere!!