What is Heuristic in AI | Why we use Heuristic | How to Calculate Heuristic | Must Watch

Gate Smashers
12 Dec 201912:57

Summary

TLDRIn this video, the concept of heuristic functions in artificial intelligence is explored, explaining their role in making educated guesses to find quick solutions. The script delves into why heuristics are used, particularly in solving complex problems with exponential time complexity, such as in puzzles like the 8 puzzle, and games like chess. It also covers various methods to calculate heuristic values, including Euclidean and Manhattan distances, and the number of misplaced tiles, emphasizing that while heuristics ensure good solutions, they do not guarantee optimal ones. The video is a guide for those interested in AI search techniques, aiming to convert NP problems into more manageable polynomial time solutions.

Takeaways

  • 🧠 **Heuristic Definition**: A heuristic in AI is a technique for making educated guesses or finding quick solutions to problems.
  • πŸ” **Purpose of Heuristics**: Heuristics are used to simplify the search process in AI by making assumptions to find solutions more efficiently.
  • πŸ”„ **Problem with Uninformed Search**: Uninformed search methods can lead to exponential time complexity, making them impractical for large problems.
  • πŸ“ˆ **Exponential Growth Issue**: The time complexity in problems like the 8-puzzle grows exponentially, leading to a vast search space with billions of possible states.
  • 🏹 **Heuristic Advantage**: Heuristics can help in quickly finding good solutions by guiding the search towards more promising paths based on heuristic values.
  • 🎯 **Non-Optimality of Heuristics**: While heuristics guarantee good solutions, they do not always ensure the optimal solution due to their nature of making assumptions.
  • πŸ›£οΈ **Heuristic Methods**: Methods like Euclidean distance, Manhattan distance, and counting misplaced tiles are used to calculate heuristic values.
  • πŸ“š **Euclidean Distance**: The straight-line distance between points, used as a heuristic to estimate the minimum distance to the goal.
  • 🚢 **Manhattan Distance**: A heuristic used in grid-based problems like the 8-puzzle, calculating the sum of the horizontal and vertical distances to the goal.
  • πŸ”’ **Misplaced Tiles Count**: A heuristic method that counts the number of tiles not in their goal positions to estimate the distance to the solution.
  • πŸ”§ **Heuristic Use Cases**: Heuristics are particularly useful when a quick solution is needed, and when converting NP problems into more manageable polynomial time complexity.
  • πŸ› οΈ **Informed Search Techniques**: Heuristics are a part of informed search techniques, which use additional information, like heuristic values, to guide the search process.

Q & A

  • What is a heuristic function in artificial intelligence?

    -A heuristic function in AI is a technique designed to solve a problem quickly by making assumptions and finding a quick solution or a 'rule of thumb' to guide the search towards a good solution, although it may not always be the optimal one.

  • Why are heuristic values used in artificial intelligence?

    -Heuristic values are used to reduce the time complexity of solving problems, especially in cases where the search space is exponentially large, by guiding the search towards promising paths and avoiding blind search through all possible states.

  • What is the difference between informed and uninformed search in AI?

    -Informed search uses heuristic information to guide the search process, making it more efficient, while uninformed search, also known as blind search, explores all possible states without any guidance, which can be time-consuming and inefficient for large search spaces.

  • What is the time complexity of an uninformed search in the worst case for an 8 puzzle problem?

    -The worst-case time complexity for an uninformed search in an 8 puzzle problem is O(b^d), where b is the branching factor and d is the depth of the search space, approximately 3^20 states.

  • What is the significance of heuristic functions in solving NP problems?

    -Heuristic functions help in solving NP (non-polynomial) problems by reducing the search time from exponential to polynomial, thus providing quick solutions, although not necessarily the optimal ones.

  • How does a heuristic function differ from a greedy method?

    -While both heuristic functions and greedy methods aim to find good solutions quickly, heuristic functions provide a way to estimate the cost to reach the goal state and guide the search, whereas greedy methods simply choose the most promising option at each step without considering the overall path.

  • What is Euclidean distance and how is it used in calculating heuristic values?

    -Euclidean distance is the straight-line distance between two points in a plane, calculated using the formula \(\sqrt{(X2 - X1)^2 + (Y2 - Y1)^2}\). It is used in heuristic calculations to estimate the minimum distance to the goal state.

  • What is Manhattan distance and how does it relate to the 8 puzzle problem?

    -Manhattan distance is the sum of the absolute differences of their Cartesian coordinates, representing the distance a person would travel on a grid of streets (like in Manhattan). It is used in the 8 puzzle problem to calculate the heuristic value based on the number of moves needed to align tiles vertically or horizontally to their correct positions.

  • What is the concept of 'misplaced tiles' in the context of the 8 puzzle problem?

    -In the context of the 8 puzzle problem, 'misplaced tiles' refers to the count of tiles that are not in their correct positions in the goal state. This count is used as a heuristic to estimate how far the current state is from the goal state.

  • Why might a heuristic not always guarantee an optimal solution?

    -A heuristic does not always guarantee an optimal solution because it is based on assumptions and estimations that simplify the search process. There may be scenarios or obstacles not accounted for in the heuristic that could lead to a suboptimal path being chosen.

  • What are some common informed search techniques that use heuristic values?

    -Some common informed search techniques that use heuristic values include Heuristic DFS, Heuristic BFS, Hill Climbing, and the A* algorithm, which are designed to find good solutions more efficiently than uninformed search methods.

