Functions | Variables
makenewzGenericSpecial.c File Reference

Branch length optimization. More...

Functions

void branchLength_parallelReduce (pllInstance *tr, double *dlnLdlz, double *d2lnLdlz2, int numBranches)
 Reduce the first and second derivative of the likelihood function. More...
 
void makenewzIterative (pllInstance *tr, partitionList *pr)
 Precompute values (sumtable) from the 2 likelihood vectors of a given branch. More...
 
void execCore (pllInstance *tr, partitionList *pr, volatile double *_dlnLdlz, volatile double *_d2lnLdlz2)
 Compute first and second derivatives of the likelihood with respect to a given branch length. More...
 
void makenewzGeneric (pllInstance *tr, partitionList *pr, nodeptr p, nodeptr q, double *z0, int maxiter, double *result, boolean mask)
 Optimize branch length value(s) of a given branch with the Newton-Raphtson procedure. More...
 

Static functions

static void getVects (pllInstance *tr, partitionList *pr, unsigned char **tipX1, unsigned char **tipX2, double **x1_start, double **x2_start, int *tipCase, int model, double **x1_gapColumn, double **x2_gapColumn, unsigned int **x1_gap, unsigned int **x2_gap)
 
static void sumCAT_FLEX (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, const int states)
 
static void sumGAMMA_FLEX (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, const int states)
 
static void sumCAT_SAVE (int tipCase, double *sum, double *x1_start, double *x2_start, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, double *x1_gapColumn, double *x2_gapColumn, unsigned int *x1_gap, unsigned int *x2_gap)
 
static void sumGAMMA_GAPPED_SAVE (int tipCase, double *sumtable, double *x1_start, double *x2_start, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, double *x1_gapColumn, double *x2_gapColumn, unsigned int *x1_gap, unsigned int *x2_gap)
 
static void sumGAMMA (int tipCase, double *sumtable, double *x1_start, double *x2_start, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n)
 
static void sumCAT (int tipCase, double *sum, double *x1_start, double *x2_start, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n)
 
static void sumGAMMAPROT_GAPPED_SAVE (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, double *x1_gapColumn, double *x2_gapColumn, unsigned int *x1_gap, unsigned int *x2_gap)
 
static void sumGAMMAPROT_LG4 (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector[4], unsigned char *tipX1, unsigned char *tipX2, int n)
 
static void sumGAMMAPROT (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n)
 
static void sumGTRCATPROT (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n)
 
static void sumGTRCATPROT_SAVE (int tipCase, double *sumtable, double *x1, double *x2, double *tipVector, unsigned char *tipX1, unsigned char *tipX2, int n, double *x1_gapColumn, double *x2_gapColumn, unsigned int *x1_gap, unsigned int *x2_gap)
 
static void coreGTRGAMMAPROT_LG4 (double *gammaRates, double *EIGN[4], double *sumtable, int upper, int *wrptr, volatile double *ext_dlnLdlz, volatile double *ext_d2lnLdlz2, double lz)
 
static void coreGTRGAMMA (const int upper, double *sumtable, volatile double *ext_dlnLdlz, volatile double *ext_d2lnLdlz2, double *EIGN, double *gammaRates, double lz, int *wrptr)
 
static void coreGTRCAT (int upper, int numberOfCategories, double *sum, volatile double *d1, volatile double *d2, int *wgt, double *rptr, double *EIGN, int *cptr, double lz)
 
static void coreGTRGAMMAPROT (double *gammaRates, double *EIGN, double *sumtable, int upper, int *wrptr, volatile double *ext_dlnLdlz, volatile double *ext_d2lnLdlz2, double lz)
 
static void coreGTRCATPROT (double *EIGN, double lz, int numberOfCategories, double *rptr, int *cptr, int upper, int *wgt, volatile double *ext_dlnLdlz, volatile double *ext_d2lnLdlz2, double *sumtable)
 
