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:
42
src/org/wiigee/control/Wiigee.java
Normal file
42
src/org/wiigee/control/Wiigee.java
Normal 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+")");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 */
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user