Outlines

00:00

🧠 Introduction to Heuristics in AI

This paragraph introduces the concept of heuristics in artificial intelligence, explaining it as a method to make quick assumptions or find a quick solution to a problem. The speaker uses the analogy of solving mathematical problems with assumptions to illustrate the point. Heuristics are presented as a technique to solve problems efficiently, especially in the context of AI where the search space can grow exponentially. The paragraph also touches on the limitations of blind search methods and the exponential time complexity they can incur, such as in the 8-puzzle and chess, highlighting the need for heuristics to find good solutions more quickly, even if they may not always be optimal.

05:06

πŸ›  Heuristic Functions and Informed Search Techniques

The second paragraph delves into the use of heuristic functions and values in informed search techniques, which guide the search process towards a good solution more quickly. It explains that heuristic values are not guaranteed to find the optimal solution but are useful for finding good solutions in a reasonable time frame. The paragraph introduces different methods for calculating heuristic values, such as Euclidean distance, Manhattan distance, and the number of misplaced tiles, using examples like the 8-puzzle to illustrate how these methods work. It emphasizes the efficiency of these methods in reducing the search space and improving the time complexity compared to blind search.

10:07

πŸš€ Applications and Limitations of Heuristics

The final paragraph discusses the practical applications of heuristics, explaining why they are used and their limitations. It points out that heuristics are particularly useful when a quick solution is needed and when attempting to solve non-polynomial problems in polynomial time. The speaker uses real-life scenarios to illustrate that while heuristics can guide towards a good solution, they do not always guarantee the optimal one due to unforeseen obstacles. The paragraph concludes by emphasizing the role of heuristics in informed search algorithms like A* and other optimization techniques, acknowledging their importance in finding good solutions efficiently.

Mindmap

Keywords

πŸ’‘Heuristic function

A heuristic function is a method used in artificial intelligence to estimate the cost or effort required to reach a goal state from a given state. It plays a crucial role in informed search algorithms, helping to guide the search towards the most promising paths. In the video, the heuristic function is discussed as a means to quickly find a solution to a problem, often sacrificing the guarantee of finding the optimal solution for the sake of efficiency.

πŸ’‘Heuristic value

The heuristic value represents an estimate of the distance or cost from the current state to the goal state in a problem-solving context. It is used to prioritize different paths or states in search algorithms. The script explains that heuristic values help in making assumptions and quick decisions, as seen in the examples of the 8 puzzle and the discussion of different methods to calculate heuristic values.

πŸ’‘Artificial Intelligence (AI)

Artificial Intelligence refers to the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. The video's theme revolves around the use of heuristics in AI, particularly in problem-solving scenarios where AI must make decisions or find solutions efficiently. AI is the broader field within which heuristic functions and values are applied.

πŸ’‘Uninformed search

