Docsity

CS-7641-Machine-Learning-Final Notes, Study notes of Machine Learning

Toggle sidebar
bg1
CS7641 UL02. Clustering Mohamed Ameen Amer
Page | 1
UL02. Clustering
Clustering Problem:
• Unsupervised learning: Making sense out of unlabeled data (data description).
• The clustering problem:
- Given: A set of objects 𝑋
Inter-object distances 𝐷(𝑥,𝑦)= 𝐷(𝑦,𝑥) 𝑥,𝑦 ∈ 𝑋
- Output: Partition 𝑃𝐷(𝑥)= 𝑃𝐷(𝑦) 𝑖𝑓 𝑥 𝑎𝑛𝑑 𝑦 𝑎𝑟𝑒 𝑖𝑛 𝑡ℎ𝑒 𝑠𝑎𝑚𝑒 𝑐𝑙𝑢𝑠𝑡𝑒𝑟
Single Linkage Clustering – SLC:
• Consider each object a cluster (𝑛 objects).
• Define inter-cluster distance as the distance between the closest points in the two clusters.
• Merge the two closest clusters.
• Repeat 𝑛 − 𝑘 times to make 𝑘 clusters.
- 𝑘 is an input.
• How you define the inter-cluster distance is a domain knowledge.
• Running time of SLC: 𝑂(𝑛3)
• Issues with SLC: It might end up with wrong clusters, depending on the distance definition.
𝑘-Means Clustering:
• Pick 𝑘 random center points.
• Each center claims its closest points.
• Recompute the centers by averaging the clustered points.
• Repeat until converge.
• 𝑘-means in Euclidean space:
− 𝑃𝑡(𝑥): Partition/cluster of object 𝑥.
− 𝐶𝑖𝑡: Set of all points in cluster 𝑖 = {𝑥 𝑠𝑢𝑐ℎ 𝑡ℎ𝑎𝑡 𝑃(𝑥)= 𝑖}
− 𝑐𝑒𝑛𝑡𝑒𝑟𝑖𝑡: ∑𝑦
𝑦∈𝐶𝑖𝑡|𝐶𝑖|
⁄
𝑃𝑡(𝑥)= 𝑎𝑟𝑔𝑚𝑖𝑛𝑖‖𝑥− 𝑐𝑒𝑛𝑡𝑒𝑟𝑖𝑡−1‖2
2
𝑐𝑒𝑛𝑡𝑒𝑟𝑖𝑡=∑𝑦
𝑦∈𝐶𝑖𝑡|𝐶𝑖|
⁄
Use the new center to re-compute 𝑃𝑡(𝑥).
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download CS-7641-Machine-Learning-Final Notes and more Study notes Machine Learning in PDF only on Docsity!

CS7641 UL02. Clustering Mohamed Ameen Amer

UL02. Clustering

Clustering Problem:

  • Unsupervised learning: Making sense out of unlabeled data (data description).
  • The clustering problem:
    • Given: A set of objects 𝑋

Inter-object distances 𝐷

  • Output: Partition 𝑃

𝐷

𝐷

