Wednesday, March 31, 2021

Sampling in Artificial Intelligent (Instructor Name: Nuruzzaman Faruqui)

 Sampling

 

Introduction:

Sampling is a method that allows us to get information about the population based on the statistics from a subset of the population (sample), without having to investigate every individual. Data sampling refers to statistical methods for selecting observations from the domain with the objective of estimating a population parameter. 

The below diagram perfectly illustrates what sampling is.


 This is an important part of Artificial Intelligence course and this  lab report is done by myself under the supervision of Nuruzzaman Faruqui, lecturer of City University, Bangladesh. From this course we get to explore the real applicable approaches through AI and also acquires better knowledge of the functionality of AI and how AI is making our daily life easier. That's why this is the best Artificial Intelligence course in Bangladesh. 

 

Problem Statement:

Sampling is one technique of approximate inference. In sampling, each variable is sampled for a value according to its probability distribution. 

Here we discuss an example with sampling the Rain variable, the value none will be generated with probability of 0.7, the value light will be generated with probability of 0.2, and the value heavy will be generated with probability of 0.1. If you want to know about sampling, then definitely you want to know more about uncertainty. From this, we  will find out an approximate probability for P(Train = on time)We can also solve the involve conditional probability, such as P(Rain = light | Train = on time).

 Code Commentary:

We implement the problem in Python Language. 



 

 Result:

 

 

Conclusion: 

In this  lab work, we learned, what is sampling, how can get the inference approximate. Sampling is an active process of gathering observations intent on estimating from any group of variable. In this report, we learned about the concept of sampling, steps involved in sampling. Sampling has wide applications in the statistical world as well as the real world.

Tuesday, March 30, 2021

Authenticity of Banknotes Using Machine Learning Methods (Instructor Name: Nuruzzaman Faruqui)

 Inrtoduction:

Banknotes are one of the most important assets of a country. This is a classification problem where we are given some input data and we have to classify the input into one of the several predefined categories. Rule-based as well as statistical techniques are commonly used for solving classification problems. Machine learning algorithms fall in the category of statistical techniques.

This is an important part of Artificial Intelligence course and this  lab report is done by myself under the supervision of Nuruzzaman Faruqui, lecturer of City University, Bangladesh. From this course we get to explore the real applicable approaches through AI and also acquires better knowledge of the functionality of AI and how AI is making our daily life easier. That's why this is the best Artificial Intelligence course in Bangladesh.

 

Problem Statement:

Machine learning algorithms learn from the data set. Statistical algorithms are used behind the scenes to make a machine learning model learn from the data. Therefore, to identify whether a banknote is real or not, we needed a data set of real as well as fake bank notes along with their different features.

We used Python libraries for the analysis of our data set as well as for training the machine learning models. To import the data set we used the some libraries. Once we import the libraries, the next step is to load the data set into our application. To do so, we used the “read_csv()” function of the library, which reads data set that is in the CSV format.

Here we have a data set. Now we are going to train the machine to predict that it is an actual and fake banknote.


 

In the above data set there are five-section and the last section depends on the first four sections. In the last sections, it will find the notes is real or fake. The first section is variance, the second is skewness, the third is kurtosis, fourth is entropy. we'll use 40% of our dataset in our program. 


Code Commentary:

 


Result:

Here, we are using Perceptron, SVM, KNN, GaussianNB models and will count the accuracy of the real notes that what percent of the real notes here in the first 40% of the data set.


Model

Correct

Incorrect

Accuracy

Perceptron

539

9

98.36%

SVM

545

3

99.45%

KNN

548

0

100%

GaussianNB

457

91

83.39%



In the banknotes.py file, we are importing the data set of banknotes. For this we install sci-kit-learn in python. Then import the random library cause it will count the data set randomly. We can see that K neighbor Classifier perform well its accuracy is 100%. But GaussianNB has very poor accuracy it's 83.03%.

 

Conclusion:

 Banknote authentication is an important task. It is difficult to manually detect fake bank notes. Machine learning algorithms can help in this regard. In this article, we explained how we solved the problem of banknote authentication using machine learning techniques. We compared three different algorithms in terms of performance and concluded that the Random Forest algorithms is the best algorithm for banknote authentication with an accuracy of 99.45%.

Thursday, March 25, 2021

Knowledge Representation lab report using comments (Instructor Name: Nuruzzaman Faruqui)

 Knowledge Representation

 

Introduction: 

Knowledge Representation in AI describes the representation of knowledge. Basically, it is a study of how the beliefs, intentions, and judgments of an intelligent agent can be expressed suitably for automated reasoning. One of the primary purposes of Knowledge Representation includes modeling intelligent behavior for an agent. Humans are best at understanding, reasoning, and interpreting knowledge. Human knows things, which is knowledge and as per their knowledge they perform various actions in the real world. But how machines do all these things comes under knowledge representation and reasoning. Knowledge Representation and Reasoning (KR, KRR) represents information from the real world for a computer to understand and then utilize this knowledge to solve complex real-life problems like communicating with human beings in natural language. Knowledge representation in AI is not just about storing data in a database, it allows a machine to learn from that knowledge and behave intelligently like a human being. 

