Hands-On Julia Programming : An Authoritative Guide to the Production-Ready Systems in Julia

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Build production-ready machine learning and NLP systems using functional programming, development platforms, and cloud deployment. Key Features ● In-depth explanation and code samples highlighting the features of the Julia language. ● Extensive coverage of the Julia development ecosystem, package management, DevOps environment integration, and performance management tools. ● Exposure to the most important Julia packages that aid in Data and Text Analytics and Deep Learning. Description The Julia Programming language enables data scientists and programmers to create prototypes without sacrificing performance. Nonetheless, skeptics question its readiness for production deployments as a new platform with a 1.0 release in 2018. This book removes these doubts and offers a comprehensive glimpse at the language's use throughout developing and deploying production-ready applications. The first part of the book teaches experienced programmers and scientists about the Julia language features in great detail. The second part consists of gaining hands-on experience with the development environment, debugging, programming guidelines, package management, and cloud deployment strategies. In the final section, readers are introduced to a variety of third-party packages available in the Julia ecosystem for Data Processing, Text Analytics, and developing Deep Learning models. This book provides an extensive overview of the programming language and broadens understanding of the Julia ecosystem. As a result, it assists programmers, scientists, and information architects in selecting Julia for their next production deployments. What you will learn ● Get to know the complete fundamentals of Julia programming. ● Explore Julia development frameworks and how to work with them. ● Dig deeper into the concepts and applications of functional programming. ● Uncover the Julia infrastructure for development, testing, and deployment. ● Learn to practice Julia libraries and the Julia package ecosystem. ● Processing Data, Deep Learning, and Natural Language Processing with Julia.

Author(s): Sambit Kumar Dash
Edition: 1
Publisher: BPB Publications
Year: 2022

Language: English
Pages: 338

1. Getting Started .............................................................................................................1
Introduction.............................................................................................................1
Structure...................................................................................................................1
Objectives.................................................................................................................2
Purpose of Julia.......................................................................................................2
1. Performance is the core...................................................................................2
2. Modern programming language.....................................................................2
3. Integration with other platforms....................................................................3
4. Designed for researchers.................................................................................3
5. Metaprogramming..........................................................................................4
6. Development toolset........................................................................................4
7. Package ecosystem..........................................................................................5
8. Server platforms support................................................................................5
9. Open source and flexible licensing.................................................................5
10. Enterprise-friendly architecture...................................................................6
11. Active community.........................................................................................6
12. Get under the hood........................................................................................7
A brief history..........................................................................................................7
The book outline.....................................................................................................7
Module 1. The Julia language.............................................................................8
Chapter 1. Getting started........................................................................................8
Chapter 2. Data types...............................................................................................8
Chapter 3. Conditions, control flow, and iterations.................................................8
Chapter 4. Functions and methods..........................................................................8
Chapter 5. Collections..............................................................................................9
Chapter 6. Arrays.....................................................................................................9
Chapter 7. Strings....................................................................................................9
Chapter 8. Metaprogramming...............................................................................10
Chapter 9. Standard libraries.................................................................................10
Module 2. The development environment........................................................10
Chapter 10. Programming guidelines in Julia.......................................................10
 xiii
Chapter 11. Performance management..................................................................11
Chapter 12. IDE and debugging............................................................................11
Chapter 13. Package management.........................................................................11
Chapter 14. Deployment........................................................................................12
Module 3. Packages in Julia..............................................................................12
Chapter 15. Data transformations.........................................................................12
Chapter 16. Text analytics......................................................................................12
Chapter 17. Deep learning.....................................................................................12
Setting up Julia......................................................................................................13
Downloading installer binaries..........................................................................13
Julia versions..........................................................................................................13
Linux (x86).......................................................................................................14
Windows...........................................................................................................14
Read-Eval-Print Loop (REPL).............................................................................15
Interactive Julia and Jupyter...............................................................................16
Julia programs.......................................................................................................18
Conclusion.............................................................................................................18
Exercises.................................................................................................................19
2. Data Types...................................................................................................................21
Introduction...........................................................................................................21
Structure.................................................................................................................21
Objectives...............................................................................................................22
Types in Julia.........................................................................................................22
Variables............................................................................................................22
Definition versus initialization..............................................................................23
Constants..........................................................................................................24
Literals..............................................................................................................24
Tuples................................................................................................................25
Built-in types.........................................................................................................26
Nothing.............................................................................................................26
Numeric types...................................................................................................27
Bool.........................................................................................................................27
Integral types..........................................................................................................27
xiv 
Floating point numbers..........................................................................................27
Abstract types.........................................................................................................28
Primitive types.......................................................................................................29
Bit types..................................................................................................................30
Rational and complex.............................................................................................30
Char..................................................................................................................30
String................................................................................................................30
User-defined types................................................................................................30
struct.................................................................................................................31
mutable struct...................................................................................................31
Members...........................................................................................................32
Any.........................................................................................................................32
Parametric data types...........................................................................................33
Operations on types.............................................................................................34
typeof.................................................................................................................35
isa......................................................................................................................35
supertype...........................................................................................................36
Printing data types...............................................................................................36
show..................................................................................................................37
print..................................................................................................................37
string.................................................................................................................37
Conclusion.............................................................................................................38
Exercises.................................................................................................................38
3. Conditions, Control Flows, and Iterations...........................................................39
Introduction...........................................................................................................39
Structure.................................................................................................................39
Objectives...............................................................................................................39
Compound statements.........................................................................................40
begin…end........................................................................................................40
Conditional execution..........................................................................................40
if...else...............................................................................................................40
The Missing switch...case.................................................................................41
Unstructured branching...................................................................................43
 xv
