Changing things all the day. Badly more to come to prepare the lib for a demonstration in a magazine. :)

git-svn-id: svn://svn.code.sf.net/p/wiigee/code/trunk@91 c7eff9ee-dd40-0410-8832-91a4d88773cf
This commit is contained in:
bepo23
2009-06-09 13:06:09 +00:00
parent d6a6705bef
commit d836f00c91
6 changed files with 251 additions and 58 deletions

View File

@@ -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

View File

@@ -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+")");
}
}

View File

@@ -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 */

View File

@@ -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<fwd.length; i++) {
retVal[0] += fwd[i][0];
}
// iterate
for(int t=1; t<fwd[0].length; t++) {
for(int i=0; i<fwd.length; i++) {
retVal[t] += fwd[i][t];
}
}
return retVal;
}
// NEW b = state/symbol
private double[][] getScaledForwardProc(int[] sequence) {
double[][] fwd = this.forwardProc(sequence);
double[] s = this.getScalingFactors(sequence);
double[][] retVal = new double[fwd.length][fwd[0].length];
// init
// fixed t = 0 time
retVal[0][0] = this.b[0][0];
for(int i=0; i<retVal[0].length; i++) {
retVal[0][i] = 0.0;
}
// iterate
// t > 0 time
for(int t=1; t<retVal[0].length; t++) {
}
return null;
}
/***
* Returns the scaled Forward variable.
* TODO: Maybe try out if the other precalculated method is faster.

View File

@@ -0,0 +1,128 @@
/*
* 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.TestCase;
import org.wiigee.device.Device;
import org.wiigee.event.AccelerationEvent;
/**
*
* @author bepo
*/
public class ClassifierTest extends TestCase {
public ClassifierTest(String testName) {
super(testName);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Test of classifyGesture method, of class Classifier.
*/
public void testClassifyGesture() {
// create a pseudo-device
Device d = new Device();
// create 3 gestures
Gesture g0 = new Gesture();
Gesture g1 = new Gesture();
Gesture g2 = new Gesture();
g0.add(new AccelerationEvent(d, 0.0, 0.0, 0.0, 0.0));
g0.add(new AccelerationEvent(d, 1.0, 1.0, 1.0, 0.0));
g0.add(new AccelerationEvent(d, 2.0, 2.0, 2.0, 0.0));
g0.add(new AccelerationEvent(d, 1.0, 1.0, 1.0, 0.0));
g1.add(new AccelerationEvent(d, -1.0, 1.0, -1.0, 0.0));
g1.add(new AccelerationEvent(d, -1.0, 3.0, -1.0, 0.0));
g1.add(new AccelerationEvent(d, -1.0, 1.0, -1.0, 0.0));
g1.add(new AccelerationEvent(d, -1.0, 3.0, -1.0, 0.0));
g2.add(new AccelerationEvent(d, -2.0, -2.0, -2.0, -2.0));
g2.add(new AccelerationEvent(d, -2.0, -2.0, -2.0, -2.0));
g2.add(new AccelerationEvent(d, -2.0, -2.0, -2.0, -2.0));
g2.add(new AccelerationEvent(d, -2.0, -2.0, -2.0, -2.0));
// create 3 gesturesets with 1 gesture each
Vector<Gesture> gs0 = new Vector<Gesture>();
Vector<Gesture> gs1 = new Vector<Gesture>();
Vector<Gesture> gs2 = new Vector<Gesture>();
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() {
}
}

View File

@@ -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<int[]> trainsequence = new Vector<int[]>();
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.");
}
}
}