📘 CodingMarble Learn

Knowledge Representation, Heuristic Search, Bayes and Expert Systems

Classic AI works in four ideas. Knowledge representation stores facts and rules so a computer can use them. Heuristic search uses a clue about the goal to check far fewer options than blind search. Bayesian reasoning updates a belief when new evidence arrives. An expert system joins a knowledge base of rules to an inference engine that answers like a human expert.

🎬 Step-by-step story

  1. Knowledge is stored as a network. Each arrow means "is a kind of". A child inherits the facts of its parents. Tap an animal and see the facts it gets.
  2. Blind search checks squares in every direction, like ripples in water. It finds the goal, but it checks 45 squares.
  3. Heuristic search uses a clue: how far is the goal? It leans toward the goal and checks only 9 squares for the same job.
  4. Bayes: 100 people, 10 are sick. A test finds 9 of them, but it also wrongly flags some healthy people. A positive test is not the same as being sick.
  5. An expert system has a knowledge base of rules and an inference engine. Pick a case and watch the facts travel to a rule and then to an answer.
  6. Free play: choose blind or heuristic search, with or without a wall. Compare how many squares each one checks.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why does the penguin cannot-fly fact beat the bird can-fly fact?

The most specific fact wins. The special fact stored at Penguin overrides the general one inherited from Bird.

Why does blind search check so many squares?

It has no clue about where the goal is, so it spreads out in every direction like ripples.

Does the heuristic make the path longer?

No. In the 3D both find a path of 8 steps. The heuristic only saves checking time.

If the test is 90% good, why is a positive only 50% sure?

Most people are healthy, so even a small false-alarm rate creates as many false positives (9) as true positives (9).

What happens when no rule matches in an expert system?

The system cannot answer by itself. Try "Headache only": it says to ask a doctor.

Does a wall change the shortest path length?

Yes. With the wall the path becomes 14 steps instead of 8, because it must go around.

Knowledge representation

A computer cannot use knowledge unless it is written in a form it can handle. Knowledge representation means storing facts and relations so that a program can reason with them.

Other forms are frames (a record with slots such as name, colour, size), logic statements, and tables. A good representation is clear, easy to update and quick to search.

Heuristic search

Many AI problems are "find a path": a route on a map, a move in a puzzle, a step in a plan. A program tries options one after another. This is a search.

Blind (uninformed) search, such as breadth-first search, checks every neighbour level by level. It is sure to find the shortest path in a simple grid, but it wastes time on places far from the goal. In the 3D grid it checks 45 squares.

Heuristic search uses an extra clue, the heuristic h: a quick guess of how far the goal is. On a grid, h can be the number of squares straight across plus up or down (Manhattan distance). The search picks the most promising square first. In the 3D it checks only 9 squares.

A* search picks the square with the smallest f = g + h, where g is the steps taken so far and h is the guess to the goal. If h never overestimates, A* finds the shortest path.

A heuristic is only a hint. With a wall in the way, the hint can mislead for a while, so the search still checks more squares (29 in the 3D wall case), but still fewer than blind search (58).

Bayesian reasoning

Real life is uncertain. Bayesian reasoning tells us how to change our belief when we get new evidence.

Use natural counts. Take 100 people. 10 are sick (so the prior is 10%). The test finds 9 of the 10 sick. It also wrongly flags 10% of the 90 healthy people, that is 9 people. All positives: 9 + 9 = 18. Only 9 are really sick.

Chance of being sick given a positive test = 9 / 18 = 50%.

This surprises people. A test that is 90% good can still be wrong half the time when the disease is rare. In symbols, Bayes' rule is

P(A | B) = P(B | A) × P(A) / P(B)

Here A = sick and B = positive. The posterior (belief after evidence) depends on the prior, the test quality and the false alarms. More false alarms mean a positive test means less. AI uses this for spam filters, medical help and robots that guess where they are.

Expert systems

An expert system is a program that gives advice like a human expert in a narrow area, such as plant diseases, car faults or loan checks.

Strengths: works day and night, gives the same answer each time, can explain its reason. Limits: knows only its own rules, cannot learn by itself, and fails when no rule fits (as in the "headache only" case). Today many systems mix rules with machine learning.

Try it

On paper, draw a 9 by 7 grid. Put S on the left middle and G on the right middle. First tick squares in rings around S until you hit G. Count the ticks. Then start again and move only toward G, ticking each square. Compare your two counts with 45 and 9 in the 3D. Next, in step 4 of the 3D, move the false-alarm slider to 20% and predict the percent before you read it.

Key formulas and definitions

Worked examples

1. In a semantic network, Sparrow is a Bird and Bird is an Animal. Bird: has wings. Animal: needs food. Sparrow: can fly. List the facts of Sparrow.

Sparrow inherits from Bird and Animal: can fly (own), has wings (from Bird), needs food (from Animal).

2. 100 people, 10 sick. A test finds 9 sick people and wrongly flags 9 healthy people. A person tests positive. What is the chance they are sick?

Positives = 9 + 9 = 18. Sick among them = 9. Chance = 9/18 = 50%.

3. Same test, but the false-alarm rate is 20% of the 90 healthy people. Find the chance now.

False positives = 0.20 × 90 = 18. Positives = 9 + 18 = 27. Chance = 9/27 = 33.3%.

4. A grid search finds the goal. Blind search checked 45 squares and heuristic search checked 9. Which is better, and by how many times?

Heuristic search is better. 45 / 9 = 5 times fewer squares checked.

5. An expert system has R1: IF fever AND cough THEN flu likely. A user enters fever and cough. Which part matches the rule, and what is the output?

The inference engine matches the facts to R1. The output is "flu is likely".

Common mistakes

Practice quiz

1. Storing facts so a program can use them is called:
2. A heuristic is:
3. In A* search, f equals:
4. Bayes' rule helps us:
5. Which part of an expert system matches facts to rules?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is a heuristic in AI?

A heuristic is a quick, useful guess that helps a search choose the most promising option first, such as "how far is the goal?"

What is the difference between blind search and heuristic search?

Blind search checks options with no clue about the goal, so it checks many. Heuristic search uses a clue to head toward the goal and checks fewer.

Where is this topic taught?

It appears under artificial intelligence in senior-secondary information technology and computer science in several countries, and in many first-year AI courses.

Where this is taught

China高三Sel.4 Introduction to AI

Learn first

Learn next

Related lessons

All Computer Science lessons