Single Linkage Clustering – SLC:

  • Consider each object a cluster (𝑛 objects).
  • Define inter-cluster distance as the distance between the closest points in the two clusters.
  • Merge the two closest clusters.
  • Repeat 𝑛 − 𝑘 times to make 𝑘 clusters.
    • 𝑘 is an input.
  • How you define the inter-cluster distance is a domain knowledge.
  • Running time of SLC: 𝑂(𝑛

3

  • Issues with SLC: It might end up with wrong clusters, depending on the distance definition.

𝑘-Means Clustering:

  • Pick 𝑘 random center points.
  • Each center claims its closest points.
  • Recompute the centers by averaging the clustered points.
  • Repeat until converge.
  • 𝑘-means in Euclidean space:

𝑡

(𝑥): Partition/cluster of object 𝑥.

𝑖

𝑡

: Set of all points in cluster 𝑖 = {𝑥 𝑠𝑢𝑐ℎ 𝑡ℎ𝑎𝑡 𝑃(𝑥) = 𝑖}

𝑖

𝑡

𝑦∈𝐶

𝑖

𝑡

𝑖

𝑡

𝑖

𝑖

𝑡− 1

2

2

𝑖

𝑡

𝑦∈𝐶

𝑖

𝑡

𝑖

Use the new center to re-compute 𝑃

𝑡

CS7641 UL02. Clustering Mohamed Ameen Amer

  • 𝑘-means as an optimization problem:
    • Configurations:
  • Scores: How much error you introduce by representing these points as centers.

𝑃(𝑥)

2

2

𝑥

  • Neighborhood: The neighborhood of a configuration is the set of pairs where you keep the

centers the same and you change the partitions, or you keep the partitions the same and you

move the centers.

′

′

  • Looking into 𝑘-means this way, we can notice that it follows the same procedures of Hill

Climbing:

  1. The first function that updates 𝑃

𝑡

(𝑥) moves the cluster only if the error goes down.

  1. The second function that updates 𝑐𝑒𝑛𝑡𝑒𝑟

𝑖

𝑡

can never bring the error up because average

minimizes squared error.

  • Properties of 𝑘-means clustering:
    • Each iteration is polynomial 𝑂(𝑘𝑛).
    • Finite (exponential) iterations 𝑂(𝑘

𝑛

  • Error decreases (if ties are broken consistently).
  • Can get stuck, if it started with wrong centers. This is similar to converging to a local optima. One

solution to this problem is to use random restarts.

Soft Clustering:

  • Soft Clustering attaches cluster probability to each point, instead of a specific cluster.
  • Assume the data was generated by:
    • Select one of 𝑘 possible Gaussians (Fixed know variance) uniformly.
    • Sample 𝑥

𝑖

from that Gaussian.

  • Repeat 𝑛 times.
  • Task: Find a hypothesis ℎ = 〈𝜇 1

𝑘

1

𝑘

are Gaussian means) that maximizes the

probability of the data (Maximum likelihood).

  • Maximum Likelihood Gaussian: The Maximum Likelihood mean of the Gaussian 𝜇 is the mean of the

data.

CS7641 UL03. Feature Selection Mohamed Ameen Amer

UL03. Feature Selection

The Feature Selection Problem:

  • Determine which features really matter.
  • Understand the data better.
  • Selecting the most relevant features helps in avoiding the Curse of

Dimensionality.

  • For 𝑁 features, it takes exponential time ( 2

𝑁

) to select the most relevant subset of features 𝑀,

where 𝑀 ≤ 𝑁. We have to try all the possible subsets of 𝑁 to produce 𝑀.

Approaches to Feature Selection:

  • Filtering: Given a set of features, apply a search algorithm to produce fewer features to be passed to

the learning algorithm.

  • Faster than wrapping.
  • Doesn’t account for the relationships between features.
  • Ignores the learning process (no feedback).
  • We can use an algorithm that can select the best features, like Decision Tree, then use another

algorithm, with another inductive bias, for learning.

  • We can use different criterion to evaluate the usefulness of a subset of features:
    1. Information gain.
    2. Variance.
    3. Entropy.
    4. Eliminate dependent features.
  • Wrapping: Given a set of features, apply a search algorithm to produce fewer features, pass them to

the learning algorithm, then use the output to update the selected set of features.

  • Takes into account the learning model’s bias.
  • Very slow.

CS7641 UL03. Feature Selection Mohamed Ameen Amer

  • We can use different techniques to search:
    1. Randomized Optimization algorithms.
    2. Forward Selection: Select a feature and evaluate the effect of creating different

combinations of this feature with other features. Stop once you stagnate. This is similar to

Hill Climbing.

  1. Backward Elimination: Start with all the features and evaluate the effect of eliminating each

feature.

Relevance:

𝑖

is strongly relevant if removing it degrades the Bayes Optimal Classifier.

𝑖

is weakly relevant if:

  • Not strongly relevant.
  • There’s a subset of features 𝑆 such that adding 𝑥

𝑖

to 𝑆 improves the Bayes Optimal Classifier.

𝑖

is irrelevant otherwise.

  • Relevance vs. Usefulness:
    • Relevance measures the effect on B.O.C. This basically measures how much information a

particular feature provides.

  • Usefulness measures effect on error. This basically measures if a feature helps in minimizing error

given a particular model.

CS7641 UL04. Feature Transformation Mohamed Ameen Amer

  • Principal Components Analysis is an example of an eigenproblem which will transform the features

set by:

  • Finding the direction (vector) that maximizes variance. The is called the Principal Component.
  • Finding directions that are orthogonal to the Principal Component.
  • Each Principal Component has a prescribed eigen value. We can throw away the components with

the least eigenvalues as they correspond to the features that matter less in the reconstruction.

  • PCA gives the ability to do reconstruction, because it’s a linear rotation of the original space that

minimizes L2 error by moving 𝑁 to 𝑀 dimensions. So, we don’t lose information.

  • We can center the problem around the origin by subtracting the mean of the data.
  • In effect, PCA produces a set of orthogonal Gaussians.
  • PCA is a global algorithm that is very fast.

Independent Components Analysis:

  • ICA attempts to maximize independence. It tries to find a linear transformation of the feature space,

such that each of the individual new features are mutually statistically independent.

  • The mutual information between any two random features equals zero:

𝑖

𝑗

  • The mutual information between the new features set and the old features set is as high as

possible:

Random Components Analysis:

  • Similar to Principal Components Analysis, but instead of generating directions that maximize

variance, it generates random directions.

  • It captures some of the correlations that works well with classification settings.
  • It’s faster than PCA and ICA.

Linear Discriminant Analysis:

  • Linear Discriminant Analysis finds a projection that discriminates based on the label. That is, it finds

projections of features that ultimately align best with the desired output (wrapping function instead

of filtering).

CS7641 RL01. Markov Decision Processes Mohamed Ameen Amer

RL01. Markov Decision Processes

Introduction:

  • In Supervised Learning, you’re given (𝑥, 𝑦) pairs, and the goal is to find a

function 𝑓(𝑥) that maps a new 𝑥 to a proper 𝑦 (function approximation).

  • In Unsupervised Learning, you’re given a dataset of 𝑥 points, and the goal is to

find a function 𝑓(𝑥) the provides a description of this dataset (Clustering).

  • In Reinforcement Learning, we’re doing a similar task as in Supervised Learning. But instead of

having (𝑥, 𝑦) pairs as an input, we’ll be given (𝑥, 𝑧) pairs, and our job is to find 𝑓(𝑥) that generates

Markov Decision Processes:

  • A Markov Decision Process captures the world in terms of:
    • States 𝑆: This is literally the state of the object of interest represented in any way.
    • Model: This is the Transition Model (function), which is the probability of transitioning to a new

state 𝑠

′

given that the object starts at state 𝑠 and performs action 𝑎.

′

𝑟

′

  1. This model follows the Markovian Property, which states that only the current state 𝑠

affects the result of the model (only present matters).

  1. The model assumes that the rules don’t change over time.
  • Actions: 𝐴(𝑠) are the things the object is allowed to do in a particular state 𝑠.
  • Reward: 𝑅(𝑠) (or 𝑅(𝑠, 𝑎) or 𝑅(𝑠, 𝑎, 𝑠

′

)) is the reward the object gets when transitioning to a

state 𝑠, which tells it the “usefulness” of transitioning to that state.

  • Policy: The previous four points define a Markov Decision Problem; the Policy defines the

solution. The policy is a function 𝜋(𝑠) that takes a state 𝑠 as an input and returns the proper

action 𝑎. A problem might have different policies.

The optimum policy 𝜋

∗

is the policy that maximizes the long term expected reward.

  • We will be given (𝑠, 𝑎, 𝑟) and our task would be to learn the optimum policy 𝜋

∗

that produces the

optimum action (highest reward).

More About Rewards:

  • In the Reinforcement Learning context, we don’t get a reward for each action. Instead, we get a

“delayed reward” in terms of a positive or negative label for the state we end up in.

  • Because we don’t have instant rewards for each action, we have the problem of figuring out which

specific action(s) lead us to a positive/negative outcome. This problem is called Temporal Credit

Assignment.

CS7641 RL01. Markov Decision Processes Mohamed Ameen Amer

  1. If 𝛾 → 0 , we get the first reward and then everything else will fall off to nothing.
  2. If 𝛾 → 1 , we get a maximized reward.

This is called Discounted Rewards, and it allows us to go infinite distance in finite time.

More About Policies:

  • The optimum policy is the one that maximizes the long term expected reward:

∗

𝜋

𝐸[∑ 𝛶

𝑡

𝑡

∞

𝑡= 0

| 𝜋]

  • We’ll then define the utility of a state in such a way that will help us solve for the optimum policy.

The utility of a particular state will be the expected set of states that we’re going to see if we started

from the given state and followed to given policy:

𝜋

= 𝐸[∑ 𝛶

𝑡

𝑡

∞

𝑡= 0

0

= 𝑠]

Note that the utility of a state represents the long-term feedback (delayed reward) we get is we

started from this state, which is different from the reward of the state. In other words, the utility is

the reward of the state plus all the rewards that we get if we started from that state.

  • Taking the utility of the state into consideration, we can rewrite the function of the optimum policy

as follows:

∗

𝑎

′

𝜋

∗

′

∞

𝑡= 0

This means that the optimum policy is the one that for every state returns the action that maximizes

the expected utility, which in turn maximizes the overall reward.

  • Now, the true utility of a state is defined by Bellman Equation:

𝑎

′

′

∞

𝑡= 0

Solving Bellman Equation:

  • If we have 𝑛 utilities, then we have 𝑛 equations in 𝑛 unknows. If the equations are linear, they

would have been solvable, but the 𝑚𝑎𝑥 operator makes the equations non-linear.

  • Value Iteration:
    • So, to solve this equation we’ll follow this algorithm:
      1. Start with arbitrary utilities.
      2. Update utilities based on neighbors.
      3. Repeat until convergence.
    • We’ll use this function to update the utilities:

𝑡+ 1

𝑎

′

′

𝑡

𝑠

′

CS7641 RL01. Markov Decision Processes Mohamed Ameen Amer

We basically update the estimate of utility of state 𝑠 by calculating the actual reward for this

state plus the discounted utility expected from the original estimate of utility of 𝑠.

  • This is guaranteed to converge because with each step we’re adding 𝑅(𝑠), which is a true value.

So, even if we started with a very wrong estimate of utility, we’ll keep adding the true value 𝑅(𝑠)

over and over that it will dominate the original wrong estimate.

  • Policy Iteration:
    • Since we care about policies, and not the actual values, we can follow a simpler faster algorithm:
      1. Start with an arbitrary policy 𝜋

0

  1. Evaluate how good that policy is by calculating the utility of using the policy:

𝑡

𝜋

𝑡

  1. Improve:

𝑡+ 1

𝑎

′

′

𝑡

𝑠

′

  • To calculate the utility at the evaluation step, we use Bellman Equation:

𝑡

′

′

𝑡

𝑠

′

Note that rather than having the 𝑚𝑎𝑥 over actions as in the normal Bellman equation, we

already know what action to take according to the policy we’re evaluating. This trick removes the

𝑚𝑎𝑥 operator, making this a set of 𝑛 solvable linear equations in 𝑛 unknowns.

CS7641 RL02. Reinforcement Learning Mohamed Ameen Amer

  • The policy at state 𝑠, considering all the actions we can take to leave that state, we iterate over

all the possible next states and calculate the probability of the utility of landing in a specific

state:

𝑎

′

′

𝑠

′

  • Another function is the Q-function:

′

𝑎

′

′

𝑠

′

This is the utility of leaving state 𝑠 via action 𝑎, which is the reward of state 𝑠 plus the

discounted expected value of taking action 𝑎 multiplied by the value of the optimum action in

state 𝑠

′

  • Now, 𝑈

and 𝜋

can be defined via 𝑄

𝑎

𝑎

  • Estimating the value of 𝑄(𝑠, 𝑎) is called Q-Learning.

𝑄 − Learning:

  • Q-Learning is estimating the value of 𝑄

based on transitions and rewards:

′

𝑎

′

′

𝑠

′

  • The issue is we don’t have 𝑅

and 𝑇

′

since we’re not in an MDP setting.

  • Given a transition < 𝑠, 𝑎, 𝑟, 𝑠

′

𝑎

′

′

𝛼

𝑡

𝑟 + 𝛾 𝑚𝑎𝑥

𝑎

′

′

is an estimate of the Q-function that we’ll update by a learning rate 𝛼

𝑡

in the direction of

the immediate reward 𝑟 plus the estimated value of the next state.

Estimating 𝑄 from Transitions:

  • The goal is to estimate this function:

′

𝑎

′

′

𝑠

′

  • We use the above equation to do this estimation. We’re computing the expected value of the right-

hand term:

𝛼

𝑡

𝑟 + 𝛾 𝑚𝑎𝑥

𝑎

′

′

= 𝔼[𝑟 + 𝛾 𝑚𝑎𝑥

𝑎

′

′

)]

