private double branchLLInPopsIOtree(PopsIONode node, double alpha, double beta) { int q = node.coalcount; double gamma = node.coalintensity; double llhood = 0.0; for (int i = 1; i <= q - 1; i++) { llhood += Math.log(alpha + i); } llhood += alpha * Math.log(beta); llhood -= (alpha + q) * Math.log(beta + gamma); return llhood; }
private double logsumexp(double x[]) { double maxx = Double.MIN_VALUE; for (double d : x) { if (d > maxx) { maxx = d; } } double sum = 0.0; for (double d : x) { sum += Math.exp(d - maxx); } return maxx + Math.log(sum); }
public double logLhoodAllGeneTreesInSpeciesTree() { double[] llhoodcpts = new double[priorComponents.length]; double totalweight = 0.0; for (int i = 0; i < priorComponents.length; i++) { totalweight += priorComponents[i].weight; } for (int i = 0; i < priorComponents.length; i++) { llhoodcpts[i] = Math.log(priorComponents[i].weight / totalweight); double sigma = popPriorScale.getParameterValue(0); double alpha = priorComponents[i].alpha; double beta = sigma * priorComponents[i].beta; llhoodcpts[i] += logLhoodAllGeneTreesInSpeciesSubtree(pionodes[rootn], alpha, beta); } return logsumexp(llhoodcpts); }