Wednesday, December 23, 2009

Artifitial Intelligence: Chapter 3 Problem Solving - Introduction to Production Systems

In AI programs there is a clean separation of -
  • computational components of data,
  • operations and
  • control
Search forms the core of many intelligent processes. So it is useful to structure AI programs in a way that facilitates describing the search process.

Production System
A formalism for structuring AI programs which facilitates search process. It consists of
  • Initial or start state of the problem
  • Final or goal state of the problem
It consists of one or more databases
  • consisting of appropriate information for the particular task.
  • information in these databases may be structured using knowledge representation schemes.
Set of production rules
  • each consisting of a left side that determines the applicability of the rule and
  • a right side that describes the action to be performed if the rule is applied.
  • These rules operate on the databases.
  • Application of rules change the database.
A control strategy is one that specifies the order in which the rules will be applied when several rules match at once.


In addition to its usefulness as a way to describe search, the production model has other advantages as a formalism in AI.
  • It is a good way to model the strong state driven nature of intelligent action. As new inputs enter the database, the behavior of the system changes.s
  • New rules can easily be added to account for new situations without disturbing the rest of the system, which is quite important in real-time environment.
Example: Water Jug Problem
Given two jugs, a 4-gallon and 3-gallon having no measuring markers on them. There is a pump that can be used to fill the jugs with water. How can you get exactly 2 gallons of water into 4-gallon jug.
Solution: State space for this problem can be described as the set of ordered pairs of integers (X, Y) such that X represents the number of gallons of water in 4-gallon jug and Y for 3-gallon jug.
1.Start state is (0,0)
2.Goal state is (2, N) for any value of N.
Following are the production rules for this problem.
Production Rules:
R1:(X, Y | X < 4)                        ==> (4, Y){Fill 4-gallon jug}
R2:(X, Y | Y < 3)                        ==> (X, 3){Fill 3-gallon jug}
R3:(X, Y | X > 0)                        ==> (0, Y){Empty 4-gallon jug}
R4:(X, Y | Y > 0)                        ==> (X, 0){Empty 3-gallon jug}
R5:(X, Y | X+Y >= 4 ΛY > 0)    ==> (4, Y –(4 –X)){Pour water from 3-gallon jug into 4-gallon jug until 4-gallon jug is full}
R6:(X, Y | X+Y >= 3 ΛX > 0)    ==> (X –(3 –Y), 3){Pour water from 4-gallon jug into 3-gallon jug until 3-gallon jug is full}
R7:(X, Y | X+Y <= 4 ΛY > 0)    ==> (X+Y, 0){Pour all water from 3-gallon jug into 4-gallon jug }
R8:(X, Y | X+Y <= 3 ΛX > 0)    ==> (0, X+Y){Pour all water from 4-gallon jug into 3-gallon jug }

Superficial Rules: {May not be used in this problem}
R9:(X, Y | X > 0) ==> (X –D, Y){Pour some water D out from 4-gallon jug}
R10:(X, Y | Y > 0) ==> (X, Y -D){Pour some water D out from 3-gallon jug}

Steps involved in solving the water jug problem

Number of Steps
Rules applied
4-g jug 3-g jug
1
Initial State
0 0
2
R2 {Fill 3-g jug}
0 3
3
R7 {Pour all water from 3 to 4-g jug }
3 0
4
R2 {Fill 3-g jug}
3 3
5
R5 {Pour from 3 to 4-g jug until it is full}
4 2
6
R3 {Empty 4-gallon jug}
0 2
7
R7 {Pour all water from 3 to 4-g jug}
2 0 (Goal State)


