diff --git a/nbproject/project.properties b/nbproject/project.properties index 80e6b09..37def62 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -23,13 +23,9 @@ dist.dir=dist dist.jar=${dist.dir}/wiigee-lib.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= -file.reference.android.jar=lib/android.jar -file.reference.bluecove-2.1.0.jar=lib/bluecove-2.1.0.jar includes=** jar.compress=false -javac.classpath=\ - ${file.reference.bluecove-2.1.0.jar}:\ - ${file.reference.android.jar} +javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/org/wiigee/control/Wiigee.java b/src/org/wiigee/control/Wiigee.java new file mode 100644 index 0000000..4ac7d95 --- /dev/null +++ b/src/org/wiigee/control/Wiigee.java @@ -0,0 +1,42 @@ +/* + * wiigee - accelerometerbased gesture recognition + * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga + * + * Developed at University of Oldenburg + * Contact: benjamin.poppinga@informatik.uni-oldenburg.de + * + * This file is part of wiigee. + * + * wiigee is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.wiigee.control; + +import org.wiigee.util.Log; + +/** + * + * @author bepo + */ +public class Wiigee { + + protected static String version = "1.5 alpha"; + protected static String releasedate = "20090605"; + + protected Wiigee() { + Log.write("This is wiigee version "+version+" ("+releasedate+")"); + } + +} diff --git a/src/org/wiigee/logic/HMM.java b/src/org/wiigee/logic/HMM.java index 53fbc63..3e0ce22 100755 --- a/src/org/wiigee/logic/HMM.java +++ b/src/org/wiigee/logic/HMM.java @@ -40,20 +40,20 @@ import org.wiigee.util.Log; public class HMM { /** The number of states */ - private int numStates; + protected int numStates; /** The number of observations */ - private int numObservations; + protected int numObservations; /** The initial probabilities for each state: p[state] */ - private double pi[]; + protected double pi[]; /** The state change probability to switch from state A to * state B: a[stateA][stateB] */ - private double a[][]; + protected double a[][]; /** The probability to emit symbol S in state A: b[stateA][symbolS] */ - private double b[][]; + protected double b[][]; /** * Initialize the Hidden Markov Model in a left-to-right version. @@ -199,7 +199,7 @@ public class HMM { * @return Array[State][Time] * */ - private double[][] forwardProc(int[] o) { + protected double[][] forwardProc(int[] o) { double[][] f = new double[numStates][o.length]; for (int l = 0; l < f.length; l++) { f[l][0] = pi[l] * b[l][o[0]]; @@ -241,7 +241,7 @@ public class HMM { * @param o observation sequence o * @return Array[State][Time] */ - public double[][] backwardProc(int[] o) { + protected double[][] backwardProc(int[] o) { int T = o.length; double[][] bwd = new double[numStates][T]; /* Basisfall */ diff --git a/src/org/wiigee/logic/PreciseHMM.java b/src/org/wiigee/logic/PreciseHMM.java index 8e50b25..9e9ce9e 100755 --- a/src/org/wiigee/logic/PreciseHMM.java +++ b/src/org/wiigee/logic/PreciseHMM.java @@ -249,52 +249,6 @@ public class PreciseHMM { return sf; } // calculateScalingFactor - - // NEW - // returns s(t). - private double[] getScalingFactors(int[] sequence) { - double[][] fwd = this.forwardProc(sequence); // i t - double[] retVal = new double[fwd[0].length]; - - // init - // fixed t = 0 time - for(int i=0; i 0 time - for(int t=1; t gs0 = new Vector(); + Vector gs1 = new Vector(); + Vector gs2 = new Vector(); + gs0.add(g0); + gs1.add(g1); + gs2.add(g2); + + // create three gesturemodels and train these + GestureModel gm0 = new GestureModel(); + GestureModel gm1 = new GestureModel(); + GestureModel gm2 = new GestureModel(); + gm0.train(gs0); + gm1.train(gs1); + gm2.train(gs2); + + // create a classifier and add gesturemodels + Classifier classifier = new Classifier(); + classifier.addGestureModel(gm0); + classifier.addGestureModel(gm1); + classifier.addGestureModel(gm2); + + // classify gesture + int result0 = classifier.classifyGesture(g0); + int result1 = classifier.classifyGesture(g1); + int result2 = classifier.classifyGesture(g2); + + if((result0 != 0) || + (result1 != 1) || + (result2 != 2)) { + fail("Wrong gesture classified."); + } + + } + + + + /** + * Test of addGestureModel method, of class Classifier. + */ + public void testAddGestureModel() { + } + + /** + * Test of getGestureModel method, of class Classifier. + */ + public void testGetGestureModel() { + } + + /** + * Test of getGestureModels method, of class Classifier. + */ + public void testGetGestureModels() { + } + + /** + * Test of getCountOfGestures method, of class Classifier. + */ + public void testGetCountOfGestures() { + } + + /** + * Test of clear method, of class Classifier. + */ + public void testClear() { + } + +} diff --git a/test/org/wiigee/logic/HMMTest.java b/test/org/wiigee/logic/HMMTest.java new file mode 100644 index 0000000..d24039d --- /dev/null +++ b/test/org/wiigee/logic/HMMTest.java @@ -0,0 +1,73 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.wiigee.logic; + +import java.util.Vector; +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * + * @author bepo + */ +public class HMMTest extends TestCase { + + public HMMTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Probabilistic test of the train method, of class HMM. + */ + public void testTrain() { + System.out.println("train"); + + HMM instance = new HMM(8, 14); + + // setup a trainsequence + Vector trainsequence = new Vector(); + trainsequence.add(new int[] { 0, 1, 2, 1, 6, 4, 3, 2}); + trainsequence.add(new int[] { 0, 1, 2, 2, 6, 3, 3, 1}); + trainsequence.add(new int[] { 0, 1, 2, 2, 6, 3, 2, 2}); + + // setup a failing trainsequence + int[] fail = new int[] { 5, 5, 5, 5, 5, 5, 5, 5}; + + // train the hmm + instance.train(trainsequence); + + double probA = instance.getProbability(trainsequence.elementAt(0)); + double probB = instance.getProbability(trainsequence.elementAt(1)); + double probC = instance.getProbability(trainsequence.elementAt(2)); + double probFAIL = instance.getProbability(fail); + + System.out.println("probA = "+probA); + System.out.println("probB = "+probB); + System.out.println("probC = "+probC); + System.out.println("probFAIL = "+probFAIL); + + if((probA <= 1.0E-10) || + (probB <= 1.0E-10) || + (probC <= 1.0E-10)) { + fail("Probabilities to low to be accurate."); + } + + if(probFAIL > 0.0) { + fail("Fake probability to high."); + } + } + +}