𝑠

′ [𝑚𝑎𝑥

𝑎

′

′

)]

CS7641 RL02. Reinforcement Learning Mohamed Ameen Amer

  • The distribution of the expected values over the next states (𝔼

𝑠

′ ) of the maximum estimated

value (𝑚𝑎𝑥

𝑎

′ ) of the estimated 𝑄 value of the next state (𝑄

′

′

). This distribution is actually

determined by the transition function, so we end up with this:

′

𝑎

′

′

𝑠

′

  • The only issue with this analysis is that the value of 𝑄

′

′

) is actually changing over time. But

it turns out that this update rule can solve the Markov Decision Processes.

  • 𝑄 − Learning Convergence:

starts anywhere.

𝛼 𝑡

𝑎

′ 𝑄

′

′

will converge to 𝑄

, which solves the Bellman Equation.

  1. This is only true if we visited all the (𝑠, 𝑎) pairs (infinity!)
  2. Rules:

𝑡

𝑡

𝑡

2

𝑡

′

′

Choosing Actions:

  • We have three question:
    • How to initialize 𝑄
  • How 𝛼

𝑡

will decay?

  • How to choose actions?
  • Method to choose actions:
  • Always choose a single specific action: We don’t learn anything, and we violate the 4

th

rule of

𝑄 − Learning (visiting all (𝑠, 𝑎) pairs).

  • Choose randomly: We don’t learn.
  • Use our estimate 𝑄

