What is the difference between Hill Climbing Search and Best First Search? - algorithm

I am trying to learn some search concepts but ran into a wall in the process. Can anyone explain to me what the difference is between hill climbing search and best first search? To me, they both look like expanding the nodes with the heuristic value closest to the goal. If anyone can explain the difference to me, it'd be greatly appreciated. Thanks!

You can view search algorithm as having a queue of remaining nodes to search. This answer demonstrates this principle.
In depth-first search, you add the current node's children to the front of the queue (a stack). In breadth-first search, you add the current node's children to the back of the queue. Think for a moment about how this leads to the right behaviour for those algorithms.
Now, in hill-climbing search, you sort[1] the current node's children before adding them to the queue. In best-first search, you add the current node's children to the queue in any old order, then sort[1] the entire queue. If you think about the effect that might have on the order in which nodes are searched, you should get an idea of the practical difference.
I found this concept too tangly to understand from purely abstract terms, but if you work through a couple of examples with a pencil it becomes simple.
[1]: sort according to some problem-specific evaluation of the solution node, for example "distance from destination" in a path-finding search.

A liitle late, but here goes.
In BFS, it's about finding the goal. So it's about picking the best node (the one which we hope will take us to the goal) among the possible ones. We keep trying to go towards the goal.
But in hill climbing, it's about maximizing the target function. We pick the node which provides the highest ascent. So unlike BFS, the 'value' of the parent node is also taken into account. If we can't go higher, we just give up. In that case we may not even reach the goal. We might be at a local maxima.

The difference lies in understanding what is more concerned in searching for the goal state.
Ask the question what is our aim...
the final goal state?
or the Best path to reach the goal state
The Best First Search is a systematic search algorithm where systematicity is achieved by moving forward iteratively on the basis of finding out the
best heuristic value for the adjacent nodes for every current node.
Here the evaluation function ( heuristic function ) calculates the
best possible path to achieve the goal state. So here we could see the Best First search is concerned about the best PATH to reach to the goal state.
However there are many problems where "Path to the Goal" is not a concern, the only thing is concerned is to achieve the final state in any possible ways or paths.
(For eg: 8-queens problem).
Hence for this local search algorithms are used.
Local search algorithms operate using a single current node and generally move only to neighbor of that node.
Hill Climbing algorithm is a local search algorithm.
So here we need to understand the approach to get to the goal state not the best path to reach when thinking about hill climbing.
(As stated in AI-A Modern Approach,SR & PN)
Basically, to understand local search we need to consider state-space landscape.
A landscape has both
(i) location (defined by the state) and
(ii) Elevation (defined by the value of heuristic function or objective function)
We need to understand the two types of elevations,
(i) If elevation corresponds to an objective function,then the aim is to find the highest peak i.e. a Global Maximum.
(So these type of elevation are useful in different scenarios which are not concerned with cost and which are only concerned with finding the best instant moves)
(ii) If elevation corresponds to cost, then the aim is to find the lowest valley i.e. a Global Minimum.
(Here is the common thing i.e. Steepest(always stepping up with better estimations i.e. no plateau problem or any other) hill climbing is similar to Best First Search. Here the elevation function is the heuristic function which provide the best minimum cost. And hill climbing here is only concerned with current node and iterates through the adjacent nodes for minimum value and proceeds with expanding the best node which is similar to Best First Search)
Note:
Hill Climbing algorithm does not look ahead beyond the immediate neighbors of the current state. It is only concerned with best neighboring node to expand.And the best neighboring is decided by the above evaluations functions.
Whereas, Best First Search algorithm look ahead of the immediate neighbors to find the best path to the goal(using Heuristic evaluation) and then proceeding with the best one.
So difference lies in approach of local searches and systematic search algorithms.
Understand the difference in approaches, you will get to know why both are named different.

Let me Wiki that for you:
In simple hill climbing, the first
closer node is chosen, whereas in
steepest ascent hill climbing all
successors are compared and the
closest to the solution is chosen.
...
Steepest ascent
hill climbing is similar to best-first
search, which tries all possible
extensions of the current path instead
of only one.

So Basically Steepest HC in the second step itself gets the answer to the problem as it's second move will be the most optimal solution and leading to the answer

Related

A* Algorithm with know Costs

