use of beast.core.Function in project beast2 by CompEvol.
the class SpeciesTreeLogger method log.
@Override
public void log(final long sample, final PrintStream out) {
// make sure we get the current version of the inputs
final Tree tree = (Tree) treeInput.get().getCurrent();
Function metadata = parameterInput.get();
if (metadata instanceof StateNode) {
metadata = ((StateNode) metadata).getCurrent();
}
Function metadataTop = parameterTopInput.get();
if (metadataTop != null && metadataTop instanceof StateNode) {
metadataTop = ((StateNode) metadataTop).getCurrent();
}
List<Function> metadataList = metadataInput.get();
for (int i = 0; i < metadataList.size(); i++) {
if (metadataList.get(i) instanceof StateNode) {
metadataList.set(i, ((StateNode) metadataList.get(i)).getCurrent());
}
}
// write out the log tree with meta data
out.print("tree STATE_" + sample + " = ");
tree.getRoot().sort();
out.print(toNewick(tree.getRoot(), metadata, metadataTop, metadataList));
// out.print(tree.getRoot().toShortNewick(false));
out.print(";");
}
use of beast.core.Function in project beast2 by CompEvol.
the class TreeWithMetaDataLogger method toNewick.
String toNewick(Node node, List<Function> metadataList, BranchRateModel.Base branchRateModel) {
StringBuffer buf = new StringBuffer();
if (node.getLeft() != null) {
buf.append("(");
buf.append(toNewick(node.getLeft(), metadataList, branchRateModel));
if (node.getRight() != null) {
buf.append(',');
buf.append(toNewick(node.getRight(), metadataList, branchRateModel));
}
buf.append(")");
} else {
buf.append(node.labelNr + 1);
}
if (someMetaDataNeedsLogging) {
buf.append("[&");
if (metadataList.size() > 0) {
for (Function metadata : metadataList) {
buf.append(((BEASTObject) metadata).getID());
buf.append('=');
if (metadata instanceof Parameter<?>) {
Parameter<?> p = (Parameter<?>) metadata;
int dim = p.getMinorDimension1();
if (dim > 1) {
buf.append('{');
for (int i = 0; i < dim; i++) {
if (metadata instanceof RealParameter) {
RealParameter rp = (RealParameter) metadata;
appendDouble(buf, rp.getMatrixValue(node.labelNr, i));
} else {
buf.append(p.getMatrixValue(node.labelNr, i));
}
if (i < dim - 1) {
buf.append(',');
}
}
buf.append('}');
} else {
if (metadata instanceof RealParameter) {
RealParameter rp = (RealParameter) metadata;
appendDouble(buf, rp.getArrayValue(node.labelNr));
} else {
buf.append(metadata.getArrayValue(node.labelNr));
}
}
} else {
buf.append(metadata.getArrayValue(node.labelNr));
}
if (metadataList.indexOf(metadata) < metadataList.size() - 1) {
buf.append(",");
}
}
if (branchRateModel != null) {
buf.append(",");
}
}
if (branchRateModel != null) {
buf.append("rate=");
appendDouble(buf, branchRateModel.getRateForBranch(node));
}
buf.append(']');
}
buf.append(":");
if (substitutions) {
appendDouble(buf, node.getLength() * branchRateModel.getRateForBranch(node));
} else {
appendDouble(buf, node.getLength());
}
return buf.toString();
}
use of beast.core.Function in project beast2 by CompEvol.
the class CompoundValuable method initAndValidate.
@Override
public void initAndValidate() {
// determine dimension
int dimension = 0;
for (BEASTObject beastObject : m_values.get()) {
if (!(beastObject instanceof Function)) {
throw new IllegalArgumentException("Input does not implement Valuable");
}
dimension += ((Function) beastObject).getDimension();
}
m_fValues = new double[dimension];
}
use of beast.core.Function in project beast2 by CompEvol.
the class CompoundValuable method recompute.
/**
* collect values of the compounds into an array *
*/
private void recompute() {
int k = 0;
for (BEASTObject beastObject : m_values.get()) {
Function valuable = (Function) beastObject;
if (beastObject instanceof StateNode) {
valuable = ((StateNode) beastObject).getCurrent();
}
int dimension = valuable.getDimension();
for (int i = 0; i < dimension; i++) {
m_fValues[k++] = valuable.getArrayValue(i);
}
}
m_bRecompute = false;
}
use of beast.core.Function in project MultiTypeTree by tgvaughan.
the class ExcludablePrior method initAndValidate.
@Override
public void initAndValidate() {
super.initAndValidate();
Function x = m_x.get();
if (x instanceof RealParameter || x instanceof IntegerParameter) {
if (x.getDimension() != xIncludeInput.get().getDimension())
throw new IllegalArgumentException("Length of xInclude does " + "not match length of x.");
}
}
Aggregations