## Data Analysis with Rust Notebooks

A practical book on Data Analysis with Rust Notebooks that teaches you the concepts and how they’re implemented in practice.

Get the book

The Rust programming language has become a popular choice amongst software engineers since its release in 2010. Besides being something new and interesting, Rust promised to offer exceptional performance and reliability. In particular, Rust achieves memory-safety and thread-safety through its ownership model. Instead of runtime checks, this safety is assured at compile time by Rust's borrow checker. This prevents undefined behaviour such as dangling pointers!

println!("Hello World!");


I first encountered Rust sometime around 2015 when I was updating my teaching materials on memory management in C. A year later in 2016, I implemented a simple multi-objective evolutionary algorithm in Rust as an academic exercise (available: https://github.com/shahinrostami/simple_ea). I didn't have any formal training with Rust, nor did I complete any tutorial series, I just figured things out using the documentation as I progressed through my project.

Some example code from this project takes ZDT1 from its mathematical expression in Equation 1

$\begin{array}{rl}\text{(1)}& {f}_{1}\left({x}_{1}\right)& ={x}_{1}{f}_{2}\left(x\right)& =g\cdot h\\ g\left({x}_{2},\dots ,{x}_{\mathrm{D}}\right)& =1+9\cdot \sum _{d=2}^{\mathrm{D}}\frac{{x}_{d}}{\left(D-1\right)}\\ h\left({f}_{1},g\right)& =1-\sqrt{f1/g}\end{array}$

to the Rust implementation below.

pub fn zdt1(parameters: [f32; 30]) -> [f32; 2] {
let f1 = parameters[0];
let mut g = 1_f32;

for i in 1..parameters.len() {
g = g + ((9_f32 / (parameters.len() as f32 - 1_f32)) * parameters[i]);
}

let h = 1_f32 - (f1 / g).sqrt();
let f2 = g * h;

return [f1, f2];
}


It was interesting to see that since writing this code in 2016, some of my dependencies had been deprecated and superseded.

My greatest challenge was breaking away from what I already knew. Until this point, I was familiar with languages such as C, C++, C#, Java, Python, MATLAB, etc., with the majority of my time spent working with memory managed languages. I found myself resisting Rust's intended usage, and it is still something I'm working on.

Now that I am about to commence my sabbatical from my University post, I've decided to try Rust again. This time, I'm going to write a book which focusses on using Rust and Jupyter Notebooks to implement algorithms and conduct experiments, most likely in the fields of search, optimisation, and machine learning. Can we write and execute all our code in a Jupyter Notebook? Yes! Should we? Probably not. However, I enjoy the workflow, and making this an enjoyable process is important to me.

Note

I aim to generate everything in this book through code. This means you will see the code for all my figures and tables, including things like flowcharts.

## Data Analysis with Rust Notebooks

A practical book on Data Analysis with Rust Notebooks that teaches you the concepts and how they’re implemented in practice.

Get the book

## ISBN

978-1-915907-10-3

## Cite

Rostami, S. (2020). Data Analysis with Rust Notebooks. Polyra Publishing.