Functions | Variables
optimizeModel.c File Reference

Model optimization routines. More...

Functions

void optRateCatPthreads (pllInstance *tr, partitionList *pr, double lower_spacing, double upper_spacing, double *lhs, int n, int tid)
 
void updatePerSiteRates (pllInstance *tr, partitionList *pr, boolean scaleRates)
 
void resetBranches (pllInstance *tr)
 Reset all branch lengths to default values. More...
 
void modOpt (pllInstance *tr, partitionList *pr, double likelihoodEpsilon)
 

Static functions

static void optParamGeneric (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll, int numberOfModels, int rateNumber, double lim_inf, double lim_sup, int whichParameterType)
 Optimize model parameters. More...
 
static void setRateModel (partitionList *pr, int model, double rate, int position)
 Set a specific rate in the substitition matrix. More...
 
static void changeModelParameters (int index, int rateNumber, double value, int whichParameterType, pllInstance *tr, partitionList *pr)
 Wrapper function for changing a specific model parameter to the specified value. More...
 
static void evaluateChange (pllInstance *tr, partitionList *pr, int rateNumber, double *value, double *result, boolean *converged, int whichFunction, int numberOfModels, linkageList *ll)
 Evaluate the change of a parameter. More...
 
static void brentGeneric (double *ax, double *bx, double *cx, double *fb, double tol, double *xmin, double *result, int numberOfModels, int whichFunction, int rateNumber, pllInstance *tr, partitionList *pr, linkageList *ll, double lim_inf, double lim_sup)
 Brent's algorithm. More...
 
static int brakGeneric (double *param, double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, double lim_inf, double lim_sup, int numberOfModels, int rateNumber, int whichFunction, pllInstance *tr, partitionList *pr, linkageList *ll, double modelEpsilon)
 Bracketing function. More...
 
static void optAlphasGeneric (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll)
 Optimize alpha rates. More...
 
static void optFreqs (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll, int numberOfModels, int states)
 Wrapper function for optimizing base frequency rates. More...
 
static void optBaseFreqs (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll)
 Optimize base frequencies. More...
 
static void optRates (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll, int numberOfModels, int states)
 Wrapper function for optimizing substitution rates. More...
 
static boolean AAisGTR (partitionList *pr)
 Check whether all protein partitions have been assigned a joint GTR matrix. More...
 
static void optRatesGeneric (pllInstance *tr, partitionList *pr, double modelEpsilon, linkageList *ll)
 Optimize substitution rates. More...
 
static int catCompare (const void *p1, const void *p2)
 
static void categorizePartition (pllInstance *tr, partitionList *pr, rateCategorize *rc, int model, int lower, int upper)
 
static void optRateCatModel (pllInstance *tr, partitionList *pr, int model, double lower_spacing, double upper_spacing, double *lhs)
 Optimize rates for CAT model. More...
 
static void optimizeRateCategories (pllInstance *tr, partitionList *pr, int _maxCategories)
 Optimize rate categories for CAT model. More...
 
static void printAAmatrix (partitionList *pr, double epsilon)
 Print protein GTR substitution matrix to file. More...
 
static void autoProtein (pllInstance *tr, partitionList *pr)
 Compute the best protein substitution model. More...
 

Variables

static const double MNBRAK_GOLD = 1.618034
 
static const double MNBRAK_TINY = 1.e-20
 
static const double MNBRAK_GLIMIT = 100.0
 
static const double BRENT_ZEPS = 1.e-5
 
static const double BRENT_CGOLD = 0.3819660
 
int optimizeRatesInvocations
 
int optimizeAlphaInvocations
 
int optimizeInvarInvocations
 
double masterTime
 
char ratesFileName [1024]
 
char workdir [1024]
 
char run_id [128]
 
char lengthFileName [1024]
 
char lengthFileNameModel [1024]
 
char * protModels [PLL_NUM_PROT_MODELS]
 

Detailed Description

Model optimization routines.

Function Documentation

static boolean AAisGTR ( partitionList pr)
static

Check whether all protein partitions have been assigned a joint GTR matrix.

Check whether there exists at least one protein partition and whether all protein partitions have been assigned a joint GTR matrix.

Parameters
prList of partitions
Returns
Return PLL_TRUE in case there exists at least one protein partition and all of protein partitions are assigned a joint GTR matrix. Otherwise return PLL_FALSE

