/* * wiigee - accelerometerbased gesture recognition * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga * * Developed at University of Oldenburg * Contact: wiigee@benjaminpoppinga.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.logic; import java.util.Vector; import org.wiigee.event.AccelerationEvent; import org.wiigee.util.Log; /** * This Class units a Quantizer-Component and an Model-Component. * In this implementation a k-mean-algorithm for quantization and * a hidden markov model as instance for the model has been used. * * @author Benjamin 'BePo' Poppinga */ public class GestureModel { /** The number of states the hidden markov model consists of */ private int numStates; /** The number of observations for the hmm and k-mean */ private int numObservations; /** The quantization component */ private Quantizer quantizer; /** The statistical model, hidden markov model */ private HMM markovmodell; /** The default probability of this gesturemodel, * needed for the bayes classifier */ private double defaultprobability; /** Creates a Unit (Quantizer&Model). * * @param id * int representation of a gesture "name"/class. */ public GestureModel() { this.numStates=8; // n=8 states empirical value this.numObservations=14; // k=14 observations empirical value this.markovmodell = new HMM(numStates, numObservations); // init model this.quantizer = new Quantizer(numStates); // init quantizer } /** * Trains the model to a set of motion-sequences, representing * different evaluations of a gesture * * @param trainsequence a vector of gestures */ public void train(Vector trainsequence) { // summarize all vectors from the different gestures in one // gesture called sum. double maxacc=0; double minacc=0; Gesture sum = new Gesture(); for(int i=0; i t = trainsequence.elementAt(i).getData(); // add the max and min acceleration, we later get the average maxacc+=trainsequence.elementAt(i).getMaxAcceleration(); minacc+=trainsequence.elementAt(i).getMinAcceleration(); // transfer every single accelerationevent of each gesture to // the new gesture sum for(int j=0; j seqs = new Vector(); for(int i=0; i defsequence) { double prob=0; for(int i=0; i