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

Compartir libro
  1. 466 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Julia 1.0 Programming Complete Reference Guide

Discover Julia, a high-performance language for technical computing

Ivo Balbaert, Adrian Salceanu

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Julia 1.0 Programming Complete Reference Guide un PDF/ePUB en línea?
Sí, puedes acceder a Julia 1.0 Programming Complete Reference Guide de Ivo Balbaert, Adrian Salceanu en formato PDF o ePUB, así como a otros libros populares de Informatik y Programmierung. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2019
ISBN
9781838824679
Edición
1
Categoría
Informatik
Categoría
Programmierung

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...

Índice