Uninformed search, also known as blind search, is a search method that explores possible solutions without any domain-specific knowledge. The script mentions uninformed search in the context of exploring all possible states in a problem space, which can lead to exponential time complexity, highlighting the inefficiency compared to informed search methods that use heuristics.

πŸ’‘Informed search

Informed search is a type of search algorithm that uses additional information, such as heuristic values, to guide the search process towards the goal more efficiently. The video explains that informed search techniques, aided by heuristic values, can significantly reduce the time complexity compared to uninformed search, making them suitable for solving complex problems more quickly.

πŸ’‘Euclidean distance

Euclidean distance is a measure of the straight-line distance between two points in Euclidean space. In the context of the video, it is used as a method to calculate the heuristic value by estimating the direct distance from the current state to the goal state. The script provides an example of how Euclidean distance can be used to quickly determine the path of least resistance in problem-solving.

πŸ’‘Manhattan distance

Manhattan distance is the distance between two points in a grid-based system, based on the sum of the absolute differences of their Cartesian coordinates. The video script uses the Manhattan distance as an example of how to calculate the heuristic value for the 8 puzzle problem, emphasizing its use in estimating the minimum number of moves to reach the goal state.

πŸ’‘Misplaced tiles

In the context of the 8 puzzle problem discussed in the video, misplaced tiles refer to the tiles that are not in their correct positions in the goal state. The number of misplaced tiles is used as a heuristic to estimate the effort required to solve the puzzle, with fewer misplaced tiles indicating a closer proximity to the goal state.

πŸ’‘NP problems

NP, short for Non-deterministic Polynomial time, refers to a class of problems in computational complexity theory that are at least as hard as the hardest problems in NP. The script mentions NP problems to illustrate the challenges of finding optimal solutions in polynomial time, and how heuristics can be used to find good solutions more quickly, even if they are not guaranteed to be optimal.

πŸ’‘A* algorithm

The A* algorithm is a popular informed search algorithm that combines the benefits of Dijkstra's algorithm (for finding the shortest path) with a heuristic to estimate the cost to the goal. The video script highlights the A* algorithm as an important technique that utilizes heuristic functions to efficiently navigate through large search spaces and find solutions in a more time-effective manner.

Highlights

Heuristic functions in AI are used to make assumptions and find quick solutions.

In mathematics, heuristics can simplify problem-solving by making initial assumptions, like setting variables to 100.

Heuristics in AI are techniques designed for quick problem-solving, contrasting with uninformed search methods.

Uninformed search can lead to exponential time complexity, making it inefficient for large problems like the 8-puzzle.

The 8-puzzle problem illustrates the exponential growth of search space, with up to 3^20 possible states.

For larger puzzles like the 15-puzzle, the search space can reach up to 10^13 states, showing the scalability issue.

In chess, the search space can grow up to 35^80 due to a high branch factor and depth, highlighting the need for heuristics.

Heuristic functions help in finding good solutions quickly without guaranteeing the optimal solution.

Heuristics reduce time complexity by guiding the search towards paths with the best heuristic values.

Informed search techniques use heuristic values as a guide to efficiently navigate the search space.

Heuristic values can be calculated using methods like Euclidean distance, Manhattan distance, and counting misplaced tiles.

Euclidean distance is used to calculate the straight-line distance between nodes in a search space.

Manhattan distance calculates the sum of the absolute differences in each dimension, useful in grid-based puzzles.

Counting misplaced tiles is a method to estimate the distance to the goal state by counting incorrectly positioned elements.

Heuristics provide a good solution but do not guarantee the optimal solution due to the potential presence of obstacles.

Heuristics are particularly useful when a quick solution is needed, and the conversion from NP to polynomial time is desired.

Informed search algorithms like A* utilize heuristics to improve search efficiency over uninformed or brute force methods.

Transcripts

play00:00

Hello friends, welcome to Gate Smashers

play00:02

In today's video we are going to discuss

play00:04

What is heuristic function

play00:07

Heuristic value in artificial intelligence

play00:09

Why we use heuristic

play00:10

And how to calculate the heuristic value

play00:14

In artificial intelligence you will get many topics

play00:18

Where we use heuristic values and heuristic functions

play00:20

So guys in this video we are going to discuss all 3 points

play00:23

What why and how

play00:26