to choose actions. We can have some issues if we poorly initialized 𝑄

so that

it always prefers a specific action over all the other actions. So, we initialize 𝑄

so that:

0

𝑠

𝑠,𝑎≠𝑎 0

  • Random restarts: It will take a lot of time to get to the optimum answer.
  • Simulated Annealing, on the other hand, can facilitate a random but faster approach, while

exploring the whole space:

𝑎

CS7641 RL03-04. Game Theory Mohamed Ameen Amer

RL03. Game Theory I

What is Game Theory?

  • Game Theory is the mathematics of conflicts of interests when making decisions.

This can be related to AI when there’re multiple agents acting in the

environment.

A Simple Game:

  • Imagine a world with two agents, 𝑎 and 𝑏, acting in a simple game where 𝑎 makes a choice, then 𝑏

makes a choice, then 𝑎 might get a chance to make another choice, and so on.

  • We can represent the game in this tree, where the leaves

represent 𝑟𝑒𝑤𝑎𝑟𝑑𝑠 given to 𝑎. Whenever 𝑎 gets a 𝑟𝑒𝑤𝑎𝑟𝑑, 𝑏

will get −𝑟𝑒𝑤𝑎𝑟𝑑.

  • This specific game is called “A 2-player zero-sum finite

deterministic game of perfect information”. It’s the simplest

