| 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 |
package dr.evomodel.tree; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodelxml.tree.UniformNodeHeightPriorParser; |
| 31 |
import dr.inference.model.AbstractModelLikelihood; |
| 32 |
import dr.inference.model.Model; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
import dr.inference.model.Variable; |
| 35 |
import dr.math.LogTricks; |
| 36 |
import dr.math.MathUtils; |
| 37 |
import dr.math.Polynomial; |
| 38 |
|
| 39 |
import java.util.*; |
| 40 |
import java.util.logging.Logger; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public class UniformNodeHeightPrior extends AbstractModelLikelihood { |
| 57 |
|
| 58 |
|
| 59 |
public static final int MAX_ANALYTIC_TIPS = 60; |
| 60 |
public static final int DEFAULT_MC_SAMPLE = 100000; |
| 61 |
|
| 62 |
private static final double tolerance = 1E-6; |
| 63 |
|
| 64 |
private int k = 0; |
| 65 |
private double logFactorialK; |
| 66 |
|
| 67 |
private double maxRootHeight; |
| 68 |
|
| 69 |
private boolean isNicholls; |
| 70 |
private boolean useAnalytic; |
| 71 |
private boolean useMarginal; |
| 72 |
private boolean leadingTerm; |
| 73 |
private int mcSampleSize; |
| 74 |
|
| 75 |
Set<Double> tipDates = new TreeSet<Double>(); |
| 76 |
List<Double> reversedTipDateList = new ArrayList<Double>(); |
| 77 |
Map<Double, Integer> intervals = new TreeMap<Double, Integer>(); |
| 78 |
|
| 79 |
public UniformNodeHeightPrior(Tree tree, boolean useAnalytic, boolean marginal, boolean leadingTerm) { |
| 80 |
this(UniformNodeHeightPriorParser.UNIFORM_NODE_HEIGHT_PRIOR, tree, useAnalytic, DEFAULT_MC_SAMPLE, marginal, leadingTerm); |
| 81 |
} |
| 82 |
|
| 83 |
public UniformNodeHeightPrior(Tree tree, boolean useAnalytic, int mcSampleSize) { |
| 84 |
this(UniformNodeHeightPriorParser.UNIFORM_NODE_HEIGHT_PRIOR,tree,useAnalytic,mcSampleSize, false, false); |
| 85 |
} |
| 86 |
|
| 87 |
private UniformNodeHeightPrior(String name, Tree tree, boolean useAnalytic, int mcSampleSize, |
| 88 |
boolean marginal, boolean leadingTerm) { |
| 89 |
|
| 90 |
super(name); |
| 91 |
|
| 92 |
this.tree = tree; |
| 93 |
this.isNicholls = false; |
| 94 |
this.useAnalytic = useAnalytic; |
| 95 |
this.useMarginal = marginal; |
| 96 |
this.mcSampleSize = mcSampleSize; |
| 97 |
this.leadingTerm = leadingTerm; |
| 98 |
|
| 99 |
if (tree instanceof TreeModel) { |
| 100 |
addModel((TreeModel) tree); |
| 101 |
} |
| 102 |
|
| 103 |
for (int i = 0; i < tree.getExternalNodeCount(); i++) { |
| 104 |
double h = tree.getNodeHeight(tree.getExternalNode(i)); |
| 105 |
tipDates.add(h); |
| 106 |
} |
| 107 |
|
| 108 |
if (tipDates.size() == 1 || leadingTerm) { |
| 109 |
|
| 110 |
k = tree.getInternalNodeCount() - 1; |
| 111 |
Logger.getLogger("dr.evomodel").info("Uniform Node Height Prior, Intervals = " + (k + 1)); |
| 112 |
|
| 113 |
logFactorialK = logFactorial(k); |
| 114 |
} else { |
| 115 |
reversedTipDateList.addAll(tipDates); |
| 116 |
Collections.reverse(reversedTipDateList); |
| 117 |
|
| 118 |
|
| 119 |
double intervalStart = tree.getNodeHeight(tree.getRoot()); |
| 120 |
List<Double> pruneDates = new ArrayList<Double>(); |
| 121 |
|
| 122 |
for (Double intervalEnd : reversedTipDateList) { |
| 123 |
if (intervalStart - intervalEnd < tolerance) { |
| 124 |
pruneDates.add(intervalStart); |
| 125 |
} |
| 126 |
intervalStart = intervalEnd; |
| 127 |
} |
| 128 |
|
| 129 |
for (Double date : pruneDates) |
| 130 |
reversedTipDateList.remove(date); |
| 131 |
|
| 132 |
if (!useAnalytic) { |
| 133 |
logLikelihoods = new double[mcSampleSize]; |
| 134 |
drawNodeHeights = new double[tree.getNodeCount()][mcSampleSize]; |
| 135 |
minNodeHeights = new double[tree.getNodeCount()]; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
if (tree.getExternalNodeCount() < 30) { |
| 142 |
polynomialType = Polynomial.Type.DOUBLE; |
| 143 |
} else if (tree.getExternalNodeCount() < 45){ |
| 144 |
polynomialType = Polynomial.Type.LOG_DOUBLE; |
| 145 |
} else { |
| 146 |
|
| 147 |
polynomialType = Polynomial.Type.LOG_DOUBLE; |
| 148 |
} |
| 149 |
Logger.getLogger("dr.evomodel").info("Using "+polynomialType+" polynomials!"); |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
public UniformNodeHeightPrior(Tree tree, double maxRootHeight) { |
| 154 |
this(UniformNodeHeightPriorParser.UNIFORM_NODE_HEIGHT_PRIOR, tree, maxRootHeight); |
| 155 |
} |
| 156 |
|
| 157 |
private UniformNodeHeightPrior(String name, Tree tree, double maxRootHeight) { |
| 158 |
|
| 159 |
super(name); |
| 160 |
|
| 161 |
this.tree = tree; |
| 162 |
this.maxRootHeight = maxRootHeight; |
| 163 |
isNicholls = true; |
| 164 |
if (tree instanceof TreeModel) { |
| 165 |
addModel((TreeModel) tree); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
UniformNodeHeightPrior(String name) { |
| 170 |
super(name); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
protected final void handleModelChangedEvent(Model model, Object object, int index) { |
| 182 |
|
| 183 |
likelihoodKnown = false; |
| 184 |
treePolynomialKnown = false; |
| 185 |
return; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
protected final void storeState() { |
| 237 |
storedLikelihoodKnown = likelihoodKnown; |
| 238 |
storedLogLikelihood = logLikelihood; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
protected final void restoreState() { |
| 248 |
likelihoodKnown = storedLikelihoodKnown; |
| 249 |
logLikelihood = storedLogLikelihood; |
| 250 |
|
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
protected final void acceptState() { |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
public final Model getModel() { |
| 262 |
return this; |
| 263 |
} |
| 264 |
|
| 265 |
public double getLogLikelihood() { |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
if (!likelihoodKnown) { |
| 270 |
logLikelihood = calculateLogLikelihood(); |
| 271 |
likelihoodKnown = true; |
| 272 |
} |
| 273 |
return logLikelihood; |
| 274 |
} |
| 275 |
|
| 276 |
public final void makeDirty() { |
| 277 |
likelihoodKnown = false; |
| 278 |
treePolynomialKnown = false; |
| 279 |
} |
| 280 |
|
| 281 |
public double calculateLogLikelihood() { |
| 282 |
|
| 283 |
double rootHeight = tree.getNodeHeight(tree.getRoot()); |
| 284 |
|
| 285 |
if (isNicholls) { |
| 286 |
int nodeCount = tree.getExternalNodeCount(); |
| 287 |
|
| 288 |
if (rootHeight < 0 || rootHeight > (0.999 * maxRootHeight)) return Double.NEGATIVE_INFINITY; |
| 289 |
|
| 290 |
|
| 291 |
return rootHeight * (2 - nodeCount) - Math.log(maxRootHeight - rootHeight); |
| 292 |
|
| 293 |
} else { |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
double logLike; |
| 301 |
|
| 302 |
if (k > 0) { |
| 303 |
|
| 304 |
logLike = logFactorialK - (double) k * Math.log(rootHeight); |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
} else { |
| 323 |
|
| 324 |
if (useAnalytic) { |
| 325 |
|
| 326 |
|
| 327 |
if (useMarginal) { |
| 328 |
|
| 329 |
if (!treePolynomialKnown) { |
| 330 |
|
| 331 |
treePolynomials = constructRootPolyonmials(tree,polynomialType); |
| 332 |
treePolynomialKnown = true; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
logLike = -treePolynomials[0].logEvaluate(rootHeight) - treePolynomials[1].logEvaluate(rootHeight); |
| 337 |
|
| 338 |
if (Double.isNaN(logLike)) { |
| 339 |
|
| 340 |
|
| 341 |
logLike = -treePolynomials[0].logEvaluateHorner(rootHeight) - treePolynomials[1].logEvaluateHorner(rootHeight); |
| 342 |
if (Double.isNaN(logLike)) { |
| 343 |
logLike = Double.NEGATIVE_INFINITY; |
| 344 |
} |
| 345 |
} |
| 346 |
} else { |
| 347 |
|
| 348 |
tmpLogLikelihood = 0; |
| 349 |
recursivelyComputeDensity(tree, tree.getRoot(), 0); |
| 350 |
logLike = tmpLogLikelihood; |
| 351 |
|
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
} else { |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
final double[] drawRootHeight = drawNodeHeights[tree.getRoot().getNumber()]; |
| 363 |
Arrays.fill(drawRootHeight,rootHeight); |
| 364 |
|
| 365 |
|
| 366 |
recursivelyFindNodeMinHeights(tree,tree.getRoot()); |
| 367 |
|
| 368 |
|
| 369 |
Arrays.fill(logLikelihoods,0.0); |
| 370 |
recursivelyComputeMCIntegral(tree, tree.getRoot(), tree.getRoot().getNumber()); |
| 371 |
|
| 372 |
|
| 373 |
logLike = -LogTricks.logSum(logLikelihoods) + Math.log(mcSampleSize); |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
assert !Double.isInfinite(logLike) && !Double.isNaN(logLike); |
| 381 |
return logLike; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
private double recursivelyComputeDensity(Tree tree, NodeRef node, double parentHeight) { |
| 421 |
if (tree.isExternal(node)) |
| 422 |
return tree.getNodeHeight(node); |
| 423 |
|
| 424 |
double thisHeight = tree.getNodeHeight(node); |
| 425 |
double heightChild1 = recursivelyComputeDensity(tree, tree.getChild(node, 0), thisHeight); |
| 426 |
double heightChild2 = recursivelyComputeDensity(tree, tree.getChild(node, 1), thisHeight); |
| 427 |
double minHeight = (heightChild1 > heightChild2) ? heightChild1 : heightChild2; |
| 428 |
|
| 429 |
if (!tree.isRoot(node)) { |
| 430 |
double diff = parentHeight - minHeight; |
| 431 |
if (diff <= 0) |
| 432 |
tmpLogLikelihood = Double.NEGATIVE_INFINITY; |
| 433 |
else |
| 434 |
tmpLogLikelihood -= Math.log(diff); |
| 435 |
|
| 436 |
} else { |
| 437 |
|
| 438 |
} |
| 439 |
return minHeight; |
| 440 |
} |
| 441 |
|
| 442 |
private double recursivelyFindNodeMinHeights(Tree tree, NodeRef node) { |
| 443 |
|
| 444 |
double minHeight; |
| 445 |
|
| 446 |
if (tree.isExternal(node)) |
| 447 |
minHeight = tree.getNodeHeight(node); |
| 448 |
else { |
| 449 |
double minHeightChild0 = recursivelyFindNodeMinHeights(tree, tree.getChild(node,0)); |
| 450 |
double minHeightChild1 = recursivelyFindNodeMinHeights(tree, tree.getChild(node,1)); |
| 451 |
minHeight = (minHeightChild0 > minHeightChild1) ? minHeightChild0 : minHeightChild1; |
| 452 |
} |
| 453 |
|
| 454 |
minNodeHeights[node.getNumber()] = minHeight; |
| 455 |
return minHeight; |
| 456 |
} |
| 457 |
|
| 458 |
private void recursivelyComputeMCIntegral(Tree tree, NodeRef node, int parentNodeNumber) { |
| 459 |
|
| 460 |
if (tree.isExternal(node)) |
| 461 |
return; |
| 462 |
|
| 463 |
final int nodeNumber = node.getNumber(); |
| 464 |
|
| 465 |
if (!tree.isRoot(node)) { |
| 466 |
|
| 467 |
final double[] drawParentHeight = drawNodeHeights[parentNodeNumber]; |
| 468 |
final double[] drawThisNodeHeight = drawNodeHeights[nodeNumber]; |
| 469 |
final double minHeight = minNodeHeights[nodeNumber]; |
| 470 |
|
| 471 |
final boolean twoChild = (tree.isExternal(tree.getChild(node,0)) && tree.isExternal(tree.getChild(node,1))); |
| 472 |
|
| 473 |
for(int i=0; i<mcSampleSize; i++) { |
| 474 |
|
| 475 |
final double diff = drawParentHeight[i] - minHeight; |
| 476 |
if (diff <= 0) { |
| 477 |
logLikelihoods[i] = Double.NEGATIVE_INFINITY; |
| 478 |
break; |
| 479 |
} |
| 480 |
|
| 481 |
if (!twoChild) |
| 482 |
drawThisNodeHeight[i] = MathUtils.nextDouble() * diff + minHeight; |
| 483 |
|
| 484 |
logLikelihoods[i] += Math.log(diff); |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
recursivelyComputeMCIntegral(tree, tree.getChild(node,0), nodeNumber); |
| 489 |
recursivelyComputeMCIntegral(tree, tree.getChild(node,1), nodeNumber); |
| 490 |
|
| 491 |
} |
| 492 |
|
| 493 |
private static final double INV_PRECISION = 10; |
| 494 |
|
| 495 |
private static double round(double x) { |
| 496 |
return Math.round(x * INV_PRECISION) / INV_PRECISION; |
| 497 |
} |
| 498 |
|
| 499 |
private Polynomial[] constructRootPolyonmials(Tree tree, Polynomial.Type type) { |
| 500 |
NodeRef root = tree.getRoot(); |
| 501 |
return new Polynomial[] { |
| 502 |
recursivelyComputePolynomial(tree,tree.getChild(root,0),type).getPolynomial(), |
| 503 |
recursivelyComputePolynomial(tree,tree.getChild(root,1),type).getPolynomial() |
| 504 |
}; |
| 505 |
} |
| 506 |
|
| 507 |
private TipLabeledPolynomial recursivelyComputePolynomial(Tree tree, NodeRef node, Polynomial.Type type) { |
| 508 |
|
| 509 |
if (tree.isExternal(node)) { |
| 510 |
double[] value = new double[]{1.0}; |
| 511 |
double height = round(tree.getNodeHeight(node)); |
| 512 |
return new TipLabeledPolynomial(value, height, type, true); |
| 513 |
} |
| 514 |
|
| 515 |
TipLabeledPolynomial childPolynomial1 = recursivelyComputePolynomial(tree, tree.getChild(node, 0), type); |
| 516 |
TipLabeledPolynomial childPolynomial2 = recursivelyComputePolynomial(tree, tree.getChild(node, 1), type); |
| 517 |
|
| 518 |
TipLabeledPolynomial polynomial = childPolynomial1.multiply(childPolynomial2); |
| 519 |
|
| 520 |
if (!tree.isRoot(node)) { |
| 521 |
polynomial = polynomial.integrateWithLowerBound(polynomial.label); |
| 522 |
} |
| 523 |
|
| 524 |
return polynomial; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
class TipLabeledPolynomial extends Polynomial.Abstract { |
| 565 |
|
| 566 |
TipLabeledPolynomial(double[] coefficients, double label, Polynomial.Type type, boolean isTip) { |
| 567 |
switch (type) { |
| 568 |
case DOUBLE: |
| 569 |
polynomial = new Polynomial.Double(coefficients); |
| 570 |
break; |
| 571 |
case LOG_DOUBLE: |
| 572 |
polynomial = new Polynomial.LogDouble(coefficients); |
| 573 |
break; |
| 574 |
case BIG_DOUBLE: |
| 575 |
polynomial = new Polynomial.BigDouble(coefficients); |
| 576 |
break; |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
default: |
| 585 |
throw new RuntimeException("Unknown polynomial type"); |
| 586 |
} |
| 587 |
this.label = label; |
| 588 |
this.isTip = isTip; |
| 589 |
} |
| 590 |
|
| 591 |
TipLabeledPolynomial(Polynomial polynomial, double label, boolean isTip) { |
| 592 |
this.polynomial = polynomial; |
| 593 |
this.label = label; |
| 594 |
this.isTip = isTip; |
| 595 |
} |
| 596 |
|
| 597 |
public TipLabeledPolynomial copy() { |
| 598 |
Polynomial copyPolynomial = polynomial.copy(); |
| 599 |
return new TipLabeledPolynomial(copyPolynomial, this.label, this.isTip); |
| 600 |
} |
| 601 |
|
| 602 |
public Polynomial getPolynomial() { |
| 603 |
return polynomial; |
| 604 |
} |
| 605 |
|
| 606 |
public TipLabeledPolynomial multiply(TipLabeledPolynomial b) { |
| 607 |
double maxLabel = Math.max(label, b.label); |
| 608 |
return new TipLabeledPolynomial(polynomial.multiply(b), maxLabel, false); |
| 609 |
} |
| 610 |
|
| 611 |
public int getDegree() { |
| 612 |
return polynomial.getDegree(); |
| 613 |
} |
| 614 |
|
| 615 |
public Polynomial multiply(Polynomial b) { |
| 616 |
return polynomial.multiply(b); |
| 617 |
} |
| 618 |
|
| 619 |
public Polynomial integrate() { |
| 620 |
return polynomial.integrate(); |
| 621 |
} |
| 622 |
|
| 623 |
public void expand(double x) { |
| 624 |
polynomial.expand(x); |
| 625 |
} |
| 626 |
|
| 627 |
public double evaluate(double x) { |
| 628 |
return polynomial.evaluate(x); |
| 629 |
} |
| 630 |
|
| 631 |
public double logEvaluate(double x) { |
| 632 |
return polynomial.logEvaluate(x); |
| 633 |
} |
| 634 |
|
| 635 |
public double logEvaluateHorner(double x) { |
| 636 |
return polynomial.logEvaluateHorner(x); |
| 637 |
} |
| 638 |
|
| 639 |
public void setCoefficient(int n, double x) { |
| 640 |
polynomial.setCoefficient(n, x); |
| 641 |
} |
| 642 |
|
| 643 |
public TipLabeledPolynomial integrateWithLowerBound(double bound) { |
| 644 |
return new TipLabeledPolynomial(polynomial.integrateWithLowerBound(bound), label, isTip); |
| 645 |
} |
| 646 |
|
| 647 |
public double getCoefficient(int n) { |
| 648 |
return polynomial.getCoefficient(n); |
| 649 |
} |
| 650 |
|
| 651 |
public String toString() { |
| 652 |
return polynomial.toString() + " {" + label + "}"; |
| 653 |
} |
| 654 |
|
| 655 |
public String getCoefficientString(int n) { |
| 656 |
return polynomial.getCoefficientString(n); |
| 657 |
} |
| 658 |
|
| 659 |
private double label; |
| 660 |
private Polynomial polynomial; |
| 661 |
private boolean isTip; |
| 662 |
} |
| 663 |
|
| 664 |
private double logFactorial(int n) { |
| 665 |
if (n == 0 || n == 1) { |
| 666 |
return 0; |
| 667 |
} |
| 668 |
|
| 669 |
double rValue = 0; |
| 670 |
|
| 671 |
for (int i = n; i > 1; i--) { |
| 672 |
rValue += Math.log(i); |
| 673 |
} |
| 674 |
return rValue; |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
public org.w3c.dom.Element createElement(org.w3c.dom.Document d) { |
| 682 |
throw new RuntimeException("createElement not implemented"); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
Tree tree = null; |
| 693 |
|
| 694 |
double logLikelihood; |
| 695 |
private double storedLogLikelihood; |
| 696 |
boolean likelihoodKnown = false; |
| 697 |
private boolean storedLikelihoodKnown = false; |
| 698 |
private boolean treePolynomialKnown = false; |
| 699 |
private boolean storedTreePolynomialKnown = false; |
| 700 |
private Polynomial treePolynomial; |
| 701 |
private Polynomial[] treePolynomials; |
| 702 |
private Polynomial storedTreePolynomial; |
| 703 |
|
| 704 |
private double tmpLogLikelihood; |
| 705 |
|
| 706 |
|
| 707 |
private Polynomial.Type polynomialType; |
| 708 |
|
| 709 |
private double[] logLikelihoods; |
| 710 |
private double[][] drawNodeHeights; |
| 711 |
private double[] minNodeHeights; |
| 712 |
|
| 713 |
} |