Practical Artificial Intelligence Programming in Java - Mark Watson.pdf

(1253 KB) Pobierz
Practical Artificial Intelligence Programming in Java
Version 1.02, last updated November 18, 2005.
by Mark Watson.
This work is licensed under the Creative Commons Attribution­NoDerivs­NonCommercial 
License. To view a copy of this license, visit http://creativecommons.org/licenses/by­nd­nc/1.0 or 
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 
Additional license terms:
No commercial use without author's permission
The work is published "AS IS" with no implied or expressed warranty - you accept all risks
for the use of both the Free Web Book and any software program examples that are bundled
with the work.
This web book may be distributed freely in an unmodified form. Please report any errors to 
markw@markwatson.com
 and look occasionally at Open Content (Free Web Books) at 
www.markwatson.com
 for newer versions.
Requests from the author
I live in a remote area, the mountains of Northern Arizona and work remotely via the Internet. 
Although I really enjoy writing Open Content documents like this Web Book and working on 
Open Source projects, I earn my living as a Java consultant. I also develop software in Ruby, 
Python, and Common Lisp. Please keep me in mind for consulting jobs! Also, please read my 
resume and consulting terms at 
www.markwatson.com
.
Copyright 2001-2005 by Mark Watson. All rights reserved. Page 1 11/18/2005 08:48:15
Table of Contents
Table of Contents............................................................................................................................2
Preface............................................................................................................................................5
Acknowledgements...................................................................................................................................5
Introduction....................................................................................................................................6
Notes for users of UNIX and Linux.........................................................................................................7
Use of the Unified Modeling Language (UML) in this book................................................................8
Chapter 1. Search.........................................................................................................................11
1.1 Representation of State Space, Nodes in Search Trees and Search Operators...................11
1.2 Finding paths in mazes.....................................................................................................................13
1.3 Finding Paths in Graphs..................................................................................................................20
1.4 Adding heuristics to Breadth First Search.....................................................................................26
1.5 Search and Game Playing................................................................................................................27
1.5.1 Alpha-Beta search.........................................................................................................................................27
1.5.2 A Java Framework for Search and Game Playing........................................................................................29
1.5.3 TicTacToe using the alpha beta search algorithm........................................................................................34
1.5.4 Chess using the alpha beta search algorithm................................................................................................38
Chapter 2. Natural Language Processing...................................................................................47
2.1 ATN Parsers......................................................................................................................................48
2.1.1 Lexicon data for defining word types...........................................................................................................52
2.1.2 Design and implementation of an ATN parser in Java.................................................................................52
2.1.3 Testing the Java ATN parser.........................................................................................................................58
2.2 Using Prolog for NLP.......................................................................................................................59
2.2.1 Prolog examples of parsing simple English sentences.................................................................................60
2.2.2 Embedding Prolog rules in a Java application.............................................................................................62
Chapter 3. Expert Systems............................................................................................................66
3.1 A tutorial on writing expert systems with Jess..............................................................................66
3.2 Implementing a reasoning system with Jess...................................................................................72
3.3 Embedding Jess Expert Systems in Java Programs......................................................................77
Chapter 4. Genetic Algorithms.....................................................................................................80
4.1 Java classes for Genetic Algorithms................................................................................................83
4.2 Example System for solving polynomial regression problems......................................................87
Copyright 2001-2005 by Mark Watson. All rights reserved. Page 2 11/18/2005 08:48:15
Chapter 5. Neural networks.........................................................................................................91
5.1 Hopfield neural networks.................................................................................................................92
5.2 Java classes for Hopfield neural networks.....................................................................................93
5.3 Testing the Hopfield neural network example class......................................................................96
5.5 Backpropagation neural networks..................................................................................................97
5.6 A Java class library and examples for using back propagation neural networks.....................100
5.7 Solving the XOR Problem..............................................................................................................108
5.8 Notes on using back propagation neural networks......................................................................109
6. Machine Learning using Weka..............................................................................................111
6.1 Using machine learning to induce a set of production rules.......................................................111
6.2 A sample learning problem............................................................................................................112
6.3 Running Weka.................................................................................................................................113
Chapter 7. Statistical Natural Language Processing................................................................115
7.1 Hidden Markov Models..................................................................................................................115
7.2 Training Hidden Markov Models..................................................................................................117
7.3 Using the trained Markov model to tag text.................................................................................118
Chapter 8. Using Bayes' Rule For SPAM Email Detection.....................................................120
Bibliography................................................................................................................................122
Index............................................................................................................................................124
Copyright 2001-2005 by Mark Watson. All rights reserved. Page 3 11/18/2005 08:48:15
For my grandson Calvin and granddaughter Emily
Copyright 2001-2005 by Mark Watson. All rights reserved. Page 4 11/18/2005 08:48:15
Preface
This book was written for both professional programmers and home hobbyists who already know 
how to program in Java and who want to learn practical AI programming techniques. I have tried 
to make this a fun book to work through. In the style of a “cook book”, the chapters in this book 
can be studied in any order. Each chapter follows the same pattern: a motivation for learning a 
technique, some theory for the technique, and a Java example program that you can experiment 
with.
Acknowledgements
I would like to thank Kevin Knight for writing a flexible framework for game search algorithms 
in Common LISP (Rich, Knight 1991) and giving me permission to use some of his ideas; the 
game search Java classes in Chapter 1 were loosely patterned after this Common LISP 
framework and allows new games to be written by sub classing three abstract Java classes. I 
would like to thank Sieuwert van Otterloo for writing the Prolog in Java program and for giving 
me permission to use it in this free web book. I would like to thank Ernest J. Friedman­Hill at 
Sandia National Laboratory for writing the Jess expert system toolkit. I would like to thank 
Christopher Manning and Hinrich Schutze for writing their “Foundations of Statistical Natural 
Language Processing” book; it is one of the most useful textbooks that I own. I would like to 
thank my wife Carol for her support in both writing this book, and all of my other projects. I 
would also like to acknowledge the use of the Poseidon UML modeling tool 
(www.gentleware.com) for writing this book. I would like to thank Paul Graham for giving me 
permission to use his ideas from his paper “Plan for SPAM” 
(http://www.paulgraham.com/spam.html) for Chapter 8.
Copyright 2001-2005 by Mark Watson. All rights reserved. Page 5 11/18/2005 08:48:15
Zgłoś jeśli naruszono regulamin