Book Image

Hands-On Artificial Intelligence for Search

By : Devangini Patel
Book Image

Hands-On Artificial Intelligence for Search

By: Devangini Patel

Overview of this book

With the emergence of big data and modern technologies, AI has acquired a lot of relevance in many domains. The increase in demand for automation has generated many applications for AI in fields such as robotics, predictive analytics, finance, and more. In this book, you will understand what artificial intelligence is. It explains in detail basic search methods: Depth-First Search (DFS), Breadth-First Search (BFS), and A* Search, which can be used to make intelligent decisions when the initial state, end state, and possible actions are known. Random solutions or greedy solutions can be found for such problems. But these are not optimal in either space or time and efficient approaches in time and space will be explored. We will also understand how to formulate a problem, which involves looking at it and identifying its initial state, goal state, and the actions that are possible in each state. We also need to understand the data structures involved while implementing these search algorithms as they form the basis of search exploration. Finally, we will look into what a heuristic is as this decides the quality of one sub-solution over another and helps you decide which step to take.
Table of Contents (5 chapters)

Installing and setting up libraries

Before we get into the basic concepts of searching, we will take a look at the following libraries that have to be installed and how to install them in Windows:

  • Pip: The tools for installing Python packages are as follows:
    • Pydot: A Python interface to Graphviz's DOT language
    • Matplotlib: This is a Python 2D plotting library

Execute the steps in the following section to install the preceding libraries.

Setting up Python

The steps for setting up Python are as follows:

  1. For the applications in this book, we'll be using Python 2.7.6, which we can download from https://www.python.org/downloads/.
  2. Once an appropriate installer has been downloaded, double-click on it and go ahead with the default options.
  3. Based on your operating system, select the Python installer to download, as shown in the following screenshot:
Figure 1
  1. The following screenshot shows the location where Python will be installed; make a note of this location:
Figure 2

Now, Python will be installed.

  1. The next step is to add Python's path to the Path environment variable. In the System Properties | Advanced tab, click on the Environment Variables... button.
  2. In the Environment Variables… window, go to System variables | Path and add the Python location that you made a note of in step 4 (which is C:\Python27 in our case).
  1. Now, to check whether Python works, open the Command Prompt and type in the python -- version command. You will get the following output:
Figure 3

The output shown in the preceding screenshot confirms that Python has been installed successfully.

Depending on your OS, Python might already be installed.

Setting up Graphviz

The following steps describe how to set up Graphviz:

  1. We can download the graph visualization software from https://graphviz.gitlab.io/download/.
  2. Since we are using Windows, we select the option that says Stable 2.38 Windows install packages, as shown in the following screenshot:
Figure 4

Select the .msi downloadable file, shown as follows:

Figure 5
  1. Once the Graphviz executable has downloaded, go ahead and install the file with the default options; again, make a note of the path, as shown in the following screenshot:
Figure 6
  1. Now, we will add Graphviz's bin folder to the path variable, as we did when installing Python in the previous section. Then, copy the location where Graphviz is installed and append \bin, as shown in the following screenshot:
Figure 7
  1. To validate whether this library has been installed properly, open a new Command Prompt window and type the dot -V command, and you will get the following result:
Figure 8

The output shown in the preceding screenshot confirms that Graphviz has been installed successfully.

Installing pip

The steps for installing pip are as follows:

  1. To install pip, you need to download the get-pip.py file from https://bootstrap.pypa.io/get-pip.py, and make a note of the path where the file is located. In my case, the file is located at Documents\ai\softwares.
  2. Open the Command Prompt and go to the Documents\ai\softwares folder by using the cd command, as shown in the following screenshot:
Figure 9
  1. Use the dir command to take a look at the contents of this folder, where you will see get-pip.py, shown in the following screenshot:
Figure 10
  1. Next, we'll run the python get-pip.py command.
  2. Now, let's add Python's scripts folder to the Path environment variable.
  3. Open another Command Prompt window and test the installation of pip by typing the pip --version command. Upon successful installation, you will get the following output:
Figure 11
  1. Once pip has installed, you can install pydot by running the following command:
pip install pydot 
  1. Finally, install matplotlib by executing the following command:
pip install matplotlib  
  1. We can check whether the libraries have been installed properly by using the import command in Python's interpreter, as shown in the following screenshot:
Figure 12

Now, we're done installing the libraries that we will need in Windows for this book . In the next topic, we will look at how we can go about developing a file search application.