Search in sources :

Example 1 with Function

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(";");
}
Also used : TreePopSizeFunction(beast.evolution.speciation.SpeciesTreePrior.TreePopSizeFunction) Function(beast.core.Function) StateNode(beast.core.StateNode) Tree(beast.evolution.tree.Tree)

Example 2 with Function

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();
}
Also used : Function(beast.core.Function) Parameter(beast.core.parameter.Parameter) RealParameter(beast.core.parameter.RealParameter) RealParameter(beast.core.parameter.RealParameter)

Example 3 with Function

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];
}
Also used : Function(beast.core.Function) BEASTObject(beast.core.BEASTObject)

Example 4 with Function

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;
}
Also used : Function(beast.core.Function) StateNode(beast.core.StateNode) BEASTObject(beast.core.BEASTObject)

Example 5 with Function

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.");
    }
}
Also used : Function(beast.core.Function) IntegerParameter(beast.core.parameter.IntegerParameter) RealParameter(beast.core.parameter.RealParameter)

Aggregations

Function (beast.core.Function)10 IntegerParameter (beast.core.parameter.IntegerParameter)3 Parameter (beast.core.parameter.Parameter)3 RealParameter (beast.core.parameter.RealParameter)3 BEASTObject (beast.core.BEASTObject)2 StateNode (beast.core.StateNode)2 TreePopSizeFunction (beast.evolution.speciation.SpeciesTreePrior.TreePopSizeFunction)2 BEASTInterface (beast.core.BEASTInterface)1 Distribution (beast.core.Distribution)1 BooleanParameter (beast.core.parameter.BooleanParameter)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 Tree (beast.evolution.tree.Tree)1 Prior (beast.math.distributions.Prior)1 LinkedHashSet (java.util.LinkedHashSet)1