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