1
/* RAxML-VI-HPC (version 2.2) a program for sequential and parallel estimation of phylogenetic trees
2
* Copyright August 2006 by Alexandros Stamatakis
4
* Partially derived from
5
* fastDNAml, a program for estimation of phylogenetic trees from sequences by Gary J. Olsen
9
* Programs of the PHYLIP package by Joe Felsenstein.
11
* This program is free software; you may redistribute it and/or modify its
12
* under the terms of the GNU General Public License as published by the Free
13
* Software Foundation; either version 2 of the License, or (at your option)
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22
* For any other enquiries send an Email to Alexandros Stamatakis
23
* Alexandros.Stamatakis@epfl.ch
25
* When publishing work that is based on the results from RAxML-VI-HPC please cite:
27
* Alexandros Stamatakis:"RAxML-VI-HPC: maximum likelihood-based phylogenetic analyses with thousands of taxa and mixed models".
28
* Bioinformatics 2006; doi: 10.1093/bioinformatics/btl446
32
#include <sys/times.h>
33
#include <sys/types.h>
48
extern char **globalArgv;
49
extern int globalArgc;
50
extern char workdir[1024];
51
extern char run_id[128];
52
extern double masterTime;
56
extern volatile int NumberOfThreads;
57
extern volatile int NumberOfJobs;
60
static double getBranch(tree *tr, double *b, double *bb)
66
assert(tr->fracchange != -1.0);
67
assert(b[0] == bb[0]);
73
z = -log(z) * tr->fracchange;
81
for(i = 0; i < tr->numBranches; i++)
83
assert(b[i] == bb[i]);
84
assert(tr->partitionContributions[i] != -1.0);
85
assert(tr->fracchanges[i] != -1.0);
91
x = -log(x) * tr->fracchanges[i];
93
z += x * tr->partitionContributions[i];
101
static double getBranchPerPartition(tree *tr, double *b, double *bb, int j)
107
assert(tr->fracchange != -1.0);
108
assert(b[0] == bb[0]);
114
z = -log(z) * tr->fracchange;
120
i = tr->readPartition[j];
122
assert(b[i] == bb[i]);
123
assert(tr->fracchanges[i] != -1.0);
129
z = -log(z) * tr->fracchanges[i];
137
static char *Tree2StringClassifyRec(char *treestr, tree *tr, nodeptr p, int *countBranches,
138
int *inserts, boolean originalTree, boolean jointLabels, boolean likelihood)
140
branchInfo *bInf = p->bInf;
141
int i, countQuery = 0;
143
*countBranches = *countBranches + 1;
149
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
150
if(bInf->epa->countThem[i] > 0)
163
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
165
if(bInf->epa->countThem[i] > 0)
172
sprintf(branchLength, "%f", bInf->epa->branches[i]);
173
sprintf(treestr,"QUERY___%s:%s", tr->nameList[inserts[i]], branchLength);
176
sprintf(treestr,"QUERY___%s", tr->nameList[inserts[i]]);
178
while (*treestr) treestr++;
179
if(localCounter < countQuery - 1)
187
sprintf(treestr,"):0.0,");
188
while (*treestr) treestr++;
196
if(isTip(p->number, tr->rdta->numsp))
198
char *nameptr = tr->nameList[p->number];
200
sprintf(treestr, "%s", nameptr);
201
while (*treestr) treestr++;
206
treestr = Tree2StringClassifyRec(treestr, tr, p->next->back,
207
countBranches, inserts, originalTree, jointLabels, likelihood);
209
treestr = Tree2StringClassifyRec(treestr, tr, p->next->next->back,
210
countBranches, inserts, originalTree, jointLabels, likelihood);
216
sprintf(treestr, ":%8.20f[%s]", 0.5 * p->bInf->epa->originalBranchLength, p->bInf->epa->branchLabel);
217
while (*treestr) treestr++;
227
if(p == tr->leftRootNode)
229
sprintf(treestr, ":%8.20f{%d", p->bInf->epa->originalBranchLength * 0.5, p->bInf->epa->jointLabel);
230
assert(tr->rootLabel == p->bInf->epa->jointLabel);
234
if(p == tr->rightRootNode)
236
sprintf(treestr, ":%8.20f{%d", p->bInf->epa->originalBranchLength * 0.5, tr->numberOfBranches);
237
assert(tr->rootLabel == p->bInf->epa->jointLabel);
240
sprintf(treestr, ":%8.20f{%d", p->bInf->epa->originalBranchLength, p->bInf->epa->jointLabel);
244
sprintf(treestr, ":%8.20f{%d", p->bInf->epa->originalBranchLength, p->bInf->epa->jointLabel);
247
sprintf(treestr, ":%8.20f[%s", p->bInf->epa->originalBranchLength, p->bInf->epa->branchLabel);
252
sprintf(treestr, ":%8.20f[%s", 0.5 * p->bInf->epa->originalBranchLength, p->bInf->epa->branchLabel);
254
sprintf(treestr, ":%8.20f[%s", p->bInf->epa->originalBranchLength, p->bInf->epa->branchLabel);
257
while (*treestr) treestr++;
259
assert(!(countQuery > 0 && originalTree == TRUE));
262
sprintf(treestr, "}");
264
sprintf(treestr, "]");
266
while (*treestr) treestr++;
274
char *Tree2StringClassify(char *treestr, tree *tr, int *inserts,
275
boolean originalTree, boolean jointLabels, boolean likelihood)
284
if(jointLabels && tr->wasRooted)
286
assert(originalTree);
289
treestr = Tree2StringClassifyRec(treestr, tr, tr->leftRootNode, &countBranches,
290
inserts, originalTree, jointLabels, likelihood);
292
treestr = Tree2StringClassifyRec(treestr, tr, tr->rightRootNode, &countBranches,
293
inserts, originalTree, jointLabels, likelihood);
297
assert(countBranches == 2 * tr->ntips - 2);
300
while (*treestr) treestr++;
306
p = tr->nodep[tr->mxtips + 1];
310
assert(!isTip(p->number, tr->mxtips));
313
treestr = Tree2StringClassifyRec(treestr, tr, p->back, &countBranches,
314
inserts, originalTree, jointLabels, likelihood);
316
treestr = Tree2StringClassifyRec(treestr, tr, p->next->back, &countBranches,
317
inserts, originalTree, jointLabels, likelihood);
319
treestr = Tree2StringClassifyRec(treestr, tr, p->next->next->back, &countBranches,
320
inserts, originalTree, jointLabels, likelihood);
324
assert(countBranches == 2 * tr->ntips - 3);
327
while (*treestr) treestr++;
335
void markTips(nodeptr p, int *perm, int maxTips)
337
if(isTip(p->number, maxTips))
347
markTips(q->back, perm, maxTips);
354
static boolean containsRoot(nodeptr p, tree *tr, int rootNumber)
357
if(isTip(p->number, tr->mxtips))
359
if(p->number == rootNumber)
366
if(p->number == rootNumber)
370
if(containsRoot(p->next->back, tr, rootNumber))
374
if(containsRoot(p->next->next->back, tr, rootNumber))
384
static nodeptr findRootDirection(nodeptr p, tree *tr, int rootNumber)
386
if(containsRoot(p, tr, rootNumber))
389
if(containsRoot(p->back, tr, rootNumber))
392
/* one of the two subtrees must contain the root */
398
void setPartitionMask(tree *tr, int i, boolean *executeModel)
403
if(tr->perPartitionEPA)
405
for(model = 0; model < tr->NumberOfModels; model++)
406
executeModel[model] = FALSE;
408
executeModel[tr->readPartition[i]] = TRUE;
412
for(model = 0; model < tr->NumberOfModels; model++)
413
executeModel[model] = TRUE;
417
void resetPartitionMask(tree *tr, boolean *executeModel)
422
for(model = 0; model < tr->NumberOfModels; model++)
423
executeModel[model] = TRUE;
428
static boolean allSmoothedEPA(tree *tr)
431
boolean result = TRUE;
433
for(i = 0; i < tr->numBranches; i++)
435
if(tr->partitionSmoothed[i] == FALSE)
438
tr->partitionConverged[i] = TRUE;
444
static boolean updateEPA(tree *tr, nodeptr p, int j)
447
boolean smoothedPartitions[NUM_BRANCHES];
449
double z[NUM_BRANCHES], z0[NUM_BRANCHES];
454
for(i = 0; i < tr->numBranches; i++)
457
setPartitionMask(tr, j, tr->executeModel);
458
makenewzGeneric(tr, p, q, z0, newzpercycle, z, FALSE);
460
for(i = 0; i < tr->numBranches; i++)
461
smoothedPartitions[i] = tr->partitionSmoothed[i];
463
for(i = 0; i < tr->numBranches; i++)
465
if(!tr->partitionConverged[i])
469
if(ABS(z[i] - z0[i]) > _deltaz)
471
smoothedPartitions[i] = FALSE;
474
p->z[i] = q->z[i] = z[i];
478
for(i = 0; i < tr->numBranches; i++)
479
tr->partitionSmoothed[i] = smoothedPartitions[i];
484
static boolean localSmoothEPA(tree *tr, nodeptr p, int maxtimes, int j)
489
if (isTip(p->number, tr->rdta->numsp)) return FALSE;
491
for(i = 0; i < tr->numBranches; i++)
492
tr->partitionConverged[i] = FALSE;
494
while (--maxtimes >= 0)
496
for(i = 0; i < tr->numBranches; i++)
497
tr->partitionSmoothed[i] = TRUE;
502
if (! updateEPA(tr, q, j)) return FALSE;
507
if (allSmoothedEPA(tr))
511
for(i = 0; i < tr->numBranches; i++)
513
tr->partitionSmoothed[i] = FALSE;
514
tr->partitionConverged[i] = FALSE;
521
static void testInsertThorough(tree *tr, nodeptr r, nodeptr q)
524
originalBranchLength = getBranch(tr, q->z, q->back->z),
530
root = (nodeptr)NULL,
534
*inserts = tr->inserts,
541
root = findRootDirection(q, tr, tr->mxtips + 1);
544
if((q == tr->leftRootNode && x == tr->rightRootNode) ||
545
(x == tr->leftRootNode && q == tr->rightRootNode))
550
r1 = findRootDirection(q, tr, tr->leftRootNode->number),
551
r2 = findRootDirection(q, tr, tr->rightRootNode->number);
559
for(j = 0; j < tr->numBranches; j++)
573
for(j = 0; j < tr->numberOfTipsForInsertion; j++)
575
if(q->bInf->epa->executeThem[j])
578
s = tr->nodep[inserts[j]];
582
modifiedBranchLength,
585
hookup(r->next, q, z, tr->numBranches);
586
hookup(r->next->next, x, z, tr->numBranches);
587
hookupDefault(r, s, tr->numBranches);
590
if(tr->perPartitionEPA)
592
setPartitionMask(tr, j, tr->executeModel);
593
newviewGenericMasked(tr, r);
595
setPartitionMask(tr, j, tr->executeModel);
596
localSmoothEPA(tr, r, smoothings, j);
598
setPartitionMask(tr, j, tr->executeModel);
599
evaluateGeneric(tr, r);
601
result = tr->perPartitionLH[tr->readPartition[j]];
603
resetPartitionMask(tr, tr->executeModel);
607
newviewGeneric(tr, r);
608
localSmooth(tr, r, smoothings);
609
result = evaluateGeneric(tr, r);
613
if(tr->perPartitionEPA)
614
tr->bInf[q->bInf->epa->branchNumber].epa->branches[j] = getBranchPerPartition(tr, r->z, r->back->z, j);
616
tr->bInf[q->bInf->epa->branchNumber].epa->branches[j] = getBranch(tr, r->z, r->back->z);
618
tr->bInf[q->bInf->epa->branchNumber].epa->likelihoods[j] = result;
620
if(tr->perPartitionEPA)
621
modifiedBranchLength = getBranchPerPartition(tr, q->z, q->back->z, j) + getBranchPerPartition(tr, x->z, x->back->z, j);
623
modifiedBranchLength = getBranch(tr, q->z, q->back->z) + getBranch(tr, x->z, x->back->z);
625
ratio = originalBranchLength / modifiedBranchLength;
627
if(tr->wasRooted && atRoot)
629
/* always take distal length from left root node and then fix this later */
631
if(x == tr->leftRootNode)
633
if(tr->perPartitionEPA)
634
distalLength = getBranchPerPartition(tr, x->z, x->back->z, j);
636
distalLength = getBranch(tr, x->z, x->back->z);
640
assert(x == tr->rightRootNode);
641
if(tr->perPartitionEPA)
642
distalLength = getBranchPerPartition(tr, q->z, q->back->z, j);
644
distalLength = getBranch(tr, q->z, q->back->z);
651
if(tr->perPartitionEPA)
652
distalLength = getBranchPerPartition(tr, x->z, x->back->z, j);
654
distalLength = getBranch(tr, x->z, x->back->z);
659
if(tr->perPartitionEPA)
660
distalLength = getBranchPerPartition(tr, q->z, q->back->z, j);
662
distalLength = getBranch(tr, q->z, q->back->z);
666
distalLength *= ratio;
668
assert(distalLength <= originalBranchLength);
670
tr->bInf[q->bInf->epa->branchNumber].epa->distalBranches[j] = distalLength;
676
hookup(q, x, qz, tr->numBranches);
678
r->next->next->back = r->next->back = (nodeptr) NULL;
683
static void testInsertFast(tree *tr, nodeptr r, nodeptr q)
695
*inserts = tr->inserts;
698
assert(!tr->grouped);
700
for(i = 0; i < tr->numBranches; i++)
703
z[i] = sqrt(q->z[i]);
711
hookup(r->next, q, z, tr->numBranches);
712
hookup(r->next->next, x, z, tr->numBranches);
714
newviewGeneric(tr, r);
716
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
718
if(q->bInf->epa->executeThem[i])
720
hookupDefault(r, tr->nodep[inserts[i]], tr->numBranches);
722
if(!tr->perPartitionEPA)
724
result = evaluateGeneric (tr, r);
728
setPartitionMask(tr, i, tr->executeModel);
729
evaluateGeneric(tr, r);
731
result = tr->perPartitionLH[tr->readPartition[i]];
733
resetPartitionMask(tr, tr->executeModel);
737
r->back = (nodeptr) NULL;
738
tr->nodep[inserts[i]]->back = (nodeptr) NULL;
740
tr->bInf[q->bInf->epa->branchNumber].epa->likelihoods[i] = result;
744
hookup(q, x, qz, tr->numBranches);
746
r->next->next->back = r->next->back = (nodeptr) NULL;
752
static void addTraverseRob(tree *tr, nodeptr r, nodeptr q,
756
testInsertThorough(tr, r, q);
758
testInsertFast(tr, r, q);
760
if(!isTip(q->number, tr->rdta->numsp))
766
addTraverseRob(tr, r, a->back, thorough);
774
size_t getContiguousVectorLength(tree *tr)
779
for(model = 0; model < tr->NumberOfModels; model++)
782
realWidth = tr->partitionData[model].upper - tr->partitionData[model].lower;
785
states = tr->partitionData[model].states;
787
length += (realWidth * (size_t)states * (size_t)(tr->discreteRateCategories));
793
static size_t getContiguousScalingLength(tree *tr)
801
for(model = 0; model < tr->NumberOfModels; model++)
802
length += tr->partitionData[model].upper - tr->partitionData[model].lower;
807
static void allocBranchX(tree *tr)
812
for(i = 0; i < tr->numberOfBranches; i++)
817
b->epa->left = (double*)rax_malloc(sizeof(double) * tr->contiguousVectorLength);
818
b->epa->leftScaling = (int*)rax_malloc(sizeof(int) * tr->contiguousScalingLength);
820
b->epa->right = (double*)rax_malloc(sizeof(double) * tr->contiguousVectorLength);
821
b->epa->rightScaling = (int*)rax_malloc(sizeof(int) * tr->contiguousScalingLength);
825
static void updateClassify(tree *tr, double *z, boolean *partitionSmoothed, boolean *partitionConverged, double *x1, double *x2, unsigned char *tipX1, unsigned char *tipX2, int tipCase, int insertions)
829
boolean smoothedPartitions[NUM_BRANCHES];
835
for(i = 0; i < tr->numBranches; i++)
838
makenewzClassify(tr, newzpercycle, newz, z0, x1, x2, tipX1, tipX2, tipCase, partitionConverged, insertions);
840
for(i = 0; i < tr->numBranches; i++)
841
smoothedPartitions[i] = partitionSmoothed[i];
843
for(i = 0; i < tr->numBranches; i++)
845
if(!partitionConverged[i])
847
if(ABS(newz[i] - z0[i]) > deltaz)
848
smoothedPartitions[i] = FALSE;
854
for(i = 0; i < tr->numBranches; i++)
855
partitionSmoothed[i] = smoothedPartitions[i];
859
static double localSmoothClassify (tree *tr, int maxtimes, int leftNodeNumber, int rightNodeNumber, int insertionNodeNumber, double *e1, double *e2, double *e3,
860
branchInfo *b, int insertions)
866
partitionSmoothed[NUM_BRANCHES],
867
partitionConverged[NUM_BRANCHES];
882
*tipX1 = (unsigned char *)NULL,
883
*tipX2 = (unsigned char *)NULL;
885
x3 = tr->temporaryVector;
886
ex3 = tr->temporaryScaling;
889
for(i = 0; i < tr->numBranches; i++)
890
partitionConverged[i] = FALSE;
892
while (--maxtimes >= 0)
894
for(i = 0; i < tr->numBranches; i++)
895
partitionSmoothed[i] = TRUE;
898
if(isTip(leftNodeNumber, tr->mxtips) && isTip(rightNodeNumber, tr->mxtips))
902
tipX1 = tr->contiguousTips[leftNodeNumber];
903
tipX2 = tr->contiguousTips[rightNodeNumber];
905
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
909
if (isTip(leftNodeNumber, tr->mxtips))
913
tipX1 = tr->contiguousTips[leftNodeNumber];
916
ex2 = b->epa->rightScaling;
917
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
921
if(isTip(rightNodeNumber, tr->mxtips))
925
tipX1 = tr->contiguousTips[rightNodeNumber];
928
ex2 = b->epa->leftScaling;
929
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e2, e1, insertions);
933
tipCase = INNER_INNER;
936
ex1 = b->epa->leftScaling;
939
ex2 = b->epa->rightScaling;
940
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
949
x2 = tr->temporaryVector;
950
tipX1 = tr->contiguousTips[insertionNodeNumber];
952
updateClassify(tr, e3, partitionSmoothed, partitionConverged, x1, x2, tipX1, tipX2, tipCase, insertions);
954
/* e1 **********************************************************/
956
tipX1 = tr->contiguousTips[insertionNodeNumber];
958
if(isTip(rightNodeNumber, tr->mxtips))
962
tipX2 = tr->contiguousTips[rightNodeNumber];
969
ex2 = b->epa->rightScaling;
972
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e3, e2, insertions);
974
if(isTip(leftNodeNumber, tr->mxtips))
978
tipX1 = tr->contiguousTips[leftNodeNumber];
982
tipCase = INNER_INNER;
987
updateClassify(tr, e1, partitionSmoothed, partitionConverged, x1, x3, tipX1, (unsigned char*)NULL, tipCase, insertions);
989
/* e2 *********************************************************/
991
tipX1 = tr->contiguousTips[insertionNodeNumber];
993
if(isTip(leftNodeNumber, tr->mxtips))
997
tipX2 = tr->contiguousTips[leftNodeNumber];
1001
tipCase = TIP_INNER;
1004
ex2 = b->epa->leftScaling;
1007
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e3, e1, insertions);
1009
if(isTip(rightNodeNumber, tr->mxtips))
1011
tipCase = TIP_INNER;
1013
tipX1 = tr->contiguousTips[rightNodeNumber];
1017
tipCase = INNER_INNER;
1022
updateClassify(tr, e2, partitionSmoothed, partitionConverged, x1, x3, tipX1, (unsigned char*)NULL, tipCase, insertions);
1026
for(i = 0; i < tr->numBranches; i++)
1028
if(partitionSmoothed[i] == FALSE)
1029
allSmoothed = FALSE;
1031
partitionConverged[i] = TRUE;
1039
if(isTip(leftNodeNumber, tr->mxtips) && isTip(rightNodeNumber, tr->mxtips))
1043
tipX1 = tr->contiguousTips[leftNodeNumber];
1044
tipX2 = tr->contiguousTips[rightNodeNumber];
1046
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1050
if (isTip(leftNodeNumber, tr->mxtips))
1052
tipCase = TIP_INNER;
1054
tipX1 = tr->contiguousTips[leftNodeNumber];
1057
ex2 = b->epa->rightScaling;
1058
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1062
if(isTip(rightNodeNumber, tr->mxtips))
1064
tipCase = TIP_INNER;
1066
tipX1 = tr->contiguousTips[rightNodeNumber];
1069
ex2 = b->epa->leftScaling;
1070
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e2, e1, insertions);
1074
tipCase = INNER_INNER;
1077
ex1 = b->epa->leftScaling;
1080
ex2 = b->epa->rightScaling;
1081
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1087
tipCase = TIP_INNER;
1089
x2 = tr->temporaryVector;
1090
tipX1 = tr->contiguousTips[insertionNodeNumber];
1092
result = evalCL(tr, x2, ex3, tipX1, e3, insertions);
1101
void testInsertThoroughIterative(tree *tr, int branchNumber)
1109
*x3 = tr->temporaryVector;
1112
*b = &(tr->bInf[branchNumber]);
1115
root = (nodeptr)NULL,
1126
leftNodeNumber = b->epa->leftNodeNumber,
1127
rightNodeNumber = b->epa->rightNodeNumber,
1128
*ex3 = tr->temporaryScaling;
1130
assert(x->number == leftNodeNumber);
1131
assert(q->number == rightNodeNumber);
1134
root = findRootDirection(q, tr, tr->mxtips + 1);
1137
if((q == tr->leftRootNode && x == tr->rightRootNode) ||
1138
(x == tr->leftRootNode && q == tr->rightRootNode))
1143
r1 = findRootDirection(q, tr, tr->leftRootNode->number),
1144
r2 = findRootDirection(q, tr, tr->rightRootNode->number);
1152
for(insertions = 0; insertions < tr->numberOfTipsForInsertion; insertions++)
1154
if(b->epa->executeThem[insertions])
1157
*x1 = (double*)NULL,
1158
*x2 = (double*)NULL;
1165
*tipX1 = (unsigned char *)NULL,
1166
*tipX2 = (unsigned char *)NULL;
1170
modifiedBranchLength,
1173
for(model = 0; model < tr->numBranches; model++)
1175
z = sqrt(b->epa->branchLengths[model]);
1183
e3[model] = defaultz;
1186
if(isTip(leftNodeNumber, tr->mxtips) && isTip(rightNodeNumber, tr->mxtips))
1190
tipX1 = tr->contiguousTips[leftNodeNumber];
1191
tipX2 = tr->contiguousTips[rightNodeNumber];
1193
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1197
if (isTip(leftNodeNumber, tr->mxtips))
1199
tipCase = TIP_INNER;
1201
tipX1 = tr->contiguousTips[leftNodeNumber];
1204
ex2 = b->epa->rightScaling;
1205
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1209
if(isTip(rightNodeNumber, tr->mxtips))
1211
tipCase = TIP_INNER;
1213
tipX1 = tr->contiguousTips[rightNodeNumber];
1216
ex2 = b->epa->leftScaling;
1217
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e2, e1, insertions);
1221
tipCase = INNER_INNER;
1224
ex1 = b->epa->leftScaling;
1227
ex2 = b->epa->rightScaling;
1228
newviewMultiGrain(tr, x1, x2, x3, ex1, ex2, ex3, tipX1, tipX2, tipCase, e1, e2, insertions);
1233
result = localSmoothClassify(tr, smoothings, leftNodeNumber, rightNodeNumber, tr->inserts[insertions], e1, e2, e3, b, insertions);
1235
b->epa->likelihoods[insertions] = result;
1237
if(tr->perPartitionEPA)
1238
b->epa->branches[insertions] = getBranchPerPartition(tr, e3, e3, insertions);
1240
b->epa->branches[insertions] = getBranch(tr, e3, e3);
1242
if(tr->perPartitionEPA)
1243
modifiedBranchLength = getBranchPerPartition(tr, e1, e1, insertions) + getBranchPerPartition(tr, e2, e2, insertions);
1245
modifiedBranchLength = getBranch(tr, e1, e1) + getBranch(tr, e2, e2);
1247
ratio = b->epa->originalBranchLength / modifiedBranchLength;
1249
if(tr->wasRooted && atRoot)
1251
/* always take distal length from left root node and then fix this later */
1253
if(x == tr->leftRootNode)
1255
if(tr->perPartitionEPA)
1256
distalLength = getBranchPerPartition(tr, e1, e1, insertions);
1258
distalLength = getBranch(tr, e1, e1);
1262
assert(x == tr->rightRootNode);
1263
if(tr->perPartitionEPA)
1264
distalLength = getBranchPerPartition(tr, e2, e2, insertions);
1266
distalLength = getBranch(tr, e2, e2);
1273
if(tr->perPartitionEPA)
1274
distalLength = getBranchPerPartition(tr, e1, e1, insertions);
1276
distalLength = getBranch(tr, e1, e1);
1281
if(tr->perPartitionEPA)
1282
distalLength = getBranchPerPartition(tr, e2, e2, insertions);
1284
distalLength = getBranch(tr, e2, e2);
1288
distalLength *= ratio;
1290
assert(distalLength <= b->epa->originalBranchLength);
1292
b->epa->distalBranches[insertions] = distalLength;
1303
void addTraverseRobIterative(tree *tr, int branchNumber)
1309
*b = &(tr->bInf[branchNumber]);
1314
defaultArray[NUM_BRANCHES];
1317
assert(!tr->useFastScaling);
1319
for(inserts = 0; inserts < tr->numBranches; inserts++)
1321
z[inserts] = sqrt(b->epa->branchLengths[inserts]);
1322
defaultArray[inserts] = defaultz;
1324
if(z[inserts] < zmin)
1326
if(z[inserts] > zmax)
1330
newviewClassify(tr, b, z, inserts);
1332
for(inserts = 0; inserts < tr->numberOfTipsForInsertion; inserts++)
1334
result = evalCL(tr, tr->temporaryVector, tr->temporaryScaling, tr->contiguousTips[tr->inserts[inserts]], defaultArray, inserts);
1336
b->epa->likelihoods[inserts] = result;
1351
static void setupBranchMetaInfo(tree *tr, nodeptr p, int nTips, branchInfo *bInf)
1355
countBranches = tr->branchCounter;
1357
if(isTip(p->number, tr->mxtips))
1359
p->bInf = &bInf[countBranches];
1360
p->back->bInf = &bInf[countBranches];
1362
bInf[countBranches].oP = p;
1363
bInf[countBranches].oQ = p->back;
1365
bInf[countBranches].epa->leftNodeNumber = p->number;
1366
bInf[countBranches].epa->rightNodeNumber = p->back->number;
1368
bInf[countBranches].epa->originalBranchLength = getBranch(tr, p->z, p->back->z);
1369
bInf[countBranches].epa->branchNumber = countBranches;
1371
for(i = 0; i < tr->numBranches; i++)
1372
bInf[countBranches].epa->branchLengths[i] = p->z[i];
1374
#ifdef _USE_PTHREADS
1376
newviewGeneric(tr, p->back);
1377
masterBarrier(THREAD_GATHER_LIKELIHOOD, tr);
1380
tr->branchCounter = tr->branchCounter + 1;
1386
assert(p == p->next->next->next);
1388
p->bInf = &bInf[countBranches];
1389
p->back->bInf = &bInf[countBranches];
1391
bInf[countBranches].oP = p;
1392
bInf[countBranches].oQ = p->back;
1394
bInf[countBranches].epa->leftNodeNumber = p->number;
1395
bInf[countBranches].epa->rightNodeNumber = p->back->number;
1397
bInf[countBranches].epa->originalBranchLength = getBranch(tr, p->z, p->back->z);
1398
bInf[countBranches].epa->branchNumber = countBranches;
1400
for(i = 0; i < tr->numBranches; i++)
1401
bInf[countBranches].epa->branchLengths[i] = p->z[i];
1404
#ifdef _USE_PTHREADS
1406
newviewGeneric(tr, p);
1408
if(!isTip(p->back->number, tr->mxtips))
1411
newviewGeneric(tr, p->back);
1414
masterBarrier(THREAD_GATHER_LIKELIHOOD, tr);
1417
tr->branchCounter = tr->branchCounter + 1;
1423
setupBranchMetaInfo(tr, q->back, nTips, bInf);
1433
static void setupJointFormat(tree *tr, nodeptr p, int ntips, branchInfo *bInf, int *count)
1435
if(isTip(p->number, tr->mxtips))
1437
p->bInf->epa->jointLabel = *count;
1438
*count = *count + 1;
1444
setupJointFormat(tr, p->next->back, ntips, bInf, count);
1445
setupJointFormat(tr, p->next->next->back, ntips, bInf, count);
1447
p->bInf->epa->jointLabel = *count;
1448
*count = *count + 1;
1459
static void setupBranchInfo(tree *tr, nodeptr q)
1462
originalNode = tr->nodep[tr->mxtips + 1];
1467
tr->branchCounter = 0;
1469
setupBranchMetaInfo(tr, q, tr->ntips, tr->bInf);
1471
assert(tr->branchCounter == tr->numberOfBranches);
1475
assert(tr->leftRootNode->back == tr->rightRootNode);
1476
assert(tr->leftRootNode == tr->rightRootNode->back);
1478
if(!isTip(tr->leftRootNode->number, tr->mxtips))
1480
setupJointFormat(tr, tr->leftRootNode->next->back, tr->ntips, tr->bInf, &count);
1481
setupJointFormat(tr, tr->leftRootNode->next->next->back, tr->ntips, tr->bInf, &count);
1484
tr->leftRootNode->bInf->epa->jointLabel = count;
1485
tr->rootLabel = count;
1488
if(!isTip(tr->rightRootNode->number, tr->mxtips))
1490
setupJointFormat(tr, tr->rightRootNode->next->back, tr->ntips, tr->bInf, &count);
1491
setupJointFormat(tr, tr->rightRootNode->next->next->back, tr->ntips, tr->bInf, &count);
1496
setupJointFormat(tr, originalNode->back, tr->ntips, tr->bInf, &count);
1497
setupJointFormat(tr, originalNode->next->back, tr->ntips, tr->bInf, &count);
1498
setupJointFormat(tr, originalNode->next->next->back, tr->ntips, tr->bInf, &count);
1501
assert(count == tr->numberOfBranches);
1507
static int infoCompare(const void *p1, const void *p2)
1509
info *rc1 = (info *)p1;
1510
info *rc2 = (info *)p2;
1522
static void consolidateInfoMLHeuristics(tree *tr, int throwAwayStart)
1529
*inf = (info*)rax_malloc(sizeof(info) * tr->numberOfBranches);
1531
assert(tr->useEpaHeuristics);
1533
for(j = 0; j < tr->numberOfTipsForInsertion; j++)
1535
for(i = 0; i < tr->numberOfBranches; i++)
1537
inf[i].lh = tr->bInf[i].epa->likelihoods[j];
1541
qsort(inf, tr->numberOfBranches, sizeof(info), infoCompare);
1543
for(i = throwAwayStart; i < tr->numberOfBranches; i++)
1544
tr->bInf[inf[i].number].epa->executeThem[j] = 0;
1547
for(i = 0; i < tr->numberOfBranches; i++)
1548
for(j = 0; j < tr->numberOfTipsForInsertion; j++)
1549
tr->bInf[i].epa->likelihoods[j] = unlikely;
1559
static void consolidateInfo(tree *tr)
1563
for(j = 0; j < tr->numberOfTipsForInsertion; j++)
1571
for(i = 0; i < tr->numberOfBranches; i++)
1573
if(tr->bInf[i].epa->likelihoods[j] > max)
1575
max = tr->bInf[i].epa->likelihoods[j];
1580
assert(max_index >= 0);
1582
tr->bInf[max_index].epa->countThem[j] = tr->bInf[max_index].epa->countThem[j] + 1;
1593
static void printPerBranchReadAlignments(tree *tr)
1599
for(j = 0; j < tr->numberOfBranches; j++)
1604
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
1605
if(tr->bInf[j].epa->countThem[i] > 0)
1613
alignmentFileName[2048] = "",
1619
strcpy(alignmentFileName, workdir);
1620
strcat(alignmentFileName, "RAxML_BranchAlignment.I");
1622
sprintf(buf, "%d", j);
1624
strcat(alignmentFileName, buf);
1626
af = myfopen(alignmentFileName, "wb");
1629
fprintf(af, "%d %d\n", readCounter, tr->rdta->sites);
1631
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
1633
if(tr->bInf[j].epa->countThem[i] > 0)
1635
unsigned char *tip = tr->yVector[tr->inserts[i]];
1637
fprintf(af, "%s ", tr->nameList[tr->inserts[i]]);
1639
for(l = 0; l < tr->cdta->endsite; l++)
1641
for(w = 0; w < tr->cdta->aliaswgt[l]; w++)
1642
fprintf(af, "%c", getInverseMeaning(tr->dataVector[l], tip[l]));
1650
printBothOpen("Branch read alignment for branch %d written to file %s\n", j, alignmentFileName);
1658
static void analyzeReads(tree *tr)
1662
*inserts = tr->inserts;
1664
tr->readPartition = (int *)rax_malloc(sizeof(int) * (size_t)tr->numberOfTipsForInsertion);
1666
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
1672
whichPartition = -1,
1675
nodeNumber = tr->nodep[inserts[i]]->number;
1678
*tipX1 = tr->yVector[nodeNumber];
1680
for(model = 0; model < tr->NumberOfModels; model++)
1686
undetermined = getUndetermined(tr->partitionData[model].dataType);
1688
for(j = tr->partitionData[model].lower; j < tr->partitionData[model].upper; j++)
1690
if(tipX1[j] != undetermined)
1697
whichPartition = model;
1701
assert(partitionCount == 1);
1702
assert(whichPartition >= 0 && whichPartition < tr->NumberOfModels);
1704
tr->readPartition[i] = whichPartition;
1709
void classifyML(tree *tr, analdef *adef)
1722
entropyFileName[1024],
1723
jointFormatTreeFileName[1024],
1724
labelledTreeFileName[1024],
1725
originalLabelledTreeFileName[1024],
1726
classificationFileName[1024];
1731
*classificationFile;
1733
adef->outgroup = FALSE;
1734
tr->doCutoff = FALSE;
1736
assert(adef->restart);
1738
tr->numberOfBranches = 2 * tr->ntips - 3;
1740
if(tr->perPartitionEPA)
1741
printBothOpen("\nRAxML Evolutionary Placement Algorithm for partitioned multi-gene datasets (experimental version)\n");
1743
printBothOpen("\nRAxML Evolutionary Placement Algorithm\n");
1745
if(adef->useBinaryModelFile)
1747
evaluateGenericInitrav(tr, tr->start);
1748
// treeEvaluate(tr, 2);
1752
evaluateGenericInitrav(tr, tr->start);
1754
modOpt(tr, adef, TRUE, 1.0);
1757
printBothOpen("\nLikelihood of reference tree: %f\n\n", tr->likelihood);
1759
perm = (int *)rax_calloc(tr->mxtips + 1, sizeof(int));
1760
tr->inserts = (int *)rax_calloc(tr->mxtips, sizeof(int));
1762
markTips(tr->start, perm, tr->mxtips);
1763
markTips(tr->start->back, perm ,tr->mxtips);
1765
tr->numberOfTipsForInsertion = 0;
1767
for(i = 1; i <= tr->mxtips; i++)
1771
tr->inserts[tr->numberOfTipsForInsertion] = i;
1772
tr->numberOfTipsForInsertion = tr->numberOfTipsForInsertion + 1;
1778
printBothOpen("RAxML will place %d Query Sequences into the %d branches of the reference tree with %d taxa\n\n", tr->numberOfTipsForInsertion, (2 * tr->ntips - 3), tr->ntips);
1780
assert(tr->numberOfTipsForInsertion == (tr->mxtips - tr->ntips));
1782
tr->bInf = (branchInfo*)rax_malloc(tr->numberOfBranches * sizeof(branchInfo));
1784
for(i = 0; i < tr->numberOfBranches; i++)
1786
tr->bInf[i].epa = (epaBranchData*)rax_malloc(sizeof(epaBranchData));
1788
tr->bInf[i].epa->countThem = (int*)rax_calloc(tr->numberOfTipsForInsertion, sizeof(int));
1790
tr->bInf[i].epa->executeThem = (int*)rax_calloc(tr->numberOfTipsForInsertion, sizeof(int));
1792
for(j = 0; j < tr->numberOfTipsForInsertion; j++)
1793
tr->bInf[i].epa->executeThem[j] = 1;
1795
tr->bInf[i].epa->branches = (double*)rax_calloc(tr->numberOfTipsForInsertion, sizeof(double));
1796
tr->bInf[i].epa->distalBranches = (double*)rax_calloc(tr->numberOfTipsForInsertion, sizeof(double));
1798
tr->bInf[i].epa->likelihoods = (double*)rax_calloc(tr->numberOfTipsForInsertion, sizeof(double));
1799
tr->bInf[i].epa->branchNumber = i;
1801
sprintf(tr->bInf[i].epa->branchLabel, "I%d", i);
1804
r = tr->nodep[(tr->nextnode)++];
1807
q = findAnyTip(tr->start, tr->rdta->numsp);
1809
assert(isTip(q->number, tr->rdta->numsp));
1810
assert(!isTip(q->back->number, tr->rdta->numsp));
1814
if(tr->perPartitionEPA)
1817
#ifdef _USE_PTHREADS
1818
tr->contiguousVectorLength = getContiguousVectorLength(tr);
1819
tr->contiguousScalingLength = getContiguousScalingLength(tr);
1821
masterBarrier(THREAD_INIT_EPA, tr);
1824
setupBranchInfo(tr, q);
1826
if(tr->useEpaHeuristics)
1829
heuristicInsertions = MAX(5, (int)(0.5 + (double)(tr->numberOfBranches) * tr->fastEPAthreshold));
1831
printBothOpen("EPA heuristics: determining %d out of %d most promising insertion branches\n", heuristicInsertions, tr->numberOfBranches);
1833
#ifdef _USE_PTHREADS
1834
NumberOfJobs = tr->numberOfBranches;
1835
masterBarrier(THREAD_INSERT_CLASSIFY, tr);
1837
addTraverseRob(tr, r, q, FALSE);
1840
consolidateInfoMLHeuristics(tr, heuristicInsertions);
1843
#ifdef _USE_PTHREADS
1844
NumberOfJobs = tr->numberOfBranches;
1845
masterBarrier(THREAD_INSERT_CLASSIFY_THOROUGH, tr);
1847
addTraverseRob(tr, r, q, TRUE);
1849
consolidateInfo(tr);
1851
printBothOpen("Overall Classification time: %f\n\n", gettime() - masterTime);
1855
assert(adef->compressPatterns == FALSE);
1856
printPerBranchReadAlignments(tr);
1859
strcpy(entropyFileName, workdir);
1860
strcpy(jointFormatTreeFileName, workdir);
1861
strcpy(labelledTreeFileName, workdir);
1862
strcpy(originalLabelledTreeFileName, workdir);
1863
strcpy(classificationFileName, workdir);
1865
strcat(entropyFileName, "RAxML_entropy.");
1866
strcat(jointFormatTreeFileName, "RAxML_portableTree.");
1867
strcat(labelledTreeFileName, "RAxML_labelledTree.");
1868
strcat(originalLabelledTreeFileName, "RAxML_originalLabelledTree.");
1869
strcat(classificationFileName, "RAxML_classification.");
1871
strcat(entropyFileName, run_id);
1872
strcat(jointFormatTreeFileName, run_id);
1873
strcat(labelledTreeFileName, run_id);
1874
strcat(originalLabelledTreeFileName, run_id);
1875
strcat(classificationFileName, run_id);
1877
strcat(jointFormatTreeFileName, ".jplace");
1879
rax_free(tr->tree_string);
1880
tr->treeStringLength *= 16;
1882
tr->tree_string = (char*)rax_calloc(tr->treeStringLength, sizeof(char));
1885
treeFile = myfopen(labelledTreeFileName, "wb");
1886
Tree2StringClassify(tr->tree_string, tr, tr->inserts, FALSE, FALSE, TRUE);
1887
fprintf(treeFile, "%s\n", tr->tree_string);
1891
treeFile = myfopen(originalLabelledTreeFileName, "wb");
1892
Tree2StringClassify(tr->tree_string, tr, tr->inserts, TRUE, FALSE, TRUE);
1893
fprintf(treeFile, "%s\n", tr->tree_string);
1897
JSON format only works for sequential version
1898
porting this to Pthreads will be a pain in the ass
1902
treeFile = myfopen(jointFormatTreeFileName, "wb");
1903
Tree2StringClassify(tr->tree_string, tr, tr->inserts, TRUE, TRUE, TRUE);
1905
fprintf(treeFile, "{\n");
1906
fprintf(treeFile, "\t\"tree\": \"%s\", \n", tr->tree_string);
1907
fprintf(treeFile, "\t\"placements\": [\n");
1911
*inf = (info*)rax_malloc(sizeof(info) * tr->numberOfBranches);
1913
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
1923
for(j = 0; j < tr->numberOfBranches; j++)
1925
inf[j].lh = tr->bInf[j].epa->likelihoods[i];
1926
inf[j].pendantBranch = tr->bInf[j].epa->branches[i];
1927
inf[j].distalBranch = tr->bInf[j].epa->distalBranches[i];
1928
inf[j].number = tr->bInf[j].epa->jointLabel;
1931
qsort(inf, tr->numberOfBranches, sizeof(info), infoCompare);
1933
for(j = 0; j < tr->numberOfBranches; j++)
1934
if(inf[j].lh == unlikely)
1939
assert(validEntries > 0);
1945
fprintf(treeFile, "\t{\"p\":[");
1950
I keep at most 7 placements and throw away anything that has less than
1953
my old cutoff was at 0.95 accumulated likelihood weight:
1958
/*#define _ALL_ENTRIES*/
1961
assert(validEntries == tr->numberOfBranches);
1962
while(j < validEntries)
1964
while(j < validEntries && j < 7)
1974
for(k = 0; k < validEntries; k++)
1975
all += exp(inf[k].lh - lmax);
1977
acc += (prob = (exp(inf[j].lh - lmax) / all));
1981
#ifndef _ALL_ENTRIES
1982
if(prob >= maxprob * 0.01)
1987
if(tr->wasRooted && inf[j].number == tr->rootLabel)
1990
b = getBranch(tr, tr->leftRootNode->z, tr->rightRootNode->z);
1992
if(inf[j].distalBranch > 0.5 * b)
1993
fprintf(treeFile, ",[%d, %f, %f, %f, %f]", tr->numberOfBranches, inf[j].lh, prob, inf[j].distalBranch - 0.5 * b, inf[j].pendantBranch);
1995
fprintf(treeFile, ",[%d, %f, %f, %f, %f]", inf[j].number, inf[j].lh, prob, 0.5 * b - inf[j].distalBranch, inf[j].pendantBranch);
1998
fprintf(treeFile, ",[%d, %f, %f, %f, %f]", inf[j].number, inf[j].lh, prob, inf[j].distalBranch, inf[j].pendantBranch);
2002
if(tr->wasRooted && inf[j].number == tr->rootLabel)
2005
b = getBranch(tr, tr->leftRootNode->z, tr->rightRootNode->z);
2007
if(inf[j].distalBranch > 0.5 * b)
2008
fprintf(treeFile, "[%d, %f, %f, %f, %f]", tr->numberOfBranches, inf[j].lh, prob, inf[j].distalBranch - 0.5 * b, inf[j].pendantBranch);
2010
fprintf(treeFile, "[%d, %f, %f, %f, %f]", inf[j].number, inf[j].lh, prob, 0.5 * b - inf[j].distalBranch, inf[j].pendantBranch);
2013
fprintf(treeFile, "[%d, %f, %f, %f, %f]", inf[j].number, inf[j].lh, prob, inf[j].distalBranch, inf[j].pendantBranch);
2020
if(i == tr->numberOfTipsForInsertion - 1)
2021
fprintf(treeFile, "], \"n\":[\"%s\"]}\n", tr->nameList[tr->inserts[i]]);
2023
fprintf(treeFile, "], \"n\":[\"%s\"]},\n", tr->nameList[tr->inserts[i]]);
2030
assert(j == tr->numberOfBranches);
2033
fprintf(treeFile, "\t ],\n");
2034
fprintf(treeFile, "\t\"metadata\": {\"invocation\": ");
2036
fprintf(treeFile, "\"");
2041
for(i = 0; i < globalArgc; i++)
2042
fprintf(treeFile,"%s ", globalArgv[i]);
2044
fprintf(treeFile, "\", \"raxml_version\": \"%s\"", programVersion);
2045
fprintf(treeFile,"},\n");
2047
fprintf(treeFile, "\t\"version\": 2,\n");
2048
fprintf(treeFile, "\t\"fields\": [\n");
2049
fprintf(treeFile, "\t\"edge_num\", \"likelihood\", \"like_weight_ratio\", \"distal_length\", \n");
2050
fprintf(treeFile, "\t\"pendant_length\"\n");
2051
fprintf(treeFile, "\t]\n");
2052
fprintf(treeFile, "}\n");
2056
/* JSON format end */
2058
classificationFile = myfopen(classificationFileName, "wb");
2060
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
2061
for(j = 0; j < tr->numberOfBranches; j++)
2063
if(tr->bInf[j].epa->countThem[i] > 0)
2064
fprintf(classificationFile, "%s I%d %d %8.20f\n", tr->nameList[tr->inserts[i]], j, tr->bInf[j].epa->countThem[i],
2065
tr->bInf[j].epa->branches[i] / (double)(tr->bInf[j].epa->countThem[i]));
2068
fclose(classificationFile);
2071
printBothOpen("\n\nLabelled reference tree including branch labels and query sequences written to file: %s\n\n", labelledTreeFileName);
2072
printBothOpen("Labelled reference tree with branch labels (without query sequences) written to file: %s\n\n", originalLabelledTreeFileName);
2073
printBothOpen("Labelled reference tree with branch labels in portable pplacer/EPA format (without query sequences) written to file: %s\n\n", jointFormatTreeFileName);
2074
printBothOpen("Classification result file written to file: %s\n\n", classificationFileName);
2080
*inf = (info*)rax_malloc(sizeof(info) * tr->numberOfBranches);
2083
*likelihoodWeightsFile;
2086
likelihoodWeightsFileName[1024];
2088
strcpy(likelihoodWeightsFileName, workdir);
2089
strcat(likelihoodWeightsFileName, "RAxML_classificationLikelihoodWeights.");
2090
strcat(likelihoodWeightsFileName, run_id);
2092
likelihoodWeightsFile = myfopen(likelihoodWeightsFileName, "wb");
2093
entropyFile = myfopen(entropyFileName, "wb");
2095
for(i = 0; i < tr->numberOfTipsForInsertion; i++)
2105
for(j = 0; j < tr->numberOfBranches; j++)
2107
inf[j].lh = tr->bInf[j].epa->likelihoods[i];
2111
qsort(inf, tr->numberOfBranches, sizeof(info), infoCompare);
2113
for(j = 0; j < tr->numberOfBranches; j++)
2114
if(inf[j].lh == unlikely)
2119
assert(validEntries > 0);
2125
while(acc <= 0.95 && j < validEntries)
2134
for(k = 0; k < validEntries; k++)
2135
all += exp(inf[k].lh - lmax);
2137
acc += (prob = (exp(inf[j].lh - lmax) / all));
2139
fprintf(likelihoodWeightsFile, "%s I%d %f %f\n", tr->nameList[tr->inserts[i]], inf[j].number, prob, acc);
2146
while(j < validEntries)
2155
for(k = 0; k < validEntries; k++)
2156
all += exp(inf[k].lh - lmax);
2158
prob = exp(inf[j].lh - lmax) / all;
2161
entropy -= ( prob * log(prob) ); /*pp 20110531 */
2166
/* normalize entropy by dividing with the log(validEntries) which is the maximum Entropy possible */
2168
fprintf(entropyFile, "%s\t%f\n", tr->nameList[tr->inserts[i]], entropy / log((double)validEntries));
2173
fclose(entropyFile);
2174
fclose(likelihoodWeightsFile);
2176
printBothOpen("Classification result file using likelihood weights written to file: %s\n\n", likelihoodWeightsFileName);
2177
printBothOpen("Classification entropy result file using likelihood weights written to file: %s\n\n", entropyFileName);