Compiling+Weka+with+gcj+(book+version)

toc

Sometimes it can be necessary to compile Java into native code to improve performance. [|gcj] offers a cross-platform approach for compiling Java 1.4 code (as of July 2007) into native code. Since doesn't support the full Java API, one has to manually select the classes one wants to compile. This article explains how to compile the classifier **Id3** into native code on Linux (should work for Win32 as well).

= Requirements =
 * Weka book version (this article is based on 3.4.11)
 * gcj >= 4.1.1

= Procedure =

Selecting scheme

 * Identify the scheme you want to compile into native code. In our case, this is **Id3**.

Obtaining Weka source code

 * Unzip the weka source code (from ) into a temporary directory.

Creating new ANT project
code format="text" weka.gcj | |- jar | |- src |   |- weka |      |- classifiers | |       |  |- evaluation | |       |  |- trees    //# this one is only for Id3// |      |- core | |       |  |- matrix |      |- estimators |      |- experiment code code format="text" weka/classifiers/Evaluation.java weka/classifiers/trees/Id3.java weka/classifiers/CostMatrix.java weka/classifiers/Classifier.java weka/classifiers/Sourcable.java weka/classifiers/UpdateableClassifier.java weka/core/Attribute.java weka/core/AttributeStats.java weka/core/FastVector.java weka/core/Instance.java weka/core/Instances.java weka/core/Utils.java weka/core/Range.java weka/core/NoSupportForMissingValuesException.java weka/core/Option.java weka/core/SerializedObject.java weka/core/UnassignedClassException.java weka/core/UnassignedDatasetException.java weka/core/UnsupportedAttributeTypeException.java weka/core/UnsupportedClassTypeException.java weka/core/Statistics.java weka/core/matrix/CholeskyDecomposition.java weka/core/matrix/EigenvalueDecomposition.java weka/core/matrix/LinearRegression.java weka/core/matrix/LUDecomposition.java weka/core/matrix/Maths.java weka/core/matrix/Matrix.java weka/core/matrix/QRDecomposition.java weka/core/matrix/SingularValueDecomposition.java weka/core/Drawable.java weka/core/Matrix.java weka/core/ProtectedProperties.java weka/core/WekaException.java weka/core/OptionHandler.java weka/core/Copyable.java weka/core/Summarizable.java weka/core/SparseInstance.java weka/estimators/ConditionalEstimator.java weka/estimators/DDConditionalEstimator.java weka/estimators/DiscreteEstimator.java weka/estimators/DKConditionalEstimator.java weka/estimators/DNConditionalEstimator.java weka/estimators/Estimator.java weka/estimators/KDConditionalEstimator.java weka/estimators/KernelEstimator.java weka/estimators/KKConditionalEstimator.java weka/estimators/MahalanobisEstimator.java weka/estimators/NDConditionalEstimator.java weka/estimators/NNConditionalEstimator.java weka/estimators/NormalEstimator.java weka/estimators/PoissonEstimator.java weka/experiment/Stats.java code
 * create the following directory structure:
 * Place the [[file:gcj-build-book.xml]] file in the directory as.
 * Copy from the temporary directory where you unzipped the Weka sources to into the corresponding folder under.
 * Compile the sources with ANT (in directory with ) and add all the necessary classes until the compilation is successful. In the case of  these should be the following ones:

Generating native code
code format="bash" gcj --main=weka.classifiers.trees.Id3 -o id3 dist/weka.jar code code format="bash" ./id3 -t /some/where/file.arff -c first code
 * gcj can work on jars which makes it easy to compile the generated
 * Since Java classes can have more than one class with a method, you need to specify, which one of those should be used with the  option.
 * Here's the full commandline (from within the directory) to compile the  into the executable  (on Windows you'd choose ):
 * Now you can use the generated binary like any other Java classifier from commandline, e.g.:

= Downloads =
 * [[file:gcj-build-book.xml]] (save as //build.xml//)

= Links =
 * [|gcj homepage]
 * [|gcj on WikiPedia]
 * [|ANT homepage]