Learn

Sunday, 3 December 2017

How to do Resoning in AI? Which Framework Libraries used for reasoning in Java Artificial Intelligence Programming



Reasoning: 

       The reasoning is a broad topic. In this blog we will concentrate on the use of the PowerLoom descriptive logic reasoning system. PowerLoom is available with a Java runtime and Java API – this is what we will use for the examples in this chapter. PowerLoom can also be used with JRuby. PowerLoom is available in Common Lisp and C++ versions. Additionally, we will look briefly at different kinds of reasoning systems in next blog on the Semantic Web.

      While the material in this chapter will get you started with development using a powerful reasoning system and embedding this reasoning system in Java applications, you will likely want to dig deeper and I suggest sources for further study at the end of this chapter. PowerLoom is a newer version of the classic Loom Descriptive Logic reasoning system written at ISI. The required JAR files for PowerLoom are included in the ZIP file for this book but at some point, you will probably want to download the entire PowerLoom distribution to get more examples and access to documentation; the PowerLoom web site can be found at http://www.isi.edu/isd/LOOM/PowerLoom/.

     While we will look at an example of embedding the PowerLoom runtime and a PowerLoom model in a Java example program, I want to make a general comment on PowerLoom development: you will spend most of your time interactively running PowerLoom in an interactive shell that lets you type in concepts, relations, rules, and queries and immediately see the results. If you have ever programmed in Lisp, then this mode of interactive programming will be familiar to you. As seen in Figure 3.1 after interactive development you can deploy in a Java application. This style of development supports entering facts and trying rules and relations interactively and as you get things working you can paste what works into a PowerLoom source file. 

If you have only worked with compiled languages like Java and C++ this development style may take a while to get used to and appreciate. As seen in Figure
the PowerLoom runtime system, with relations and rules, can be embedded in Java applications that typically clear PowerLoom data memory, assert facts from other live data sources, and then use PowerLoom for inferencing.

Figure: Overview of  PowerLoom for development and
deployment

How Does Alpha Beta search works in Artificial Intelligence Java Programming



Alpha-Beta Search:

         The first game that we will implement will be tic-tac-toe, so we will use this simple game to explain how the min-max search (with alpha-beta cutoffs) works. Figure shows the possible moves generated from a tic-tac-toe position where X has made three moves and O has made two moves; it is O’s turn to move. This is “level 0” in Figure 2.8. At level 0, O has four possible moves. How do we assign a fitness value to each of O’s possible moves at level 0? The basic min-max search algorithm provides a simple solution to this problem: for each possible move by O in level 1, make the move and store the resulting 4 board positions. Now, at level 1,  it is X’s turn to move. How do we assign values to each of X’s possible three moves


Figure: Alpha-beta algorithm applied to part of a game of tic-tac-toe


In Figure above,  we continue to search by making each of X’s possible moves and storing each possible board position for level 2. We keep recursively applying this algorithm until we either reach a maximum search depth, or there is a win, loss, or draw detected in a generated move. We assume that there is a fitness function available that rates a given board position relative to either side. Note that the value of any board position for X is the negative of the value for O. To make the search more efficient, we maintain values for alpha and beta for each search level. Alpha and beta determine the best possible/worst possible move available at a given level. If we reach a situation like the second position in level 2 where X has won, then we can immediately determine that O’s last move in level 1 that produced this position (of allowing X an instant win) is a low valued move for O (but a high valued move for X). This allows us to immediately “prune” the search tree by ignoring all other possible positions arising from the first O move in level

1. This alpha-beta cutoff (or tree pruning) procedure can save a large percentage of search time, especially if we can set the search order at each level with “probably best” moves considered first.

While tree diagrams as seen in Figure  quickly get complicated, it is easy for a computer program to generate possible moves, calculate new possible board positions and temporarily store them, and recursively apply the same procedure to the next search level (but switching min-max “sides” in the board evaluation). We will see in the next section that it only requires about 100 lines of Java code to implement an abstract class framework for handling the details of performing an alpha-beta enhanced
search. The additional game specific classes for tic-tac-toe require about an additional 150 lines of code to implement; chess requires an additional 450 lines of code.