Iterative execution................................................................................................44
for......................................................................................................................44
Continue and break................................................................................................45
for…in....................................................................................................................46
Multiple range objects............................................................................................46
while..................................................................................................................47
Missing do...while.............................................................................................48
Exception handling...............................................................................................48
try…catch.........................................................................................................49
throw/rethrow...................................................................................................49
finally................................................................................................................50
Information from exceptions.............................................................................50
Stack traces.............................................................................................................51
Parallel execution..................................................................................................52
Conclusion.............................................................................................................52
Exercises.................................................................................................................52
4. Functions and Methods............................................................................................53
Introduction...........................................................................................................53
Structure.................................................................................................................53
Objectives...............................................................................................................54
Introduction...........................................................................................................54
8-Queens problem.............................................................................................54
Two mutually safe queens......................................................................................55
Operators................................................................................................................56
Short form..............................................................................................................56
Anonymous Functions.....................................................................................57
Input arguments...................................................................................................57
Fixed arguments length....................................................................................57
Variable number of arguments.........................................................................58
Default values...................................................................................................59
Slurping and splatting......................................................................................60
Return value..........................................................................................................60
Type safety........................................................................................................61
xvi 
Multiple values.................................................................................................62
Recursion...............................................................................................................62
Tail call..............................................................................................................65
Polymorphic methods..........................................................................................68
Data types.........................................................................................................68
Multiple dispatch...................................................................................................69
Constructors.....................................................................................................69
Return value...........................................................................................................70
Parametric data type.........................................................................................71
Dispatch interface...................................................................................................71
Type interaction....................................................................................................72
Conversion........................................................................................................73
Promotion.........................................................................................................74
Conclusion.............................................................................................................75
Exercises.................................................................................................................76
5. Collections...................................................................................................................77
Introduction...........................................................................................................77
Structure.................................................................................................................77
Objectives...............................................................................................................78
Predefined data structures..................................................................................78
Tuple.......................................................................................................................78
NTuple..............................................................................................................79
Tuple as a collection..........................................................................................79
Integers as type parameters..............................................................................80
Value parameters..............................................................................................82
Singleton................................................................................................................83
Ranges....................................................................................................................83
UnitRange........................................................................................................83
StepRange.........................................................................................................84
Decreasing ranges.............................................................................................84
Array.......................................................................................................................85
Memory layout and indexing.............................................................................86
Effects of paging.....................................................................................................86
 xvii
Some useful functions.......................................................................................87
Constructors...........................................................................................................87
zeros and ones.........................................................................................................89
trues and falses.......................................................................................................89
fill and similar........................................................................................................90
collect......................................................................................................................90
reshape....................................................................................................................90
hcat, vcat, and hvcat...............................................................................................91
Associative collection...........................................................................................92
Dict...................................................................................................................92
get Methods............................................................................................................93
setindex! Method....................................................................................................94
Hashing..................................................................................................................94
Set.....................................................................................................................95
Union and intersection...........................................................................................95
Iteration..................................................................................................................96
for loop..............................................................................................................96
function...do......................................................................................................97
Iteration framework.............................................................................................98
Iterate methods..................................................................................................99
Optional methods...................................................................................................99
Example..........................................................................................................100
Generators and comprehensions......................................................................101
Conclusion...........................................................................................................102
Exercises...............................................................................................................103
6. Arrays..........................................................................................................................105
Introduction.........................................................................................................105
Structure...............................................................................................................105
Objectives.............................................................................................................106
Containers............................................................................................................106
Dimensions..........................................................................................................107
Indexing...............................................................................................................109
Scalars.............................................................................................................109
Ranges.............................................................................................................109
xviii 
Vectors............................................................................................................110
Linear index.....................................................................................................111
Cartesian index................................................................................................111
Boolean index..................................................................................................112
Assignment.....................................................................................................113
Special indices.................................................................................................113
Interface..........................................................................................................113
Slicing...................................................................................................................114
Broadcasting........................................................................................................116
Performance....................................................................................................118
broadcast versus map......................................................................................118
Reduction.............................................................................................................119
Associativity...................................................................................................119
Map and reduce..............................................................................................120
Slices...............................................................................................................120
Abstract array types...........................................................................................121
Sparse arrays.......................................................................................................123
Sparse vector storage......................................................................................123
Sparse matrix storage.....................................................................................124
Efficiency.........................................................................................................125
Linear algebra......................................................................................................125
Conclusion...........................................................................................................126
Exercises...............................................................................................................126
7. Strings.........................................................................................................................127
Introduction.........................................................................................................127
Structure...............................................................................................................127
Objectives.............................................................................................................128
Background..........................................................................................................128
Strings............................................................................................................128
Characters.......................................................................................................128
Encoding.........................................................................................................129
ASCII..............................................................................................................129
ISO-8859........................................................................................................130
 xix
