ToPS
|
00001 /* 00002 * TrainPHMMBaumWelch.cpp 00003 * 00004 * Copyright 2011 Vitor Onuchic <vitoronuchic@gmail.com> 00005 * Andre Yoshiaki Kashiwabara <akashiwabara@usp.br> 00006 * Ígor Bonádio <ibonadio@ime.usp.br> 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 "ProbabilisticModel.hpp" 00026 #include "ProbabilisticModelCreator.hpp" 00027 #include "ConfigurationReader.hpp" 00028 #include "TrainPHMMBaumWelch.hpp" 00029 #include "util.hpp" 00030 #include "ProbabilisticModelCreatorClient.hpp" 00031 #include "PairHiddenMarkovModel.hpp" 00032 namespace tops { 00033 00034 ProbabilisticModelPtr TrainPHMMBaumWelch::create( ProbabilisticModelParameters & parameters) const 00035 { 00036 ProbabilisticModelParameterValuePtr initmodelpar = parameters.getMandatoryParameterValue("initial_model"); 00037 ProbabilisticModelParameterValuePtr trainpar = parameters.getMandatoryParameterValue("training_set"); 00038 ProbabilisticModelParameterValuePtr thrpar = parameters.getOptionalParameterValue("threshold"); 00039 ProbabilisticModelParameterValuePtr maxiterpar = parameters.getOptionalParameterValue("maxiter"); 00040 double threshold = 1e-5; 00041 if(thrpar != NULL) 00042 threshold = thrpar->getDouble(); 00043 int maxiter = 500; 00044 if(maxiterpar != NULL) 00045 maxiter = maxiterpar->getInt(); 00046 00047 ProbabilisticModelCreatorClient creator; 00048 std::string name = initmodelpar->getString(); 00049 ProbabilisticModelPtr m = creator.create(name); 00050 SequenceEntryList sample_set; 00051 AlphabetPtr alphabet = m->alphabet(); 00052 readSequencesFromFile(sample_set, alphabet, trainpar->getString()); 00053 SequenceList seqs; 00054 for(int i = 0; i < (int)sample_set.size(); i++) 00055 seqs.push_back(sample_set[i]->getSequence()); 00056 m->pairDecodable()->trainBaumWelch(seqs, maxiter, threshold); 00057 return m; 00058 } 00059 };