Compiling+Weka+with+gcj+(developer+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. Using [|retroweaver] one can turn the 1.5 byte-code of Weka into 1.4 byte-code to make it digestible for. 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 developer version (this article is based on 3.5.6)
 * gcj >= 4.1.1
 * retroweaver 2.0

= Limitations =
 * Unfortunately, the jar must be still in the CLASSPATH to be able to run the generated executable

= 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.

Downloading retroweaver

 * Download [|retroweaver] and unzip it into a temporary directory.

Creating new ANT project
code format="text" weka.gcj | |- jar | |- src |   |- weka |      |- classifiers | |       |  |- evaluation | |       |  |- functions | |       |  |- trees    //# this one is only for Id3// | |       |  |- xml |      |- core | |       |  |- converters | |       |  |- matrix | |       |  |- xml |      |- estimators |      |- experiment |      |- filter | |       |  |- unsupervised |    |       |     |- attribute |      |- gui code code format="text" weka/core/Attribute.java weka/core/AttributeStats.java weka/core/Capabilities.java weka/core/Capabilities.props weka/core/Copyable.java weka/core/FastVector.java weka/core/Instance.java weka/core/Instances.java weka/core/Matrix.java weka/core/NoSupportForMissingValuesException.java weka/core/Option.java weka/core/OptionHandler.java weka/core/Range.java weka/core/SerializedObject.java weka/core/SparseInstance.java weka/core/Summarizable.java weka/core/UnassignedClassException.java weka/core/UnassignedDatasetException.java weka/core/UnsupportedAttributeTypeException.java weka/core/UnsupportedClassTypeException.java weka/core/Utils.java weka/core/WekaException.java weka/core/Version.java weka/core/matrix/CholeskyDecomposition.java weka/core/matrix/DoubleVector.java weka/core/matrix/EigenvalueDecomposition.java weka/core/matrix/ExponentialFormat.java weka/core/matrix/FlexibleDecimalFormat.java weka/core/matrix/FloatingPointFormat.java weka/core/matrix/IntVector.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/xml/KOML.java weka/core/xml/MethodHandler.java weka/core/xml/PropertyHandler.java weka/core/xml/SerialUIDChanger.java weka/core/xml/XMLBasicSerialization.java weka/core/xml/XMLDocument.java weka/core/xml/XMLInstances.java weka/core/xml/XMLOptions.java weka/core/xml/XMLSerialization.java weka/core/xml/XMLSerializationMethodHandler.java weka/core/ProtectedProperties.java weka/core/Statistics.java weka/core/SingleIndex.java weka/core/converters/AbstractFileLoader.java weka/core/converters/AbstractFileSaver.java weka/core/converters/AbstractLoader.java weka/core/converters/AbstractSaver.java weka/core/converters/ArffLoader.java weka/core/converters/ArffSaver.java weka/core/converters/BatchConverter.java weka/core/converters/C45Loader.java weka/core/converters/C45Saver.java weka/core/converters/ConverterUtils.java weka/core/converters/CSVLoader.java weka/core/converters/CSVSaver.java weka/core/converters/DatabaseConnection.java weka/core/converters/DatabaseConverter.java weka/core/converters/DatabaseLoader.java weka/core/converters/DatabaseSaver.java weka/core/converters/FileSourcedConverter.java weka/core/converters/IncrementalConverter.java weka/core/converters/LibSVMLoader.java weka/core/converters/LibSVMSaver.java weka/core/converters/Loader.java weka/core/converters/Saver.java weka/core/converters/SerializedInstancesLoader.java weka/core/converters/SerializedInstancesSaver.java weka/core/converters/TextDirectoryLoader.java weka/core/converters/URLSourcedLoader.java weka/core/converters/XRFFLoader.java weka/core/converters/XRFFSaver.java weka/core/TechnicalInformation.java weka/core/Drawable.java weka/core/TechnicalInformationHandler.java weka/core/CapabilitiesHandler.java weka/core/AttributeExpression.java weka/core/ClassDiscovery.java weka/core/MultiInstanceCapabilitiesHandler.java weka/core/WeightedInstancesHandler.java weka/core/Optimization.java weka/core/AttributeLocator.java weka/core/RelationalLocator.java weka/core/StringLocator.java weka/core/Queue.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/EstimatorUtils.java weka/estimators/IncrementalEstimator.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 weka/experiment/DatabaseUtils.java weka/experiment/DatabaseUtils.props weka/experiment/ResultProducer.java weka/experiment/ResultListener.java weka/classifiers/Classifier.java weka/classifiers/trees/**Id3**.java weka/classifiers/CostMatrix.java weka/classifiers/Evaluation.java weka/classifiers/Sourcable.java weka/classifiers/UpdateableClassifier.java weka/classifiers/evaluation/ConfusionMatrix.java weka/classifiers/evaluation/CostCurve.java weka/classifiers/evaluation/EvaluationUtils.java weka/classifiers/evaluation/NominalPrediction.java weka/classifiers/evaluation/NumericPrediction.java weka/classifiers/evaluation/Prediction.java weka/classifiers/evaluation/ThresholdCurve.java weka/classifiers/evaluation/TwoClassStats.java weka/classifiers/xml/XMLClassifier.java weka/classifiers/functions/Logistic.java weka/gui/GenericPropertiesCreator.java weka/gui/GenericPropertiesCreator.props weka/filter/Filter.java weka/filter/Sourcable.java weka/filter/unsupervised/attribute/RemoveUseless.java weka/filter/unsupervised/attribute/ReplaceMissingValues.java weka/filter/unsupervised/attribute/PotentialClassIgnorer.java weka/filter/unsupervised/attribute/Remove.java weka/filter/unsupervised/attribute/NominalToBinary.java weka/filter/UnsupervisedFilter.java weka/filter/StreamableFilter.java code
 * create the following directory structure:
 * Place the [[file:gcj-build-developer.xml]] file in the directory as.
 * Copy the in the  directory
 * 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 and props files 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 -I dist/retroweaver-all- .jar -findirect-dispatch -o id3 dist/weka.jar code code format="bash" export CLASSPATH=./weka.gcj/jar/retroweaver-all- .jar ./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-developer.xml]] (save as //build.xml//)

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