possible game.

  • In MDP we had the notion of a “Policy”, which is mapping

from states to actions. In Game Theory we have the notion of

a “Strategy”.

  • A Strategy is mapping of “all possible” states to actions.
  • Ultimately, a game can be completely captured in a

matrix of all strategies 𝑎 and 𝑏 can choose along the

axes of a matrix. The outcome of the games per each

of these strategies will be represented in the cells of

the matrix.

  • Minimax: Since 𝑎 and 𝑏 are taking decisions against

each other’s interests, they both have to consider the

worst case. So 𝑎 will always try to choose the

“maximum minimum” and 𝑏 will try to choose the

“minimum maximum”. This is called the Minimax Algorithm.

Fundamental Result:

  • In a 2-player zero-sum finite deterministic game of perfect information, Minimax is equal to

Maximin. There always exists an optimal pure strategy for each player.

  • The optimal strategy here means that everyone is trying to maximize his own reward while knowing

that everyone else is trying to do the same.

CS7641 RL03-04. Game Theory Mohamed Ameen Amer

Game Tree:

  • Now we consider a more complex scenario, a 2-player zero-sum finite non- deterministic game of

perfect information. The game involves a non-deterministic behavior in certain states.

Minipoker:

  • Now we consider an even more complex scenario, a 2-player zero-sum finite non- deterministic

