public double mergeValueInLogSpace( RealParameter removed, RealParameter merge, ParametricDistribution distr) throws Exception { double val1 = Math.log(removed.getValue()); double val2 = Math.log(merge.getValue()); double x = val1 - val2; return distr.calcLogP(new RealParameter(new Double[] {x})) - val1; }
public double mergeDiscreteValue( RealParameter removed, RealParameter merge, ConditionalCategoricalDistribution distr) { int removedModel = (int) (double) removed.getValue(); int mergeModel = (int) (double) merge.getValue(); return distr.logConditionalDensity(mergeModel, removedModel); }
public double mergeValue(RealParameter removed, RealParameter merge, ParametricDistribution distr) throws Exception { Double[] x = new Double[removed.getDimension()]; for (int i = 0; i < x.length; i++) { x[i] = removed.getValue(i) - merge.getValue(i); } return distr.calcLogP(new RealParameter(x)); }
private void update() { final double geneTreeRate = meanRate.getValue(); final double[] speciesTreeRates = speciesTreeRatesX.getRatesArray(); final double[] speciesOccupancy = geneTree.getSpeciesOccupancy(); final int speciesNodeCount = speciesTreeRates.length; for (int i = 0; i < geneNodeCount - 1; i++) { double weightedSum = 0.0; double branchLength = 0.0; for (int j = 0; j < speciesNodeCount; j++) { // System.out.println(String.format("%d, %d: %f, %f", i, j, speciesTreeRates[j], // speciesOccupancy[i * speciesNodeCount + j])); weightedSum += speciesTreeRates[j] * speciesOccupancy[i * speciesNodeCount + j]; branchLength += speciesOccupancy[i * speciesNodeCount + j]; } branchRates[i] = geneTreeRate * weightedSum / branchLength; } // set the rate for the root branch of this gene to equal the input mean rate branchRates[geneNodeCount - 1] = geneTreeRate; needsUpdate = false; }