This is an important part of Artificial Intelligence course and this  lab report is done by myself under the supervision of Nuruzzaman Faruqui, lecturer of City University, Bangladesh. From this course we get to explore the real applicable approaches through AI and also acquires better knowledge of the functionality of AI and how AI is making our daily life easier. That's why this is the best Artificial Intelligence course in Bangladesh.

 

Problem Statement: 

Artificial Intelligent Systems usually consist of various components to display their intelligent behavior. Some of these components include in figure below. Here this figure is shown the different components of the system and how it works:


Knowledge representation is a way to feed information to a Knowledge-based agent. An intelligent agent needs knowledge about the real world for taking decisions and reasoning to act efficiently.Knowledge-based agents are those agents who have the capability of maintaining an internal state of knowledge, reason over that knowledge, update their knowledge after observations and take actions. These agents can represent the world with some formal representation and act intelligently. Generally we humans use sentences to collect information. The machine can not be fed directly with human language. That’s where propositional logic comes to the rescue. It helps to make sentences in a way that AI can store knowledge and infer new information.

Here we have a scenario to understand how we can build a knowledge-based agent and its operation, consider the following example: -


  •   If it didn’t rain, Harry visited Hagrid today.
  •  Harry visited Hagrid or Dumbledore today, but not both.
  •  Harry visited Dumbledore today.
So, we will use the above scenario to make a knowledge-base and make an intelligent system that will tell us, did it rain today? Or, did Harry visit Hagrid today? 
And here we will use the basic logical connectives that we have learned in discrete mathematics will applied to make a knowledge-base. Such as, Not (¬), And (), Or (), Implication (→), Bidirectional (↔). Another logical connective you may or may not be familiar that is Entailment (). What it means is, if a b, then in any world where a is true, b is also true.
 

Code Commentary: 


Here we have used Python Language to implement the scenario by logical connectives.

 


 

To import libraries in Python we will import the above code to use all the logical connectives.

 

 

Result:

After executing the code, we get the following output/result


 

 

Conclusion:

Knowledge-base is required for updating knowledge for an agent to learn with experiences and take action as per the knowledge and also it an important topic in Artificial Intelligent. It has to do with the ‘thinking’ of AI systems and contributes to its intelligent behavior. Knowledge Representation is a radical and new approach in AI that is changing the world. Let’s look into what it is and its applications. knowledge representation allows machines to behave like humans by empowering an AI machine to learn from available information, experience or experts. However, it is important to choose the right type of knowledge representation.

 

 

Thursday, March 11, 2021

Maze Solver- The search algorithm (Instructor Name: Nuruzzaman Faruqui)


 The Maze:

A maze is a path or collection of paths, typically from an entrance to a goal. The word is used to refer both to branching tour puzzles through which the solver must find a route, and to simpler non-branching patterns that lead unambiguously through a convoluted layout to a goal.

 Introduction

The maze solver basically a search problem that defines paths an agent is looking for. The agent is a term used in Artificial Intelligence to solve several kinds of search problems like the maze solver. Rational agents or Problem-solving agents in AI mostly used these search strategies or algorithms to solve a specific problem and provide the best result. We use search algorithm and solve the maze. The automation of operations in various factories, certain robots that can make decisions without human help, cars that can drive alone this type of problem solve need maze solver.


 

 This is an important part of Artificial Intelligence course and this  lab report is done by myself under the supervision of Nuruzzaman Faruqui, lecturer of City University, Bangladesh. From this course we get to explore the real applicable approaches through AI and also acquires better knowledge of the functionality of AI and how AI is making our daily life easier. That's why this is the best Artificial Intelligence course in Bangladesh.  

 

Problem Statement: 

The automation of operations in various factories, certain robots that can make decisions without human help, cars that can drive alone this type of problem solve need maze solver. We solve any maze to maintain some state by state. Those state are given bellow-

Initial State: It means exactly what it sounds. Where the agent begins its journey.

Actions: In any state, the agent can perform its operation to move toward the target state. That agent has to make choices for that. This set of choices are evaluated as actions.

Transition Model: After performing action there’s a change or movement that occurs in any state of an environment. The transition model describes that change through the result function.

Goal Test: After the transition model, the agent must look at whether the new state it’s in is the target state it was searching for or not.

Path cost: Once the agent reaches the target state it can determine the total cost it had to spend since the beginning of its journey. The cost provides numerical values.

 The Maze solver algorithm using Stack and Queue Frontier is given bellow-

Algorithm

1.      A frontier that contains the initial state.

2.      An empty explored set

Repeat

3.      If the frontier is empty.

a.       Stop. No solution to the problem.

4.      Remove a node from the frontier. This node will be considered and move to explored set.

5.      If the node contains goal state,

a.        return the solution. Stop.

6.      Else

a.       Add the current node to the explored set.

b.      Expand node. Add resulting nodes to the frontier if they aren’t already in the frontier.

 

