Docsity

Perceptron Learning Algorithm: On-Line Machine Learning with Linear Functions - Prof. Dan , Study notes of Computer Science

Toggle sidebar
bg1
CS 446: Machine Learning
Lecture 4, Part 2: On-Line Learning
0.1 Linear Functions
So far, we have been looking at Linear Functions as a class of functions which can
separate some data and not others. f(x) = 1if W1X1+W2X2+. . . +WnXn≥Θ
0Otherwise
Linear functions can be used for:
Disjunction:
y=X1∨X3∨X5
y= (1 ·X1+ 1 ·X3+ 1 ·X5≥1)
At least m of n:
y=at least 2of {X1∨X3∨X5}
y= (1 ·X1+ 1 ·X3+ 1 ·X5≥2)
However, linear functions are not useful for:
Exclusive-OR:
y= (X1∧¯
X2)∧(¯
X1∧X2)
Non-trivial DNF:
y= (X1∧X2)∨(¯
X3∧X4)
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Perceptron Learning Algorithm: On-Line Machine Learning with Linear Functions - Prof. Dan and more Study notes Computer Science in PDF only on Docsity!

CS 446: Machine Learning

Lecture 4, Part 2: On-Line Learning

0.1 Linear Functions

So far, we have been looking at Linear Functions as a class of functions which can

separate some data and not others. f (x) =

1 if W 1 X 1 + W 2 X 2 +... + WnXn ≥ Θ 0 Otherwise

Linear functions can be used for: Disjunction:

y = X 1 ∨ X 3 ∨ X 5 y = (1 · X 1 + 1 · X 3 + 1 · X 5 ≥ 1)

At least m of n:

y = at least 2 of {X 1 ∨ X 3 ∨ X 5 } y = (1 · X 1 + 1 · X 3 + 1 · X 5 ≥ 2)

However, linear functions are not useful for: Exclusive-OR:

y = (X 1 ∧ X¯ 2 ) ∧ ( X¯ 1 ∧ X 2 )

Non-trivial DNF:

y = (X 1 ∧ X 2 ) ∨ ( X¯ 3 ∧ X 4 )

0.2 Perceptron Learning Rule

Perceptron is an on-line, mistake driven algorithm. Rosenblatt (1959) suggested that when a target output value is provided for a single neuron with fixed in- put, it can incrementally change weights and learn to produce output using the Perceptron learning rule. The perceptron equals the Linear Threshold Unit.

Figure 2: Perceptron

0.3 Perceptron Learning Rule

We learn f : X → {− 1 , +1} represented as f = sgn{w · x), where X = { 0 , 1 }n or X = Rn, w ∈ Rn. Given labeled examples:{(x^1 , y^2 ), (x^2 , y^2 ),... , (xm, ym)}, we sketch the following outline for an algorithm:

  1. Initialize w = 0 ∈ Rn
  2. Cycle through all examples

(a) Predict the label of instance x to be y′^ = sgn{w · x) (b) If y′^6 = y, update the weight vector: w = w + ryx (r – a constant, the learning rate) Otherwise, if y′^6 = y, leave weights unchanged.

If x is Boolean, only weights of active features are updated. w · x > 0 is equivalent to (^) 1+exp^1 (w·x) > 12.

Perceptron has no threshold in this algorithm. However, that does not mean that we lose generality:

0.3.1 Perceptron Learnability

Obviously Perceptron cannot learn that which it cannot represent, which means that it can only be used with linearly separable functions. Minsky and Papert (1969) wrote an influential book demonstrating Perceptron’s representational lim- itaions. Among these limitations are that parity functions cannot be learned (XOR) and, in vision, if patterns are represented with local features, then they cannot rep- resent symmetry or connectivity. Research on neural networks stopped for years. Rosenblatt himself(1959) asked, “What pattern recognition problems can be trans- formed so as to become linearly separable?” Recall from previous sections, that patterns that are not linearly separable can be represented in higher dimensions and thereby become linearly separable.

0.3.2 Perceptron Covergence

The Perceptron Convergence Theorem states that, If there exists a set of weights that are amenable to treatment with Perceptron (i.e., the data is linearly separable), then the Perceptron learning algorithm will converge.

An interesting question which will be discussed in the following section is how long it takes for the learning algorithm to converge. The Perceptron Cycling Theorem states that, if the training data is not linearly seperable, then the Perceptron learning algorithm will eventually repeat the same set of weights and therefore enter an infinite loop.

How can we provide robustness and more expressivity?

0.3.3 Perceptron: Mistake Bound Theorem

This maintains a weight vector w ∈ <N^ , w 0 = (0,... , 0), and upon receiving an example x ∈N^ , makes a prediction according to the linear threshold function w · x ≥ 0. Theorem [Novikoff, 1963] Let (x 1 ; y 1 ),... , : (xt; yt) be a sequence of labeled examples with xi ∈ <N^ , ||xi|| ≤ R and yi ∈ {− 1 , 1 } for all i. Let u ∈ <N^ , γ > 0 be such that, ||u|| = 1 and yiu · xi ≥ γ for all i. Then Perceptron makes at most ||u||^2 R^2 /γ 2 mistakes on this example sequence. In this theorem, γ is the margin complexity parameter.