I'm working on the A* Algorithm.
I have these questions:
Is it possible to use different heuristics in the same search process? For some nodes I have the actual cost from each of these nodes to the end node. Can I use this cost as the heuristic for these nodes, while for the other nodes (for which I don't know the cost to end node) I calculate the heuristics using Euclidean or other metrics? I tried this, but the algorithm couldn't find the End Node!!!
I have a part of search space that is searched using A*. The search space has been increased (by which I mean the boundaries around the original search space). How can I use information from original search process to make the new search process in the increased space search more informed? (if there are papers related to these topics, please inform me!)
Thanks a lot for any information.
1) As long as your heuristics are admissible, the algorithm should find the answer. An admissible heuristic is a heuristic that never overestimates the distance to the goal.
2) You could use the values you already know as part of your heuristic for the expanded space.

Steepest Ascent Hill Climbing vs Best First Search

I am trying to solve a problem using different algorithms and Steepest Ascent Hill Climbing (SAHC) and Best First Search are two of these algorithms that I need to implement.
According to Wikipedia:
"In steepest ascent hill climbing all successors are compared and the closest to the solution is chosen..."
"Steepest ascent hill climbing is similar to best-first search, which tries all possible extensions of the current path instead of only one."
SAHC: All successors are compared and the closest to the solution is chosen.
BestFS: Tries all possible extensions of the current path instead of only one.
I don't really understand how these are different. Could some please help me with this, preferably with some sort of an explanation using trees?
They are quite similar. The difference is that best-first search considers all paths from the start node to the end node, whereas steepest ascent hill climbing only remembers one path during the search.
For example, say we have a graph like
start ---- A ---- B ---- end
\ /
------\ /---------
\ /
C
where each edge has the same weight: ignore my crappy ASCII art skills :).
Also suppose that in our heuristic function, A is considered as closer to the end than C. (This could still be an admissible heuristic – it just underestimates the true distance of A.)
Then steepest-ascent hill climbing would choose A first (because it has the lowest heuristic value), then B (because its heuristic value is lower than the start node's), and then the end node.
A best-first search, on the other hand, would
Add A and C to the open list.
Take A, the best value, off the open list, and add B. Then OPEN = {B, C}.
Take the best node off the open list (either B or C, more on that in a second), and add its successor, the goal state.
Take the goal state off the open list and return the path that got there.
The choice of B or C in step 3 depends on exactly the best-first search algorithm you're using. A* would evaluate the node as the cost to get there plus the estimate of the cost to get to the end, in which case C would win (and in fact, with an admissible heuristic, A* is guaranteed to always get you the optimal path). A "greedy best-first search" would choose between the two options arbitrarily. In any case, the search maintains a list of possible places to go from rather than a single one.
Is it clearer how the two are different now?
SAHC is going to choose a single, (possibly non-optimal) path greedily - it'll simply take the best node at each step until it hits the target.
Best-first, on the other hand, generates an entire search tree. Often (in the case of A*) it will find the optimal solution, this is not guaranteed for SAHC.
Dint know how to flag so pasted it again, Sorry for that. So here goes what I got as a difference.
The difference lies in understanding what is more concerned in searching for the goal state.
Ask the question what is our aim...
the final goal state?
or the Best path to reach the goal state
The Best First Search is a systematic search algorithm where systematicity is achieved by moving forward iteratively on the basis of finding out the
best heuristic value for the adjacent nodes for every current node.
Here the evaluation function ( heuristic function ) calculates the
best possible path to achieve the goal state. So here we could see the Best First search is concerned about the best PATH to reach to the goal state.
However there are many problems where "Path to the Goal" is not a concern, the only thing is concerned is to achieve the final state in any possible ways or paths.
(For eg: 8-queens problem).
Hence for this local search algorithms are used.
Local search algorithms operate using a single current node and generally move only to neighbor of that node.
Hill Climbing algorithm is a local search algorithm.
So here we need to understand the approach to get to the goal state not the best path to reach when thinking about hill climbing.
(As stated in AI-A Modern Approach,SR & PN)
Basically, to understand local search we need to consider state-space landscape.
A landscape has both
(i) location (defined by the state) and
(ii) Elevation (defined by the value of heuristic function or objective function)
We need to understand the two types of elevations,
(i) If elevation corresponds to an objective function,then the aim is to find the highest peak i.e. a Global Maximum.
(So these type of elevation are useful in different scenarios which are not concerned with cost and which are only concerned with finding the best instant moves)
(ii) If elevation corresponds to cost, then the aim is to find the lowest valley i.e. a Global Minimum.
(Here is the common thing i.e. Steepest(always stepping up with better estimations i.e. no plateau problem or any other) hill climbing is similar to Best First Search. Here the elevation function is the heuristic function which provide the best minimum cost. And hill climbing here is only concerned with current node and iterates through the adjacent nodes for minimum value and proceeds with expanding the best node which is similar to Best First Search)
Note:
Hill Climbing algorithm does not look ahead beyond the immediate neighbors of the current state. It is only concerned with best neighboring node to expand.And the best neighboring is decided by the above evaluations functions.
Whereas, Best First Search algorithm look ahead of the immediate neighbors to find the best path to the goal(using Heuristic evaluation) and then proceeding with the best one.
So difference lies in approach of local searches and systematic search algorithms.
Understand the difference in approaches, you will get to know why both are named different.

How to design an approximate path solution?

I am attempting to write (or expand on an existing) graph search algorithm that will let me find the path to get closest to destination node considering there is no guarantee that the nodes will be connected.
To provide a realistic application of this, let's say I need to get from Brampton, Ontario to Hamilton, Ontario. I know my possible options at my start point are Local transit, GO bus or Walking. I know that walking is the least desired way to get to my destination so I look at GO bus first. I know I can take GO to a point close to Hamilton, but at that point the GO bus turns and goes another direction at that closest point is at a place where I have no options (other than walk, but the algorithm would only consider walking for short distances otherwise it will consider the route not feasible)
Using this same example, if the algorithm were to find that I can get there a way that is longer but gets me closer to the destination node (or possible at the destination node) that would be a higher weighted path (The weightings don't matter so much while its searching, only when the results are delivered, it would list by which path was closest to the destination in ascending order). For example, one GO Bus may get me 3km from the destination node, while 3 public transit buses would get me 500m away
So my question is two fold:
1) What algorithm should I start with that does something similar
2) How would I programmaticly explain that it's ok if nodes don't connect so that it doesn't just jump from node A to node R. Would starting from the end and working backward accomplish this
Edit: I forgot to ask how to aim for the best approximate solution because especially with a large graph there will be possibly millions of solutions for this problem.
Thanks,
Michael
Read up on the A* algorithm. It is a generalization of Dijkstra's shortest path algorithm, that allows you to specify a heuristic, which provides a lower bound for distances between two verteces. In your case, the heuristic function would simply return the Euclidean distance.
Run the algorithm and keep track of the vertex with the best characteristic value, which you somehow compute from the graph distance from source and Euclidean distance to target. The only tricky part is to determine when to terminate (unless you want to traverse the entire graph).
Why can't you assume that all nodes are connected? In the real world, they normally are, i.e. you can always walk or call a taxi, etc.?
In this case, you could simply change your model the following way: You have one graph for each transportation method. The nodes that are at the same place are connected with edges of weight 0 (i.e. if you are dropped off by car at an airport or train station).
Then, label each vertex and edge with the transportation type and you can simply use existing routing algorithms. Oh, by the way: A* will not scale well to really big networks. To get something that software like Yahoo/Google/Microsoft Maps actually would use, have a look here. The work of this research group includes the winner of the DIMACS shortest path challenge.
Sounds very much like a travelling salesman problem with additional node characteristics. Just be wary that this type of problem is NP Complete and your best bet would be to go with some sort of approximation algorithm.