The ‘C’ Encoding............................................................................................130
Unicode...........................................................................................................130
Unicode transformations................................................................................131
Unicode support in Julia.................................................................................132
Fonts and Glyphs............................................................................................132
String....................................................................................................................132
String methods....................................................................................................133
Comparison.....................................................................................................133
Iteration..........................................................................................................134
Split and concatenate......................................................................................136
Case conversion..............................................................................................138
Pattern matching............................................................................................139
Regular expressions........................................................................................140
Encodings.............................................................................................................141
Useful functions..............................................................................................142
Character array...................................................................................................143
Custom strings....................................................................................................144
AbstractChar..................................................................................................144
AbstractString................................................................................................144
Conclusion...........................................................................................................145
Exercises...............................................................................................................146
8. Metaprogramming...................................................................................................147
Introduction.........................................................................................................147
Structure...............................................................................................................147
Objectives.............................................................................................................148
Background..........................................................................................................148
Abstract Syntax Trees (AST)..........................................................................149
Symbols and interned strings.........................................................................150
Inline evaluations...........................................................................................152
Multiline expressions.....................................................................................152
Nested quotes and interpolation.....................................................................154
Functions........................................................................................................156
Macros..................................................................................................................156
xx 
Calling conventions........................................................................................157
Custom string literals.........................................................................................158
Generated functions...........................................................................................159
Commonly used macros....................................................................................160
Source locations..............................................................................................160
eval..................................................................................................................161
assert ..............................................................................................................162
time.................................................................................................................163
Conclusion...........................................................................................................164
Exercises...............................................................................................................164
9. Standard Libraries....................................................................................................165
Introduction.........................................................................................................165
Structure...............................................................................................................165
Objective..............................................................................................................166
Background..........................................................................................................166
Modules..........................................................................................................166
Standard modules...............................................................................................169
System..................................................................................................................171
Filesystem............................................................................................................172
Parallel programming........................................................................................174
Asynchronous programming..........................................................................175
Tasks.....................................................................................................................176
Channels...............................................................................................................177
Locks.....................................................................................................................178
Multithreading...............................................................................................178
Distributed computing ........................................................................................180
I/O and network.................................................................................................182
Default streams...............................................................................................182
Text I/O................................................................................................................182
Binary I/O............................................................................................................184
File I/O.................................................................................................................184
Delimited files.................................................................................................186
Network communication................................................................................187
Memory and I/O.............................................................................................189
 xxi
Constants.............................................................................................................190
Notable modules.................................................................................................191
Dates...............................................................................................................191
Logging...........................................................................................................194
Statistics.........................................................................................................196
Random numbers............................................................................................196
Conclusion...........................................................................................................197
Exercises...............................................................................................................198
10. Programming Guidelines in Julia.........................................................................199
Introduction.........................................................................................................199
Structure...............................................................................................................199
Objective..............................................................................................................200
Background..........................................................................................................200
Guidelines for maintainability..........................................................................200
Coding style....................................................................................................204
Functional programming principles................................................................207
Declarative programming...............................................................................208
Functions with no side effects.........................................................................209
Higher-order functions...................................................................................210
Immutability...................................................................................................210
Commonly used patterns..................................................................................211
Interfaces.........................................................................................................211
Super types...........................................................................................................212
Holy traits............................................................................................................214
Delegation.......................................................................................................217
Accessor methods............................................................................................218
Contributing to open source.............................................................................219
Contributing to Julia......................................................................................220
Conclusion...........................................................................................................220
Exercises...............................................................................................................220
11. Performance Management......................................................................................221
Introduction.........................................................................................................221
Structure...............................................................................................................221
xxii 
Objective..............................................................................................................221
Background..........................................................................................................222
The right level of optimization........................................................................222
Resources........................................................................................................224
The choice of algorithm...................................................................................224
Optimize wisely..............................................................................................225
Julia versus competition.................................................................................225
Benchmarking.....................................................................................................226
Code generation tools........................................................................................229
Type stability...................................................................................................229
Unnecessary allocations.................................................................................234
Parametric data types.....................................................................................235
Remove unnecessary code...............................................................................236
Profiling................................................................................................................238
Guidelines for high-performance code............................................................240
Memoization...................................................................................................240
Global variables...............................................................................................243
Conclusion...........................................................................................................245
Exercises...............................................................................................................245
12. IDE and Debugging.................................................................................................247
Introduction.........................................................................................................247
Structure.........................................................................................................247
Objective..............................................................................................................248
Background..........................................................................................................248
Editor integration...............................................................................................250
vim..................................................................................................................250
Emacs..............................................................................................................251
Notepad++......................................................................................................253
IDE........................................................................................................................254
Atom...............................................................................................................255
Visual Studio Code.........................................................................................256
Debugging...........................................................................................................258
print, log, and @assert....................................................................................259
 xxiii
