Imagine that you have to get to Grandma’s house, which, according to legend, is over the hills and through the woods, and two states away. That would be two countries away if you live in Europe. To plan your trip, you can start in one of two ways. Ignoring the fact that Google has taken away most map reading and navigation skills from today’s youth, you would get out a map and either:
- Start at your house and try to find the roads that are closest to a straight line to Grandma’s house
- Start at Grandma’s house and try to find roads leading to your home
From either direction, you will find that the road or path you seek forks, intersects, changes, meanders, and may even come to a dead end. Also, all roads are not created equally – some are bigger, with higher speed limits, and some are smaller, with more stop signs. In the end, you pick your route by the combination of decisions that results in the lowest cost. This cost may be in time – how long to get there. It may be in distance – how many miles to cover. Or it may be in monetary terms – there is a toll road that charges an extra fee.
We will be discussing several ways to solve problems involving choosing a chain of multiple decisions where there is some metric – such as cost – to help us select which combination is somehow the best.
There is a lot of information here that is widely used in robotics, and we will be expanding our horizons a bit beyond our toy-grabbing robot to look at robot path planning and decision making in general. These are critical skills for any robotics practitioner, so they are included here.
This chapter covers the basics of decision-making processes for artificial intelligence where the problem can be described in terms of either a classification problem (determining if this situation belongs to one or more groups of similar situations) or a regression problem (fitting or approximating a function that can be a curve or a path).
We will be applying the following machine learning or artificial intelligence techniques:
- Decision trees and random forests
- Path planning, grid searches, and the A* (A-Star) algorithm
- Dynamic planning with the D* (D-Star) technique
- Expert systems and knowledge bases
Finally, we will be applying two approaches to our robot problem – an expert system and random forests.
At first glance, the concepts we will cover in this section, namely path planning, decision trees, random forests, grid searches, and GPS route finders, don’t have much in common, other than all being part of artificial intelligence computer algorithms. From my point of view, they are all basically the same concept and approach problems in the same way.
We will be using PyKE – the Python Knowledge Engine – as our expert system. It can be installed from:
https://sourceforge.net/projects/pyke/?source=directory
The other tool you should have already installed from earlier chapters – Scikit_Learn:
http://scikit-learn.org/stable/developers/advanced_installation.html
Or if you have the pip installer in Python:
pip install –U scikit-learn
Check out the following video to see the Code in Action:
http://bit.ly/2PN1soo
Our task in this chapter is one that you may have been waiting for, if you have been keeping score since Chapter 3, where we discussed our storyboards. We need to choose a way to pick up the toys with the robot arm. This involves picking a proper orientation for the wrist joint. Since our toys are randomly placed, by those experts at random, my grandkids, the toy may be in any orientation relative to the floor, and at any angle relative to the robot. We need some method for observing the toy with the robot and appropriately orienting the robot’s hand to grasp the toy.
The concept of a decision tree is fairly simple. You are walking down the sidewalk, and come to a corner. Here you can go right, turn left, or go straight ahead. That is your decision. After making the decision – turn left – you now have different decisions ahead of you than if you turned right. Each decision creates paths that lead to other decisions:
In this decision tree, I decide what to have for breakfast on any given morning. Should I make something, or get a prepared food out of the pantry? Hot or cold? Healthy or not?
Now as we are walking down the sidewalk, we have a goal in mind. We are not just wandering around aimlessly; we are trying to get to some goal. One or more combinations of decisions will get us to the goal. Let’s say the goal is to get to the grocery store to buy bread. There may be four or five paths down sidewalks that will get you to the store, but each path may be different in length, or may have different paths. If one path goes up a hill, that may be harder than going the level path. Another path may have you wait at a traffic light, which costs time. We assign a value to each of these attributes, and generally want to pick the path with the lowest cost, or the highest reward, depending on the problem.
The general problem with decision tree type problems is one of exponential growth. Let’s consider a chess game, a favorite problem set for artificial intelligence. We have 20 choices for an opening move (eight pawns and two knights, each with two possible moves). Each of these 20 moves has 20 possible next moves, and so on. So the first move has 20 choices, the second moves has 400 choices. The third move is 197,281 choices! We soon have a very, very large decision tree as we try to plan ahead. We can call each of these possible decisions a branch, the state we are in after making the decision is a leaf, and the entire conceptual structure is a decision tree.
Let me emphasize one very important concept for this chapter.
The secret to working with decision trees is to ruthlessly prune the branches so you consider as few decisions as possible
There are two ways to deal with a decision tree (actually, there are three – see if you can guess the third before I explain it…).
The first way is to start at the beginning, and work outwards towards your goal. You may come to a dead end, which means back-track...