Docsity

Learning as Search-Artificial Intelligence-lecture Handout, Exercises of Artificial Intelligence

Toggle sidebar
bg1
Artificial Intelligence (CS607)
© Copyright Virtual University of Pakistan
2.2 Concept learning as search
Now that we are well familiar with most of the terminologies of machine learning,
we can define the learning process in technical terms as:
“We have to assume that the concept lies in the hypothesis space. So we search
for a hypothesis belonging to this hypothesis space that best fits the training
examples, such that the output given by the hypothesis is same as the true
output of concept.”
In short:-
Assume C
∈
H, search for an h
∈
H that best fits D
Such that
∀
xi
∈
D, h(xi) = C(xi).
The stress here is on the word ‘search’. We need to somehow search through
the hypothesis space.
2.2.1 General to specific ordering of hypothesis space
Many algorithms for concept learning organize the search through the hypothesis
space by relying on a very useful structure that exists for any concept learning
problem: a general-to-specific ordering of hypotheses. By taking advantage of
this naturally occurring structure over the hypothesis space, we can design
learning algorithms that exhaustively search even infinite hypothesis spaces
without explicitly enumerating every hypothesis. To illustrate the general-to-
specific ordering, consider two hypotheses:
h1 = < H, H >
h2 = < ?, H >
Now consider the sets of instances that are classified positive by h1 and by h2.
Because h2 imposes fewer constraints on the instance, it classifies more
instances as positive. In fact, any instance classified positive by h1 will also be
classified positive by h2. Therefore, we say that h2 is more general than h1.
So all the hypothesis in H can be ordered according to their generality, starting
from < ?, ? > which is the most general hypothesis since it always classifies all
the instances as positive. On the contrary we have < Ø , Ø > which is the most
specific hypothesis, since it doesn’t classify a single instance as positive.
2.2.2 FIND-S
FIND-S finds the maximally specific hypothesis possible within the version space
given a set of training data. How can we use the general to specific ordering of
hypothesis space to organize the search for a hypothesis consistent with the
observed training examples? One way is to begin with the most specific possible
hypothesis in H, then generalize the hypothesis each time it fails to cover an
observed positive training example. (We say that a hypothesis “covers” a positive
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Learning as Search-Artificial Intelligence-lecture Handout and more Exercises Artificial Intelligence in PDF only on Docsity!

2.2 Concept learning as search

Now that we are well familiar with most of the terminologies of machine learning, we can define the learning process in technical terms as:

“We have to assume that the concept lies in the hypothesis space. So we search for a hypothesis belonging to this hypothesis space that best fits the training examples, such that the output given by the hypothesis is same as the true output of concept.”

In short:- Assume C∈H, search for an h∈H that best fits D Such that ∀ xi∈D, h(xi) = C(xi).

The stress here is on the word ‘search’. We need to somehow search through the hypothesis space.

2.2.1 General to specific ordering of hypothesis space

Many algorithms for concept learning organize the search through the hypothesis space by relying on a very useful structure that exists for any concept learning problem: a general-to-specific ordering of hypotheses. By taking advantage of this naturally occurring structure over the hypothesis space, we can design learning algorithms that exhaustively search even infinite hypothesis spaces without explicitly enumerating every hypothesis. To illustrate the general-to- specific ordering, consider two hypotheses: h1 = < H, H > h2 = < ?, H > Now consider the sets of instances that are classified positive by h1 and by h2. Because h2 imposes fewer constraints on the instance, it classifies more instances as positive. In fact, any instance classified positive by h1 will also be classified positive by h2. Therefore, we say that h2 is more general than h1.

So all the hypothesis in H can be ordered according to their generality, starting from < ?,? > which is the most general hypothesis since it always classifies all the instances as positive. On the contrary we have < Ø , Ø > which is the most specific hypothesis, since it doesn’t classify a single instance as positive.

2.2.2 FIND-S

FIND-S finds the maximally specific hypothesis possible within the version space given a set of training data. How can we use the general to specific ordering of hypothesis space to organize the search for a hypothesis consistent with the observed training examples? One way is to begin with the most specific possible hypothesis in H, then generalize the hypothesis each time it fails to cover an observed positive training example. (We say that a hypothesis “covers” a positive

example if it correctly classifies the example as positive.) To be more precise about how the partial ordering is used, consider the FIND-S algorithm:

To illustrate this algorithm, let us assume that the learner is given the sequence of following training examples from the SICK domain:

D T BP SK x 1 H H 1 x 2 L L 0 x 3 N H 1

The first step of FIND-S is to initialize h to the most specific hypothesis in H: h = < Ø , Ø > Upon observing the first training example (< H, H >, 1), which happens to be a positive example, it becomes obvious that our hypothesis is too specific. In particular, none of the “Ø” constraints in h are satisfied by this training example, so each Ø is replaced by the next more general constraint that fits this particular example; namely, the attribute values for this very training example: h = < H , H > This is our h after we have seen the first example, but this h is still very specific. It asserts that all instances are negative except for the single positive training example we have observed.

Upon encountering the second example; in this case a negative example, the algorithm makes no change to h. In fact, the FIND-S algorithm simply ignores every negative example. While this may at first seem strange, notice that in the current case our hypothesis h is already consistent with the new negative example (i.e. h correctly classifies this example as negative), and hence no revision is needed. In the general case, as long as we assume that the hypothesis space H contains a hypothesis that describes the true target concept c and that the training data contains no errors and conflicts, then the current hypothesis h can never require a revision in response to a negative example.

Initialize h to the most specific hypothesis in H For each positive training instance x For each attribute constraint ai in h If the constraint ai is satisfied by x Then do nothing Else Replace ai in h by the next more general constraint that is satisfied by x Output hypothesis h

computed version space contains all the hypotheses consistent with these examples. The algorithm is summarized below:

The Candidate-Elimination algorithm above is specified in terms of operations. The detailed implementation of these operations will depend on the specific problem and instances and their hypothesis space, however the algorithm can be applied to any concept learning task. We will now apply this algorithm to our designed problem SICK, to trace the working of each step of the algorithm. For comparison purposes, we will choose the exact training set that was employed in FIND-S: D T BP SK x 1 H H 1 x 2 L L 0 x 3 N H 1

We know the initial values of G and S:

G 0 = {< ?,? >} S 0 = {< Ø, Ø >}

Now the Candidate-Elimination learner starts: First training observation is: d 1 = (<H, H>, 1) [A positive example]

G 1 = G 0 = {< ?,? >}, since is consistent with d 1 ; both give positive outputs.

Initialize G to the set of maximally general hypotheses in H Initialize S to the set of maximally specific hypotheses in H For each training example d, do If d is a positive example Remove from G any hypothesis inconsistent with d For each hypothesis s in S that is inconsistent with d Remove s from S Add to S all minimal generalization h of s, such that h is consistent with d, and some member of G is more general than h Remove from S any hypothesis that is more general than another one in S If d is a negative example Remove from S any hypothesis inconsistent with d For each hypothesis g in G that is inconsistent with d Remove g from G Add to G all minimal specializations h of g, such that h is consistent with d, and some member of S is more specific than h Remove from G any hypothesis that is less general than another one in S

Since S 0 has only one hypothesis that is < Ø, Ø >, which implies S 0 (x 1 ) = 0, which is not consistent with d 1 , so we have to remove < Ø, Ø > from S 1. Also, we add minimally general hypotheses from H to S 1 , such that those hypotheses are consistent with d 1. The obvious choices are like <H,H>, <H,N>, <H,L>, <N,H>……… <L,N>, <L,L>, but none of these except <H,H> is consistent with d 1. So S 1 becomes:

S 1 = {< H, H >} G 1 = {< ?,? >}

Second training example is: d 2 = (<L, L>, 0) [A negative example]

S 2 = S 1 = {< H, H>}, since <H, H> is consistent with d 2 : both give negative outputs for x 2.

G 1 has only one hypothesis: < ?,? >, which gives a positive output on x 2 , and hence is not consistent, since SK(x 2 ) = 0, so we have to remove it and add in its place, the hypotheses which are minimally specialized. While adding we have to take care of two things; we would like to revise the statement of the algorithm for the negative examples: “Add to G all minimal specializations h of g, such that h is consistent with d, and some member of S is more specific than h”

The immediate one step specialized hypotheses of < ?,? > are:

{< H,? >, < N,? >, < L,? >, < ?, H >, < ?, N >, < ?, L >} Out of these we have to get rid of the hypotheses which are not consistent with d 2 = (<L, L>, 0). We see that all of the above listed hypotheses will give a 0 (negative) output on x 2 = < L, L >, except for < L,? > and < ?, L >, which give a 1 (positive) output on x 2 , and hence are not consistent with d 2 , and will not be added to G 2. This leaves us with {< H,? >, < N,? >, < ?, H >, < ?, N >}. This takes care of the inconsistent hypotheses, but there’s another condition in the algorithm that we must take care of before adding all these hypotheses to G 2. We will repeat the statement again, this time highlighting the point under consideration:

“Add to G all minimal specializations h of g, such that h is consistent with d, and some member of S is more specific than h”

This is very important condition, which is often ignored, and which results in the wrong final version space. We know the current S we have is S 2 , which is: S 2 = {< H, H>}. Now for which hypotheses do you think < H, H > is more specific to,

In tree representation, this would translate into:

where A, B, C and D are the attributes for the problem. This tree gives a positive output if either A AND B attributes are present in the instance; OR C AND D attributes are present. Through decision trees, this is how we reach the final hypothesis. This is a hypothetical tree. In real problems, every tree has to have a root node. There are various algorithms like ID3 and C4.5 to find decision trees for learning problems.

2.3.2 ID

ID stands for interactive dichotomizer. This was the 3rd^ revision of the algorithm which got wide acclaims. The first step of ID3 is to find the root node. It uses a special function GAIN, to evaluate the gain information of each attribute. For example if there are 3 instances, it will calculate the gain information for each. Whichever attribute has the maximum gain information, becomes the root node. The rest of the attributes then fight for the next slots.

2.3.2.1 Entropy

In order to define information gain precisely, we begin by defining a measure commonly used in statistics and information theory, called entropy, which characterizes the purity/impurity of an arbitrary collection of examples. Given a collection S, containing positive and negative examples of some target concept, the entropy of S relative to this Boolean classification is: Entropy(S) = - p+log 2 p+ - p-log 2 p- where p+ is the proportion of positive examples in S and p- is the proportion of negative examples in S. In all calculations involving entropy we define 0log 0 to be 0.

To illustrate, suppose S is a collection of 14 examples of some Boolean concept, including 9 positive and 5 negative examples, then the entropy of S relative to this Boolean classification is:

Entropy(S) = - (9/14)log 2 (9/14) - (5/14)log 2 (5/14)

A

B

C

D

Notice that the entropy is 0, if all the members of S belong to the same class (purity). For example, if all the members are positive (p+ = 1), then p- = 0 and so: Entropy(S) = - 1log 2 1 - 0log 2 0 = - 1 (0) - 0 [since log 2 1 = 0, also 0log 2 0 = 0] = 0 Note the entropy is 1 when the collection contains equal number of positive and negative examples (impurity). See for yourself by putting p+ and p- equal to 1/2. Otherwise if the collection contains unequal numbers of positive and negative examples, the entropy is between 0 and 1.

2.3.2.2 Information gain

Given entropy as a measure of the impurity in a collection of training examples, we can now define a measure of the effectiveness of an attribute in classifying the training data. The measure we will use, called information gain, is simply the expected reduction in entropy caused by partitioning the examples according to this attribute. That is, if we use the attribute with the maximum information gain as the node, then it will classify some of the instances as positive or negative with 100% accuracy, and this will reduce the entropy for the remaining instances. We will now proceed to an example to explain further.

2.3.2.3 Example

Suppose we have the following hypothetical training data available to us given in the table below. There are three attributes: A, B and E. Attribute A can take three values: a 1 , a 2 and a 3. Attribute B can take two values: b 1 and b 2. Attribute E can also take two values: e 1 and e 2. The concept to be learnt is a Boolean concept, so C takes a YES (1) or a NO (0), depending on the values of the attributes.

S A B E C

d 1 a 1 b 1 e 2 YES d 2 a 2 b 2 e 1 YES d 3 a 3 b 2 e 1 NO d 4 a 2 b 2 e 1 NO d 5 a 3 b 1 e 2 NO

First step is to calculate the entropy of the entire set S. We know: E(S) = - p+log 2 p+ - p-log 2 p-

log 5

log 5

( , ) ( )^1 12 ESe 2 S

Se ESe S

Se G S E = E S − − = 0.

This tells us that information gain for A is the highest. So we will simply choose A as the root of our decision tree. By doing that we’ll check if there are any conflicting leaf nodes in the tree. We’ll get a better picture in the pictorial representation shown below:

This is a tree of height one, and we have built this tree after only one iteration. This tree correctly classifies 3 out of 5 training samples, based on only one attribute A, which gave the maximum information gain. It will classify every forthcoming sample that has a value of a 1 in attribute A as YES, and each sample having a 3 as NO. The correctly classified samples are highlighted below:

S A B E C

d 1 a 1 b 1 e 2 YES d 2 a 2 b 2 e 1 YES d 3 a 3 b 2 e 1 NO d 4 a 2 b 2 e 1 NO d 5 a 3 b 1 e 2 NO

Note that a 2 was not a good determinant for classifying the output C, because it gives both YES and NO for d 2 and d 4 respectively. This means that now we have to look at other attributes B and E to resolve this conflict. To build the tree further we will ignore the samples already covered by the tree above. Our new sample space will be given by S’ as given in the table below:

S’ A B E C

d 2 a 2 B 2 e 1 YES d 4 a 2 B 2 e 2 NO

YES S’ = [d 2 , d 4 ] NO

a 1 a 2 a 3

A

We’ll apply the same process as above again. First we calculate the entropy for this sub sample space S’: E(S’) = - p+log 2 p+ - p-log 2 p-

= 2

log 2

log 2

This gives us entropy of 1, which is the maximum value for entropy. This is also obvious from the data, since half of the samples are positive (YES) and half are negative (NO).

Since our tree already has a node for A, ID3 assumes that the tree will not have the attribute repeated again, which is true since A has already divided the data as much as it can, it doesn’t make any sense to repeat A in the intermediate nodes. Give this a thought yourself too. Meanwhile, we will calculate the gain information of B and E with respect to this new sample space S’:

|S’| = 2 |S’b 2 | = 2

( ' ) | '|

( ', ) ( ')^2 E Sb 2 S

Sb G S B =E S −

log 2

log 2

G ( S',B)= 1 − − 2 − 2 = 1 - 1 = 0

Similarly for E: |S’| = 2 |S’e 1 | = 1 [since there is only one observation of e 1 which outputs a YES] E(S’e 1 ) = -1log 2 1 - 0log 2 0 = 0 [since log 1 = 0]

|S’e 2 | = 1 [since there is only one observation of e 2 which outputs a NO] E(S’e 2 ) = -0log 2 0 - 1log 2 1 = 0 [since log 1 = 0]

Hence:

( ', ) ( ')^1 12 ESe 2 S

Se E Se S

Se G S E =E S − −

G ( S',E)= 1 − − = 1 - 0 - 0 = 1

neurons. When one of those neurons fire, a positive or negative charge is received by one of the dendrites. The strengths of all the received charges are added together through the processes of spatial and temporal summation. Spatial summation occurs when several weak signals are converted into a single large one, while temporal summation converts a rapid series of weak pulses from one source into one large signal. The aggregate input is then passed to the soma (cell body). The soma and the enclosed nucleus don't play a significant role in the processing of incoming and outgoing data. Their primary function is to perform the continuous maintenance required to keep the neuron functional. The part of the soma that does concern itself with the signal is the axon hillock. If the aggregate input is greater than the axon hillock's threshold value, then the neuron fires, and an output signal is transmitted down the axon. The strength of the output is constant, regardless of whether the input was just above the threshold, or a hundred times as great. The output strength is unaffected by the many divisions in the axon; it reaches each terminal button with the same intensity it had at the axon hillock. This uniformity is critical in an analogue device such as a brain where small errors can snowball, and where error correction is more difficult than in a digital system. Each terminal button is connected to other neurons across a small gap called a synapse.

3.1.1 Comparison between computers and the brain

Biological Neural Networks Computers Speed Fast (nanoseconds) Slow (milliseconds) Processing Superior (massively parallel) Inferior (Sequential mode) Size & Complexity 1011 neurons, 10^15 interconnections Far few processing elements Storage Adaptable, interconnection strengths Strictly replaceable Fault tolerance Extremely Fault tolerant Inherently non fault tolerant Control mechanism Distributive control Central control

While this clearly shows that the human information processing system is superior to conventional computers, but still it is possible to realize an artificial neural network which exhibits the above mentioned properties. We’ll start with a single perceptron, pioneering work done in 1943 by McCulloch and Pitts.

3.2 Single perceptron

To capture the essence of biological neural systems, an artificial neuron is defined as follows: It receives a number of inputs (either from original data, or from the output of other neurons in the neural network). Each input comes via a connection that has a strength (or weight); these weights correspond to synaptic efficacy in a biological neuron. Each neuron also has a single threshold value. The weighted sum of the inputs is formed, and the threshold subtracted, to compose the activation of the neuron. The activation signal is passed through an activation function (also known as a transfer function) to produce the output of the neuron.

Neuron Firing Rule:

IF (Input1 x weight1) + (Input2 x weight2) + (Bias) satisfies Threshold value Then Output = 1 Else Output = 0

3.2.1 Response of changing bias

The response of changing the bias of a neuron results in shifting the decision line up or down, as shown by the following figures taken from matlab.

Input 1

Input 2

Bias

Output

Threshold weigh Function

weigh

3.2.2 Response of changing weight

The change in weight results in the rotation of the decision line. Hence this up and down shift, together with the rotation of the straight line can achieve any linear decision.