So guys quickly like the video

play00:28

And subscribe the channel if you have still not done

play00:30

Please press the bell button

play00:31

So that you can get all the latest notifications

play00:34

So first of all we will start with what is heuristic in artificial intelligence

play00:38

Simple meaning of heuristic is

play00:40

Making assumption for anything

play00:42

That means we are trying to guess or we are trying to find a quick solution

play00:48

If talk other then artificial intelligence

play00:50

As we solve questions in normal mathematics

play00:53

That cost price is given to you

play00:55

Or the cost price is twice the selling price

play00:58

These type of questions comes or many times question comes like

play01:01

This is the simple interest then find out what will be the principal amount

play01:06

If this much time is given to you

play01:08

So generally how do we solve these type of questions

play01:10

What we do to solve these questions

play01:12

Let X=100

play01:15

That means let cost price be this

play01:17

Or let principle be this

play01:19

So it is actually helping us

play01:22

To find out the answer quickly

play01:24

You can do it without that also

play01:26

But somewhere it is helping us in finding the answers quickly

play01:30

So in artificial intelligence we use heuristic

play01:34

So it is a technique designed to solve a problem quickly

play01:38

As we discuss about informed and uninformed search in last video

play01:43

So what are we in telling in uninformed

play01:45

We are doing blind search

play01:46

We are going in all the state spaces of the problem

play01:50

And the state which match is our goal state

play01:54

Then our search will stop

play01:57

But due to that what is the problem

play02:00

Our problem what is given actually in the question

play02:04

That problem is growing exponentially time

play02:08

Our time can be exponential time

play02:12

If we talk about 8 puzzle problem

play02:14

Simple about 8 puzzle problem also

play02:16

So if you do it in blind search way

play02:19

Then in worst case how much actually it can go

play02:22

Time complexity is O(b^d)

play02:25

In case of uninformed

play02:27

Or 3^20

play02:30

Approximate 3^20

play02:32

Search space is possible

play02:34

If you will search and compare these many states

play02:39

Then obviously time complexity will increase

play02:41

Because around 3- 3.4 billion state are created

play02:47

If instead of 8 puzzle you take 15 puzzle

play02:51

Although in 15 puzzle you have only 4 moves

play02:54

Up down left and right

play02:55

Even after that 10^13 search space are possible

play03:02

And if you take 24 puzzle

play03:05

Then in that 10^24 states are possible

play03:09

So if such a huge number is there

play03:12

So somewhere a time complexity is growing exponential time

play03:17

In case you are taking some big game

play03:19

If you are taking chess then the branch factor in chess

play03:21

The value of b can be up to 35

play03:24

And the value of d can grow up to 80 or 90

play03:27

Then 35^80

play03:29

That is a very huge number

play03:31

So if you want to calculate these values

play03:34

What do we call these type of problems

play03:36

NP that is non polynomial problem

play03:40

And obviously in non polynomial over time complexity is exponential

play03:45

In this we have one advantage

play03:47

It will definitely give optimal solution

play03:49

So I want that this much time should not be used

play03:53

We want to find out a quick solution

play03:55

Or we also call it as rule of thumb

play03:58

That means that we are finding out a solution

play04:00

With a greedy method

play04:02

We are finding the best method

play04:04

So due to that my time

play04:06

That time is reduced

play04:09

Because this finds out with which way?

play04:11

It finds out that you have multiple solutions

play04:14

Instead of exploring all the solutions

play04:17

The one which is the best whoes heuristic value is the best

play04:20

You go on that method

play04:23

That means if we have these much solutions

play04:24

Let's say it's heuristic value is 10

play04:26

And its heuristic value is 15

play04:28

Then the value which is less

play04:30

Generally if we talk in the way of distance or time

play04:32

Then we generally talk that the lower number is best for us

play04:36

Then lower the number if its cost is less

play04:38

Then what we will do we will move towards this side

play04:41

That means we will not explore this side

play04:44

In worst case it is possible that I have to do on this side also

play04:46

But generally what we do

play04:48

Because heuristic functions

play04:50

That gives us guarantee that it will provide us good solutions

play04:54

But optimal solution may come or may not come

play04:56

This is not guaranteed

play04:58

