Monday 28 October 2013

The Shortest Blog?

Since starting I have discovered that there are excellent examples of Julia code such as those at Rosetta.

I have also discovered that there is a lot of work going on to expand Julia's capabilities and Daniel Jones has invited me to do some work on the color palettes for plotting which I think will prove interesting.

So thanks to those who read and or contributed to the blog.

Friday 25 October 2013

Problem Set

Well, the problem wasn't particularly difficult so I'm not planning to post code for this one.  I did learn a few things about the differences:

- remember to use return with Python functions, it doesn't just return the last result if you leave it open
- you have to go back to for i in range(1, h+1) from for i=1:h
- remember that everything starts with 0 in Python not 1
- its xxx.method(c) not method(xx, c)

I'm not sure if working on two languages at once is something I'm capable of or not.  For interest I decided to look at memoizing fib.  This is an interesting exercise in scope and closures.  In Python you can do it with something like this:

But in Julia you run into a couple of problems.  First, redefining a function in the Main() scope is not permitted but that can be overcome by putting fib in a module and importing it (within the same REPL seems fine).  Second, the recursive calls to fib are not updating the cache dictionary so it doesn't speed up.  I've asked for help to understand the error in my thinking.

IJulia Notebook.

The other thing I continued experimenting with was Gadfly.  I didn't know a sine wave could look like this:



And I've created a first draft of a Gadfly Reference Card.

Wednesday 23 October 2013

Tomorrow we begin with the joys of functions and sorting.  I remembered how slow the basic recursive fibonacci calculation could be and decide to compare Python to Julia.  Both are running on one of four CPUs and garbage collection is on so no cheating.  The code is:

Well, for fib(50) Julia took 107 seconds.  Seems slow until you find that Python took (actually I'm still waiting and it started before I wrote the Julia code) ... ... 

I also started learning a bit about Julia's Glamor of Graphics style plotting module, Gadfly.  Here's todays experiment:


Still waiting for Python to finish ... perhaps after dinner ... 1 hour 10 minutes and 5 seconds.  So Julia is 39 times faster than Python calculating the fib.

Monday 21 October 2013

Rosetta Code

I went over to the Rosetta Code website to look at the examples of Julia in action. Amongst them I found one marked as not completed so I took the challenge. This code picks the middle three digits from numbers returning an error message if it's not possible. It illustrates the use of the @sprintf macro for formatting text. You don't waste a lot of keystrokes when you write Julia:

Saturday 19 October 2013

Documentation and the Julia Reference Card

The Julia Manual and Julia Standard Library are excellent but a newbie like me needs something shorter to keep him on track.  I've always liked Michael Goerz's Python 2.5 reference card so I'm building one following his layout.  It's about 7/8 completed and you can download it here (v0.2).  Suggestions welcome.

Wednesday 16 October 2013

Week One

Week One was quiet with the main assignment being the installation of Python for those without it and a number of multi-choice questions to test understanding.

The code was a simple Hello World and a conditional variation so here is Julia code similar to the Python.


Note that Julia doesn't require Python's colons but instead uses an end to finish evaluations and functions.  Also Python uses indentation rigorously but Julia could care less about indentation or white space.  I will use Python conventions usually, simply because I like them.

If you want a quick look at the language Learn Julia in Y Minutes is surprisingly good.

Tuesday 15 October 2013

Why Learn Julia?

About a year ago I came across a cool new computing language called Julia.  I liked the concepts but at the time Julia was so new that I decided to let it grow a little.

I've written a lot of C, some Python and a smattering of R so why would I want to learn a new language?  I liked Julia because I'm impressed by R's statistics capabilities, I enjoy the structure and flow of Python, I liked their interactivity and not having to wait for a compiler, but I wanted to be close to the speed of C.  Julia promised to grow to all these things.

A year later and I'm doing Roger Peng's R Mooc at Coursera.  With a little spare time I took another look at Julia and it had matured greatly.
  • IJulia provides the notebooks I'd come to love with IPython
  • Pyplot was there along with Pycall so all that Python functionality seems to be at my finger tips
  • Gadfly based on ggplot2 offers plotting based on The Grammar of Graphics something that had really impressed me with R
  • Tools like Julia Studio and julia-vim had been developed
  • and the language was filling out as was access to C, Fortran and R libraries
So over the last couple of weeks I rewrote R assignments with Julia and learned enough R and Julia to be a tiny little bit dangerous.

Julia's fun to write in, even more fun than Python, and it is fast, so I was hooked.



This week I'm commencing the a Computer Science course.  Over the 8 weeks of the course I plan to complete each assignment in both Python and Julia.  I'll post the Julia versions here, plus comparisons with Python and code as long as it won't give too much away to future students.   It's a broad overview of Computer Science so it'll be interesting to see if I can complete everything with Julia.

John