Code Commentary: 


import sys

class Node():

def __init__(self, state, parent, action):
self.state = state
self.parent = parent
self.action = action

class StackFrontier():

def __init__(self):
self.frontier = []

def add(self, node):
self.frontier.append(node)

def empty(self):
return len(self.frontier) == 0

def remove(self):
if self.empty():
raise Exception("The frontier is empty")
else:
node = self.frontier[-1]
self.frontier = self.frontier[:-1]
return node

def contains_state(self, state):
return any(node.state == state for node in self.frontier)

# Instead of Stack we have to use Queue

class Maze():

def __init__(self, filename):

with open(filename) as f:
contents = f.read()

if contents.count("A") != 1:
raise Exception("The maze doesn't have a starting point")
if contents.count("B") != 1:
raise Exception("The maze doesn't have a exit (exit means goal)")

# Study the structure of the maze (We will start from here)

contents = contents.splitlines()
self.height = len(contents)
self.width = max(len(line) for line in contents)

# We want to track the walls here
self.walls = []
for i in range(self.height):
row = []
for j in range(self.width):
try:
if contents[i][j] == "A":
self.start = (i, j)
row.append(False)
elif contents[i][j] == "B":
self.goal = (i, j)
row.append(False)
elif contents[i][j] == " ":
row.append(False)
else:
row.append(True)
except IndexError:
row.append(False)

self.walls.append(row)

self.solution = None

def print(self):
solution = self.solution[1] if self.solution is not None else None
print()
for i, row in enumerate(self.walls):
for j, col in enumerate(row):
if col:
print("█", end="")
elif (i, j) == self.start:
print("A", end="")
elif (i, j) == self.goal:
print("B", end="")
elif solution is not None and (i, j) in solution:
print("*", end="")
else:
print(" ", end="")
print()
print()


def neighbors(self, state):
row, col = state
candidates = [
("up", (row - 1, col)),
("down", (row + 1, col)),
("left", (row, col-1)),
("right", (row, col+1))
]
result = []
for action, (r, c) in candidates:
if 0 <= r < self.height and 0 <= c < self.width and not self.walls[r][c]:
result.append((action, (r, c)))
return result

def solve(self):

self.num_explored = 0

start = Node(state=self.start, parent=None, action=None)
frontier = StackFrontier()
frontier.add(start)

self.explored = set()

while True:
if frontier.empty():
raise Exception("There is no solution")

node = frontier.remove()
self.num_explored += 1

if node.state == self.goal:
actions = []
cells = []

while node.parent is not None:
actions.append(node.action)
cells.append(node.state)
node = node.parent
actions.reverse()
cells.reverse()
self.solution = (actions, cells)
return
self.explored.add(node.state)

for action, state in self.neighbors(node.state):
if not frontier.contains_state(state) and state not in self.explored:
child = Node(state=state, parent=node, action=action)
frontier.add(child)

def output_image(self, filename, show_solution=True, show_explored=True):
from PIL import Image, ImageDraw
cell_size = 50
cell_border = 2

img = Image.new(
"RGBA",
(self.width * cell_size, self.height * cell_size),
"black"
)

draw = ImageDraw.Draw(img)

solution = self.solution[1] if self.solution is not None else None
for i, row in enumerate(self.walls):
for j, col in enumerate(row):
if col:
fill = (40, 40, 40)
elif(i, j) == self.start:
fill = (255, 0, 0)
elif (i, j) == self.goal:
fill = (0, 171, 28)
elif solution is not None and show_solution and (i, j) in solution:
fill = (220, 235, 113)
elif solution is not None and show_explored and (i, j) in self.explored:
fill = (212, 97, 85)
else:
fill = (237, 240, 252)

draw.rectangle(
([(j * cell_size + cell_border, i * cell_size + cell_border),
((j + 1) * cell_size - cell_border, (i + 1) * cell_size - cell_border)]),
fill = fill
)
img.save(filename)

if len(sys.argv) != 2:
sys.exit("use this command: python maze.py maze1.txt")

m = Maze(sys.argv[1])
print("This is our Maze:")
m.print()
print("Solving the maze ...")
m.solve()
print("Number of explored states: ", m.num_explored)
print("This is the Solution: ")
m.print()
m.output_image("The_Maze.png", show_explored=True)

 

Result:

We implement the maze solving algorithm in Python Language.

 


Conclusion:

In this lab work we discussed the introduction of Maze Solver, then how to solve this problem with AI. This kind of work teach how the machine decides search algorithm works in AI, How can we use AI in our daily life to make things easier? The above problem we just solved is a great example of that. To solve the search problem, we have an agent. That agent we need to make intelligent. So that it can make a decision when it encounters some difficulties to find the path. In above this discussion we with help of maze solving algorithm we can make things more easier.

 

 

Linear Programming in Artificial Intelligent ((Instructor Name: Nuruzzaman Faruqui)

  Linear Programming   Introduction: Linear Programming is the technique of portraying complicated relationships between elements by using...