Figure 4: Representing the Pattern in a Higher Dimensionality

If f (x) = 0 but w · x ≥ θ, wi ← wi/ 2 (if xi = 1) (demotion)

For the class of disjunction, it is possible to use elimination instead of demo- tion.

1.1 Winnow - Example

The Winnow Algorithm works as follows on the example below: f = x 1 ∨ x 2 ∨ x 1023 ∨ x 1024 Initialize: Θ = 1024; w = (1, 1 ,... , 1) 〈(1, 1 ,... , 1), +〉 w · x ≥ Θ w = (1, 1 ,... , 1) ok 〈(0, 0 ,... , 0), −〉 w · x < Θ w = (1, 1 ,... , 1) ok 〈(0, 0 , 111 ,... , 0), −〉 w · x < Θ w = (1, 1 ,... , 1) ok 〈(1, 0 , 0 , , 0), +〉 w · x < Θ w = (2, 1 ,... , 1) mistake 〈(1, 0 , 1 , 1 , 0 , , 0), +〉 w · x < Θ w = (4, 1 , 2 , 2 ,... , 1) mistake 〈(1, 0 , 1 , 0 , 0 , , 1), +〉 w · x < Θ w = (8, 1 , 4 , 2 ,... , 2) mistake

.................. log(n/2) (for each good variable) w = (512, 1 , 256 , 256 ,... , 256) 〈(1, 0 , 1 , 0 ,... , 1), +〉 w · x ≥ Θ w = (512, 1 , 256 , 256 ,... , 256) ok

〈(0, 0 , 1 , 0 , 111 ,... , 0), −〉 w · x ≥ Θ w = (512, 1 , 0 ,... , 0 ,... , 256) mistake (elimiation version)

.................. w = (1024, 1024 , 0 , 0 , 0 , 1 , 32 ,... , 1024 , 1024) (final hypothesis)

Notice that the same algorithm will learn a conjunction over these variables (w = (256, 256 , 0 ,... , 32 ,... , 256 , 256)).

1.2 Winnow - Mistake Bound

Claim: Winnow makes O(k log n) mistakes on k-disjunctions. Initialize: Θ = n; wi = 1 Prediction is 1 iff w · x ≥ Θ If no mistake: do nothing If f (x) = 1 but w · x < Θ, wi ← 2 wi (ifxi = 1) (promotion) If f (x) = 0 but w · x ≥ Θ wi ← wi/ 2 (if xi = 1) (demotion)

  • u – number of mistakes on positive examples (promotions)
  • v – number of mistakes on negative examples (demotions)
  1. u < k log(2n) A weight that corresponds to a good variable is only promoted. When these weights get to n there will be no more mistakes on positives.
  2. v < 2(u + 1) Total weight: T W = n Mistake on positive: T W (t + 1) < T W (t) + n Mistake on negative: T W (t + 1) < T W (t) = n/ 2 0 < T W < n + un − vn/2 =⇒ v < 2(u + 1)

Number of mistakes: u + v < 3 u + 2 = O(k log n)

1.3 Winnow - Extensions

This algorithm learns montone functions. For the general case:

  • Duplicate variables: For the negation of variable x, introduce a new variable y and learn monotone function over 2 n variables.
  • Balance version: Keep two weights for each variable. The effective weight is the difference.

Update rule: If f (x) = 1 but (w+^ − w−) · x ≤ Θ, w i+ ← 2 w+ i w i− ← 12 w i− where xi = 1(promotion) If f (x) = 0 but (w+^ − w−) · x ≥ Θ, w i+ ← f rac 12 w i+ w− i ← 2 w i− where xi = 1 (demotion)

SNoW is a version of Winnow that supports the general case. (Infinite attribute domain) Multi Class predictor – one vs. all vs. the rightway... (later)

update algorithms. An example is SNoW and close relatives include Boosting and Max Entropy.

2.1 Which Algorithm to Choose?

There are various questions which arise in determining which algorithm to choose. First we consider Generalization.

The l 1 norm: ‖x‖ 1 = Σ 1 |xi| The l 2 norm: math‖x‖ 2 = (Σn 1 |xi|^2 )^1 /^2 The lp norm: ‖x‖p = (Σn 1 |xi|p)^1 /p^ The l∞ norm: ‖x‖∞ = maxi |xi|

With Multiplicative algorithms, the bounds depend on ‖u‖, the separating hy- perplane, and

M = 2 ln n ‖u‖^21 maxi

∥x(i)

∥^2

∞ /mini(u^ ·^ x

i) (^2).

