/* testPMat.c
November 2003, Z Yang
This small program tests two methods or routines for calculating the
transition probability matrix for a time reversible Markov rate matrix.
The first is the routine matexp(), which uses repeated squaring and works
on a general matrix (not necesarily time reversible). For large distances,
more squaring should be used, but I have not tested this extensively. You
can change TimeSquare to see its effect.
The second method, PMatQRev, uses a routine for eigen values and eigen
vectors for a symmetrical matrix. It involves some copying and moving
around when some frequencies are 0.
For each algorithm, this program generates random frequencies and random rate
matrix and then calls an algorithm to calculate P(t) = exp(Q*t).
cl -O2 -Ot -W4 testPMat.c tools.c
cc -O3 testPMat.c tools.c -lm
testPMat
*/
#include "paml.h"
int main(void)
{
int n=400, noisy=0, i,j;
int nr=10, ir, TimeSquare=10, algorithm; /* TimeSquare should be larger for large t */
double t=5, *Q, *pi, *space, s;
char timestr[96], *AlgStr[2]={"repeated squaring", "eigensolution"};
if((Q=(double*)malloc(n*n*5*sizeof(double))) ==NULL) error2("oom");
pi=Q+n*n; space=pi+n;
for(algorithm=0; algorithm<2; algorithm++) {
starttime();
SetSeed(1234567);
for (i=0; i