It can come also and it may not come also

play04:59

Wherever we want to solve non polynomial problem in polynomial time

play05:05

We want to solve it quickly

play05:06

Over there we use heuristic functions

play05:10

Or heuristic value

play05:12

And generally over here all the informed search techniques

play05:17

In that we say what is the meaning of informed search

play05:20

We have a guide

play05:21

We have an information

play05:22

What is the information actually

play05:24

Heuristic value

play05:26

This is the concept actually

play05:28

Why do we use euro stock value so that we can find out quickly

play05:31

We know that good solution will come

play05:33

But optimal solution can come and even it cannot come

play05:37

And how do we calculate

play05:39

That how do we calculate heuristic value

play05:42

There are different methods for it

play05:44

Like one method is

play05:49

Euclidean distance

play05:51

That is called a straight line distance if you want to find out

play05:54

Let's say if you have One node

play05:57

You have a start node

play05:58

Let's say this is your goal state

play06:00

You consider it as a city

play06:02

If this is your start state

play06:04

This is your goal state

play06:05

Let's say to go till goal state

play06:08

You have these 3 different states

play06:11

Other than these there can be other also

play06:13

What you want to reach at goal state

play06:17

In minimum cost

play06:18

If you want to reach earliest

play06:20

Then obviously how will you find out

play06:21

What is the best method for you

play06:23

That you find out the distance

play06:26

It is called a straight line distance

play06:27

Which we call as Euclidian distance

play06:28

So what we do to find this out

play06:31

This is X1 and Y1

play06:33

These are its coordinates X2 and Y2

play06:35

Then we will do ((X2 - X1)^2 +(Y2-Y1)^2)^2

play06:42

Show over here we are taking square root of whole

play06:46

So if you find out the distance

play06:48

Obviously you will come to know that this is the minimum distance

play06:52

Because this distance you can come to know by seeing only that it is more

play06:55

But this distance will be less

play06:58

So obviously instead of exploring them

play07:01

You will directly go in this path

play07:03

So you don't have to explore multiple path

play07:07

But in blind search you have to go over here also

play07:09

Over here also over here also

play07:11

So obviously your complexity will go on increasing

play07:14

Or we use Manhattan distance

play07:18

We use Manhattan distance basically if we want to find out vertical and horizontal distance

play07:24

Like if you take example of 8 puzzle problem

play07:27

In 8 puzzle problem let's say we have

play07:31

Start state is given

play07:34

Goal state is given

play07:36

This is our start state

play07:38

And lets say this is our goal state

play07:40

In goal state we want 1 2 3

play07:42

4 5 6

play07:44

7 8

play07:45

And this is empty

play07:47

And lets say you take start state as 1

play07:49

3 2

play07:50

5 6 4

play07:53

8

play07:54

7

play07:55

Anything

play07:55

Your start state can be any

play07:57

So if you want to go from start state to goal state

play08:00

So as I told in 8 puzzle

play08:02

If you do blind search

play08:03

Then there are 3^20 possible search space

play08:06

Then you will get an final optimal answer

play08:09

And you will achieve goal state

play08:11

But if we want to calculate heuristic value over here

play08:14

Then I can find it out with the help of Manhattan distance

play08:18

What is the meaning of Manhattan distance

play08:19

That you calculate the distance

play08:22

For example one is there is one on its right position

play08:24

According to the goal state

play08:26

It is on the right position

play08:27

So that means how many movements you will have to do

play08:29

Vertically or horizontally how many movements you have

play08:31

You don't have to do any movement

play08:32

One is at its place

play08:34

Look at 2

play08:35

Actually 2 should be over here

play08:36

Because it is over here in the goal state

play08:37

But 2 is over here

play08:39

So if you will move this one left side

play08:41

Then obviously it will come on it's right position

play08:44

That means how much distance you have to cover? 1

play08:47

In the same way let's say 3

play08:49

3 is over here but you want it should reach over here

play08:52

This is your goal state

play08:53

So obviously if we will move one

play08:55

Then it will reach at its right position

play08:58

Look at 4

play08:58

4 is over here

play09:00

And in this case it is over here

play09:01

So if you will move this two position left

play09:04

If you move it horizontally 2 towards left

