Get the entire book!
Introduction to Neural Networks with Java

This book contains many examples that illustrate the use of neural networks. These examples are contained on the companion CD-ROM. The individual chapters do not describe how to compile and execute each example. Instead, this appendix is given to show you how to compile and execute the example programs under the Windows platform. If you are trying to compile examples under a UNIX environment refer to Appendix D, "Compiling Examples under UNIX/Linux".

Java Environment

The examples contained in this book were all tested using Sun’s JDK 1.4. A copy of JDK1.4 is included on the companion CD-ROM. You must have JDK 1.4 installed. Installing JDK is pretty straight forward. You download the exe from Sun (http://java.sun.com) and double click the exe, usually named j2sdk-1_4_0-win.exe, to begin the installation process. This will install the JDK into the directory c:\ j2sdk1.4.0\ or similar.

Installing JOONE

Many of the example programs contained in this book use the Java Objected Oriented Neural Engine (JOONE). To correctly execute these examples you must install JOONE. JOONE consists of a series of JAR files that must be added to your Java CLASSPATH. The JAR files necessary to run JOONE are included in a directory named "jar" on the companion CD-ROM for this book. The JAR files included in this directory are summarized as follows:

JAR File Purpose
crimson.jar Part of the Sun XML parser. Note: this file is not needed if you are using JDK 1.4 or higher.
jhotdraw.jar JHotDraw is a two-dimensional graphics framework for structured drawing editors that are written

in Java. It is used internally by JOONE’s editor. For more information on jhotdraw see

http://sourceforge.net/projects/jhotdraw.
joone-editor.jar The JOONE editor. This is Java application that lets you graphically edit neural networks.
joone-engine.jar The JOONE engine. This JAR file must be included with programs use the JOONE engine.

This contains the core routines and not the editor.
junit.jar Used internally by JOONE.
log4j.jar This is a logging API developed by Apache. JOONE uses this internally. For more information on Log4J

see http://jakarta.apache.org/log4j/.
ppi.jar Used internally by JOONE.
xalan.jar Part of the Sun XML parser. Note: this file is not needed if you are using JDK 1.4 or higher.

In order to use JOONE, and the examples that require JOONE, these files must be accessible on the CLASSPATH. Several two of these JARs are now included as part of JDK 1.4. If you are using JDK 1.4 you will most likely use a CLASSPATH such as:

./;c:\jar\joone-editor.jar;c:\jar\joone-engine.jar;c:\jar\jhotdraw.jar;c:\jar\junit.jar; c:\jar\ppi.jar;c:\jar\log4j.jar

If you are using a version of the JDK that is lower than JDK 1.4 you will need a longer CLASSPATH that includes all of the previously mentioned JARs.

./;c:\jar\joone-editor.jar;c:\jar\joone-engine.jar;c:\jar\crimson.jar;c:\jar\jhotdraw.jar; 
c:\jar\junit.jar;c:\jar\xalan.jar;c:\jar\ppi.jar;c:\jar\log4j.jar

To add these to your CLASSPATH you must modify your system’s environmental variables. In addition to setting the CLASSPATH you must also modify your path environmental to make the JDK part of your system path. By making JDK part of the system path you can invoke the Java commands, such as javac and java from, any directory. Additionally you must also set the environmental variable JAVA_HOME to point to this directory. JDK_HOME is used by various Apache tools to locate Java. In this book we will be using Apache ANT. ANT will be discussed later in this appendix. The exact directions for setting your environmental variables are different, depending on which version of Windows you are using.

Setting the Environmental Variables in Windows XP/2000 Professional

To set environmental variables under the professional Editions of Microsoft Windows you must use the System Properties panel. The System Properties panel can be found under the "Control Panel" option on the Windows Start Menu. The System Properties Panel is shown in Figure C.1. Once the System Properties panel is open you should click the advanced tab.


Figure C.1: The System Properties panel

From the System Properties panel you can access the Environmental Variables panel. This window contains a number of tabs. You should click the tab labeled "Advanced". This is done by clicking the button labeled "Environmental Variables" near the bottom of the System Properties panel. Your screen should now resemble Figure C.2, which shows these settings in the System Properties dialog box under Windows XP Professional Edition.


Figure C.2: The Environmental Variables panel

When you enter the Environmental Variables panel you will see that there are two sets of environmental variables (shown in Figure C.2). The top set is for the current user. The bottom set is for the entire system. I suggest modifying them for the system because this seems to be where most systems modify the CLASSPATH setting. To do so, follow these steps:

1. Find the path setting. If your JDK installation was not in the system path, you would have to add its bin directory to the system path. Add the location of the bin directory (usually C:\ j2sdk1.4.0\bin\) to the PATH environmental variable. This is done by appending your bin directory to whatever currently exists in the PATH variable. Do not forget to put a semicolon (;) at the end of the current path if you must add on.

2. Create an environmental variable named JAVA_HOME. The value of JAVA_HOME should be set to the root of your JDK installation. For most systems this is C:\j2sdk1.4.0\bin\.

3. Either create or append to the CLASSPATH setting the complete location of the required jars which were discussed in the previous section. Note that each path setting is delimited by a semicolon (;). If there already is a CLASSPATH, simply append the required JARs to the end, if there is no CLASSPATH, you must click New, to create a CLASSPATH.

4. Click OK to accept your changes. This completes the process.

Make sure you include the dot slash (./) portion of your CLASSPATH. If you do not include the dot-slash (./), which represents the current directory, many Java programs will execute properly.

Setting Environmental Variables in Windows 95/98/ME

To modify the system path and CLASSPATH under these versions of Windows, the autoexec.bat file must be modified. Your autoexec.bat file may look like the one shown in Figure C.3, but also may not. It all depends on which system you use. However, no matter what your autoexec.bat looks like, you should be able to follow these steps to execute it regardless of which system you use.

1. Locate the autoexec.bat file in the root of your C drive. Open the file with Notepad. You may want to save a copy of your current autoexec.bat file to a backup, such as autoexec.bak.

2. Create an environmental variable named JAVA_HOME. The value of JAVA_HOME should be set to the root of your JDK installation. For most systems line will be "set JAVA_HOME = C:\j2sdk1.4.0\".

3. Locate the set classpath command. If you cannot find this command, type it in (as it is shown in Figure C.3). . Add the bot.jar to the CLASSPATH by appending a "SET CLASSPATH = " line to the end of the autoexec.bat file.

4. Locate the path statement, and add the location of your bin directory. Figure C.3 shows a properly modified autoexec.bat file.

Your autoexec.bat file will look slightly different than this example. This example is shown primarily to give you an idea of how it should look. Always make sure that the current directory, represented by a dot-slash (./), is part of the CLASSPATH. Without the current directory as part of the CLASSPATH, most Java programs will not correctly execute.

The information provided here is meant to give you a general idea of how Java should be set up. To completely describe how to configure the Java environment would is beyond the scope of this book. The information provided here is meant to give you a general idea of how Java should be set up. For more information on CLASSPATHs and installing JDK, please refer to the JDK installation instructions or a book about the Java programming language, .A book that provides an introduction to Java, such as "Java2 Complete, (Sybex, 1999)", ISBN 0782124682 , would provide more information.


Figure C.3: An autoexec.bat file

Testing Your Environment

You should now have both JDK and JOONE properly installed. To test these configurations try the following command from a DOS or command prompt window. The directory you are in is unimportant.

java org.joone.edit.JoonEdit c:\jar\layers.xml

For convince I have included a copy of the layers.xml file in stored in the JAR directory. For more information about the layers file refer to Chapter 3, "Using Multilayer Neural Networks". The layers file does not need to be in the JAR directory and could be stored anywhere so long as a complete path is given to the JOONE Editor. If you have properly installed your environment you should see the JOONE editor, as shown in Figure C.4.


Figure C.4: The JOONE Editor

If you get an error message instead of the window shown in Figure C.4 recheck the steps in the previous sections. If you are getting an error, it most likely means that either your system path or CLASSPATH are configured incorrectly.

Compiling and Executing Examples

This book contains many example programs to illustrate neural networks. This section shows you how to compile and execute these examples. Before you can compile and execute the examples you must properly configure your system as described in the previous section.

The examples contain build scripts that use ANT. ANT is a utility that was created by Apache to allow cross-platform build scripts to be created for Java programs. A copy of ANT is included on the companion CD-ROM for this book. For more information about ANT refer to http://jakarta.apache.org/ant/.

Installing Ant

ANT is distributed as a simple ZIP file that must be extracted to a directory on your system. The copy of ANT that I am currently using is installed in the directory c:\jakarta-ant-1.4.1. To properly use ANT you must include its bin directory (c:\jakarta-ant-1.4.1\bin\) as part of your system path. Refer to the previous section to see how to do this. To test to see if you have properly installed ANT just enter the command "ant" from the command prompt. You should get output as follows:

C:\>ant
Buildfile: build.xml does not exist!
Build failed
C:\>

Do not worry about the build failed; at this point we just wanted to see if ANT could be found. The next section shows you how to properly specify a script.

Compiling an Example

In order to compile an example it is necessary to execute the build script with ANT. All of the examples in this book have a build file named build.xml. The build file will be stored in that example’s directory on the CD-ROM. Please note, you can not compile examples from the CD-ROM due to the fact that CD-ROM’s are read only.

To begin the build process you should enter the following command.

ant -buildfile build.xml

For this example we are using the Hopfield example from Chapter 2. If the build is successful you will see the following output.

Buildfile: build.xml

init:
    [mkdir] Created dir: C:\NeuralNetworks\examples\Ch2\Hopfield\bui
ld

compile:
    [javac] Compiling 3 source files to C:\NeuralNetworks\examples\Ch2\Hopfield\build

dist:
    [mkdir] Created dir: C:\NeuralNetworks\examples\Ch2\Hopfield\dist\lib
      [jar] Building jar: C:\NeuralNetworks\examples\Ch2\Hopfield\dist\lib\Hopfield.jar

BUILD SUCCESSFUL

Total time: 2 seconds

Executing an Example

If the build is successful a JAR file will be created that contains the example. For Chapter 2’s Hopfield example the JAR file created is Hopfield.jar. You should be able to execute the JAR file simply by double clicking it. If this fails you will have to run the JAR by moving to its directory ( dist\lib) and enter the following command.

java -jar Hopfield.jar

If the Hopfield example executes correctly you should see a window like Figure C.5.


Figure C.5: The Hopfield example

Using an IDE Such as Visual Café

Using an IDE, such as WebGain Visual Cafe or Borland JBuilder can often speed development and debugging times. Every example in this book also comes with a Visual Cafe project file. This allows you to open the project in Visual Cafe. Once the project is opened you might have to reconfigure the project directories. Currently every project file is configured to assume that the JOONE JAR files are stored in c:\jar\. If you have installed these files elsewhere you will have to change the directory setting for the projects. You can see this configuration screen in Figure C.6.


Figure C.6: Editing directories in Visual Cafe


Copyright 2005 - 2010 by Heaton Research, Inc.. Heaton Research™ and Encog™ are trademarks of Heaton Research. Click here for copyright and trademark information.