Julia 1.0 Programming Complete Reference Guide
eBook - ePub

Julia 1.0 Programming Complete Reference Guide

Discover Julia, a high-performance language for technical computing

Ivo Balbaert, Adrian Salceanu

Share book
  1. 466 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Julia 1.0 Programming Complete Reference Guide

Discover Julia, a high-performance language for technical computing

Ivo Balbaert, Adrian Salceanu

Book details
Book preview
Table of contents
Citations

About This Book

Learn dynamic programming with Julia to build apps for data analysis, visualization, machine learning, and the web

Key Features

  • Leverage Julia's high speed and efficiency to build fast, efficient applications
  • Perform supervised and unsupervised machine learning and time series analysis
  • Tackle problems concurrently and in a distributed environment

Book Description

Julia offers the high productivity and ease of use of Python and R with the lightning-fast speed of C++. There's never been a better time to learn this language, thanks to its large-scale adoption across a wide range of domains, including fintech, biotech and artificial intelligence (AI).

You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. This Learning Path walks you through two important collection types: arrays and matrices. You'll be taken through how type conversions and promotions work, and in further chapters you'll study how Julia interacts with operating systems and other languages. You'll also learn about the use of macros, what makes Julia suitable for numerical and scientific computing, and how to run external programs.

Once you have grasped the basics, this Learning Path goes on to how to analyze the Iris dataset using DataFrames. While building a web scraper and a web app, you'll explore the use of functions, methods, and multiple dispatches. In the final chapters, you'll delve into machine learning, where you'll build a book recommender system.

By the end of this Learning Path, you'll be well versed with Julia and have the skills you need to leverage its high speed and efficiency for your applications.

This Learning Path includes content from the following Packt products:

  • Julia 1.0 Programming - Second Edition by Ivo Balbaert
  • Julia Programming Projects by Adrian Salceanu

What you will learn

  • Create your own types to extend the built-in type system
  • Visualize your data in Julia with plotting packages
  • Explore the use of built-in macros for testing and debugging
  • Integrate Julia with other languages such as C, Python, and MATLAB
  • Analyze and manipulate datasets using Julia and DataFrames
  • Develop and run a web app using Julia and the HTTP package
  • Build a recommendation system using supervised machine learning

Who this book is for

If you are a statistician or data scientist who wants a quick course in the Julia programming language while building big data applications, this Learning Path is for you. Basic knowledge of mathematics and programming is a must.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Julia 1.0 Programming Complete Reference Guide an online PDF/ePUB?
Yes, you can access Julia 1.0 Programming Complete Reference Guide by Ivo Balbaert, Adrian Salceanu in PDF and/or ePUB format, as well as other popular books in Informatica & Programmazione. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781838824679
Edition
1

Creating Our First Julia App

Now that you have a working Julia installation and your IDE of choice is ready to run, it's time to put them to some good use. In this chapter, you'll learn how to apply Julia for data analysis—a domain that is central to the language, so expect to be impressed!
We will learn to perform exploratory data analysis with Julia. In the process, we'll take a look at RDatasets, a package that provides access to over 700 learning datasets. We'll load one of them, the Iris flowers dataset, and we'll manipulate it using standard data analysis functions. Then we'll look more closely at the data by employing common visualization techniques. And finally, we'll see how to persist and (re)load our data.
But, in order to do that, first we need to revisit and take a look at some of the language's most important building blocks.
We will cover the following topics in this chapter:
  • Declaring variables (and constants)
  • Working with Strings of characters and regular expressions
  • Numbers and numeric types
  • Our first Julia data structures—Tuple, Range, and Array
  • * Exploratory data analysis using the Iris flower dataset—RDatasets and core Statistics
  • Quick data visualization with Gadfly
  • * Saving and loading tabular data with CSV and Feather
  • Interacting with MongoDB databases

Technical requirements

