julia my new optimization friend
play

Julia, my new optimization friend Intro to the Julia programming - PowerPoint PPT Presentation

Julia, my new optimization friend Intro to the Julia programming language, for MATLAB users Date: 14th of June 2 18 Who: Lilian Besson & Pierre Haessig (SCEE & AUT team @ IETR / CentraleSup lec campus Rennes) 1 Julia, my


  1. « Julia, my new optimization friend » Intro to the Julia programming language, for MATLAB users Date: 14th of June 2  18 Who: Lilian Besson & Pierre Haessig (SCEE & AUT team @ IETR / CentraleSup é lec campus Rennes) 1 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  2. Agenda for today [25 min] 1. What is Julia [3 min] 2. Comparison with MATLAB [3 min] 3. Examples of problems solved Julia [5 min] 4. Longer example on optimization with JuMP [1  min] 5. Links for more information ? [2 min] 2 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  3. 1. What is Julia ? Developed and popular from the last 7 years Open-source and free programming language (MIT license) Interpreted and compiled, very efficient But easy syntax, dynamic typing, inline documentation etc Multi-platform, imperative MATLAB-like syntax for linear algebra etc Designed and acknowledged as simple to learn and use Easy to run your code in parallel (multi-core & cluster) Used worldwide: research, data science, finance etc … 3 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  4. Ressources Website : JuliaLang.org for the language & Pkg.JuliaLang.org for packages Documentation : docs.JuliaLang.org 4 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  5. Comparison with MATLAB Julia MATLAB Cost Free Hundreds of euros / year 1 year user license (no longer after your License Open-source PhD!) A non-profit foundation, and the Comes from MathWorks company community Scope Mainly numeric Numeric only Performances Very good performance Faster than Python, slower than Julia 5 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  6. Comparison with MATLAB Julia MATLAB Pkg manager included. Based on git Toolboxes already included but Packaging + GitHub, very easy to use have to pay if you wat more! Jupyter is recommended ( Juno is also Editor/IDE Good IDE already included good) Parallel Very easy, low overhead cost Possible, high overhead computations 6 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  7. Comparison with MATLAB Julia MATLAB Research in academia and Usage Generic, worldwide industry Fame Young but starts to be known Old and known, in decline 1 Community (StackOverflow, mailing lists Support? By MathWorks etc). Documentation OK and growing, inline/online OK, inline/online 1 Note : JuliaPro offer paid licenses, if professional support is needed. 7 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  8. How to install Julia (1/2) You can try online for free on JuliaBox.com On Linux, Mac OS or Windows: You can use the default installer from the website julialang.org/downloads Takes about 4 minutes... and it's free ! You also need Python 3 to use Jupyter , I suggest to use Anaconda.com/download if you don't have Python yet. 8 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  9. How to install Julia (2/2) 1. Select the binary of your platform 2. Run the binary ! 3. Wait … ! Test with julia 4. Done in a terminal 9 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  10. Different tools to use Julia Use julia for the command line for short experiments Use the Juno IDE to edit large projects Demo time ! 1  « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  11. Different tools to use Julia Use Ju pyter notebooks to write or share your experiments (examples: github.com/Naereen/notebooks ) Demo time ! 11 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  12. How to install modules in Julia ? Installing is easy ! julia> Pkd.add�"IJulia"� # installs IJulia Updating also! julia> Pkg.update�� How to find the module you need ? First … ask your colleagues ! Complete list on pkg.JuliaLang.org 12 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  13. Overview of famous Julia modules Winston.jl for easy plotting like MATLAB The JuliaDiffEq collection for differential equations The JuliaOpt collection for optimization The JuliaStats collection for statistics And many more! Find more specific packages on GitHub.com/svaksha/Julia.jl/ 13 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  14. Many packages, and a quickly growing community Julia is still in development, in version v  .6 but version 1.  is planned soon! 14 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  15. 2. Main differences in syntax between Julia and MATLAB Ref: cheatsheets.quantecon.org Julia MATLAB .jl .m File ext. # blabla��� % blabla��� Comment a[�] to a[end] a��� to a�end� Indexing a[�����] a������� Slicing (view) ( copy) Operations Linear algebra by default Linear algebra by default Use end Use endif endfor Block to close all blocks etc 15 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  16. Julia MATLAB ?func help func Help a & b a �� b And a | b a �� b Or Arra� Datatype of any type multi-dim doubles array [� �; � �] [� �; � �] Array size�a� size�a� Size ndims�a� ndims�a� Nb Dim a[end] a�end� Last 16 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  17. Julia MATLAB a.' a.' Tranpose a' a' Conj. transpose a * b a * b Matrix x a .* b a .* b Element-wise x a ./ b a ./ b Element-wise / a ^ � a .^ � Element-wise ^ zeros��, �, �� zeros��, �, �� Zeros ones��, �, �� ones��, �, �� Ones e�e���� e�e���� Identity range��, ���, �� or ������� ������� Range 17 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  18. Julia MATLAB ma��a� ma��ma��a�� Maximum ? rand��, �� rand��, �� Random matrix norm�v� norm�v� L2 Norm inv�a� inv�a� Inverse a \ b a \ b Solve syst. V, D = eig�a� [V,D]=eig�a� Eigen vals fft�a� , ifft�a� fft�a� , ifft�a� FFT/IFFT Very close to MATLAB for linear algebra! 18 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  19. 3. Scientific problems solved with Julia Just to give examples of syntax and modules 1. 1D numerical integration and plot nd 2. Solving a 2 order Ordinary Differential Equation 19 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  20. 3.1. 1D numerical integration and plot Exercise : evaluate and plot this function on [-1, 1] : ∞ e u ∫ Ei( x ) := d u u − x How to? Use packages and everything is easy! QuadGK.jl for integration Winston.jl for 2D plotting 2  « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  21. using QuadGK function Ei��, minfloat=�e-�, ma�float=���� f = t �� e�p��t� / t # inline function, with '- >' if � > � return quadgk�f, ��, �minfloat�[�] + quadgk�f, minfloat, ma�float�[�] else return quadgk�f, ��, ma�float�[�] end end X = linspace�-�, �, ����� # ���� points Y = [ Ei��� for � in X ] using Winston plot�X, Y� title�"The function Ei���"� �label�"�"�; �label�"�"� savefig�"figures/Ei_integral.png"� 21 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  22. 22 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  23. nd 3.2. Solving a 2 order ODE Goal : solve and plot the differential equation of a pendulum: ′′ ′ θ ( t ) + b θ ( t ) + c sin( θ ( t )) = 0 ′ For b = 1/4 , c = 5 , θ (0) = π − 0.1 , θ (0) = 0 , t ∈ [0, 10] How to? Use packages! DifferentialEquations.jl function for ODE integration Winston.jl for 2D plotting 23 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  24. using DifferentialEquations b, c = �.��, �.� # macro magic! pend� = @ode_def Pendulum begin dθ = ω # ��� �es, this is UTF8 dω = ��b * ω� - �c * sin�θ�� end prob = ODEProblem�pend, ��, ��.�, ��.��� sol = solve�prob� # ↑ solve on interval [�,��] t, � = sol.t, hcat�sol.u����' using Winston plot�t, �[:, �], t, �[:, �]� title�"�D Differential Equation"� savefig�"figures/Pendulum_solution.png"� 24 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

  25. 25 « Julia, my new optimization friend » | 14 June 2  18 | By: Lilian Besson | IETR @ Vannes

Recommend


More recommend