play09:07

Then it will reach at its right position

play09:08

So its distances 2

play09:10

5 is on the right position so zero

play09:12

Sixes over here for that you will have to do 2 right

play09:17

So add 2 in this

play09:18

Plus 7

play09:19

For 7 you will have to move 2

play09:22

8

play09:23

8 is already on the right position

play09:25

So this will be your Manhattan distance

play09:27

So now multiple states when you will explore this

play09:31

When you will move this empty space towards up on the left side

play09:35

The multiple branches that will be formed

play09:36

You find out from that multiple branches whose heuristic value

play09:41

Whose Manhattan distance is less so you follow that path

play09:44

This is one of your method

play09:45

Or we can also use one more method in this

play09:48

If you calculate number of misplaced tiles

play09:52

Let's say over here 1 is at its right position? Yes

play09:54

2 is there? No it not

play09:56

So 1 will come

play09:58

You have to find the number of misplaced tiles

play10:01

So look over here is 3 at its right position ? No

play10:04

Is 2 is not at its right position, so 2

play10:06

1 is at its right position so it is okay

play10:08

4 is at it's right position? No

play10:10

3

play10:10

5 is there? Yes

play10:12

6 is at right position? No

play10:13

4 are there

play10:14

7

play10:15

7 is at right position? No

play10:16

5 are there

play10:17

8 is on right position? Yes it is at right position

play10:20

That means total misplaced tiles are 5

play10:24

When you will convert it into branches and make multiple branches

play10:28

Then you find the misplaced

play10:30

In which there are less number of misplaced

play10:33

You explored that path

play10:35

So that in less time and cost

play10:37

You will get your solution

play10:40

There are multiple ways it depends on the solution

play10:42

Like we can use Elucedian distance

play10:44

We can use Manhattan distance

play10:46

Or we can use number of misplaced tiles

play10:49

So with these methods we are making an assumption

play10:52

We are calculating heuristic values

play10:54

Or you can say that like rule of thumb

play10:56

That I will go towards this way

play10:58

Because it is taking me to the minimum path

play11:00

But I want to tell last point over here

play11:03

We have discussed what is this why we use and how

play11:06

But always remember in heuristic

play11:09

It always gives the guarantee

play11:11

To find the good solution

play11:14

But it does not give the guarantee

play11:16

To find the optimal solution

play11:19

Blind search will give optimal

play11:22

Greedy will give you optimal or not it is not guaranteed

play11:26

Yes it gives guarantee of good solution

play11:28

See with a simple example

play11:29

As we had calculated Eucledian distance over here

play11:32

Obviously you will follow this path only

play11:34

Because the distance of this as compared to all the other is less

play11:39

But if you consider this in real life scenario

play11:42

You are going from one place to another

play11:44

Then there will be very rare chances that you will get a straight line

play11:48

Or you will get state path

play11:50

Let's say you started following this path

play11:52

And in future you came to know

play11:54

That over here mountain is there

play11:56

Let's suppose if there is any obstacle over here

play11:59

Mountain is there so obviously what will happen

play12:01

You will go over here and follow the path this way

play12:04

So what is better it is possible that this path

play12:07

Or this path can take you in minimum distance

play12:11

These are the methods

play12:13

That is why it does not give guarantee to find optimal

play12:14

Yes it gives guarantee of good solution

play12:16

So mainly when is heuristic used

play12:19

Or why should we use

play12:20

When we want the solution quickly

play12:23

When we want to convert it from NP to polynomial time

play12:27

Yes in worst case this can also go to non polynomial

play12:30

But in normal average or best case

play12:33

It will perform better

play12:34

Better in terms of time as compared to the blind search

play12:38

Or what we call as brute force method

play12:40

Or which we called as uninformed search

play12:42

So informed search we use heuristic

play12:45

In which heuristic DFS heuristic BFS hill climbing is there

play12:49

A* algorithm which is very important

play12:51

We discuss all these algorithms

play12:54

Thank you

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Heuristic FunctionsArtificial IntelligenceProblem SolvingAI TechniquesSearch AlgorithmsHeuristic ValueInformed SearchUninformed SearchEuclidean DistanceManhattan DistanceAI Optimization