![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <CONSTANZE/HMM.hpp> 00029 00030 using namespace constanze; 00031 00032 HMM::HMM(int numberOfStates): 00033 numberOfStates(numberOfStates) 00034 { 00035 // data type for transitionsMatrix and observationMatrix are vector of vector 00036 transitionsMatrix = new std::vector<std::vector<baumWelchDataType>*>(); 00037 observationMatrix = new std::vector<std::vector<baumWelchDataType>*>(); 00038 startStateProbability = new std::vector<baumWelchDataType>(); 00039 00040 for(int i = 0; i < numberOfStates; i++){ 00041 transitionsMatrix->push_back(new std::vector<baumWelchDataType>()); 00042 } 00043 00044 for(int j = 0; j < numberOfStates; j++){ 00045 observationMatrix->push_back(new std::vector<baumWelchDataType>()); 00046 } 00047 00048 // initialize transitionsMatrix, observationMatrix and startStateProbability 00049 for(int k = 0; k < numberOfStates; k++){ 00050 for(int l = 0; l < numberOfStates; l++){ 00051 transitionsMatrix->at(k)->push_back(1.0/numberOfStates); 00052 if(k == l) 00053 observationMatrix->at(k)->push_back(1.0); 00054 else 00055 observationMatrix->at(k)->push_back(0.0); 00056 } 00057 startStateProbability->push_back(1.0/numberOfStates); 00058 } 00059 00060 } 00061 00062 HMM::HMM(int numberOfStates, 00063 std::vector<std::vector<baumWelchDataType>*> *transitionsMatrix, 00064 std::vector<std::vector<baumWelchDataType>*> *observationMatrix, 00065 std::vector<baumWelchDataType> *startStateProbability): 00066 00067 numberOfStates(numberOfStates), 00068 transitionsMatrix(transitionsMatrix), 00069 observationMatrix(observationMatrix), 00070 startStateProbability(startStateProbability) 00071 { 00072 } 00073 00074 HMM::~HMM() 00075 { 00076 //set memory for interior vector free 00077 for(int i = 0; i < numberOfStates; i++){ 00078 delete transitionsMatrix->at(i); 00079 } 00080 00081 for(int j = 0; j < numberOfStates; j++){ 00082 delete observationMatrix->at(j); 00083 } 00084 00085 //set memory for exterior vector free 00086 delete transitionsMatrix; 00087 delete observationMatrix; 00088 delete startStateProbability; 00089 } 00090 00091 int 00092 HMM::getNumberOfStates() 00093 { 00094 return numberOfStates; 00095 } 00096 00097 baumWelchDataType 00098 HMM::getStartStateProbability(int index) 00099 { 00100 return startStateProbability->at(index); 00101 } 00102 00103 baumWelchDataType 00104 HMM::getElementInTransitionsMatrix(int row, int column) 00105 { 00106 return transitionsMatrix->at(row)->at(column); 00107 } 00108 00109 baumWelchDataType 00110 HMM::getElementInObservationMatrix(int row, int column) 00111 { 00112 return observationMatrix->at(row)->at(column); 00113 } 00114 00115 std::vector<std::vector<baumWelchDataType>*>* 00116 HMM::getTransitionsMatrix() 00117 { 00118 return transitionsMatrix; 00119 }
1.5.5