[marf-cvs] apps/TestPlugin HashAddFeatureExctractor.java,NONE,1.1 HashClassifier.java,1.1,1.2 Makefi
Brought to you by:
mokhov
From: Serguei A. M. <mo...@us...> - 2005-12-28 04:27:43
|
Update of /cvsroot/marf/apps/TestPlugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20281 Modified Files: HashClassifier.java Makefile TestPlugin.java Added Files: HashAddFeatureExctractor.java Log Message: Advance TestPlugin application. Add an example of a FeatureExtraction plugin -- HashAddFeatureExctractor. Adjust Makefile so it actually compiles HashAddFeatureExctractor and HashClassifier as they are only references in the application by name. Add some documentation in the form of comments. Index: HashClassifier.java =================================================================== RCS file: /cvsroot/marf/apps/TestPlugin/HashClassifier.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HashClassifier.java 19 Aug 2005 16:27:10 -0000 1.1 --- HashClassifier.java 28 Dec 2005 04:27:29 -0000 1.2 *************** *** 5,20 **** --- 5,67 ---- import marf.Storage.ResultSet; + + /** + * <p>A sample classification module plugin for MARF. + * Simply illustrates how to write classification plugins. + * + * The actual functionality is nothing serious. The results + * are represented as a sum, OR, AND, and XOR of the sum + * mod the number of speakers we have to get an ID. We get + * four "closest" results, which we collect in the ResultSet, + * and declare that the one with maximum value is the closest + * one.</p> + * + * <p>Note, this class actually directly implements the IClassification + * interface as the most general case. If your class doesn't inherit + * from anything, then you can inherit from the abstract Classification + * class to get most of the common implemenation in, and just implement + * the train(), classify(), and getResult() methods only. + * </p> + * + * <p>Copyright (c) 2005 The MARF Research and Development Group. + * For more details, please consult <a href="http://marf.sf.net">http://marf.sf.net</a>. + * </p> + * + * $Id$ + * + * @author Serguei Mokhov + * @since 0.3.0.5 of MARF + * @version $Revision$ + */ public class HashClassifier implements IClassification { + /** + * Local reference to the feature extraction module. + */ private IFeatureExtraction oFeatureExtraction = null; + + /** + * Final collection of the results. + */ private ResultSet oResultSet = new ResultSet(); + /** + * Number of samples in the database, to get a + * valid ID within the range. + */ public static final int MOD_BASE = 26; + /** + * Builds up a default classifier. + * We have nothing else to try. + */ public HashClassifier() { } + /** + * @see marf.Classification.IClassification#classify() + */ public boolean classify() throws ClassificationException *************** *** 52,55 **** --- 99,105 ---- } + /** + * @see marf.Classification.IClassification#train() + */ public boolean train() throws ClassificationException *************** *** 58,67 **** } public Result getResult() { - //return this.oResultSet.getMinimumResult(); return this.oResultSet.getMaximumResult(); } public ResultSet getResultSet() { --- 108,122 ---- } + /** + * @see marf.Classification.IClassification#getResult() + */ public Result getResult() { return this.oResultSet.getMaximumResult(); } + /** + * @see marf.Classification.IClassification#getResultSet() + */ public ResultSet getResultSet() { *************** *** 69,72 **** --- 124,130 ---- } + /** + * @see marf.Classification.IClassification#setFeatureExtraction(marf.FeatureExtraction.IFeatureExtraction) + */ public void setFeatureExtraction(IFeatureExtraction poFeatureExtraction) { *************** *** 74,77 **** --- 132,138 ---- } + /** + * @see marf.Classification.IClassification#getFeatureExtraction() + */ public IFeatureExtraction getFeatureExtraction() { --- NEW FILE: HashAddFeatureExctractor.java --- import marf.FeatureExtraction.FeatureExtractionException; import marf.FeatureExtraction.IFeatureExtraction; import marf.Preprocessing.IPreprocessing; /** * <p>A sample feature extraction module plugin for MARF. * Simply illustrates how to write feature extraction plugins. * * The actual functionality is nothing serious. The incoming * preprocessed data is split into chunks of 100 elements, * and then every chunk is added pairwise. * </p> * * <p>Note, this class actually directly implements the IFeatureExtraction * interface as the most general case. If your class doesn't inherit * from anything, then you can inherit from the abstract FeatureExtraction * class to get most of the common implemenation in, and just implement * the extracFeatures() method only. * </p> * * <p>Copyright (c) 2005 The MARF Research and Development Group. * For more details, please consult <a href="http://marf.sf.net">http://marf.sf.net</a>. * </p> * * $Id: HashAddFeatureExctractor.java,v 1.1 2005/12/28 04:27:29 mokhov Exp $ * * @author Serguei Mokhov * @since 0.3.0.5 of MARF * @version $Revision: 1.1 $ */ public class HashAddFeatureExctractor implements IFeatureExtraction { /** * Default size of the output vector with features. */ public static final int FEATURE_VECTOR_SIZE = 100; /** * The feature vector. */ private double[] adFeatures = new double[FEATURE_VECTOR_SIZE]; /** * Local reference to the preprocessing object. */ private IPreprocessing oPreprocessing = null; /** * Just a default constructor that has to be there * for the module to be instantiated via Class.newInstance(). */ public HashAddFeatureExctractor() { } /** * Just a constructor with specified preprocessing module * reference. * @param poPreprocessing the desired preprocessing module */ public HashAddFeatureExctractor(IPreprocessing poPreprocessing) { setPreprocessing(poPreprocessing); } /** * @see marf.FeatureExtraction.IFeatureExtraction#extractFeatures() */ public boolean extractFeatures() throws FeatureExtractionException { double[] adData = this.oPreprocessing.getSample().getSampleArray(); for(int i = 0; i < adData.length; i++) { this.adFeatures[i % FEATURE_VECTOR_SIZE] += adData[i]; } return true; } /** * @see marf.FeatureExtraction.IFeatureExtraction#getFeaturesArray() */ public double[] getFeaturesArray() { return this.adFeatures; } /** * @see marf.FeatureExtraction.IFeatureExtraction#getPreprocessing() */ public IPreprocessing getPreprocessing() { return this.oPreprocessing; } /** * @see marf.FeatureExtraction.IFeatureExtraction#setPreprocessing(marf.Preprocessing.IPreprocessing) */ public void setPreprocessing(IPreprocessing poPreprocessing) { assert poPreprocessing == null; this.oPreprocessing = poPreprocessing; } } // EOF Index: Makefile =================================================================== RCS file: /cvsroot/marf/apps/TestPlugin/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile 24 Dec 2005 22:38:12 -0000 1.2 --- Makefile 28 Dec 2005 04:27:29 -0000 1.3 *************** *** 13,19 **** # Lists of all *.java and *.class files JAVAFILES := $(APPDIRS:%=%/*.java) - CLASSES := $(APPDIRS:%=%/*.class) EXE = TestPlugin CLASSPATH = marf.jar:. --- 13,24 ---- # Lists of all *.java and *.class files JAVAFILES := $(APPDIRS:%=%/*.java) EXE = TestPlugin + CLASSFILES = \ + $(EXE).class \ + HashAddFeatureExctractor.class \ + HashClassifier.class + + CLASSPATH = marf.jar:. *************** *** 23,26 **** --- 28,35 ---- JVM = java + .SUFFIXES: .java .class + + .java.class: + $(JAVAC) $(JFLAGS) $< # *************** *** 28,32 **** # ! all: $(EXE).class @echo "$(EXE) build ok" --- 37,41 ---- # ! all: $(CLASSFILES) @echo "$(EXE) build ok" *************** *** 34,37 **** --- 43,50 ---- $(JAVAC) $(JFLAGS) $(EXE).java + HashAddFeatureExctractor.class: HashAddFeatureExctractor.java + HashClassifier.class: HashClassifier.java + + # # Run and Test *************** *** 97,101 **** clean: ! rm -f $(CLASSES) *~ maintainer-clean: clean --- 110,114 ---- clean: ! rm -f $(CLASSFILES) *~ maintainer-clean: clean Index: TestPlugin.java =================================================================== RCS file: /cvsroot/marf/apps/TestPlugin/TestPlugin.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestPlugin.java 19 Aug 2005 16:27:10 -0000 1.1 --- TestPlugin.java 28 Dec 2005 04:27:29 -0000 1.2 *************** *** 3,9 **** import marf.util.MARFException; public class TestPlugin { ! public static void main(String[] argv) throws MARFException { --- 3,29 ---- import marf.util.MARFException; + + /** + * <p>An application that tests plugin infratructure of MARF. + * It also serves as an example of how to write plugins for MARF. + * </p> + * + * <p>Copyright (c) 2005 The MARF Research and Development Group. + * For more details, please consult <a href="http://marf.sf.net">http://marf.sf.net</a>. + * </p> + * + * $Id$ + * + * @author Serguei Mokhov + * @since 0.3.0.5 of MARF + * @version $Revision$ + */ public class TestPlugin { ! /** ! * @param argv command-line arguments ! * @throws MARFException in case of any MARF error ! */ ! public static final void main(String[] argv) throws MARFException { *************** *** 12,17 **** MARF.setPreprocessingMethod(MARF.RAW); //MARF.setFeatureExtractionMethod(MARF.MIN_MAX_AMPLITUDES); ! MARF.setFeatureExtractionMethod(MARF.FFT); //MARF.setFeatureExtractionMethod(MARF.LPC); MARF.setClassificationMethod(MARF.CLASSIFICATION_PLUGIN); MARF.setClassificationPluginClass("HashClassifier"); --- 32,41 ---- MARF.setPreprocessingMethod(MARF.RAW); //MARF.setFeatureExtractionMethod(MARF.MIN_MAX_AMPLITUDES); ! ! //MARF.setFeatureExtractionMethod(MARF.FFT); //MARF.setFeatureExtractionMethod(MARF.LPC); + MARF.setFeatureExtractionMethod(MARF.FEATURE_EXTRACTION_PLUGIN); + MARF.setFeatureExtractionPluginClass("HashAddFeatureExctractor"); + MARF.setClassificationMethod(MARF.CLASSIFICATION_PLUGIN); MARF.setClassificationPluginClass("HashClassifier"); *************** *** 20,24 **** MARF.setSampleFile("/dev/null"); MARF.recognize(); ! System.out.println("Result: " + MARF.getResult()); System.out.println("ResultSet: " + MARF.getResultSet()); --- 44,48 ---- MARF.setSampleFile("/dev/null"); MARF.recognize(); ! System.out.println("Result: " + MARF.getResult()); System.out.println("ResultSet: " + MARF.getResultSet()); |