Unit tests........................................................................................................259
REPL...............................................................................................................259
Line debugging in IDE...................................................................................260
Code-Run-Fix......................................................................................................261
Conclusion...........................................................................................................262
Exercises...............................................................................................................262
13. Package Management..............................................................................................263
Introduction.........................................................................................................263
Structure...............................................................................................................263
Objective..............................................................................................................264
Background..........................................................................................................264
Projects, modules, and packages......................................................................264
Modules................................................................................................................264
Projects............................................................................................................265
Libraries..........................................................................................................265
Packages..........................................................................................................265
N-Queens revisited.........................................................................................267
Creating a new package..................................................................................268
Problem statement................................................................................................269
Package initialization...........................................................................................269
Developing the functionality................................................................................272
Registering in GitHub.........................................................................................273
Test automation...................................................................................................274
Coverage..........................................................................................................276
Documentation....................................................................................................278
Documenter configuration..............................................................................279
Continuous integration......................................................................................283
Visualization of code coverage........................................................................288
Binary dependencies..........................................................................................289
Using native binaries......................................................................................290
Environments......................................................................................................290
Package architecture...........................................................................................291
REPL command..............................................................................................293
Pkg Module.....................................................................................................294
xxiv 
Conclusion...........................................................................................................294
Exercises...............................................................................................................294
14. Deployment...............................................................................................................295
Structure...............................................................................................................295
Objective..............................................................................................................295
Cloud environments...........................................................................................296
Deploying Julia...................................................................................................297
REST-based web services................................................................................298
Docker containers...........................................................................................299
Kubernetes...........................................................................................................300
Orchestrating AKS from Julia........................................................................302
Public cloud infrastructures..............................................................................304
Amazon Web Services.....................................................................................304
Microsoft Azure...................................................................................................305
Google Cloud Platform...................................................................................305
Conclusion...........................................................................................................306
Exercises...............................................................................................................306
15. Data Transformations..............................................................................................307
Introduction.........................................................................................................307
Structure...............................................................................................................307
Objective..............................................................................................................308
Setting up the environment...............................................................................308
FileIO....................................................................................................................308
Text data...............................................................................................................309
Delimited files.................................................................................................309
XML files........................................................................................................309
HTML files......................................................................................................311
PDF files.........................................................................................................312
Microsoft office documents.............................................................................313
Image data...........................................................................................................316
Tabular data.........................................................................................................317
Data visualization...............................................................................................319
Conclusion...........................................................................................................321
 xxv
Exercises...............................................................................................................321
16. Text Analytics............................................................................................................323
Introduction.........................................................................................................323
Structure...............................................................................................................323
Objective..............................................................................................................324
Text processing pipeline....................................................................................324
Preprocessing .....................................................................................................326
Tokenization....................................................................................................327
Word representations......................................................................................328
Embeddings.....................................................................................................329
Semantic analysis................................................................................................331
Classifiers.............................................................................................................332
Extractive summarization.................................................................................333
Evaluation metrics..........................................................................................334
Named entity recognition..................................................................................334
ULMFiT................................................................................................................335
Conclusion...........................................................................................................335
Exercises ..............................................................................................................336
17. Deep Learning...........................................................................................................337
Introduction.........................................................................................................337
Structure...............................................................................................................337
Objective..............................................................................................................338
Deep learning......................................................................................................338
What is Flux?.......................................................................................................340
Model Zoo............................................................................................................344
Types of neural network....................................................................................344
Fully connected...............................................................................................344
CNN................................................................................................................346
RNN................................................................................................................349
Conclusion...........................................................................................................351
Exercises ..............................................................................................................351
Index....................................................................................................................353-361