game of perfect hidden information.

  • Imagine if our players are dealing red/black cards, where red is a bad choice for 𝑎, and black is the

good choice:

  • 𝑎 is dealt a card, with a 50% chance of being red or black.
  • 𝑎 may resign, if red → - 20 cents for 𝑎
  • Else 𝑎 may hold:
    1. 𝑏 resigns → +10 cents.
    2. 𝑏 sees: if red → - 40 cents.

if black → +30 cents.

Mixed Strategies:

  • In a mixed strategy, instead of making the same decisions given the same circumstances (pure

strategy), we assign probabilities to our states (distribution over strategy).

  • When using a mixed strategy between 2 options for both players, one can examine one of the

players as deterministic and calculate the outcome as a function of the other probabilistic player's

CS7641 RL03-04. Game Theory Mohamed Ameen Amer

And since we know the outcome of the final (𝑛) game, we can consider the (𝑛 − 1 ) game as the

"final" game. Therefore, proof by induction dictates that we'll always defect.

  • If you have an (𝑛) repeated games, then the (𝑛) repeated Nash equilibrium is the solution.

RL03. Game Theory II

The Iterated Prisoner’s Dilemma – IPD:

  • We already discussed that in one game, the only rational thing to do is to defect. Even in a finite and

known number of games, the ultimate choice would still be defecting.

  • The question is, what happens if the number of rounds left unknown?
  • The Uncertain End:
    • The probability that the game continues is 𝛾.
    • Each round could be the last one, or not!
    • The expected number of rounds is

1

1 −𝛾

  • 𝛾 works similar to the discount factor.
  • Tit-for-Tat:
  • This is an IPD strategy where opponents cooperate on the first round, then each one copies the

opponent’s previous move thereafter.

  • What’s the best strategy against TFT?
    1. If we have a low 𝛾, the best strategy is to always defect. The total reward would be:
  1. If we have a high 𝛾, the best strategy is to always cooperate. The total reward would be:
  1. The two strategies will result in the same reward if:

CS7641 RL03-04. Game Theory Mohamed Ameen Amer

Best Response to a Finite State Strategy:

  • If we were in a one-round game, the matrix would be all what you need to select the best strategy.
  • On the other hand, in a multi-round setting, our choice not only impacts our pay off, but also the

future decisions of the opponent.

  • So, in a multi-round scenario, we need a state machine representation to make sense of the game.
  • This state machine actually represents an MDP where we map from the opponent’s state to an

action for us.

Folk Theorem:

  • In a repeated game setting, the possibility of retaliation (defecting) opens the door for cooperation.
  • In Game Theory, the Folk Theorem describes the set of payoffs that can result from Nash strategies

in repeated games.

  • Minmax Profile: A pair of payoffs, one for each

player, that represent the payoffs that can be

achieved by a player defending itself from a

malicious adversary (some other player trying to

lower my score).

  • Security Level Profile: Minmax of PD is (D, D)

because the malicious adversary will defect, and

your best option is to defect as well. The region

above and to the right of the minmax point is

the (preferable) acceptable region, it is better

than what you can guarantee against someone acting maliciously.

  • Folk Theorem: Any feasible payoff profile that strictly dominates the minmax/security level profile

can be realized as a Nash Equilibrium payoff profile, with sufficiently large discount factor.

Proof: If it strictly dominates the minmax profile, can use it as a threat. Better off doing what you are

told.

Grim Trigger:

  • Cooperation keeps you in the state of mutual benefit, but if defected once, you enter the state of

dealing out of vengeance and stay in that state forever. This creates a Nash Equilibrium.

  • The only problem with this concept is that the threat is implausible, because it doesn’t make sense

that a player will stop taking the best response (in his interest) only to punish the other player. So, in

this setting, we end up with a setting that is not Subgame Perfect.