Encog Eclipse Examples Tutorial

From Encog Machine Learning Framework
Jump to: navigation, search

It is very easy to use the Encog examples with Eclipse. The Encog examples download contains an Eclipse project that can be imported. This project can be used in conjunction with Maven or simply with Eclipse standalone. The first step is to import the project.

Contents

Importing the Project

The first step is to import the project into Eclipse. To do this choose File:Import.... This will display a dialog that prompts for what you would like to import. Choose to import an existing project into the workspace.

Choose to import project

Now you must browse to the directory that you downloaded the Encog examples to. Choose this directory.

Choose the project to import

Once you have imported the project you will see that it has errors. This is okay, we will fix the errors in one of the next sections. You can see a project, with errors, here.

Imported project has errors

Now that the project has been imported you must tell Eclipse how to find the Encog JAR file. How this is done depends on if you would like to use a Maven Repository or simply used the version of the Encog JAR provided with the examples download. In the next section you will see how to use the provided Encog JAR. If you would like to use Maven, skip the next section.

Using Examples without Maven

First you must open the project properties. Right-click the project and choose properties. You should then navigate to the build path you see here.

Choose Maven libraries to delete

Delete any library that begins with M2_REPO. These are Mavenized versions of the JAR files. Now you should add the Encog JAR that was provided with the examples download. You can see this process here.

Add provided library

Finally, you should see the correct libraries installed. The names may be different with later versions of Encog.

Correct libraries

Now that the project is configured correctly, you can execute the examples. For more information on this advance to the section Executing Examples in Eclipse.

Using Examples with Maven

If you make use of Maven then you have a local Maven Repository that holds JAR files used by projects you have built. You may want to use this repository to hold the Encog JAR for use with Eclipse. To do this you must first have compiled the Encog examples using Maven. For more information on this visit Encog Java Examples.

To use the local Maven Repository you must define a classpath variable that defines the location of your local Maven Repository. My local Maven Repository is located here.

C:\Users\jheaton\.m2\repository

It is usually in a hidden directory, named .m2, located just off your user directory. To edit the classpath variables choose the menu Window:Preferences.

Class path variables

Now add a classpath variable named M2_REPO. This variable should point to your local Maven Repository.

Add a classpath variable

Once the classpath variable has been added, you should see it here.

Correct classpath variable

Now that you have configured Eclipse to use the local Maven Repository to use the Encog JAR, you are ready to execute the examples.

Executing Examples in Eclipse

Now that everything has been configured properly, you should see your project with no errors. This is shown here.

Project with no errors

If you are not already using hierarchy view to look at your project, this might make it easier to view. Hierarchy layout is not the default option in Eclipse, however it will present the packages of the project in a hierarchy, similar to Windows Explorer.

Switch to hierarchy layout

You are now ready to execute the example. The example is located in the package org.encog.examples.neural.xor.XORHelloWorld.

Execute example

Shown below is the output from the example.

Output from XORHelloWorld
Personal tools