1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/***************************************************************************
* Copyright (C) 2009 by BUI Quang Minh *
* minh.bui@univie.ac.at *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef STOPRULE_H
#define STOPRULE_H
#include "tools.h"
#include "checkpoint.h"
/**
Stopping rule
@author BUI Quang Minh <minh.bui@univie.ac.at>
*/
class StopRule : public CheckpointFactory
{
public:
/**
constructor
*/
StopRule();
void initialize(Params ¶ms);
/**
destructor
*/
~StopRule();
void getUFBootCountCheck(int &ufboot_count, int &ufboot_count_check);
/**
save object into the checkpoint
*/
virtual void saveCheckpoint();
/**
restore object from the checkpoint
*/
virtual void restoreCheckpoint();
/**
read improved iteration number from a file
@param fileName file name
*/
void readFile (const char *fileName);
/**
Add the iteration number that improve trees
@param iteration improved iteration number
*/
void addImprovedIteration(int iteration);
/**
Get the last iteration number that improved trees
@return the last iteration number that improved trees
*/
int getLastImprovedIteration();
/**
main function to check the stop condition
@param current_iteration current iteration number
@param cur_correlation current correlation coefficient for bootstrap convergence
@return TRUE if stop condition is met, FALSE otherwise
*/
bool meetStopCondition(int cur_iteration, double cur_correlation);
/**
return TRUE if cur_correlation is high enough
@param cur_correlation correlation coefficient
*/
bool meetCorrelation(double cur_correlation) {
return cur_correlation >= min_correlation;
}
/** get the remaining time to converge, in seconds */
double getRemainingTime(int cur_iteration);
/**
@return the number of iterations required to stop the search
*/
// int getNumIterations();
/**
@return predicted iteration, 0 if no prediction has been made
*/
// int getPredictedIteration(int cur_iteration);
int getCurIt() const {
return curIteration;
}
void setCurIt(int curIteration) {
StopRule::curIteration = curIteration;
}
void shouldStop() {
should_stop = true;
}
private:
/**
* Current iteration number
*/
int curIteration;
double predict (double &upperTime);
/**
stop condition
*/
STOP_CONDITION stop_condition;
/**
confidence value of prediction
*/
double confidence_value;
/**
minimum number of iterations
*/
int min_iteration;
/**
maximum number of iterations
*/
int max_iteration;
/**
predicted number of iterations
*/
int predicted_iteration;
/** number of unsuccessful iterations to stop the search */
int unsuccess_iteration;
/** bootstrap correlation threshold to stop */
double min_correlation;
/** step size for checking bootstrap convergence */
int step_iteration;
/** max wall-clock running time to stop */
double max_run_time;
/** starting real time of the program */
double start_real_time;
/** TRUE to override stop condition */
bool should_stop;
/* FOLLOWING CODES ARE FROM IQPNNI version 3 */
// int nTime_;
DoubleVector time_vec;
void cmpInvMat (DoubleMatrix &oriMat, DoubleMatrix &invMat, int size);
void readMat (char *fileName, DoubleMatrix &oriMat, int &size);
void multiple (DoubleMatrix &mat1, DoubleMatrix &mat2, DoubleMatrix &proMat);
void multiple (DoubleMatrix &mat1, DoubleVector &vec2, DoubleVector &proVec);
void multiple (DoubleVector &vec1, DoubleMatrix &mat2, DoubleVector &proVec);
void multiple (DoubleVector &vec1, DoubleVector &vec2, DoubleMatrix &proMat);
double multiple (DoubleVector &vec1, DoubleVector &vec2);
void readVector(DoubleVector &tmpTimeVec_);
/* THE FOLLOWING CODE COMES FROM tools.c in Yang's PAML package */
//----------------------------------------------------------------------------------------
double cmpLnGamma (double alpha);
double cmpMuy (int k);
void cmpLamdaMat (int k, DoubleMatrix &lamdaMat);
void cmpVecA (int k, DoubleVector &aVec);
double cmpExtinctTime (int k);
double cmpUpperTime (int k, double alpha);
};
#endif
|