Author Archives: Andrew Collier

#MonthOfJulia Day 2: Development Environments

The Julia REPL has a vast range of features. It’s a pleasure to use and I’m perfectly happy to run Julia from the command line and edit code in gedit or vim. That’s the way I operated with R before I discovered the beauty of RStudio. Let’s have a look at the similar options for Julia.

Juno

Juno is the current IDE of choice for Julia. Installation is pretty straightforward. If you’ve worked in any other IDE then finding your way around Juno will be simple. If you run into any snags you can always resort to reading the documentation.

When you start Juno for the first time it opens a tutorial file called, not surprisingly, Tutorial.jl. It would be worth your while to take the few minutes required to work your way through this. The image below shows some of the tutorial content.

julia-juno-session-1

Useful features:

  • Ctrl-Space brings up a command bar. You can access the tutorial at any time by searching here for “tutorial”.
  • Ctrl-Enter evaluates the current expression and the result is displayed inline.
  • Ctrl-d will pop up the documentation for the selected function.

There are some other cool bells and whistles too. For example, while you are working through the tutorial you will evaluate double(10) and find that by clicking and dragging on the function argument you can change its value and the value of the expression will be updated accordingly. I’ve not seen that in another IDE.

You can produce inline plots and the same click-and-drag mechanism mentioned above allows you to change the parameters of the plot and see the results in real-time.

IJulia Notebooks

You can run Julia code directly in your browser using the IJulia notebooks at JuliaBox.org. These notebooks are based on functionality from IPython. You can read more about how they work here.

Sign in using your Google identity. Everybody has one of those, right?

julia-juliabox

Open the tutorial folder and then select the 00 – Start Tutorial notebook. It’s worthwhile browsing through the other parts of the tutorial too, which cover topics like plotting and metaprogramming.

julia-ijulia-notebook

You can access the notebook functionality locally via the IJulia package. As before, these instructions pertain to Ubuntu Linux. First you’ll need to install IPython.

$ sudo apt-get install ipython-notebook

Then install and load the IJulia package. Finally run the notebook() function, which will launch an IJulia notebook in your browser.

julia> Pkg.add("IJulia")
julia> using IJulia
julia> notebook()
2015-08-03 07:35:33.009 [NotebookApp] Using existing profile dir: u'/home/colliera/.ipython/profile_julia'
2015-08-03 07:35:33.013 [NotebookApp] Using system MathJax
2015-08-03 07:35:33.020 [NotebookApp] Serving notebooks from local directory: /home/colliera/
2015-08-03 07:35:33.021 [NotebookApp] 0 active kernels 
2015-08-03 07:35:33.021 [NotebookApp] The IPython Notebook is running at: http://localhost:8998/
2015-08-03 07:35:33.021 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Created new window in existing browser session.

Alternatively you can use an IJulia notebook directly from the shell prompt.

$ ipython notebook --profile julia

That’s a little more direct than first running the Julia interpreter. For ease of use I created a shell alias.

$ alias ijulia='ipython notebook --profile julia'
$ ijulia 

Editor Support

There is good support for Julia in various editors. Among the ones I use (vim, gedit, Notepad++ and Sublime Text) all have Julia capabilities.

Hosting Code

Julia Studio is a project which is no longer supported and has been incorporated into Epicenter, which is a platform for hosting server-side models. It facilitates the creation of interactive web and mobile applications. I haven’t given it a go yet, but it looks interesting and it’s certainly on the agenda.

The post #MonthOfJulia Day 2: Development Environments appeared first on Exegetic Analytics.

#MonthOfJulia Day 1: Installation and Orientation

As a long-term R user I’ve found that there are few tasks (analytical or otherwise) that R cannot immediately handle. Or be made to handle after a bit of hacking! However, I’m always interested in learning new tools. A month or so ago I attended a talk entitled Julia’s Approach to Open Source Machine Learning by John Myles White at ICML in Lille, France. What John told us about Julia was impressive and intriguing. I felt compelled to take a closer look. Like most research tasks, my first stop was the Wikipedia entry, which was suitably informative.

And so I embarked on a Month of Julia. Over the next 30 days (give or take a few) I will be posting about my experiences as a new Julia user. I’ll start with some of the language basics and then dig into a few of the supplementary packages. Today I’ll start with installation and a quick tour of the interpreter.

Background Reading

If you have the time and patience you’ll find it instructive to read these:

But, if you’re like me, then you’ll get half way through the first paper and have the overpowering urge to start tinkering. Don’t delay. Tinker away.

You should undoubtedly read the papers in their entirety once the first wave of tinkering subsides.

Installation

I’m running Ubuntu 15.04, so this will be rather specific. Installation was extremely simple (handled entirely by the package manager) and it looks like other platforms are similarly straightforward (check the Downloads page). I will be using Julia version 0.3.10.

julia-install

I’m not quite sure why I was in the Pictures folder when I kicked off the install, but this is by no means a requirement!

The Julia interpreter is launched by typing julia at the command prompt. At launch it displays a nice logo which, incidentally, can be reproduced at any time for your amusement and pleasure using Base.banner().

julia-default-terminal

The default colours in the interpreter are not going to work for me, so I tracked down the configuration file (~/.juliarc.jl) and made some changes. Ah, that’s better.

julia-pimped-terminal

Interacting with the Julia Interpreter

The Julia REPL is designed for interaction. I will pick out a few of the key features (you can find further details here).

  • By default the value of an expression is echoed back as the “answer”. You can suppress this behaviour by ending the expression with a semicolon.
  • The value of the previous expression can be retrieved with the ans variable.
  • You activate the help system by typing ? at the prompt or by using help().
  • You can also search through the help documents using apropos().
    julia-help-system

  • You can get immediate access to the system shell by typing ; at the prompt.
    julia-command-shell

  • You can search back through your command history using the “normal” Ctrl-r shell binding.
  • Ctrl-l will clear the contents of the console.
  • Use Ctrl-d to exit the interpreter.
  • Tab completion rocks: use it! (It works with Unicode too, by some sort of strange magic! Check out the table of Tab completion sequences. Then try typing x^2 followed by Tab. When I first saw that this worked I almost wet my pants.)

If you’re like me then you’ll want to put your code into script files. Julia scripts normally have a “.jl” extension and are executed in the interpreter either by specifying the script name on the command line like this:

$ julia test-script.jl

or from within the interpreter using

julia> include("test-script.jl")

Keeping Up to Date

To ensure that you have the most recent released version of Julia (not necessarily available through the default Ubuntu repositories), you can add specific PPAs.

$ sudo add-apt-repository ppa:staticfloat/juliareleases
$ sudo add-apt-repository ppa:staticfloat/julia-deps
$ sudo apt-get update

Code Samples

I’ll be posting code samples on GitHub.

More to come tomorrow.

The post #MonthOfJulia Day 1: Installation and Orientation appeared first on Exegetic Analytics.