+ Here is the caller graph for this function:

static void autoProtein ( pllInstance tr,
partitionList pr 
)
static

Compute the best protein substitution model.

Automatically compute the best protein substitution model for the dataset at hand

Parameters
trThe PLL instance
prList of partitions

+ Here is the call graph for this function:

static int brakGeneric ( double *  param,
double *  ax,
double *  bx,
double *  cx,
double *  fa,
double *  fb,
double *  fc,
double  lim_inf,
double  lim_sup,
int  numberOfModels,
int  rateNumber,
int  whichFunction,
pllInstance tr,
partitionList pr,
linkageList ll,
double  modelEpsilon 
)
static

Bracketing function.

Generic bracketing function required for Brent's algorithm.

Parameters
param
ax
bx
cx
fa
fb
fc
lim_infLower bound for the rate assignment
lim_supUpper bound for the rate assignment
numberOfModelsNumber of partitions for which we are optimizing
rateNumberIndex of the parameter to optimize
whichFunctionType of the model parameter. Possible values are ALPHA_F, RATE_F and FREQ_F
trPLL instance
prList of partitions
llLinkage list
modelEpsilon
Returns
Fill this
Todo:
Fill remaining details

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void brentGeneric ( double *  ax,
double *  bx,
double *  cx,
double *  fb,
double  tol,
double *  xmin,
double *  result,
int  numberOfModels,
int  whichFunction,
int  rateNumber,
pllInstance tr,
partitionList pr,
linkageList ll,
double  lim_inf,
double  lim_sup 
)
static

Brent's algorithm.

Generic implementation of Brent's algorithm for one-dimensional parameter optimization

Parameters
ax
bx
cx
fb
tol
xmin
result
numberOfModelsNumber of partitions for which we are optimizing
whichFunctionType of the model parameter. Possible values are ALPHA_F, RATE_F and FREQ_F
rateNumberIndex of the parameter to optimize
trPLL instance
prList of partitions
llLinkage list
lim_infLower bound for the rate assignment
lim_supUpper bound for the rate assignment
Todo:
Fill the rest of the entries. Also, why not preallocate all memory instead of allocating at every call? We can save a lot of time which is lost due to function calls, finding free memory blocks by allocation strategy, and also prevent mem fragmentation.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void changeModelParameters ( int  index,
int  rateNumber,
double  value,
int  whichParameterType,
pllInstance tr,
partitionList pr 
)
static

Wrapper function for changing a specific model parameter to the specified value.

Change the rateNumber-th model parameter of the type specified by whichParameterType to the value value. This routine is usually called by model optimization routines to restore the original model parameter vlaue when optimization leads to worse likelihood than the original, or when optimizing routines and testing the new parameter. In case of changing a frequency or substitution rate the Q matrix is also decomposed (into eigenvalues and eigenvectors)

Parameters
indexIndex of partition
rateNumberThe index of the model parameter
valueThe value to which the parameter must be changed
whichParameterTypeType of model parameter. Can be RATE_F, ALPHA_F or FREQ_F, that is substitution rates, alpha rates, or base frequencies rates

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void evaluateChange ( pllInstance tr,
partitionList pr,
int  rateNumber,
double *  value,
double *  result,
boolean *  converged,
int  whichFunction,
int  numberOfModels,
linkageList ll 
)
static

Evaluate the change of a parameter.

Evaluate the likelihood for each entry i in the linkage list when changing the rateNumber-th parameter of type whichFunction (ALPHA_F, RATE_F or FREQ_F) to value[i]. The resulting likelihood for each entry list i in the linkage list is then stored in result[i]

Parameters
trPLL instance
prList of partitions
rateNumberIndex of the parameter to optimize
value
resultAn array where the total likelihood of each entry list i in the linkage list ll is stored when evaluating the new i-th parameter of array value
converged
whichFunctionType of the model parameter. Possible values are ALPHA_F, RATE_F and FREQ_F
numberOfModelsNumber of partitions for which we are optimizing
llLinkage list
Todo:
Removed argument modelEpsilon as it is not used in this function. Maybe more things can be refactored.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void optAlphasGeneric ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll 
)
static

Optimize alpha rates.

Generic routine for alpha rates optimization

