Tải bản đầy đủ (.pdf) (356 trang)

Getting started with julia programming language by ivo balbaert

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.36 MB, 356 trang )



GettingStartedwithJuliaProgramming


TableofContents
GettingStartedwithJuliaProgramming
Credits
AbouttheAuthor
AbouttheReviewers
www.PacktPub.com
Supportfiles,eBooks,discountoffers,andmore
Whysubscribe?
FreeaccessforPacktaccountholders
Preface
Whatthisbookcovers
Whatyouneedforthisbook
Whothisbookisfor
Conventions
Readerfeedback
Customersupport
Downloadingtheexamplecode
Errata
Piracy
Questions
TheRationaleforJulia
ThescopeofJulia
Julia’splaceamongtheotherprogramminglanguages
Acomparisonwithotherlanguagesforthedatascientist
MATLAB
R


Python
Usefullinks
Summary
1.InstallingtheJuliaPlatform


InstallingJulia
Windowsversion–usablefromWindowsXPSP2onwards
Ubuntuversion
OSX
Buildingfromsource
WorkingwithJulia’sshell
StartupoptionsandJuliascripts
Packages
Addinganewpackage
InstallingandworkingwithJuliaStudio
InstallingandworkingwithIJulia
InstallingSublime-IJulia
InstallingJuno
OthereditorsandIDEs
HowJuliaworks
Summary
2.Variables,Types,andOperations
Variables,namingconventions,andcomments
Types
Integers
Floatingpointnumbers
Elementarymathematicalfunctionsandoperations
Rationalandcomplexnumbers
Characters

Strings
Formattingnumbersandstrings
Regularexpressions
Rangesandarrays
Otherwaystocreatearrays
Somecommonfunctionsforarrays
Howtoconvertanarrayofcharstoastring


Datesandtimes
Scopeandconstants
Summary
3.Functions
Definingfunctions
Optionalandkeywordarguments
Anonymousfunctions
First-classfunctionsandclosures
Recursivefunctions
Map,filter,andlistcomprehensions
Genericfunctionsandmultipledispatch
Summary
4.ControlFlow
Conditionalevaluation
Repeatedevaluation
Theforloop
Thewhileloop
Thebreakstatement
Thecontinuestatement
Exceptionhandling
Scoperevisited

Tasks
Summary
5.CollectionTypes
Matrices
Tuples
Dictionaries
Keysandvalues–looping
Sets
Makingasetoftuples
Exampleproject–wordfrequency


Summary
6.MoreonTypes,Methods,andModules
Typeannotationsandconversions
Typeconversionsandpromotions
Thetypehierarchy–subtypesandsupertypes
Concreteandabstracttypes
User-definedandcompositetypes
Whenaretwovaluesorobjectsequaloridentical?
Multipledispatchexample
Typesandcollections–innerconstructors
Typeunions
Parametrictypesandmethods
Standardmodulesandpaths
Summary
7.MetaprogramminginJulia
Expressionsandsymbols
Evalandinterpolation
Definingmacros

Built-inmacros
Testing
Debugging
Benchmarking
Startingatask
Reflectioncapabilities
Summary
8.I/O,Networking,andParallelComputing
Basicinputandoutput
Workingwithfiles
ReadingandwritingCSVfiles
UsingDataFrames
Otherfileformats


WorkingwithTCPsocketsandservers
Interactingwithdatabases
Paralleloperationsandcomputing
Creatingprocesses
Usinglow-levelcommunications
Parallelloopsandmaps
Distributedarrays
Summary
9.RunningExternalPrograms
Runningshellcommands
Interpolation
Pipelining
CallingCandFORTRAN
CallingPython
Performancetips

Toolstouse
Summary
10.TheStandardLibraryandPackages
Diggingdeeperintothestandardlibrary
Julia’spackagemanager
Installingandupdatingpackages
Publishingapackage
GraphicsinJulia
UsingGadflyondata
Summary
A.ListofMacrosandPackages
Macros
Listofpackages
Index



GettingStartedwithJuliaProgramming



GettingStartedwithJuliaProgramming
Copyright©2015PacktPublishing
Allrightsreserved.Nopartofthisbookmaybereproduced,storedinaretrievalsystem,
ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthe
publisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviews.
Everyefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyofthe
informationpresented.However,theinformationcontainedinthisbookissoldwithout
warranty,eitherexpressorimplied.Neithertheauthor,norPacktPublishing,andits
dealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecaused

directlyorindirectlybythisbook.
PacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthe
companiesandproductsmentionedinthisbookbytheappropriateuseofcapitals.
However,PacktPublishingcannotguaranteetheaccuracyofthisinformation.
Firstpublished:February2015
Productionreference:1200215
PublishedbyPacktPublishingLtd.
LiveryPlace
35LiveryStreet
BirminghamB32PB,UK.
ISBN978-1-78328-479-5
www.packtpub.com



Credits
Author
IvoBalbaert
Reviewers
PascalBugnion
MichaelOtte
DustinE.Stansbury
CommissioningEditor
KevinColaco
AcquisitionEditor
KevinColaco
ContentDevelopmentEditor
NeeshmaRamakrishnan
TechnicalEditors
MrunmayeePatil

ShaliSasidharan
CopyEditor
RashmiSawant
ProjectCoordinator
PuravMotiwalla
Proofreaders
MarioCecere
PaulHindle
Indexer
MonicaAjmeraMehta
ProductionCoordinator
ConidonMiranda
CoverWork
ConidonMiranda



