// $Id: bestParamUSSRV.cpp 4951 2008-09-24 11:16:58Z osnatz $ #include "bestParamUSSRV.h" /* structure of this method: (1) checks of the number of parameters to optimize, and decide how many parameters optimizations iteration, and how many parameters+bbl iterations will be done. (2) A loop over the parameters+bbl iterations (2.1) A loop over the parameters optimization iterations (2.1.1) Optimize alpha (2.1.2) Optimize nu (2.1.3) Optimize f if the likelihood wasn't changed during this loop --> parameters converged --> break (2.2) BBL if the likelihood wasn't changed during this loop --> parameters+bbl converged --> break (3) return likelihood */ // *************** // * USSRV * // *************** MDOUBLE bestParamUSSRV::operator() (tree& et, const sequenceContainer& sc, const sequenceContainer& baseSc, ussrvModel& model, const Vdouble * weights /* =NULL */, const MDOUBLE AlphaUpperBound /* = 15 */, const MDOUBLE NuUpperBound /* = 15 */, const MDOUBLE FUpperBound /* = 1 */, const MDOUBLE epsilonParamOptimization /* = 0.01 */, const MDOUBLE epsilonLikelihoodImprovment /* = 0.01 */, const int maxIterations /* = 50 */, const int maxOfParametersAndBblIterations /* = 40 */) { _bestL = VERYSMALL; MDOUBLE newL = VERYSMALL; bestAlphaFixedTreeUSSRV alphaOptimization; bestNuFixedTreeUSSRV nuOptimization; bestFFixedTreeUSSRV fOptimization; int it, bblIt; int numberOfIterations(maxIterations); int numberOfParametersAndBblIterations(maxOfParametersAndBblIterations); // if only one parameter is optimize (only Alpha or only Nu or only F) then we need only one iteration. // if we only do bbl, without any optimization of the parameters, then we don't need iterations at all. int countParameters2Optimize(0); if (_AlphaOptimizationFlag) countParameters2Optimize++; if (_NuOptimizationFlag) countParameters2Optimize++; if (_FOptimizationFlag) countParameters2Optimize++; if (countParameters2Optimize==0) { numberOfIterations=0; numberOfParametersAndBblIterations=1; } else if (countParameters2Optimize==1) numberOfIterations=1; if (_bblOptimizationFlag == false) numberOfParametersAndBblIterations = 1; _bestAlpha = model.getAlpha(); _bestNu = model.getNu(); _bestF = model.getF(); bool changes(false); bool bblChanges(false); for (bblIt=0; bblIt < numberOfParametersAndBblIterations; ++bblIt) { LOG(8,<<"bestParamUSSRV, params+bbl, iteration: " << bblIt << endl); bblChanges = false; // parameters optimizations (without bbl) // in each iteration : optimization of Alpha and then optimization of Nu, and then of F. for (it=0; it < numberOfIterations; ++it) { changes = false; // Alpha optimization if (_AlphaOptimizationFlag) { LOGDO(5,printTime(myLog::LogFile())); newL = alphaOptimization(et,sc,baseSc,model,weights,AlphaUpperBound,epsilonParamOptimization); //the improvement in Likelihood is smaller than epsilon if (newL < _bestL) { LOG(5,<<"likelihood went down in LS! (Alpha optimization)"< _bestL+epsilonLikelihoodImprovment) bblChanges = true; if (newL < _bestL){ LOG(5,<<"likelihood went down in LS! (BBL)"<(ssrvSp.getPijAccelerator()->getReplacementModel()); gammaDistribution* gammaDist = static_cast(pMulRM->getDistribution()); _bestAlpha = gammaDist->getAlpha(); _bestNu = pMulRM->getRateOfRate(); bool changes(false); bool bblChanges(false); for (bblIt=0; bblIt < numberOfParametersAndBblIterations; ++bblIt) { bblChanges = false; // Set initial values of lower/upper bounds for params MDOUBLE AlphaLowerBoundCur = 0.0; MDOUBLE AlphaUpperBoundCur = AlphaUpperBound; MDOUBLE NuLowerBoundCur = 0.0; MDOUBLE NuUpperBoundCur = NuUpperBound; MDOUBLE TrTvLowerBoundCur = 0.0; MDOUBLE TrTvUpperBoundCur = TrTvUpperBound; MDOUBLE ThetaLowerBoundCur = 0.0; MDOUBLE ThetaUpperBoundCur = 1.0; // And for epsilon MDOUBLE epsilonParamOptimizationCur = epsilonParamOptimization; // parameters optimizations (without bbl) // in each iteration : optimization of Alpha and then optimization of Nu, and then of F. for (it=0; it < numberOfIterations; ++it) { LOG(8,<<"bestParamUSSRV, params+bbl, iteration: " << bblIt << endl); changes = false; // Alpha optimization if (_AlphaOptimizationFlag) { LOGDO(5,printTime(myLog::LogFile())); newL = alphaOptimization(et,sc,ssrvSp,weights,AlphaLowerBoundCur,AlphaUpperBoundCur,epsilonParamOptimizationCur); //the improvement in Likelihood is smaller than epsilon if (newL < _bestL) { LOG(5,<<"likelihood went down in LS! (Alpha optimization)"< _bestL+epsilonLikelihoodImprovment) bblChanges = true; if (newL < _bestL){ LOG(5,<<"likelihood went down in LS! (BBL)"<