static void coreCAT_FLEX (int upper, int numberOfCategories, double *sum, volatile double *d1, volatile double *d2, int *wgt, double *rptr, double *EIGN, int *cptr, double lz, const int states)
 
static void coreGAMMA_FLEX (int upper, double *sumtable, volatile double *ext_dlnLdlz, volatile double *ext_d2lnLdlz2, double *EIGN, double *gammaRates, double lz, int *wrptr, const int states)
 
static void topLevelMakenewz (pllInstance *tr, partitionList *pr, double *z0, int _maxiter, double *result)
 

Variables

const unsigned int mask32 [32]
 Array for setting bits 0 .. 31 in a bit vector, used in saveMemory technique for the gapVector.
 

Detailed Description

Branch length optimization.

Function Documentation

void branchLength_parallelReduce ( pllInstance tr,
double *  dlnLdlz,
double *  d2lnLdlz2,
int  numBranches 
)

Reduce the first and second derivative of the likelihood function.

We collect the first and second derivatives from the various threads and sum them up. It's similar to what we do in pllEvaluateGeneric() with the only difference that we have to collect two values (firsrt and second derivative) instead of onyly one (the log likelihood

Warning
operates on global reduction buffers globalResult
Parameters
trtree
dlnLdlzfirst derivative
d2lnLdlz2second derivative
void execCore ( pllInstance tr,
partitionList pr,
volatile double *  _dlnLdlz,
volatile double *  _d2lnLdlz2 
)

Compute first and second derivatives of the likelihood with respect to a given branch length.

Parameters
trlibrary instance
_dlnLdlzFirst derivative dl/dlz
_d2lnLdlz2Second derivative d(dl/dlz)/dlz
Warning
makenewzIterative should have been called to precompute tr->partitionData[model].sumBuffer at the given branch
Note
this function actually computes the first and second derivatives of the likelihood for a given branch stored in tr->coreLZ[model] Note that in the parallel case coreLZ must always be broadcasted together with the traversal descriptor, at least for optimizing branch lengths

+ Here is the caller graph for this function:

void makenewzGeneric ( pllInstance tr,
partitionList pr,
nodeptr  p,
nodeptr  q,
double *  z0,
int  maxiter,
double *  result,
boolean  mask 
)

Optimize branch length value(s) of a given branch with the Newton-Raphtson procedure.

Warning
A given branch may have one or several branch length values (up to PLL_NUM_BRANCHES), usually the later refers to partition-specific branch length values. Thus z0 and result represent collections rather than double values. The number of branch length values is given by tr->numBranches
Parameters
trLibrary instance
pOne node that defines the branch (p->z)
qThe other node side of the branch (usually p->back), but the branch length can be estimated even if p and q are not connected, e.g. before the insertion of a subtree.
z0Initial branch length value(s) for the given branch p->z
maxiterMaximum number of iterations in the Newton-Raphson procedure
resultResulting branch length value(s) for the given branch p->z
maskSpecifies if a mask to track partition convergence (tr->partitionConverged) is being used.
See Also
typical values for maxiter are constants iterations and PLL_NEWZPERCYCLE
Note
Requirement: q->z == p->z

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void makenewzIterative ( pllInstance tr,
partitionList pr 
)

Precompute values (sumtable) from the 2 likelihood vectors of a given branch.

Warning
These precomputations are stored in tr->partitionData[model].sumBuffer, which is used by function execCore
Parameters
trLibrary instance
Warning
the given branch is implicitly defined in tr by these nodes: pNumber = tr->td[0].ti[0].pNumber; qNumber = tr->td[0].ti[0].qNumber;
Note
This function should be called only once at the very beginning of each Newton-Raphson procedure for optimizing barnch lengths. It initially invokes an iterative newview call to get a consistent pair of vectors at the left and the right end of the branch and thereafter invokes the one-time only precomputation of values (sumtable) that can be re-used in each Newton-Raphson iteration. Once this function has been called we can execute the actual NR procedure

+ Here is the call graph for this function:

+ Here is the caller graph for this function: