Introduction¶
In this course, we study how data, geometry, probability, and optimization come together to build learning algorithms.
Python will be our computational laboratory for this journey.
We will use Python to:
- work with vectors and matrices (Modules 2–4)
- visualize geometry of data (Modules 3, 9)
- compute gradients and optimization steps (Module 5, 8)
- simulate probability models (Modules 6, 10)
Why Python?¶
Python is the standard language for scientific computing and machine learning.
The core libraries we will use are:
| Library | Purpose |
|---|---|
| NumPy | Vectors, matrices, linear algebra |
| Matplotlib | Plots and visualizations |
| SciPy | Scientific and numerical routines |
| scikit-learn | Machine learning algorithms |
These libraries let us turn mathematical formulas into executable experiments.
Installing Python on Your Computer¶
The easiest way to get everything needed for this course is Anaconda.
Step 1¶
Download Anaconda from: https://www.anaconda.com/products/distribution
Choose:
- Python 3
- Your operating system (Windows, macOS, or Linux)
Step 2¶
Install using the default options.
This installs:
- Python
- Jupyter Notebook
- All scientific libraries used in this course
Checking Your Installation¶
Open:
- Anaconda Prompt (Windows), or
- Terminal (macOS / Linux)
Type:
python --version
You should see something like:
Python 3.x.x
Starting Jupyter¶
To start Jupyter Notebook, type:
jupyter notebook
A new browser tab will open with the notebook dashboard.
What is a Jupyter Notebook?¶
A Jupyter notebook is an interactive mathematical document.
It can contain:
- text and explanations
- mathematical formulas
- code
- plots and figures
- computed results
In this course, notebooks will serve as a computational extension of the lecture notes. They allow us to connect abstract mathematics with concrete computation.
Using Google Colab¶
If you do not want to install anything on your computer, you can use Google Colab.
Google Colab is a free online Jupyter notebook service.
To use it:
- Go to https://colab.research.google.com
- Click New Notebook
- Start writing and running Python code in your browser
All computation runs on Google's servers.
Local Jupyter vs Google Colab¶
| Option | When to use |
|---|---|
| Anaconda + Jupyter | When you want everything on your own computer |
| Google Colab | When you want instant access from anywhere without installation |
Both options work equally well for this course.
Writing Mathematics in Jupyter¶
Jupyter notebooks allow us to write mathematics using LaTeX.
This means we can write formulas in the same way as in textbooks, but inside an interactive document.
Cells in a Jupyter Notebook¶
A Jupyter notebook is made of cells.
There are two types of cells we will use:
- Markdown cells — for text, explanations, and mathematics written in LaTeX
- Code cells — for Python computations
When we write formulas using LaTeX, we always use Markdown cells.
Inline Mathematics¶
To write mathematics inside a sentence, we use dollar ($) signs.
For example, we can write the square of a number as $x^2$, or a vector as $\mathbf{x}$, or an inner product as $\langle x, y \rangle$.
These formulas appear directly inside the text. We wrote this as
For example, we can write the square of a number as $x^2$,
or a vector as $\mathbf{x}$, or an inner product as $\langle x, y \rangle$.
Displayed Equations¶
When a formula is important, we write it on its own line.
For example, a quadratic function can be written as
$$ f(x) = x^2 + 3x + 1. $$
Loss functions, regression models, and probability densities will usually be written in this form. The above equation is produced by typing the following in a Markdown cell:
$$
f(x) = x^2 + 3x + 1
$$
Fractions¶
Fractions are written using the \frac command.
For example,
$$ \frac{a}{b}, \quad \frac{x+1}{x-1} $$
These are written as
\frac{a}{b}
\frac{x+1}{x-1}
Superscripts and Subscripts¶
Powers and indices are written using ^ and _.
For example,
$$ x^2,\quad x^3,\quad x_i,\quad a_{ij} $$
These are written as
x^2
x^3
x_i
a_{ij}
Greek Letters¶
Greek letters are widely used in mathematics.
For example,
$$ \alpha,\; \beta,\; \gamma,\; \mu,\; \sigma $$
These are written as
\alpha
\beta
\gamma
\mu
\sigma
Common Mathematical Symbols¶
Here are some important mathematical symbols and how to write them in LaTeX.
Inline mathematical symbols¶
| Mathematical Expression | LaTeX Code |
|---|---|
| $\sum_{i=1}^{n} x_i$ | \sum_{i=1}^{n} x_i |
| $\mathbf{x}$ | \mathbf{x} |
| $\langle \mathbf{x}, \mathbf{y} \rangle$ | \langle \mathbf{x}, \mathbf{y} \rangle |
| $\|\mathbf{x}\|$ | \|\mathbf{x}\| |
| $\frac{df}{dx}$ | \frac{df}{dx} |
| $\nabla f(\mathbf{x})$ | \nabla f(\mathbf{x}) |
| $\int_0^1 x^2\,dx$ | \int_0^1 x^2\,dx |
| $\displaystyle \lim_{x \to 0} \frac{\sin x}{x} = 1$ | \lim_{x \to 0} \frac{\sin x}{x} = 1 |
Matrix notation¶
$$ A = \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix} $$
$$
A=\begin{pmatrix}
a_{11} & a_{12} \\
a_{21} & a_{22}
\end{pmatrix}
$$
The align environment in LaTeX¶
We use align family of environments in LaTeX for writing multi-line display equations with proper alignment.
Basic usage¶
Use align when equations should be aligned at a chosen symbol (typically =).
\begin{align}
a &= b + c \\
&= d + e
\end{align}
Output: \begin{align} a &= b + c \\ &= d + e \end{align}
Each line is aligned at & and receives its own equation number.
Unnumbered equations¶
Use align* to suppress equation numbering.
\begin{align*}
y' &= f(x,y) \\
&= x^2 + y
\end{align*}
Output: \begin{align*} y' &= f(x,y) \\ &= x^2 + y \end{align*}
Controlling equation numbers¶
To number only selected lines, use \notag.
\begin{align}
y' &= f(x,y) \notag \\
&= x^2 + y
\end{align}
Output: \begin{align} y' &= f(x,y) \notag \\ &= x^2 + y \end{align}
Long expressions¶
Long right-hand sides can be split across lines while maintaining alignment.
\begin{align*}
y_{n+1} ={}& y_n + h f(x_n,y_n) \\
&+ \frac{h^2}{2} f'(x_n,y_n)
\end{align*}
Output: \begin{align*} y_{n+1} ={}& y_n + h f(x_n,y_n) \\ &+ \frac{h^2}{2} f'(x_n,y_n) \end{align*}
Piecewise Functions¶
Piecewise-defined functions are written using the cases environment.
For example,
$$ f(x) = \begin{cases} x^2, & x \ge 0, \\ -x, & x < 0. \end{cases} $$
This is written as
f(x) =
\begin{cases}
x^2, & x \ge 0, \\
-x, & x < 0.
\end{cases}
Blackboard Bold ( \mathbb )¶
Some mathematical symbols are written in a special “blackboard bold” style.
This is commonly used for standard number systems.
For example,
$$ \mathbb{R}, \quad \mathbb{N}, \quad \mathbb{Z}, \quad \mathbb{Q} $$
These represent:
- $\mathbb{R}$ — real numbers
- $\mathbb{N}$ — natural numbers
- $\mathbb{Z}$ — integers
- $\mathbb{Q}$ — rational numbers
They are written as
\mathbb{R}
\mathbb{N}
\mathbb{Z}
\mathbb{Q}
Learning More LaTeX¶
By now, you have seen the basic pattern:
- You write LaTeX commands inside
$...$or$$...$$ - You can also use environments like
alignandcases - Jupyter renders them as mathematical symbols and formulas
You are not expected to memorize all LaTeX commands.
Whenever you need a new symbol or expression, you can:
- search online
- look it up in documentation
- or ask a tool like ChatGPT
For example, you can ask: “How do I write a norm in LaTeX?” “How do I write a matrix?” “How do I write a summation?”
The important thing is to understand the pattern: type LaTeX → see mathematics.
One More Thing 🙂¶
There’s a small but very handy symbol called “plus–minus”.
It looks like
$$ \pm $$
and it is typed as
\pm
A First Glimpse of Python¶
So far, we have used Jupyter to write text and mathematics.
Now let’s see one tiny example of Python.
In the next cell, type it and run (Shift + Enter).
Jupyter will show the result below.
That’s all for today — we will learn Python properly in the next few practical classes.
2 + 3*4
14