public void forwardIBD() { int numNodes = treeModel.getNodeCount(); int stateCount = substitutionModel.getStateCount(); getDiagonalRates(diag); for (int nodeId = 0; nodeId < numNodes; ++nodeId) { NodeRef node = treeModel.getNode(nodeId); NodeRef parent = treeModel.getParent(node); if (parent == null) { // handle the root } else if (treeModel.isExternal(node)) { // Handle the tip double branchTime = branchRateModel.getBranchRate(treeModel, node) * (treeModel.getNodeHeight(parent) - treeModel.getNodeHeight(node)); for (int state = 0; state < stateCount; ++state) { ibdForward[nodeId][state] = Math.exp(-diag[state] * branchTime); } } else { // Handle internal node double branchTime = branchRateModel.getBranchRate(treeModel, node) * (treeModel.getNodeHeight(parent) - treeModel.getNodeHeight(node)); int childCount = treeModel.getChildCount(node); for (int state = 0; state < stateCount; ++state) { ibdForward[nodeId][state] = 0; for (int child = 0; child < childCount; ++child) { int childNodeId = treeModel.getChild(node, child).getNumber(); ibdForward[nodeId][state] += ibdForward[childNodeId][state]; } ibdForward[nodeId][state] *= Math.exp(-diag[state] * branchTime); } } } }
public void backwardIBD(NodeRef node) { int stateCount = substitutionModel.getStateCount(); if (node == null) { node = treeModel.getRoot(); int nodeId = node.getNumber(); for (int state = 0; state < stateCount; ++state) { ibdBackward[nodeId][state] = 0; } } getDiagonalRates(diag); int childCount = treeModel.getChildCount(node); int nodeId = node.getNumber(); for (int child = 0; child < childCount; ++child) { NodeRef childNode = treeModel.getChild(node, child); int childNodeId = childNode.getNumber(); double branchTime = branchRateModel.getBranchRate(treeModel, childNode) * (treeModel.getNodeHeight(node) - treeModel.getNodeHeight(childNode)); for (int state = 0; state < stateCount; ++state) { ibdBackward[childNodeId][state] = ibdBackward[nodeId][state]; for (int sibling = 0; sibling < childCount; ++sibling) { if (sibling != child) { int siblingId = treeModel.getChild(node, sibling).getNumber(); ibdBackward[childNodeId][state] += ibdForward[siblingId][state]; } } ibdBackward[childNodeId][state] *= Math.exp(-diag[state] * branchTime); } } for (int child = 0; child < childCount; ++child) { NodeRef childNode = treeModel.getChild(node, child); backwardIBD(childNode); } }
/** Calculates the actual rates corresponding to the category indices. */ protected void setupRates() { // System.out.println("BRRRTTZZZ " + distributionIndexParameter.getValue(0)); for (int i = 0; i < tree.getNodeCount(); i++) { // rates[i] = distributionModel.quantile(rateCategoryQuantiles.getNodeValue( // rateCategoryQuantiles.getTreeModel(), rateCategoryQuantiles.getTreeModel().getNode(i) )); if (!tree.isRoot(tree.getNode(i))) { if (useQuantilesForRates) { /* Using quantiles to represent rates */ rates[tree.getNode(i).getNumber()] = distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].quantile( rateCategoryQuantiles.getNodeValue(tree, tree.getNode(i))); } else { /* Not using quantiles to represent rates. This is practically useless for anything else other than simulation */ rates[tree.getNode(i).getNumber()] = rateCategoryQuantiles.getNodeValue(tree, tree.getNode(i)); } } } /*System.out.print(distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName() + "\t" + (int) Math.round(distributionIndexParameter.getValue(0)) + "\t" + rates[1] + "\t" + rateCategoryQuantiles.getNodeValue(tree, tree.getNode(1)));// + "\t" + distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].); if(distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName().equals("dr.inference.distribution.LogNormalDistributionModel")) { LogNormalDistributionModel lndm = (LogNormalDistributionModel) distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))]; System.out.println("\t" + lndm.getS()); } else if (distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))].getClass().getName().equals("dr.inference.distribution.InverseGaussianDistributionModel")) { InverseGaussianDistributionModel lndm = (InverseGaussianDistributionModel) distributionModels[(int) Math.round(distributionIndexParameter.getValue(0))]; System.out.println("\t" + lndm.getS()); }*/ if (normalize) computeFactor(); }
/** provide information to the categoriesParameter about the number of sites */ public void setCategoriesParameter(int siteCount) { categoriesParameter.setDimension(siteCount); categoriesParameter.addBounds(new Parameter.DefaultBounds(categoryCount, 0.0, siteCount)); for (int i = 0; i < siteCount; i++) { int r = (int) (Math.random() * categoryCount); categoriesParameter.setParameterValue(i, r); } for (int j = 0; j < categoryCount; j++) { sitesInCategory[j] = 0; } for (int i = 0; i < siteCount; i++) { int value = (int) categoriesParameter.getParameterValue(i); sitesInCategory[value] = sitesInCategory[value] + 1; } }
public static Transform[] parseListOfTransforms(XMLObject xo, int maxDim) throws XMLParseException { Transform[] transforms = null; boolean anyTransforms = false; for (int i = 0; i < xo.getChildCount(); ++i) { if (xo.getChild(i) instanceof Transform.ParsedTransform) { Transform.ParsedTransform t = (Transform.ParsedTransform) xo.getChild(i); if (transforms == null) { transforms = Transform.Util.getListOfNoTransforms(maxDim); } t.end = Math.max(t.end, maxDim); if (t.start < 0 || t.end < 0 || t.start > t.end) { throw new XMLParseException("Invalid bounds for transform in " + xo.getId()); } for (int j = t.start; j < t.end; j += t.every) { transforms[j] = t.transform; anyTransforms = true; } } } if (anyTransforms) { StringBuilder sb = new StringBuilder("Using distributional transforms in " + xo.getId() + "\n"); for (int i = 0; i < transforms.length; ++i) { if (transforms[i] != Transform.NONE) { sb.append("\t") .append(transforms[i].getTransformName()) .append(" on index ") .append(i + 1) .append("\n"); } } sb.append("Please cite:\n").append(Citable.Utils.getCitationString(Transform.LOG)); Logger.getLogger("dr.utils.Transform").info(sb.toString()); } return transforms; }