ToPS
|
00001 /* 00002 * FactorableModelPrefixSumArray.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 "FactorableModelPrefixSumArray.hpp" 00026 00027 namespace tops 00028 { 00029 00030 00032 void FactorableModelPrefixSumArray::initialize(const Sequence & s) { 00033 if(_last == s) 00034 return; 00035 _last =s ; 00036 _alpha.resize(s.size() + 1); 00037 _precision.resize(s.size() + 1); 00038 _alpha[0] = 0; 00039 for(int i = 0 ; i < (int) s.size() ; i++) { 00040 double prob = _model->evaluate(s, i, i); 00041 if(close(prob, -HUGE, 1e-1)) 00042 { 00043 _precision[i+1] = _precision[i]+1; 00044 _alpha[i+1] = _model->evaluate(s,i,i); 00045 } 00046 else 00047 { 00048 _alpha[i+1] = _alpha[i] + prob; 00049 _precision[i+1] = _precision[i]; 00050 } 00051 } 00052 #if 0 00053 for(int i = 0; i < s.size(); i++) 00054 std::cerr << " " << i << " " << m->alphabet()->getSymbol(s[i])->name() << " " << _alpha[i] << " " << _precision[i] << std::endl; 00055 #endif 00056 00057 } 00058 00060 double FactorableModelPrefixSumArray::compute(int begin, int end ) const { 00061 if((begin >= 0) && ((end + 1) < (int) _alpha.size())) 00062 { 00063 if((_precision[end+1] - _precision[begin]) > 0) 00064 return -HUGE; 00065 return _alpha[end+1] - _alpha[begin]; 00066 } 00067 else 00068 return -HUGE; 00069 } 00070 00071 00072 }