-
Notifications
You must be signed in to change notification settings - Fork 47
advanced_heuristics #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mmdrez4
wants to merge
114
commits into
sut-ai:master
Choose a base branch
from
mmdrez4:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
d19410d
add Advanced Heuristics Folder
mmdrez4 6386ff3
Create matadat.yml
mmdrez4 5d71e0f
Delete notebooks/Advanced Heuristics directory
mmdrez4 a20d57d
create advanced_heuristics folder
mmdrez4 e9f818c
Create matadata.yml
mmdrez4 6e33d36
Update index.md
mmdrez4 16e60fc
Update index.md
mmdrez4 a9db3b6
Update index.md
mmdrez4 faee70f
Update index.md
mmdrez4 57da872
Update index.md
mmdrez4 980d455
Update index.md
mmdrez4 7c38aff
Update index.md
mmdrez4 5badd0d
Update index.md
mmdrez4 51630dd
add table of contents
mmdrez4 c7d6df9
Update index.md
mmdrez4 cca9b1a
Update index.md
mmdrez4 28e2cba
Update index.md
mmdrez4 8ebe58b
Update index.md
mmdrez4 7c6fb89
Update index.md
mmdrez4 d633278
Update index.md
mmdrez4 7199db1
Update index.md
mmdrez4 09d90ec
Update index.md
mmdrez4 80ed11d
Update index.md
mmdrez4 8f34660
Create index.md
mmdrez4 e37d8ab
Update index.md
mmdrez4 96a3d16
Update index.md
mmdrez4 77a7f7a
finish table of contents
mmdrez4 c2d4f2c
Update index.md
mmdrez4 166ae07
Update index.md
mmdrez4 db2d38d
Update index.md
mmdrez4 fceb3fe
Update index.md
mmdrez4 cf99738
Update index.md
mmdrez4 d2a4e6a
Update index.md
mmdrez4 356bc7d
Update index.md
mmdrez4 9109e3c
Update index.md
mmdrez4 dbcd5bc
Update index.md
mmdrez4 4ae8652
Update index.md
mmdrez4 f095d72
Update index.md
mmdrez4 0f0e75f
Update index.md
mmdrez4 9881f03
Update index.md
mmdrez4 25d72f8
Update index.md
mmdrez4 8d8dd3d
Update index.md
mmdrez4 3ea76ad
Update index.md
mmdrez4 26dbbf9
Update index.md
mmdrez4 1515cad
Update index.md
mmdrez4 5751157
Update index.md
mmdrez4 dda4753
Update index.md
mmdrez4 b642b0b
Update index.md
mmdrez4 9703ab7
Update index.md
mmdrez4 d07cb1c
Update index.md
mmdrez4 cf0a8b3
Update index.md
mmdrez4 2d7cee3
Update index.md
mmdrez4 199e89f
Update index.md
mmdrez4 1eb2286
Update index.md
mmdrez4 ae79238
Update index.md
mmdrez4 f3accb2
Update index.md
mmdrez4 4c82f09
Update index.md
mmdrez4 891787e
Update index.md
mmdrez4 bf7c69f
Update index.md
mmdrez4 97abd5c
Update index.md
mmdrez4 c464cf7
Update index.md
mmdrez4 da79457
Update index.md
mmdrez4 e15ac06
Delete consistency.png
mmdrez4 8d14d63
Add files via upload
mmdrez4 cd85258
Delete consistency.png
mmdrez4 55919c5
Add files via upload
mmdrez4 1f464fe
Update index.md
mmdrez4 9a5c21a
Update index.md
mmdrez4 8865804
Update index.md
mmdrez4 0c39611
Update index.md
mmdrez4 0c3007d
Update index.md
mmdrez4 3785787
Update index.md
mmdrez4 9b6cf09
Delete proof.png
mmdrez4 2645c60
Add files via upload
mmdrez4 73ea219
Delete proof.png
mmdrez4 78d5272
Add files via upload
mmdrez4 1741692
Add files via upload
mmdrez4 b88ceac
Update index.md
mmdrez4 fa7b75e
Update index.md
mmdrez4 248e74d
Update index.md
mmdrez4 2b85c98
Update index.md
mmdrez4 639961f
Update index.md
mmdrez4 be6e63f
Update index.md
mmdrez4 12136f5
Update index.md
mmdrez4 bea73a9
Update index.md
mmdrez4 a8aa8b9
Delete example.png
mmdrez4 4b71e98
Add files via upload
mmdrez4 4e80933
Update index.md
sepehrkianian09 80d0a50
Update index.md
mmdrez4 c9d7006
Update index.md
mmdrez4 88155ac
Update index.md
mmdrez4 11e04cf
Add files via upload
mmdrez4 0d2bc97
Update index.md
mmdrez4 615f331
Update index.md
mmdrez4 12d111a
Update index.md
mmdrez4 25afe1a
Update index.md
mmdrez4 7cec7cc
Update index.md
mmdrez4 92deefe
Update matadata.yml
mmdrez4 c066f64
Update index.md
mmdrez4 06dee17
Update index.md
mmdrez4 9bc92f8
Update index.md
mmdrez4 5453eee
Update index.md
mmdrez4 0fab07f
Update index.md
mmdrez4 a61db97
Update index.md
mmdrez4 6cb298e
Update index.md
mmdrez4 639623a
fix(index.md): Fixed my problems
sepehrkianian09 d352360
feat(index.md): Add Pattern-DB Pics
sepehrkianian09 d5c3390
feat(index.md): Add Pattern-DB pics to the note
sepehrkianian09 0dcacf0
Fix(index.md): Fix Image dimensions
sepehrkianian09 eb8baef
Update index.md
mmdrez4 51b316b
Update index.md
sepehrkianian09 70d27a2
fix(adv_heuristics): final Fix of Sep_parts
sepehrkianian09 202f9e7
fix(adv_heuristics): Fix final parts of Sep
sepehrkianian09 8ec8e00
fix(adv_heuristics): Fix final parts of Sep
sepehrkianian09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # Advanced Heuristic | ||
| #### Kahbod Aeini, Mohammadreza Daviran and Sepehr Kianian | ||
|
|
||
| First we review some basic definitions | ||
|
|
||
| Distance is a numerical measurement of how far apart objects or points are: | ||
| * [Euclidean Distance](https://en.wikipedia.org/wiki/Euclidean_distance) calculates the distance between two real-valued vectors. | ||
| * [Manhattan Distance](https://en.wikipedia.org/wiki/Taxicab_geometry) is sum of the absolute differences of their Cartesian coordinates. | ||
| <p align="center"> | ||
| <img src="distance.png" alt="distance" width="400" height="300"/> | ||
| </p> | ||
| * Heuristic guidance means how far is the goal state from a given state approximately. | ||
|
|
||
| ***Admissiblity of a heuristic function means value of the function is always a Lower Bound of the remaining cost.*** | ||
|
|
||
| So an **Admissible Heuristic** is a *non-negative* function h of nodes, where **h(n)** is *never greater than the actual cost of the shortest path from node n to a goal.* thus it means that the cost to reach the goal is never overestimated. | ||
|
|
||
| Effect of **Admissibility** on a Heuristic is shown in the below schema: | ||
| <p align="center"> | ||
| <img src="admissible.png" alt="admissible" width="600" height="300"/> | ||
| </p> | ||
|
|
||
| Now we define **f(n)** function as **f(n) = h(n) + g(n)** where g(n) is sum of costs from root to n node. | ||
|
|
||
| ***Monotonicity or Consistency is that the heuristic function holds in triangle inequality.*** Namely **f(n) is never Decreasing.** | ||
| <p align="center"> | ||
| <img src="consistency.png" alt="consistency" width="600" height="300"/> | ||
| </p> | ||
|
|
||
|
|
||
| Effect of **Monotonicity** on a Heuristic is shown in the below schema: | ||
| <p align="center"> | ||
| <img src="monotonic.png" alt="monotonic" width="600" height="300"/> | ||
| </p> | ||
|
|
||
| We will prove that **Consistency** implies **Admissibility** whereas the opposite is not necessarily true. | ||
| <p align="center"> | ||
| <img src="proof.png" alt="proof" width="800" height="300"/> | ||
| </p> | ||
|
|
||
| Now we want to show an **inconsistent, admissible example!** | ||
| So consider this figure: | ||
|
|
||
| <p align="center"> | ||
| <img src="example.png" alt="example"/> | ||
| </p> | ||
|
|
||
| If our heuristic is admissible, we have that **h(n) $\le$ h*(n)** for every node n where **h*** is the real cost to the goal. So we deduct that **h(A) $\le$ 4**, **h(C) $\le$ 3** and **h(G) $\le$ 0**. | ||
|
|
||
| If we want our heuristic to be *Consistent* we should have **h(G) = 0** and **h(n) $\le$ cost(n, c) + h(c)** so in our case we have **h(A) $\le$ 1 + h(C)** and **h(C) $\le$ 3 + h(G) = 3** | ||
|
|
||
| Because of the *Admissibility* **h(C) should be less than 3**, but if **h(A) > 1 + h(C)** then our heuristic is *Inconsistent!*. Hence if we assume that **h(C) = 1**, **h(G) = 0** and **h(A) = 4** our heuristic is *Admissible but Inconsistent!* | ||
|
|
||
|
|
||
| We also can make a non-monotonic heuristic, monotonic with some changes! | ||
| For this we only need to define a new and more appropriate heuristic like the below schema. | ||
| <p align="center"> | ||
| <img src="c.png" alt="new heuristic" width="500" height="150"/> | ||
| </p> | ||
|
|
||
|
|
||
|
|
||
| **$\overline{h}$(n’) = max(h(n’), ℏ(n’) - c(n, a, n’))** | ||
mmdrez4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Above Heuristic is defined Recursively. | ||
| <p align="center"> | ||
| <img src="heuristic proof.png" alt="heuristic proof" width="400" height="300"/> | ||
| </p> | ||
|
|
||
| **$\overline{h}$(n’) $\ge$ $\overline{h}$(n) - c(n, a, n')** | ||
|
|
||
| So obviously we have **$\overline{h}$(n’) + c(n, a, n') $\ge$ $\overline{h}$(n)** | ||
|
|
||
| ***Heuristic Dominance*** | ||
|
|
||
| For one heuristic to dominate another, all of its values must be greater than or equal to the corresponding values of the other heuristic. | ||
| So if $h_{2}$ dominates $h_{1}$(both are admissible) it means that A* algorithm expands less nodes with $h_{2}$ in the target path than $h_{1}$. | ||
| On another hand it means if a node is expanded by $h_{2}$ it will be expanded by $h_{1}$(consider that it’s not a biconditional proposition!) | ||
|
|
||
| *Proof:* | ||
|
|
||
| If $h_{2}$ dominate $h_{1}$, A* with $h_{2}$ expands at most the same number of nodes as when using $h_{1}$. | ||
|
|
||
| A* opens all node with **f(n) < C** and some with **f(n) = C**. | ||
|
|
||
|
|
||
| Note that | ||
| **$h_{2}(n)$ | ||
| $\ge$ | ||
| $h_{1}(n)$** | ||
|
|
||
| If node n is expanded by A* with $h_{2}$ then **$h_{2}(n)$ < C - g(n)** | ||
|
|
||
| So ***$h_{1}(n)$ $\le$ $h_{2}(n)$ < C - g(n)*** and it would be expanded by A* with $h_{1}$ as well. | ||
|
|
||
| We also can improve our heuristic by some methods. | ||
|
|
||
| We are always trying to lower the difference between h* and h, expanded nodes and algorithm time complexity by making change in our heuristic. | ||
|
|
||
| One of the main ways for improving heuristics is **Relaxing** the problem. | ||
|
|
||
| In this procedure we try to enlarge the feasible answers set by simplifying the problem. | ||
|
|
||
| <hr style="border:2px solid gray"> </hr> | ||
|
|
||
| ***Relaxing*** | ||
|
|
||
| One of the most common ways to find efficient heuristic function is that we convert our hard problem which is indissoluble in reasonable time, to a *more general problem with larger state space*. | ||
|
|
||
| Discussing more specifically, original problem has a set of constraints. Noe we **ignore some constraints** and solve the expanded problem. Since number of constraints have decreased, we have more goal states and our state space expands. | ||
|
|
||
| ***Proof that Relaxing works*** | ||
|
|
||
| Consider h as the answer and h' as our heuristic | ||
|
|
||
| h' = min(S'), h = min(S) $\Lambda$ S $\subseteq$ S' $\Lambda$ $\forall$ s, s' if s $\subseteq$ s' => $min(s') \le min(s)$ => $h' \le h$ | ||
|
|
||
| ***Example*** | ||
|
|
||
| In below problem, which is an NP-hard problem (indissoluble in linear time), we want to find the Hamiltonian path with least weight. | ||
|
|
||
| <p align="center"> | ||
| <img src="hamilton path.png" alt="hamilton path" width="500" height="300"/> | ||
| </p> | ||
|
|
||
| Hamilton path is a tree which every its inner node have exactly one leaf. Hence, the problem is converting above graph to a 1-array tree, which covers all nodes of the graph with existing edges and minimum sum of edges' weight. Now we ignore being 1-array tree constraint to convert original problem to a more general one. Accordingly our problem is now a Minimum Spaning Tree problem which is soluable in $n^{2}$ time complexity. | ||
|
|
||
| ***Pattern DB*** | ||
sepehrAmini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| In previous sectionwe introduced relaxing method which improves heuristic function by lowering constraints. Pattern DB is yet another way to improve heuristic function which is actually a subset of Relaxing method. | ||
|
|
||
| In this method we choose a subset of constraints by a specific pattern and ignore the other constraints. Since we ignored some constraints we did relaxing method and hence answer of the converted problem is a heuristic gfunction. | ||
sepehrAmini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ***Combining Pattern DB*** | ||
|
|
||
| We can act further and use couple of patterns and choose couple of constraints' subsets. Therefore we have couple of heuristic functions. This helps dominancy of our heuristic function. First thing to do finding the dominant heuristic function is to choose the maximum function of the obtained heuristic functions. Since every heuristic is always less than the real answer, maximum of these functions is a lower bound of the real answer and for every set of obtained heuristic functions we can implement this method to find a dominant heuristic function. | ||
sepehrAmini marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ***Disjoint Pattern DB*** | ||
|
|
||
| One of the main flaws of choosing maximum of the obtained heuristic functions is that in many cases, there is an upper bound for these functions. Therefore even by expanding subset of chosen constraints, we will not cross the upper bound. | ||
|
|
||
| One solution for solving this drawback is Disjoint Pattern DB. In this method we apport set of constraints and define independent actions for the general problem. Now we can sum the obtained heuristic function to achieve a greater heuristic function, which improves the time complexity. It is proven that the sum of obtained heuristic functions is still a lower bound of real answer of the probelm. | ||
|
|
||
| **Example** | ||
|
|
||
| First practical problem of the first mini project of the course is an example of this method. In this problm we have an undirected graph, which each of its nodes is a florist shop and has some flower breeds. Two brothers should march from start_node towards goal_node in a way that has the least cost and they met every existing flower breeds. In this case we choose a subset of flower breeds S that reach goal_node by a specific pattern and set goal_state as satisfying path with the least cost and meeting every existing flower breeds of set S. Hitherto we used pure Pattern DB. | ||
|
|
||
| Now we can have souple of flower breeds subset and combine obtained answers by them. For example if we have K flower breeds, we can solve the problem for each flower breed and calculate its heuristic function and then choose maximum of the functions. So we used Combining Pattern DB to achieve a better heuristic function. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.