Parameters
trPLL instance
prList of partitions
modelEpsilonDon't know yet
llLinkage list
Todo:
Implement the LG4X model

+ Here is the call graph for this function:

static void optBaseFreqs ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll 
)
static

Optimize base frequencies.

Wrapper function for optimizing base frequencies

Parameters
trPLL instance
prList of partitions
modelEpsilon
llLinkage list

+ Here is the call graph for this function:

static void optFreqs ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll,
int  numberOfModels,
int  states 
)
static

Wrapper function for optimizing base frequency rates.

Wrapper function for optimizing base frequency rates of numberOfModels partitions. The function iteratively calls the function optParamGeneric for optimizing each of the states parameters

Parameters
trPLL instance
prList of partitions
modelEpsilonDont know yet
llLinkage list
numberOfModelsNumber of partitions that we are optimizing
statesNumber of states

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void optimizeRateCategories ( pllInstance tr,
partitionList pr,
int  _maxCategories 
)
static

Optimize rate categories for CAT model.

Optimize rate categories for CAT model

Parameters
trPLL instance
prList of partitions
_maxCategoriesNumber of categories

lhs = (double *)malloc(sizeof(double) * tr->originalCrunchedLength),

+ Here is the call graph for this function:

static void optParamGeneric ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll,
int  numberOfModels,
int  rateNumber,
double  lim_inf,
double  lim_sup,
int  whichParameterType 
)
static

Optimize model parameters.

Function for optimizing the rateNumber-th model parameter of type whichParameterTYpe, i.e. alpha rate, substitution rate, or base frequency rate, in all partitions with the valid flag set to PLL_TRUE.

Parameters
trPLL instance
prList of partitions
modelEpsilonA parameter passed for Brent / Brak
llLinkage list
numberOfModelsNumber of partitions for which we are optimizing
rateNumberIndex of the parameter to optimize
lim_infLower bound for the rate assignment
lim_supUpper bound for the rate assignment
whichParameterTypeType of the model parameter. Possible values are ALPHA_F, RATE_F and FREQ_F
Todo:
Describe the modelEpsilon parameter in detail

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void optRateCatModel ( pllInstance tr,
partitionList pr,
int  model,
double  lower_spacing,
double  upper_spacing,
double *  lhs 
)
static

Optimize rates for CAT model.

Parameters
trPLL instance
prList of partitions
modelPartition index
lower_specing
upper_spacing
lhs

+ Here is the caller graph for this function:

static void optRates ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll,
int  numberOfModels,
int  states 
)
static

Wrapper function for optimizing substitution rates.

Wrapper function for optimizing substitution rates of numberOfModels partitions. The function determines the number of free parameters and iteratively calls the function optParamGeneric for optimizing each parameter

Parameters
trPLL instance
prList of partitions
modelEpsilonDont know yet
llLinkage list
numberOfModelsNumber of partitions that we are optimizing
statesNumber of states

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void optRatesGeneric ( pllInstance tr,
partitionList pr,
double  modelEpsilon,
linkageList ll 
)
static

Optimize substitution rates.

Generic routine for substitution matrix (Q matrix) optimization

Parameters
trPLL instance
prList of partitions
modelEpsilonDon't know yet
llLinkage list

+ Here is the call graph for this function:

static void printAAmatrix ( partitionList pr,
double  epsilon 
)
static

Print protein GTR substitution matrix to file.

Print the protein GTR substritution matrix to a file. This is only printed if we are actually estimating a GTR model for all protein data partitions in the data

pr List of partitions

Parameters
epsilonDifference in likelihoods to be printed in the file

+ Here is the call graph for this function:

void resetBranches ( pllInstance tr)

Reset all branch lengths to default values.

Reset all branch lengths in the tree instance to default values (PLL_DEFAULTZ)

Parameters
trPLL instance

+ Here is the caller graph for this function:

static void setRateModel ( partitionList pr,
int  model,
double  rate,
int  position 
)
static

Set a specific rate in the substitition matrix.

This function is used to set the position-th substitution rate of partition index to rate.

Parameters
prList of partitions
modelIndex of partition
rateThe new value to which to set the specific substition rate
posititonThe number of the substition rate

+ Here is the caller graph for this function:

Variable Documentation

const double MNBRAK_GOLD = 1.618034
static

Golden ratio