This type of algorithm has an advantage when there are few relevant feature in concept.

With Additive algorithms, the bounds depend on ‖x‖ (Kivinen / Warmuth,

1995), and M = ‖u‖^2 maxi ‖xi‖ 2 /mini(u · xi)^2. This type of algorithm has an advantage when there are few active features per example.

2.1.1 Algorithm Descriptions

The following is a summary of how weights are updated in the two families of algorithms:

Examples: x ∈ { 0 , 1 }n; Hypothesis: w ∈ Rn Prediction is 1 iff w · x ≥ Θ

Additive weight update algorithm (Perceptron, Rosenblatt, 1958. Variations exit) If Class = 1 but w · x ≤ Θ, wi ← wi + 1 (if math xi = 1) (promotion) If Class = 0 but w · x ≥ Θ, wi ← wi/ 2 (if xi = 1) (demotion)

Multiplicative weight update algorithm (Winnow, Littlestone, 1988. Variations exit) If Class = 1 but w · x ≤ Θ, wi ← 2 wi (if xi = 1) (promotion) If Class = 0 but w · x ≥ Θ, wi ← wi/ 2 (if xi = 1) (demotion)

2.2 How to compare Algorithms?

There are several areas in which algorithms can be compared. The first is General- ization. Since the representation is the same, we can compare how many examples are needed to get a given level of accuracy. The second is Efficiency. Determin- ing the efficiency of an algorithm means asking how long it takes, per example, to learn a hypothesis and evaluate it. The third is Robustness. Robustness refers to the ability of the algorithm to adapt to new domains. The next sections will compare the Additive and Multiplicative Algorithms in a particular domain: that of context sensitive spelling correction.

2.2.1 Sentence Representation

Given a set of sentences, containing examples such as S below: S = “I don’t know whether to laugh or cry.” Define a set of features. Features are relations that hold in the sentence. If we map a sentence to its feature-based representation, this representation will pro- vide some of the information in the sentence and can be used as an example to your algorithm. Conceptually, there are two steps in coming up with a feature-based representa- tion.

What are the information sources available? Sensors: words, order of words, properties(?) of words

What features should we construct based on these sources? Why needed?

2.2.2 Domain Characteristics

In this domain, the number of potential features is very large. The instance space is sparse since we are only looking at particular pairs of words. This means that decisions will depend on a small set of features (sparse). In other words, we want to learn from a number of examples that is small relative to the dimensionality.

2.2.3 Generalization

The factors in generalization are dominated by the sparseness of the function space. Most features are irrelevant. The number of examples required by mul- tiplicative algorithms depends mostly on the number of relevant features (gener- alization bounds depend on ‖w‖).

Figure 5: Mistake Bounds

2.2.4 Efficiency

Determining efficiency is dominated by the size of the feature space. Most fea- tures are functions (e.g. conjunctions) of raw attributes. For example: X(x 1 , x 2 , x 3 , ,... xk) → X(χ 1 (x), χ 2 (x), χ 3 (x)... χn(x)) Where n >> k. Additive algorithms allow the use of kernals, with no need to explicitly generate the complex features. The basic formula for a kernel is: f (x) =

i ciK(x, xi). This could be more efficient since work is done in the original feature space rather than in more dimensions. Kernels will be discussed in more detail in the next section.

2.3 Practical Issues and Extensions

There are many extension that can be made to these basic algorithms. Some of the extensions are necessary for them to achieve good performance and some are for ease of use and tuning. In the latter category, some extensions include con- verting the output of a Perceptron/Winnow algorithm to a conditional probability, adding Multiclass classification, and adding Real valued features. The key issues in efficiency involve cases in which there is an infinite attribute domain. The key generalization issues involve regularization. This will be motivated in the section in later notes on COLT.

One extension of Perceptron or Winnow to improve the generalization is in- troducing a Thick Separator. This involves adding some margin γ to the threshold and the weight update rules are re-defined as:

Promote if w · x > θ + γ.

Demote if w · x < θ − γ.

Another extension of the Perceptron algorithm that helps with generalization is Threshold Relative Updating. In this case, the weights are changed relative to r as below:

w ← w + rxr =

θ − w · x x · x

2.4 Regularization Via Averaged Perceptron

An Averaged Perceptron Algorithm is motivated by a number of considerations. Every Mistake-Bound Algorithm can be converted efficiently to a PAC algorithm in order to yield global guarantees on performance. In the mistake bound model, we do not know when we will make the mistakes. In the PAC model we want the dependence to be on the number of examples seen and not on the number of mistakes. In order to convert from one mistake-bound model to PAC model, it is necessary to do the following:

Wait for a long stretch without mistakes (there must be one).

Use the hypothesis at the end of this stretch; its PAC behavior is relative to the length of the stretch. Average Perceptron returns a weighted average of a number of earlier hypothesis; the weights are a function of the length of the mistake-free stretch.

Figure 7: Threshold Relative Updating