Points to be noted
  • There are initial and final description of the problem.
  • There are more than one ways of solving the problem.
  • One would exercise a choice between various solution paths based on some criteria of goodness or on some heuristic function.
  • There are set of rules that describe the actions called production rules.
  • Left side of the rules is current state and right side describes new state that results from applying the rule.

    Sunday, December 20, 2009

    Artifitial Intelligence: Chapter 2 AI for Tic Tac Toe Game Part 2

    PROGRAM 2
    Data Structure
    Board
    A nine –element vector representing the board : B[1..9]
    • 2-indicates blank
    • 3-X
    • 5-0
    Turn
    An integer
    • 1-First move
    • 9-Last move
    Algorithm
    There are three sub procedures
    • Make_2 -Tries to make valid 2
      • It first tries to play in the center. If not possible, then it tries the various suitable non corner square
      • So, it returns 5 if the center is free else returns number of suitable blank non corner square.
    • PossWin(P) -Returns 0
      • It returns 0, if player P cannot win in its next move, otherwise returns the number of square that constitutes a winning move for P.
      • If PossWin(P) = 0 {P can not win}, then find whether opponent can win. If so, then block it.
      • Strategy used by PosWin - It operates by checking, one at a time, each of rows /columns and diagonals. It can test for each row/column/diagonal as follows:
    If 3 * 3 * 2 = 18then X can win
    Else if 5 * 5 * 2 = 50 then O can win.
    • Go(n) -makes a move in square n {which is blank i.e. having 2}
    These three procedures are used in the following algorithm.
    Assumption: The first player uses symbol X.
    Computer ( C ) gets chance to play first (C plays X, H plays O)-Odd moves
    Human ( H ) gets change to play first. (Computer plays O, H plays X) -Even moves
    1 move :go (5)
    2 move: If B[5] is blank, then Go(5) else Go(1)
    3 move :If B[9] is blank, then Go(9) else Go(3) {make 2}
    4 move: {By now human (playing X) has played 2 chances}If PossWin(X) then {block H}Go (PossWin(X)) else Go (Make_2)
    5 move : {By now computer has played 2 chances}If PossWin(X) then {won}Go(PossWin(X)) else {block H}if PossWin(O) then Go(PossWin(O)) else if B[7] is blank then Go(7) else Go(3)
    6 move: {By now both have played 2 chances}If PossWin(O) then {won}Go(PossWin(O)) else {block H}if PossWin(X) then Go(PossWin(X)) else Go(Make_2)
    7 & 9 moves :{By now human (playing O) has played 3 chances}If PossWin(X) then {won}Go(PossWin(X)) else {block H}if PossWin(O) then Go(PossWin(O)) else Go(Anywhere)
    8 move:{By now computer has played 3 chances}If PossWin(O) then {won}Go(PossWin(O)) else {block H}if PossWin(X) then Go(PossWin(X)) else Go(Anywhere)

    Conclusion
    • Not as efficient as first one in terms of time. Several conditions are checked before each move.
    • It is memory efficient.
    • Easier to understand &; complete strategy has been determined in advance
    • Still can not generalize to 3-D.

    Artifitial Intelligence: Chapter 2 AI for Tic Tac Toe Game - Part1

    Tic–Tac–Toe Game Playing There is one human player and other player is computer. The objective is to write a computer program which wins most of the time. We will present three approaches to play this game which increase in
    1. Complexity
    2. Use of generalization
    3. Clarity of their knowledge
    4. Extensibility of their approach
    These approaches will move towards being representations of what we will call AI techniques.

    PROGRAM 1

    Data Structures

    Board 
    Consider a Board having nine elements vector.
    Each element will contain
    • 0 for blank
    • 1 indicating X player move
    • 2 indicating O player move
    Computer may play as X or O player. First player is always X.

    Move Table
    It is a vector of 3^9 elements, each element of which is a nine element vector representing board position.
    Total of 3^9(19683) elements in move table
    Move Table
    Index Current Board position New Board position
    0             000000000                 000010000
    1             000000001                 020000001
    2             000000002                 000100002
    3             000000010                 002000010
    .
    .
    .

    Algorithm
    To make a move, do the following:
    1. View the vector (board) as a ternary number and convert it to its corresponding decimal number.
    2. Use the computed number as an index into the move table and access the vector stored there.
    3. The vector selected in step 2 represents the way the board will look after the move that should be made. So set board equal to that vector.

    Conclusion
    1. Very efficient in terms of time but has several disadvantages
    2. Lot of space to store the move table.
    3. Lot of work to specify all the entries in move table.
    4. Error prone because of the data is voluminous.
    5. Poor extensibility: 3D tic-tac-toe = 327board position to be stored.
    6. Not intelligent.

    Wednesday, December 16, 2009

    Artifitial Intelligence: Chapter 1 Introduction

    What is AI?
    1. Modeling human cognition or mental faculty using computers
    2. Study of making computers do things which at the moment people better
    3. Making computers do things which require intelligence
    Intelligence is a property of mind that encompasses many related mental abilities, such as the capacities to
    • reason
    • plan
    • solve problems
    • think abstractly,
    • comprehend ideas and language, and
    • learn
    More formally AI is a branch of computer science which is concerned with the study and creation of computer systems that exhibit
    • some form of intelligence or
    • the characteristics we associate with intelligence in human behavior
    Two Views of AI Goals
    • AI is about duplicating what the (human) brain DOES
      • Cognitive Science
    • AI is about duplicating what the (human) brain SHOULD do
      • Rationality (doing things logically)
    Cool Stuff in AI
    1. Game playing agents
    2. Machine learning
    3. Speech
    4. Language
    5. Vision
    6. Data Mining
    7. Web agents
    Useful Stuff
    1. Medical Diagnosis
    2. Fraud Detection
    3. Object Identification
    4. Space Shuttle Scheduling
    5. Information Retrieval
    What is AI today?
    Three typical components of AI Systems

    THE WORLD ----->Perception-----> Action------> Reasoning------>THE WORLD

    Recent AI: Heavy use of
    • probability theory
    • decision theory
    • statistics
    • logic (fuzzy, modal, temporal)

    Monday, December 14, 2009

    Download Free Wallpapers

    I designed these wallpapers in Photoshop during my learning. I will try to post how to build these wallpapers in a later post. Designing these wallpapers was fairly easy and fun. I own all the psd files for these wallpapers and can provide them on request if someone needs them for learning purpose. If you like any of these u can download it free of cost(though I can not somehow stop anyone from downloading :P)