ToPS
|
00001 /* 00002 * TrainGHMMTransitions.cpp 00003 * 00004 * Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br> 00005 * Ígor Bonádio <ibonadio@ime.usp.br> 00006 * Vitor Onuchic <vitoronuchic@gmail.com> 00007 * Alan Mitchell Durham <aland@usp.br> 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 * MA 02110-1301, USA. 00023 */ 00024 00025 #include "TrainGHMMTransitions.hpp" 00026 #include "DiscreteIIDModelCreator.hpp" 00027 #include "DiscreteIIDModel.hpp" 00028 #include "ConfigurationReader.hpp" 00029 #include "GeneralizedHiddenMarkovModel.hpp" 00030 #include "ProbabilisticModelCreatorClient.hpp" 00031 #include "Alphabet.hpp" 00032 #include "Symbol.hpp" 00033 #include "ProbabilisticModelParameter.hpp" 00034 #include "TrainFixedLengthMarkovChain.hpp" 00035 #include <boost/algorithm/string.hpp> 00036 00037 namespace tops { 00038 ProbabilisticModelPtr TrainGHMMTransitionsCreator::create(ProbabilisticModelParameters & parameters) const { 00039 ProbabilisticModelParameterValuePtr ghmm_model_par = parameters.getMandatoryParameterValue("ghmm_model"); 00040 GeneralizedHiddenMarkovModelPtr result = GeneralizedHiddenMarkovModelPtr(new GeneralizedHiddenMarkovModel()); 00041 00042 if(ghmm_model_par == NULL) 00043 { 00044 std::cerr << help() <<std::endl; 00045 return result; 00046 } 00047 00048 ProbabilisticModelCreatorClient creator; 00049 std::string ghmm_file_name = ghmm_model_par->getString(); 00050 ProbabilisticModelPtr ghmm = creator.create(ghmm_file_name); 00051 00052 ProbabilisticModelParameters trainFixedMarkovChain; 00053 trainFixedMarkovChain.add("training_algorithm", StringParameterValuePtr(new StringParameterValue("FixedLengthMarkovChain"))); 00054 trainFixedMarkovChain.add("order", IntParameterValuePtr(new IntParameterValue(1))); 00055 trainFixedMarkovChain.add("training_set", parameters.getMandatoryParameterValue("training_set")); 00056 trainFixedMarkovChain.add("pseudo_counts", IntParameterValuePtr(new IntParameterValue(0))); 00057 00058 00059 ProbabilisticModelParameters ghmmParameters = ghmm->parameters(); 00060 00061 trainFixedMarkovChain.add("alphabet", ghmmParameters.getOptionalParameterValue("state_names")); 00062 TrainFixedLengthMarkovChainPtr markovChainTraining = TrainFixedLengthMarkovChainPtr(new TrainFixedLengthMarkovChain()); 00063 ProbabilisticModelPtr markovChain = markovChainTraining->create(trainFixedMarkovChain); 00064 ProbabilisticModelParameters markovChainParameters = markovChain->parameters(); 00065 00066 ProbabilisticModelParameterValuePtr probabilities_par = markovChainParameters.getMandatoryParameterValue("probabilities"); 00067 00068 ghmmParameters.set("transitions", probabilities_par); 00069 00070 ProbabilisticModelPtr m= creator.create(ghmmParameters); 00071 return m; 00072 } 00073 }