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:
128
test/org/wiigee/logic/ClassifierTest.java
Normal file
128
test/org/wiigee/logic/ClassifierTest.java
Normal 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() {
|
||||
}
|
||||
|
||||
}
|
||||
73
test/org/wiigee/logic/HMMTest.java
Normal file
73
test/org/wiigee/logic/HMMTest.java
Normal 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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user