AbouttheAuthor
IvoBalbaertiscurrentlyalecturerin(web)programminganddatabasesatCVO
Antwerpen(www.cvoantwerpen.be),acommunitycollegeinBelgium.HereceivedaPhD
degreeinappliedphysicsfromtheUniversityofAntwerpin1986.Heworkedfor20years
inthesoftwareindustryasadeveloperandconsultantinseveralcompanies,andfor10
yearsasaprojectmanagerattheUniversityHospitalofAntwerp.From2000onward,he
switchedtopartlyteachinganddevelopingsoftware(KHMMechelen,CVOAntwerp).
HealsowroteanintroductorybookinDutchaboutdevelopinginRubyandRails,
ProgrammerenmetRubyenRails,VanDuurenMedia.In2012,heauthoredabookonthe
Goprogramminglanguage,TheWayToGo,iUniverse.In2013,incollaborationwith
DzenanRidzanovic,heauthoredLearningDartandDartCookbook,bothbyPackt
Publishing.
IwouldliketothankthetechnicalreviewersPascalBugnion,MichaelOtte,andDustin

Stansburyforthemanyusefulremarksthatimprovedthetext.



AbouttheReviewers
PascalBugnionisadatascientistwithastronganalyticalbackgroundaswellasapassion
forsoftwaredevelopment.HepursuedamaterialsscienceundergraduatedegreeatOxford
University.HethenwentontocompleteaPhDincomputationalphysicsatCambridge
University,duringwhichhedevelopedandappliedthequantumMonteCarlomethodsto
solid​statephysics.Thisresultedinfourpublications,includinganarticleinPhysical
ReviewLetters,theleadingphysicsjournal.HenowworksasadatabasearchitectforSCL
Elections,acompanythatspecializesinpredictingvoterbehavior.
Pascalisstronglyinterestedincontributingtoopensourcesoftware,especiallythePython
scientificstack.HehascontributedtoNumPy,matplotlib,andIPython,andmaintains
Scikit​Monaco,aPythonlibraryforMonteCarlointegrationaswellasGMaps,aPython
moduleforembeddingGooglemapsinIPythonnotebooks.
MichaelOttehasintereststhatincludetheapplicationofartificialintelligencetorobotics,
withafocusonpathplanningalgorithmsandmultirobotsystems.Hehasbeenusingthe
Julialanguagesince2012toimplementmotionplanning,graphsearch,andother
algorithms,manyofwhichhaveappearedintoppeer-reviewedpublications.See
www.ottelab.comformoredetails.Heiscurrentlyaresearchassociatewiththe
DepartmentofAerospaceEngineeringSciencesattheUniversityofColoradoatBoulder.
Priortothis,hewasapostdoctoralassociatewiththeLaboratoryforInformationand
DecisionSystems(LIDS)attheMassachusettsInstituteofTechnology.Hereceivedhis
PhDandMSdegreesattheUniversityofColoradoatBoulderincomputerscienceanda
BSdegreeinaeronauticalengineeringandcomputersciencefromClarksonUniversity.
DustinStansburyreceivedhisBSdegreeinbothphysicsandpsychologyfrom
AppalachianStateUniversityandhisPhDdegreeinvisionsciencefromtheUniversityof
California,Berkeley.Hisgraduateresearchfocusedondevelopinghierarchicalstatistical
modelsofthemammalianvisualandauditorysystems.Hecurrentlyworksinthefieldof

musicretrievalandregularlycontributestohismachinelearningblog,theclevermachine.
Dustinhascontributedachaptertothetextbook,SceneVision:Makingsenseofwhatwe
see,MITPress2014,CambridgeMA.



www.PacktPub.com


Supportfiles,eBooks,discountoffers,and
more
Forsupportfilesanddownloadsrelatedtoyourbook,pleasevisitwww.PacktPub.com.
DidyouknowthatPacktofferseBookversionsofeverybookpublished,withPDFand
ePubfilesavailable?YoucanupgradetotheeBookversionatwww.PacktPub.comandas
aprintbookcustomer,youareentitledtoadiscountontheeBookcopy.Getintouchwith
usat<>formoredetails.
Atwww.PacktPub.com,youcanalsoreadacollectionoffreetechnicalarticles,signup
forarangeoffreenewslettersandreceiveexclusivediscountsandoffersonPacktbooks
andeBooks.

/>DoyouneedinstantsolutionstoyourITquestions?PacktLibisPackt’sonlinedigital
booklibrary.Here,youcansearch,access,andreadPackt’sentirelibraryofbooks.


Whysubscribe?
FullysearchableacrosseverybookpublishedbyPackt
Copyandpaste,print,andbookmarkcontent
Ondemandandaccessibleviaawebbrowser



FreeaccessforPacktaccountholders
IfyouhaveanaccountwithPacktatwww.PacktPub.com,youcanusethistoaccess
PacktLibtodayandview9entirelyfreebooks.Simplyuseyourlogincredentialsfor
immediateaccess.



Preface
JuliaisanewprogramminglanguagethatwasdevelopedatMITintheApplied
ComputingGroupunderthesupervisionofProf.AlanEdelman.Itsdevelopmentstartedin
2009,anditwasfirstpresentedpubliclyinFebruary2012.Itisstillafairlyyoung
languagewhenyoulookatthecurrentVersionnumber(0.3),butitsfoundationisstable;
thecorelanguagehashadnobackwardsincompatiblechangessinceVersion0.1.Itis
basedonclearandsolidprinciples,anditspopularityissteadilyincreasinginthe
technical,datascientist,andhigh-performancecomputingarenas.InthesectionThe
RationaleforJulia,wepresentanoverviewoftheprinciplesonwhichJuliaisbasedand
comparethemtootherlanguages.


×