ML One
Lecture 06
Introduction to functions
+
Python basics 02
Welcome ðŸ‘Đ‍ðŸŽĪ🧑‍ðŸŽĪðŸ‘Ļ‍ðŸŽĪ
By the end of this lecture, we'll have learnt about:
The theoretical:
- What is function
- Function graphs
- Several big namer functions
- Function chaining
The practical:
- Python basics 02 (implementing functions)
First of all, don't forget to confirm your attendence on Seats App!
AI Artist for today: Jon Rafman
Recap
Scalar, vector and matrix 🧑‍ðŸŽĻ
- how to describe their shapes
-- number of rows x number of columns
Scalar, vector and matrix 🧑‍ðŸŽĻ
- how to add two matrices: they should be of the exactly same shape
Scalar, vector and matrix 🧑‍ðŸŽĻ
- how to multiply a matrix with a scalar?
-- multiply every element in the matrix with the scalar
Scalar, vector and matrix 🧑‍ðŸŽĻ
- how to multiply a row vector and a column vector?
-- dot product which results in a scalar
-- the shape rule: these two vectors have to be of the same length.
Scalar, vector and matrix 🧑‍ðŸŽĻ
- how to multiply two matrices?
-- the shape rule:
-- the shapes of the two matrices should be: M x K and K x N
-- the shape of the product matrix would be: M x N
That's quite a lot, congrats! 🎉
Another building block before we diving into AI neural networks next week:
Functions
What is a function in maths:
A function relates an input (usually a number) to an output (usually a number).
What are the keywords there? Do these sound familiar?
Where else can you find this construct of "input, process, output"?
Where else can you find this construct of "input, process, output"?
- Models!
☕ïļ sit back and watch this geeky vid from 5 years ago
Most of the time models (like the AI model we are about to see next week) can be seen as a set of functions wired up together.
Some conventions on function expression
function input: x
function output: f(x)
f(x) = x + 1
Most of the time we can use tables to describe a function.
(on whiteboard)
Most of the time we can also use graphs to represent a function.
(on whiteboard)
This video explains functions short and simple.
Big namer functions (especially in AI)
Jargons alert but don't be afraid they are cute
exponential
sigmoid
quadratic
relu
sine
tanh
Let's google their function graphs one by one and draw on the whiteboard!
- exponential
- sigmoid
- quadratic
- relu
- sine
- tanh
Note that we are not expected to memorise the math equations for each function.
Just knowing the shape of their graphs is sufficient.
Fun stuff: different "personalities" of functions
- asymptotic (quite philosophical, it touches the notion of infinity)
- squashing anything to be between 0 and 1 (remember probability?😉)
- symmetric (things can go equally wrong in different directions ...)
- ignoring negative(booo) numbers
- periodic (wooo, aperiodic signal can be represented by periodic stuff only)
-- Make sure you check this out
ðŸĪŊ (optional)
underneath these functions of different personalities,
they all have the same "DNA" (polynomials)
they can all be represented just using polynomials and here is an example
⛓ïļ Chaining functions ⛓ïļ
⛓ïļ Chaining functions ⛓ïļ
In short, we can feed the output of one function as the input to another function.
me "小" as a function:
🍎 -> 小 -> lecture
小(🍎) = lecture
ðŸĨƒ -> 小 -> ðŸĪŠ
小(ðŸĨƒ) = lEcTUrE
you "CoolStudents" as a function:
lecture -> CoolStudents -> some times good sleep ðŸ’Ī
CoolStudents(lecture)= good sleep ðŸ’Ī
we can chain functions together!
We have:
小(🍎) = lecture
and
CoolStudents(lecture)= good sleep ðŸ’Ī
We chain these up: CoolStudents(小(🍎))= good sleep ðŸ’Ī
Note that the chained function CoolStudents(小(🍎))
is a different function than either 小(🍎) and CoolStudents(lecture)
in the sense that its input and output are not the same as those of the smaller functions.
- Basically by chaining functions together we get a new and "bigger" function.
😍 Recall a model can be a set of functions wired up together. Chaining functions together is how we can wire functions up to form an AI model! To be continued next week...
That's quite a lot, congrats! 🎉
Next, we are going to:
- take a look at how these functions can be implemented in python with help from NumPy!
A prepared google colab notebook
1. click on the link and open this google colab notebook
Let's take a look at the notebook!

- 1. Make sure you have saved a copy to your GDrive or opened in playground. 🎉
- 2. Read all text cells and code cells.
- 3. Try out the only excercise (Excercise 1.).
Today we have looked at:
Functions 🧑‍ðŸŽĻ
- A function relates an input to an output.
-- Function graphs
-- Several big namer functions including exp, sigmoid, quadratic, relu, sine, tanh (and they have characteristics)
-- Chain functions together to make a new function
-- Big namer functions implemented using NumPy
We'll see you next Thursday same time and same place!