Page Nav

HIDE

Grid

GRID_STYLE

Pages

Knowledge Engineering in AI

  Introduction   To achieve a goal, we set some constraints to maintain a healthy plan. Knowledge Engineering kind of works like that. It ma...

 

Introduction 

To achieve a goal, we set some constraints to maintain a healthy plan. Knowledge Engineering kind of works like that. It makes a knowledge-base similar to constraints we use, where AI can imitate human-like decisions. Knowledge-base is where propositional logic is used to help AI understand human language. In this report, we will see by using knowledge engineering how we can infer unknown results with a card-board game called the game of clue.

This report is a part of Artificial Intelligence course Lab-work under supervision of Nuruzzaman Faruqui, Lecturer of City University, Bangladesh. This course offers students various up-to-date AI topics. Students get to explore the real applicable approaches through AI. From this course, the student acquires better knowledge of the functionality of AI and how AI is making our daily life easier. This is the best Artificial Intelligence course in Bangladesh.

 

Problem Statement: Let’s look at the game of clue. In the game, we will solve a murder mystery case using a model checking algorithm. The murder was committed by a person in a location using a tool. For each people, tools and locations will be stored in cards. These cards will be picked randomly and put in an envelope.  The participants have to find the murderer, by which tool that murderer used, and where that murder happened. So, this is what our clue looks like:




 

We will solve this game by using Knowledge Engineering. The first thing we can do is adding rules of the game to our knowledge base. Since our result is one person is the murderer among the other and certain tools and locations were used. So, we can create our knowledge base using propositional logic as follows:

(Mustard ∨ Plum ∨ Scarlet)

(knife ∨ revolver ∨ wrench)

(ballroom ∨ kitchen ∨ library)

 

Each player gets to see one person, one tool, and one location. Players are not allowed to share information with each other. Let’s say, a player randomly picks up a card and gets a Mustard, kitchen, and revolver. It makes perfect sense that these are not related to the murder. So, we will add to our Knowledge base:

¬(Mustard)

¬(kitchen)

¬(revolver)

 

Now, let’s consider another case where one player makes a guess i.e., Scarlet commits the crime in the library using a wrench. If this guess turns out to be wrong, then we can add it to our Knowledge base:

(¬Scarlet ∨ ¬library ∨ ¬wrench)

Now, if another player shows us the Plum card. Thus, we can add ¬(Plum) to our KB.

 

Adding just one more piece of knowledge, for example, that it is not the ballroom, can give us more information. First, we update our KB ¬ (ballroom)

So far whatever data we have fed into our knowledge base we can conclude that Scarlet is the murderer. If we add more information, for instance, it is not the ballroom, can give us a more accurate result.

 

 

 

 

 

 

 

Model Checking Algorithms

def check_all(knowledge, query, symbols, model): # If model has an assignment for each symbol
# (The logic below might be a little confusing: we start with a list of symbols. The function is recursive, and every time if not symbols:
# If knowledge base is true in model, then query must also be true if knowledge.evaluate(model): return query.evaluate(model)
return True else:
# Choose one of the remaining unused symbols remaining = symbols.copy() p = remaining.pop()
# Create a model where the symbol is true model_true = model.copy() model_true[p] = True
# Create a model where the symbol is false model_false = mode.copy() model_false[p] = False
# Ensure entailment holds in both models return(check_all(knowledge, query, remaining, model_true) and check_all(knowledge, query, remaining, model_false))

def check_all(knowledge, query, symbols, model):
    
# If model has an assignment for each symbol
# (The logic below might be a little confusing: we start with a list of symbols. The function is recursive, and every time
if not symbols:
          
# If knowledge base is true in model, then query must also be true
          
if knowledge.evaluate(model):
               
return query.evaluate(model)
 
return True
else:
    
# Choose one of the remaining unused symbols
 remaining = symbols.copy()
 p = remaining.pop()
 
# Create a model where the symbol is true
 model_true = model.copy()
 model_true[p] =
True
 
# Create a model where the symbol is false
 model_false = mode.copy()
 model_false[p] =
False
 
# Ensure entailment holds in both models
 
return(check_all(knowledge, query, remaining, model_true) and check_all(knowledge, query, remaining, model_false))

Now let’s see the implementation in python:

# we import termcolor to change the colour in terminal window import termcolor # we have import the logic file from logic import * #Now we are symboling all of the charecters,rooms,weapons mustard=Symbol("col.mustard") plum=Symbol("ProfPlum") scarlet=Symbol("MsScarlet") charecters=[mustard,plum,scarlet] ballroom=Symbol("ballroom") kitchen=Symbol("kitchen") library=Symbol("library") rooms=[ballroom,kitchen,library] revolber=Symbol("revolber") knife=Symbol("knife") wrench=Symbol("wrench") wreapons=[revolber,knife,wrench] # Now we are concating characters , rooms and weapons in symbols. symbols=charecters+rooms+wreapons # we are checking the model and get some truth value def check_knowledge(knowledge_base):     for symbol in symbols:          if model_check(knowledge_base,symbol):              termcolor.cprint(f"{symbol}:YES","green")          elif not model_check(knowledge_base,Not(symbol)):              print(f"{symbol}:Maybe") # Createing knowledge base knowledge_base=And(     Or(mustard,plum,scarlet),     Or(ballroom,kitchen,library),
   Or(knife,revolber,wrench) )
# They are clue knowledge_base.add(And(     Not(mustard),Not(kitchen),Not(wrench) )) knowledge_base.add(Or(     Not(scarlet),Not(library),Not(wrench) )) knowledge_base.add(Not(plum)) knowledge_base.add(Not(ballroom)) knowledge_base.add(Not(revolber)) check_knowledge(knowledge_base)

 

Result

 After executing the code, we can see Scarlet commits the murder using a knife in the library.


Conclusion

When you are given data, you pretty much cannot do anything with it until you analyze it with some process. And that process can be done once you add your data to something. In Artificial intelligence we call it knowledge-base. Using that knowledge-base we can analyze the data to understand what information your date can give you. That’s what we call knowledge engineering. In this report, we add information to the knowledge-base and infer new information that was hidden inside the data. That’s the most powerful thing you can achieve through knowledge engineering. You can reveal unknown information. A prerequisite of this topic would discrete mathematics because to feed data into a knowledge-base you must have an idea of knowledge representation.

As you can see, this course was instructed that way, we go through the topic first, then apply what we learn into a real-life problem. And solve it using python. I believe this is one of the best ways if you are a beginner, just starting out in Artificial Intelligence. Without any doubt, this course stands out as the best AI course in Bangladesh.





No comments