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
|
/*
* ratefreeinvar.h
*
* Created on: Nov 7, 2014
* Author: minh
*/
#ifndef RATEFREEINVAR_H_
#define RATEFREEINVAR_H_
#include "rateinvar.h"
#include "ratefree.h"
class RateFreeInvar: public RateInvar, public RateFree {
public:
/**
constructor
@param ncat number of rate categories
@param tree associated phylogenetic tree
*/
RateFreeInvar(int ncat, double start_alpha, string params, bool sorted_rates, double p_invar_sites, string opt_alg, PhyloTree *tree);
/**
start structure for checkpointing
*/
virtual void startCheckpoint();
/**
save object into the checkpoint
*/
virtual void saveCheckpoint();
/**
restore object from the checkpoint
*/
virtual void restoreCheckpoint();
/**
return the number of dimensions
*/
virtual int getNDim() { return RateInvar::getNDim() + RateFree::getNDim(); }
/**
get the proportion of sites under a specified category.
@param category category ID from 0 to #category-1
@return the proportion of the specified category
*/
virtual double getProp(int category) { return prop[category]; }
/**
get the rate of a specified category. Default returns 1.0 since it is homogeneous model
@param category category ID from 0 to #category-1
@return the rate of the specified category
*/
virtual double getRate(int category) { return RateFree::getRate(category); }
/**
* @return model name with parameters in form of e.g. GTR{a,b,c,d,e,f}
*/
virtual string getNameParams() {
return RateInvar::getNameParams() + RateFree::getNameParams();
}
/**
override function from Optimization class, used by the minimizeOneDimen() to optimize
p_invar or gamma shape parameter.
@param value value of p_invar (if cur_optimize == 1) or gamma shape (if cur_optimize == 0).
*/
virtual double computeFunction(double value);
/**
* setup the bounds for joint optimization with BFGS
*/
virtual void setBounds(double *lower_bound, double *upper_bound, bool *bound_check);
/**
optimize parameters
@return the best likelihood
*/
virtual double optimizeParameters(double gradient_epsilon);
/**
the target function which needs to be optimized
@param x the input vector x
@return the function value at x
*/
virtual double targetFunk(double x[]);
/**
write information
@param out output stream
*/
virtual void writeInfo(ostream &out);
/**
write parameters, used with modeltest
@param out output stream
*/
virtual void writeParameters(ostream &out);
virtual void setNCategory(int ncat);
protected:
/**
this function is served for the multi-dimension optimization. It should pack the model parameters
into a vector that is index from 1 (NOTE: not from 0)
@param variables (OUT) vector of variables, indexed from 1
*/
virtual void setVariables(double *variables);
/**
this function is served for the multi-dimension optimization. It should assign the model parameters
from a vector of variables that is index from 1 (NOTE: not from 0)
@param variables vector of variables, indexed from 1
@return TRUE if parameters are changed, FALSE otherwise (2015-10-20)
*/
virtual bool getVariables(double *variables);
private:
/**
current parameter to optimize. 0 if gamma shape or 1 if p_invar.
*/
int cur_optimize;
};
#endif /* RATEFREEINVAR_H_ */
|