![]() |
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 00029 #include <CONSTANZE/Measurement.hpp> 00030 #include <iostream> 00031 00032 using namespace constanze; 00033 00034 Measurement::Measurement(const wns::pyconfig::View& config): 00035 pyco(config), 00036 log(pyco.get("logger")), 00037 estimatorNumberOfStates(config.get<int>("estimatorNumberOfStates")), 00038 probeWindow(config.get<double>("probeWindow")), 00039 MMPPestimationResultFileName(config.get<std::string>("MMPPestimationResultFileName")) 00040 { 00041 MESSAGE_SINGLE(NORMAL, log, "Measurement created."); 00042 MESSAGE_SINGLE(NORMAL, log, "estimatorNumberOfStates="<<estimatorNumberOfStates); 00043 meanRateVector = new std::vector<double>(); 00044 00045 // pyconfig, configurate mean rate for every state 00046 for(int i = 0; i < config.get<int>("estimatorNumberOfStates"); i++) { 00047 double meanRate = pyco.get<double>("meanRateList",i); 00048 meanRateVector->push_back(meanRate); 00049 MESSAGE_SINGLE(NORMAL, log, " meanRateList["<<i<<"]="<<meanRate); 00050 } 00051 00052 boundaryVector = new std::vector<double>(); 00053 00058 for(unsigned int j = 0; j < meanRateVector->size()-1; j++){ 00059 double boundary = meanRateVector->at(j)+(meanRateVector->at(j+1)-meanRateVector->at(j))/2; 00060 boundaryVector->push_back(boundary); 00061 MESSAGE_SINGLE(NORMAL, log, " boundaryVector["<<j<<"]="<<boundary); 00062 } 00063 } 00064 00065 Measurement::~Measurement() 00066 { 00067 delete meanRateVector; 00068 delete boundaryVector; 00069 } 00070 00071 HMM* 00072 Measurement::calculate(int numberOfStates, std::vector<int> *observationVector) 00073 { 00074 int iterations = 100; // make sense 00075 00076 HMM *initialHMM = new HMM(numberOfStates); 00077 HMM *hmm = baumwelch->baumWelch(initialHMM, observationVector, iterations); 00078 00079 return hmm; 00080 } 00081 00082 void 00083 Measurement::output(std::vector<std::vector<baumWelchDataType>*> *transitionsMatrix, int numberOfStates) 00084 { 00085 for(int i = 0; i < numberOfStates; i++){ 00086 for(int j = 0; j < numberOfStates; j++){ 00087 std::cout << transitionsMatrix->at(i)->at(j) << '\t'; 00088 } 00089 std::cout << std::endl; 00090 } 00091 } 00092 00093 void Measurement::output_python(std::vector<std::vector<baumWelchDataType>*> *transitionsMatrix, int numberOfStates,std::string estimationResultFileName) 00094 { 00095 std::fstream outfile; 00096 outfile.open(estimationResultFileName.c_str(),std::ios::out); 00097 00098 00099 outfile << "numberOfStates = " << numberOfStates << std::endl; 00100 outfile << "slotTime = " << probeWindow << std::endl; 00101 for(int i = 0; i < numberOfStates; i++){ 00102 outfile << "# rate["<<i<<"] = "<< meanRateVector->at(i) << "bit/s" << std::endl; 00103 } 00104 00105 outfile << "transitionMatrix = " << " ("; 00106 for(int i = 0; i < numberOfStates; i++){ 00107 00108 if(i != 0) 00109 outfile << " "; 00110 00111 outfile << "( "; 00112 00113 for(int j = 0; j < numberOfStates; j++){ 00114 00115 if(j != numberOfStates-1) 00116 outfile << transitionsMatrix->at(i)->at(j) << ", "; 00117 else{ 00118 if(i != numberOfStates-1) 00119 outfile << transitionsMatrix->at(i)->at(j) << " ),"; 00120 else 00121 outfile << transitionsMatrix->at(i)->at(j) << " ))"; 00122 } 00123 } 00124 outfile << std::endl; 00125 } 00126 00127 outfile.close(); 00128 } 00129 00130 int 00131 Measurement::getEstimatorNumberOfStates() 00132 { 00133 return estimatorNumberOfStates; 00134 } 00135 00136 std::string 00137 Measurement::getMMPPestimationResultFileName() 00138 { 00139 return MMPPestimationResultFileName; 00140 } 00141
1.5.5