Calculating "Kevin Bacon" Numbers

I've been playing around with some things and thought up the idea of trying to figure out Kevin Bacon numbers. I have data for a site that for this purpose we can consider a social network. Let's pretend that it's Facebook (for simplification of discussion). I have people and I have a list of their friends, so I have the connections between them. How can I calculate the distance from one person to another (basically, a Kevin Bacon number)?
My best idea is a Bidirectional search, with a depth limit (to limit computational complexity and avoid the problem of people who simply can't be connected in the graph), but I realize this is rather brute force.
Could it be better to make little sub-graphs (say something equivalent to groups on Facebook), calculate the shortest distances between them (ahead of time, perhaps) and then try to use THOSE to find a link? While this requires pre-calculation, it could make it possible to search many fewer nodes (nodes could be groups instead of individuals, making the graph much smaller). This would still be a bidirectional search though.
I could also pre-calculate the number of people an individual is connected to, searching the nodes for "popular" people first since they could have the best chance of connecting to the given destination individual. I realize this would be a trade-off of speed for possible shortest path. I'd think I'd also want to use a depth-first search instead of the breadth-first search I'd plan to use in the other cases.
Can someone think of a simpler/faster way of doing this? I'd like to be able to find the shortest length between two people, so it's not as easy as always having the same end point (such as in the Kevin Bacon problem).
I realize that there are problems like I could get chains of 200 people and such, but that can be solved my having a limit to the depth I'm willing to search.
This is a standard shortest path problem. There are lots of solutions, including Dijkstra's algorithm and Bellman-Ford. You may be particularly interested in looking at the A* algorithm and seeing how it would perform with the cost function relative to the inverse of any particular node's degree. The idea would be to visit more popular nodes (those with higher degree) first.
Sounds like a job for
Dijkstra's algorithm.
ED: Eh, I shouldn't have pulled the trigger so fast. Dijkstra's (and Bellman-Ford) reduces to a breadth-first search when the weights are 1, so this isn't too useful. Oh well.
The A* algorithm, mentioned by tvanfosson, may be ideal for this. The idea is that instead of searching and recursing in whatever order the elements are in each level of the tree (rooted on your start- or end-point), you use some heuristic to determine which element you are going to try first. In your case a good bet would probably be the degree of a node (number of "friends"), but you could possibly want to use the number of people within some arbitrary number of degrees of a given person (i.e., the guy who has has three friends who each have 100 friends is likely to be a better node than the guy who has 20 friends in a clique that shuns outsiders). There's all sorts of other things you could use as a heuristic (friends get 2 points, friends-of-friends get 1 point; whatever, experiment).
Combine this with a depth limit (cut off after 6 degrees of separation, or whatever), and you can vastly improve your average case (worst case is still the same as basic BFS).
run a breadth-first search in both directions (from each endpoint) and stop when you have a connection or reach your depth limit
This one might be better overall Floyd-Warshall the all pairs shortest distance.

Astar-like algorithm with unknown endstate

A-star is used to find the shortest path between a startnode and an endnode in a graph. What algorithm is used to solve something were the target state isn't specifically known and we instead only have a criteria for the target state?
For example, can a sudoku puzzle be solved with an Astar-like algorithm? We dont know how the endstate will look like (which number is where) but we do know the rules of sudoku, a criteria for a winning state. Therefore I have a startnode and just a criteria for the endnode, which algorithm to use?
A* requires a graph, a cost function for traversal of that graph, a heuristic as to whether a node in the graph is closer to the goal than another, and a test whether the goal is reached.
Searching a Sudoku solution space doesn't really have a traversal cost to minimize, only a global cost ( the number of unsolved squares ), so all traversals would be equal cost, so A* doesn't really help - any cell you could assign costs one move and moves you one closer to the goal, so A* would be no better than choosing the next step at random.
It might be possible to apply an A* search based on the estimated/measured cost of applying the different techniques at each point, which would then try to find a path through the solution space with the least computational cost. In that case the graph would not just be the solution states of the puzzle, but you'd be choosing between the techniques to apply at that point - you'd know an estimate of the cost of a transition, but not where that transition 'goes', except that if successful, it's one step closer to the goal.
Yes, A* can be used when a specific goal state cannot be identified. (Pete Kirkham's answer implies this, but doesn't emphasise it much.)
When a specific goal state can't be identified, it's sometimes harder to come up with a useful heuristic lower bound on the remaining cost needed to complete a partial solution -- and the efficiency of A* depends on choosing an effective heuristic. But it doesn't mean it can't be applied. Any problem that can be solved on a computer can be solved using a breadth-first search, plus an array of flags indicating whether a state has been seen before; which is the same as A* with a heuristic lower bound that is always zero. (Of course, this is not the most efficient algorithm for solving many problems.)
You dont have to know the exact target endstate. It all comes down to the heuristic function, when it returns 0 you could assume to have found (at least) one of the valid endstates.
So during the a*, instead of checking if current_node == target_node, check if current_node.h() returns 0. If so, it should be infinitely close and/or overlapping the goal/endstate.

Resources