The Julia package ecosystem is under continuous development and new package versions are released on a daily basis. Most of the times this is great news, as new releases bring new features and bug fixes. However, since many of the packages are still in beta (version 0.x), any new release can introduce breaking changes. As a result, the code presented in the book can stop working. In order to ensure that your code will produce the same results as described in the book, it is recommended to use the same package versions. Here are the external packages used in this chapter and their specific versions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
In order to install a specific version of a package you need to run:
pkg> add [email protected] 
For example:
pkg> add [email protected]
Alternatively you can install all the used packages by downloading the Project.toml file provided with the chapter and using pkg> instantiate as follows:
julia> download("https://github.com/TrainingByPackt/Julia-1-Programming-Complete-Reference-Guide/tree/master/Chapter11/Project.toml", "Project.toml")
pkg> activate .
pkg> instantiate

Defining variables

We have seen in the previous chapter how to use the REPL in order to execute computations and have the result displayed back to us. Julia even lends a helping hand by setting up the ans variable, which automatically holds the last computed value.
But, if we want to write anything but the most trivial programs, we need to learn how to define variables ourselves. In Julia, a variable is simply a name associated to a value. There are very few restrictions for naming variables, and the names themselves have no semantic meaning (the language will not treat variables differently based on their names, unlike say Ruby, where a name that is all caps is treated as a constant).
Let's see some examples:
julia> book = "Julia v1.0 By Example" julia> pi = 3.14 julia> ANSWER = 42 julia> my_first_name = "Adrian" 
You can follow along through the examples in the chapter by loading the accompanying Jupyter/IJulia notebook provided with this chapter's support files.
The variables, names are case-sensitive, meaning that ANSWER and answer (and Answer and aNsWeR) are completely different things:
julia> answer ERROR: UndefVarError: answer not defined 
Unicode names (UTF-8-encoded) are also accepted as variables names:
julia> ÎŽ = 130 
Remember that you can type many Unicode math symbols by typing backslash (\) then the name of the symbol and then the Tab key. For example, \pi[Tab] will output π.
Emojis also work, if your terminal supports them:
julia> 
= "apollo 11"
The only explicitly disallowed names for variables are the names of built-in Julia statements (do, end, try, catch, if, and else, plus a few more):
julia> do = 3 ERROR: syntax: invalid "do" syntax 
julia> end = "Paris" ERROR: syntax: unexpected end
Attempting to access a variable that hasn't been defined will result in an error:
julia> MysteryVar ERROR: UndefVarError: MysteryVar not defined 
It's true that the language does not impose many restrictions, but a set of code style conventions is always useful—and even more so for an open source language. The Julia community has distilled a set of best practices for writing code. In regard to naming variables, the names should be lowercase and in just one word; word separation can be done with underscores (_), but only if the name would be difficult to read without them. For example, myvar versus total_length_horizontal.
Given that the degree of difficulty in reading a name is a subjective thing, I'm a bit split about this naming style. I normally prefer the crystal-clear clarity of separating at word boundaries. But nevertheless, it is better to follow the recommendation, given that function names in the Julia API adhere to it. By adhering to the same conventions, your code will be consistent throughout.

Constants

Constants are variables that, once declared, can't be changed. They are declared by prefixing them with the const keyword:
julia> const firstmonth = "January" 
Very importantly in Julia, constants are not concerned with their value, but rather with their type. It is a bit too early to discuss types in Julia, so for now it suffices to say that a type represents what kind of a value we're dealing with. For instance, "abc" (within double quotes) is of type String, 'a' (within single quotes) is of type Char , and 1000 is of type Int (because it's an integer). Thus, in Julia, unlike most other languages, we can change the value assigned to a constant as long as the type remains the same. For instance, we can at first decide that eggs and milk are acceptable meal choices and go vegetarian:
julia> const mealoption = "vegetarian" 
And we can change our mind later on, if we decide to go vegan. Julia will let it slide with just a warning:
julia> mealoption = "vegan" WARNING: redefining constant mealoption "vegan"  
However, attempting to say that mealoption = 2 will result in an error:
julia> mealoption = 2 ERROR: invalid redefinition of constant mealoption 
This makes sense, right? W...

Table of contents