Using with UNIX | Heaton Research

Using with UNIX

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 a UNIX platform. The examples given in this appendix were tried under Red Hat Linux 7.2; other UNIX environments should be similar. If you are trying to compile examples under a Windows environment refer to Appendix C, "Compiling Examples under Windows".

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 BIN file from Sun (http://java.sun.com). This BIN file is actually just a wrapper around a RPM file. This is done so that you accept the Sun agreement before receiving the RPM file. To extract the RPM from the bin file you should execute the BIN file. Once you have your RPM file you should switch to the root user, by using the su command, to complete the installation. To install the RPM file use the following command.

rpm - i j2sdk-1_4_0-fcs-linux-i386.rpm

This should install the JDK to the directory /usr/java/j2sdk1.4.0.

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:

./:/usr/jar/joone-editor.jar:/usr/jar/joone-engine.jar:/usr/jar/jhotdraw.jar
:/jar/junit.jar: /usr/jar/ppi.jar:/usr/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.

./:/usr/jar/joone-editor.jar:/usr/jar/joone-engine.jar:/usr/jar/crimson.jar
: /usr/jar/jhotdraw.jar:/jar/junit.jar:/usr/jar/xalan.jar:/usr/jar/ppi.jar
:/usr/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.

This is done by modifying your login profile. The exact name of this file depends on what shall you are using. If you are using a default Red Hat installation, then you will be using the bash shell. To change environmental variables under bash you must modify the .bash_profile file. This file is shown in Figure D.1.


Figure D.1: Editing the .bash_profile file

To edit your .bash_profile file make sure you are in your home directory and use xedit to open the file. This can be done as follows:

cd ~
xedit .bash_profile

Once you are editing your profile file you must make several changes to this file.

    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 /usr/java/j2sdk1.4.0/) 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 colon (:) 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 /usr/java/j2sdk1.4.0/.

    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 colon (:). 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. Make sure that these environmental variables are exported. There should be an export line for each of these variables, as seen in Figure D.1.

    5. Click SAVE 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.

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 /usr/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 D.2.


Figure D.2: The JOONE Editor

If you get an error message instead of the window shown in Figure D.2 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 /usr/jakarta-ant-1.4.1. To properly use ANT you must include its bin directory (/usr/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:

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

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.

[jheaton@localhost Hopfield]$ ant
Buildfile: build.xml

init:
    [mkdir] Created dir: /home/jheaton/cdrom/examples/Ch2/Hopfield/build

compile:
    [javac] Compiling 3 source files to /home/jheaton/cdrom/examples/Ch2/Hopfield/build

dist:
    [mkdir] Created dir: /home/jheaton/cdrom/examples/Ch2/Hopfield/dist/lib
      [jar] Building jar: /home/jheaton/cdrom/examples/Ch2/Hopfield/dist/lib/Hopfield.jar

BUILD SUCCESSFUL

Total time: 9 seconds
[jheaton@localhost Hopfield]$

One possible error that you might get is the "bad interpreter" error shown below.

bash: /usr/jakarta-ant-1.4.1/bin/antRun: bad interpreter: Permission denied

If you are getting this error then it means that the main ant script file does not have execute permission. To fix this you must change into super user then set the permission on the ant file in the bin directory. This is done with the "chmod 777 ant" command.

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 D.3.


Figure D.3: The Hopfield example

Copyright 2005-2008 by Heaton Research, Inc.