use of beast.core.BEASTObject in project beast2 by CompEvol.
the class BeautiDoc method determineLinks.
// methods for dealing with linking
void determineLinks() {
if (!allowLinking) {
return;
}
linked.clear();
for (BEASTInterface beastObject : posteriorPredecessors) {
Map<String, Integer> outputIDs = new HashMap<>();
for (Object output : beastObject.getOutputs()) {
if (posteriorPredecessors.contains(output)) {
String id = ((BEASTInterface) output).getID();
if (id.indexOf('.') >= 0) {
id = id.substring(0, id.indexOf('.'));
if (outputIDs.containsKey(id)) {
outputIDs.put(id, outputIDs.get(id) + 1);
} else {
outputIDs.put(id, 1);
}
}
}
}
for (Object output : beastObject.getOutputs()) {
if (posteriorPredecessors.contains(output)) {
String id = ((BEASTInterface) output).getID();
if (id.indexOf('.') >= 0) {
id = id.substring(0, id.indexOf('.'));
if (outputIDs.get(id) > 1) {
addLink(beastObject, (BEASTInterface) output);
}
}
}
}
// add parameters that have more than 1 outputs into susbtitution models
if (beastObject instanceof Parameter<?>) {
for (Object output : beastObject.getOutputs()) {
if (posteriorPredecessors.contains(output)) {
if (output instanceof SubstitutionModel) {
int nrOfSubstModelsInOutput = 0;
try {
for (Input<?> input : ((BEASTInterface) output).listInputs()) {
if (input.get() != null && input.get().equals(beastObject)) {
nrOfSubstModelsInOutput++;
}
}
} catch (Exception e) {
// ignore
}
if (nrOfSubstModelsInOutput > 1) {
addLink(beastObject, (BEASTInterface) output);
}
}
}
}
}
}
hasLinkedAtLeastOnce = false;
for (Input<?> input : linked) {
if (input.getType().isAssignableFrom(RealParameter.class)) {
hasLinkedAtLeastOnce = true;
break;
}
}
}
use of beast.core.BEASTObject in project beast2 by CompEvol.
the class BeautiBase method traceLogAsString.
String traceLogAsString() {
Logger logger = (Logger) doc.pluginmap.get("tracelog");
List<BEASTObject> logs = logger.loggersInput.get();
return "assertTraceLogEqual" + pluginListAsString(logs);
}
use of beast.core.BEASTObject in project beast2 by CompEvol.
the class DocMaker method getType.
// getHTML
/**
* determine type of input of a plug in with name name
*/
String getType(BEASTObject beastObject, String name) {
try {
Field[] fields = beastObject.getClass().getFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getType().isAssignableFrom(Input.class)) {
final Input<?> input = (Input<?>) fields[i].get(beastObject);
if (input.getName().equals(name)) {
Type t = fields[i].getGenericType();
Type[] genericTypes = ((ParameterizedType) t).getActualTypeArguments();
if (input.getType() != null) {
return (input.getType().isAssignableFrom(BEASTObject.class) ? "<a href='" + input.getType().getName() + ".html'>" : "") + input.getType().getName() + (input.get() != null && input.get() instanceof List<?> ? "***" : "") + (input.getType().isAssignableFrom(BEASTObject.class) ? "</a>" : "");
}
if (input.get() != null && input.get() instanceof List<?>) {
Type[] genericTypes2 = ((ParameterizedType) genericTypes[0]).getActualTypeArguments();
Class<?> _class = (Class<?>) genericTypes2[0];
Object o = null;
try {
o = Class.forName(_class.getName()).newInstance();
} catch (Exception e) {
}
if (o != null && o instanceof BEASTObject) {
return "<a href='" + _class.getName() + ".html'>" + _class.getName() + "***</a>";
} else {
return _class.getName() + "***";
}
} else {
Class<?> genericType = (Class<?>) genericTypes[0];
Class<?> _class = genericType;
Object o = null;
try {
o = Class.forName(_class.getName()).newInstance();
} catch (Exception e) {
}
if (o != null && o instanceof BEASTObject) {
return "<a href='" + _class.getName() + ".html'>" + _class.getName() + "</a>";
} else {
return _class.getName();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "?";
}
use of beast.core.BEASTObject 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.BEASTObject 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;
}
Aggregations