class: center, middle
Gerard Escudero & Samir Kanaan, 2019
.footnote[Source: inverse ]
class: left, middle, inverse
-
.cyan[Introduction]
-
Machine Learning
-
Deep Learning
-
Reinforcement Learning
-
References
.center[
class | sepal length |
sepal width |
petal length |
petal width |
---|---|---|---|---|
setosa | 5.1 | 3.5 | 1.4 | 0.2 |
setosa | 4.9 | 3.0 | 1.4 | 0.2 |
versicolor | 6.1 | 2.9 | 4.7 | 1.4 |
versicolor | 5.6 | 2.9 | 3.6 | 1.3 |
virginica | 7.6 | 3.0 | 6.6 | 2.1 |
virginica | 4.9 | 2.5 | 4.5 | 1.7 |
150 rows or examples (50 per class).red[*] | ||||
] |
-
The .blue[class] or .blue[target] column is usually refered as vector .blue[Y]
-
The matrix of the rest of columns (.blue[attributes] or .blue[features]) is usually referred as matrix .blue[X]
.footnote[.red[*] Source : Iris problem UCI repository (Frank & Asunción, 2010)]
.large[Build from data a .blue[model] able to give a prediction to new .blue[unseen] examples.]
where:
- data = previous table
- unseen = [4.9, 3.1, 1.5, 0.1]
- prediction = "setosa"
.center[
quality | density | pH | sulphates | alcohol |
---|---|---|---|---|
6 | 0.998 | 3.16 | 0.58 | 9.8 |
4 | 0.9948 | 3.51 | 0.43 | 11.4 |
8 | 0.9973 | 3.35 | 0.86 | 12.8 |
3 | 0.9994 | 3.16 | 0.63 | 8.4 |
7 | 0.99514 | 3.44 | 0.68 | 10.55 |
1599 examples & 12 columns (11 attributes + 1 target).red[*] | ||||
] |
The main diference between classification and regression is the Y or target values:
-
.blue[Classification]: discrete or nominal values
Example: Iris, {“setosa”, “virginica”, “versicolor”}. -
.blue[Regression]: continuous or real values
Example: WineQuality, values from 0 to 10.
.footnote[.red[*] Source : wine quality problem from UCI repository (Frank & Asunción, 2010)]
- How can be give a prediction to next examples?
.center[
class | sep-len | sep-wid | pet-len | pet-wid |
---|---|---|---|---|
?? | 4.9 | 3.1 | 1.5 | 0.1 |
Unseen classification example on Iris] |
.center[
target | density | pH | sulphates | alcohol |
---|---|---|---|---|
?? | 0.99546 | 3.29 | 0.54 | 10.1 |
Unseen regression example on WineQuality] |
- Let’s begin with a representation of the problems...
- classification & regression
.center[where
-
Classification example (Iris):
- distances: [0.47, 0.17, 3.66, 2.53, 6.11, 3.45]
- prediction = setosa (0.17)
-
Regression example (WineQuality):
- distances: [0.33, 1.32, 2.72, 1.71, 0.49]
- prediction = 6 (0.33)
--
-
.blue[lazy learning]: it means that the kNN does nothing in learning step
- it calculates all in classify step
-
This can produce some problems real time applications
- such as .blue[Games]
- .blue[Classification]: decision about braking a car.
Brake? | Distance | Speed |
---|---|---|
Y | 2.4 | 11.3 |
Y | 3.2 | 70.2 |
N | 75.7 | 72.7 |
N | 2.8 | 15.2 |
%? | 79.2 | 12.1 |
.center[Source: (Millington, 2019)] |
- .blue[Regression]: required amount of force in a curve.
-
A basic application is learning .blue[decisions] from .blue[observations]
-
decisions will become classes (
$Y$ ) -
observations will become features (
$X$ )
-
-
Some kind of measure is needed to evaluate the model
-
.blue[The Balance of Effort]
- Many times is harder learning than human dessign (such as Behaviour Tree)
-
.blue[Online]: learn as playing
-
.blue[Offline]:
- learn from saved matches
- .blue[bootstrapping]: AI component playing among them
Same algorithm with diferent paramenters
Diferent algorithms
(See chess example)
-
.blue[Intra-Behaviour]: atomic behaviour
- Example: previous examples of braking or curves
-
.blue[Inter-Behaviour]: learns Decision Taking layer
-
It is a simple technique that tries to guess player movements from previous recordings
-
Human behaviour is not random
-
It is also called RPS from: rock-paper-scissor game
-
Example for a simple RPS:
- Movement: Left, Right
- Recording: "LRRLRLLL"
-
It requires a window size
- Example: previous 3 movements
-
It can produce unbeatable AIs
- Some level adjustment would be needed
class: left, middle, inverse
-
.brown[Introduction]
-
.cyan[Machine Learning]
-
.cyan[Naïve Bayes]
-
Decision Trees
-
-
Deep Learning
-
Reinforcement Learning
-
References
class | cap-shape | cap-color | gill-size | gill-color |
---|---|---|---|---|
poisonous | convex | brown | narrow | black |
edible | convex | yellow | broad | black |
edible | bell | white | broad | brown |
poisonous | convex | white | narrow | brown |
edible | convex | yellow | broad | brown |
edible | bell | white | broad | brown |
poisonous | convex | white | narrow | pink |
.center[up to 8 124 examples & 22 attributes .red[*]] |
- What is
$P(poisonous)$ ?
.footnote[.red[*] Source : Mushroom problem from UCI repository (Frank & Asunción, 2010)]
.col5050[ .col1[
poisonous | 0.429 |
edible | 0.571 |
] | |
.col2[ | |
attr:value | poisonous |
:----------------- | ----------: |
cap-shape:convex | 1 |
cap-shape:bell | 0 |
cap-color:brown | 0.33 |
cap-color:yellow | 0 |
cap-color:white | 0.67 |
gill-size:narrow | 1 |
gill-size:broad | 0 |
gill-color:black | 0.33 |
gill-color:brown | 0.33 |
gill-color:pink | 0.33 |
] | |
] |
- Test example
$T$ :
class | cap-shape | cap-color | gill-size | gill-color |
---|---|---|---|---|
?? | convex | brown | narrow | black |
- Numbers:
$$P(poisonous|T) = 0.429 \cdot 1 \cdot 0.33 \cdot 1 \cdot 0.33 = 0.047$$ $$P(edible|T) = 0.571 \cdot 0.5 \cdot 0 \cdot 0 \cdot 0.25 = 0$$ - Prediction:
$$h(T) = poisonous$$
-
It needs a smoothing technique to avoid zero counts
- Example: Laplace
$$P(x_i|y)\approx\frac{N(x_i|y)+1}{N(y)+N}$$
- Example: Laplace
-
It is empiricaly a decent classifier but a bad estimator
- This means that
$P(y|T)$ is not a good probability
- This means that
- Using LINQ of C#: view.red[*] / output / download code
.footnote[.red[*] Formated with http://hilite.me/]
- How about numerical features?
Brake? | Distance | Speed |
---|---|---|
Y | 2.4 | 11.3 |
Y | 3.2 | 70.2 |
N | 75.7 | 72.7 |
N | 2.8 | 15.2 |
%? | 79.2 | 12.1 |
.center[Source: (Millington, 2019)] |
.center[where
.col5050[ .col1[ Learning model:
Y | 0.5 |
N | 0.5 |
Distance | Speed | |
---|---|---|
2.8 | 40.75 | |
39.25 | 43.95 | |
0.32 | 1734.605 | |
2657.205 | 1653.125 | |
] | ||
.col2[ | ||
Classification: |
Note:
Implementation:
-
Using LINQ of C#:
- view.red[*] / output / download code
-
Using sklearn and Unity
.footnote[.red[*] Formated with http://hilite.me/]
class: left, middle, inverse
-
.brown[Introduction]
-
.cyan[Machine Learning]
-
.brown[Naïve Bayes]
-
.cyan[Decision Trees]
-
-
Deep Learning
-
Reinforcement Learning
-
References
Splitting measure:
-
Decision Trees:
$accuracy=\frac{N(ok)}{N}$ -
ID3:
$entropy=-\sum_{\forall y} P(y) \cdot log_2(P(y))$ -
CART:
$gini = 1 - \sum_{\forall y} P(y)^2$ + binary trees -
.blue[Our approach]:
$gini$ + k-ary trees-
nominal and numeric features
-
classification and regression
-
one of the easiest decision trees
-
.cols5050[ .col1[
class | cap-shape | cap-color |
---|---|---|
poisonous | convex | brown |
edible | convex | yellow |
edible | bell | white |
poisonous | convex | white |
edible | convex | yellow |
edible | bell | white |
poisonous | convex | white |
] | ||
.col2[ | ||
algorithm: |
each node of the tree from
the minimum weighted sum of
Gini index:
.small[$gini = 1 - \sum_{\forall y} P(y)^2$] ]]
cap-shape:
cap-shape | poisonous | edible | #examples |
---|---|---|---|
convex | 3 | 2 | 5 |
bell | 0 | 2 | 2 |
.small[ .blue[For each value:]
.blue[Weighted sum:]
cap-color:
cap-color | poisonous | edible | #examples |
---|---|---|---|
brown | 1 | 0 | 1 |
yellow | 0 | 2 | 2 |
white | 2 | 2 | 4 |
.small[ .blue[For each value:]
.blue[Weighted sum:]
Selecting best feature:
- best feature will be that with minimum gini index:
.small[
-
every value with only a class will be a leaf:
- brown
$\rightarrow$ poisonous - yellow
$\rightarrow$ edible
- brown
-
a new set is built for the rest of values
.center[
class | cap-shape |
---|---|
edible | bell |
poisonous | convex |
edible | bell |
poisonous | convex |
white examples without cap-color | |
] |
- the process restarts with the new set
Resulting Tree:
What about numerical attributes?
class | width |
---|---|
versicolor | 2.9 |
versicolor | 2.9 |
virginica | 3.0 |
virginica | 2.5 |
Cutting points:
class | width | cutting points | weighted ginis |
---|---|---|---|
virginica | 2.5 | ||
versicolor | 2.9 | 2.7 | |
versicolor | 2.9 | ||
virginica | 3.0 | 2.95 | |
.center[.small[cutting points for width attribute]] |
Gini example:
width | versicolor | virginica | #examples | gini |
---|---|---|---|---|
< 2.7 | 0 | 1 | 1 | |
> 2.7 | 2 | 1 | 3 |
.cols5050[ .col1[ Resulting Tree:
]]
- standard deviation as splitting measure
.center[where
.cols5050[ .col1[ example:
target | outlook | wind |
---|---|---|
25 | sun | weak |
30 | sun | strong |
52 | rain | weak |
23 | rain | strong |
45 | rain | weak |
.center[.small[Source]] | ||
] | ||
.col2[ | ||
total amounts: |
.cols5050[ .col1[ outlook:
outlook | #examples | ||
---|---|---|---|
sun | 27.5 | 2.5 | 2 |
rain | 40.0 | 12.356 | 3 |
] | |||
.col2[ | |||
weighted sum: |
.cols5050[ .col1[ wind:
wind | #examples | ||
---|---|---|---|
weak | 40.667 | 11.441 | 3 |
strong | 26.5 | 3.5 | 2 |
] | |||
.col2[ | |||
weighted sum: |
Wins the highest score: .blue[wind]
-
Tends to overfitting when leafs with few examples
-
High variance
- small changes in training sets produce different trees
-
Prunning: for avoiding overfitting
- less than 5 instances
- maximum depth
-
Previous regression tree by averaging leaf instances:
.cols5050[
.col1[
.center[]
]
.col2[
]]
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.cyan[Deep Learning]
-
.cyan[Neural Networks]
-
Bias & Variance
-
DL Architectures
-
-
Reinforcement Learning
-
References
.footnote[Source: Artificial Neuron]
.cols5050[ .col1[
-
Classifier and regressor
- One neuron (or unit)
- Linear model
-
- Find hyperplane that splits the data set
$$\sum_{i=1}^nw_ix_i+b=0$$
- Find hyperplane that splits the data set
-
Prediction formula:
] .col2[
]]
.cols5050[ .col1[
-
.blue[Classification & regression]
- One hidden layer
- Non-linear model
-
Learning: .blue[backpropagation]:
- Gradient descent:
$W$
- Loss function:
$error(h(x),y)$
- Gradient descent:
.center[]
.center[source]
]
.col2[
.center[
]
.center[source]
]]
.footnote[source]
.blue[Splitting positives and negatives:]
.cols5050[
.col1[
]
.col2[
Excel
.blue[sklearn on Iris:]
.center[
Building a neural network framework in C#
]
- Unity Project in Github
- Backpropagation implementation
- Neural network with 2 or more hidden layers
.footnote[Source: The Neural Network Zoo]
Deep Learning high level library.
.blue[Example] on MNIST:
Usual .blue[Parameters]:
Task | Loss function | Output Layer |
---|---|---|
Bin. class | binary cross entropy | single unit, sigmoid activation |
Multiclass | categorical cross entropy | one unit per class, softmax activation |
Regression | MSE or RMSE | single unit, linear activation |
- Epochs: times all examples are trained
- Batch size: examples at each iteration
- Optimizer: gradient descent variants (AdaGrad, RMSProp, Adam)
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.cyan[Deep Learning]
-
.brown[Neural Networks]
-
.cyan[Bias & Variance]
-
DL Architectures
-
-
Reinforcement Learning
-
References
.center[
source
]
.cols5050[ .col1[ .blueUnderfitting
- Symptoms:
- high training error
- Causes
- model too simple
- not enough training ] .col2[ .blueOverfitting
- Symptoms:
- low training error
- higher validation error
- Causes
- model too complex
- too much training
- training set too small ]]
Normal use of a validation set to select parameters & avoid overfitting!
.footnote[Source: left, right]
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.cyan[Deep Learning]
-
.brown[Neural Networks]
-
.brown[Bias & Variance]
-
.cyan[DL Architectures]
-
-
Reinforcement Learning
-
References
from Computer Vision
to process image & video: .blue[invariant to translation & scale]
.footnote[Source: A Comprehensive Guide to Convolutional Neural Networks]
.cols5050[ .col1[
-
Convolution: extract the high-level features such as edges
- Learns the patterns
-
Pooling: reduce dimensionality for
- max (edges) or average (photo)
- computational cost
- dominant features (rotational and positional invariant)
-
Example:
.footnote[Source: A Comprehensive Guide to Convolutional Neural Networks]
.footnote[Source: The Neural Network Zoo]
.footnote[Source: The Neural Network Zoo]
.footnote[Source: The Neural Network Zoo]
ONNX is an open format built to represent machine learning models.
.cols5050[ .col1[ .blue[Resources]:
-
- Model converter
-
-
Vision
-
Language
-
Speech
-
Time Series ] .col2[
-
Lightweight Unity package for neural network inference.
-
Example:
.footnote[.red[*] Formated with http://hilite.me/]
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.brown[Deep Learning]
-
.cyan[Reinforcement Learning]
-
.cyan[Q-Learning]
-
RL Platforms
-
-
References
.cols5050[ .col1[
- an agent
- a set of states
$S$ - a set of actions
$A$
]
.col2[
Learning a reward function
]]
-
Q-Learning: method for learning an aproximation of
$Q$ .
.footnote[Source: My Journey Into Deep Q-Learning with Keras and Gym]
.footnote[Source: Reinforcement Q-Learning from Scratch in Python with OpenAI Gym]
- Simple example of Q-learning & Q-Table.
- Unity Package (in Spanish)
- See the folder Scripts in Assets
- Convolutional Neural Network for learning
$Q$
.footnote[Source: Deep Reinforcement Learning]
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.brown[Deep Learning]
-
.cyan[Reinforcement Learning]
-
.brown[Q-Learning]
-
.cyan[RL Platforms]
-
-
References
Toolkit for developing and comparing reinforcement learning algorithms.
.cols5050[
.col1[
]
.col2[
.blue[Gym]:
-
Input:
action
(0 or 1); training target -
Output:
next_state
,reward
,info
; training featuresdone
: game ended?
max: 501
-
Gaëtan Juvin. My Journey Into Deep Q-Learning with Keras and Gym (github), 2017.
Unity plugin for training intelligent agents.
Address: https://github.com/Unity-Technologies/ml-agents
Contain: .blue[AI Gym], .blue[Deep Learning] & .blue[Reinforcement Learning].
Unity Learn course by Adam Kelly.
.center[
source
]
-
Intelligent hummingbirds:
Navigate to flowers, dip their beaks in, and drink nectar. -
Reinforcement Learning with Unity ML-Agents.
.cols5050[ .col1[
-
The agent's current rotation
-
The direction to the nearest flower
-
The distance to the nearest flower
-
How close the agent's beak is to pointing at the flower ] .col2[
]]
-
How close the agent's beak is to being in front of the flower
-
Several raycasts that act like LIDAR so that the agent can avoid obstacles
public override void CollectObservations(VectorSensor sensor)
sensor.AddObservation(new float[10]);
.footnote[source]
-
A small positive reward each timestep if tehe bird's beak is touching the nectar:
AddReward(.01)
-
A large negative reward or hitting the ground or boundaries of the training area:
AddReward(-.5f)
.footnote[source]
Output of the Neural Network:
/// <summary>
/// Called when and action is received from either
/// the player input or the neural network
///
/// vectorAction[i] represents:
/// Index 0: move vector x (+1 = right, -1 = left)
/// Index 1: move vector y (+1 = up, -1 = down)
/// Index 2: move vector z (+1 = forward, -1 = backward)
/// Index 3: pitch angle (+1 = pitch up, -1 = pitch down)
/// Index 4: yaw angle (+1 = turn right, -1 = turn left)
/// </summary>
/// <param name="vectorAction">The actions to take</param>
public override void OnActionReceived(float[] vectorAction)
{
...
};
class: left, middle, inverse
-
.brown[Introduction]
-
.brown[Machine Learning]
-
.brown[Deep Learning]
-
.brown[Reinforcement Learning]
-
.cyan[References]
-
Gerard Escudero. Supervised Machine Learning. 2020.
-
Aurélien Géron. Hands-On Machine Learning with Scikit-Learn, Keras & Tensorflow, 2nd Edition. O'Reilly, 2019.
-
Sefik Ilkin Serengil. chefboost (2019): A Step by Step CART Decision Tree Example (2018).
-
Gaëtan Juvin. My Journey Into Deep Q-Learning with Keras and Gym (github), 2017.
-
DeepMind. Deep Reinforcement Learning.
-
Ian Millington. AI for Games (3rd edition). CRC Press, 2019.
-
Micheal Lanham. Learn Unity ML-Agents - Fundamental of Unity Machine Learning. Packt, 2018.
-
Károly Zsolnai-Fehér. OpenAI Plays Hide and Seek…and Breaks The Game!. Two Minute Papers.
-
Károly Zsolnai-Fehér. DeepMind’s AlphaStar: A Grandmaster Level StarCraft 2 AI. Two Minute Papers.
-
Siraj Raval. How to Make an Amazing Video Game Bot Easily (OpenAI Gym), 2016.
-
Adam Kelly. ML-Agents: Hummingbirds. Unity Learn.
.cols5050[ .col1[
-
ONNX. ] .col2[
-
scikit-learn ]]