Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions beast-fx/src/main/java/beastfx/app/inputeditor/IIDInputEditor.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
package beastfx.app.inputeditor;







import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import beast.base.core.BEASTInterface;
import beast.base.core.Input;
import beast.base.inference.Distribution;
import beast.base.parser.PartitionContext;
import beast.base.spec.domain.Int;
import beast.base.spec.domain.NonNegativeInt;
import beast.base.spec.domain.NonNegativeReal;
import beast.base.spec.domain.PositiveInt;
import beast.base.spec.domain.PositiveReal;
import beast.base.spec.domain.Real;
import beast.base.spec.domain.*;
import beast.base.spec.inference.distribution.IID;
import beast.base.spec.inference.distribution.ScalarDistribution;
import beast.base.spec.inference.distribution.TensorDistribution;
import beast.base.spec.inference.parameter.BoolScalarParam;
import beast.base.spec.inference.parameter.IntScalarParam;
import beast.base.spec.inference.parameter.IntVectorParam;
import beast.base.spec.inference.parameter.RealScalarParam;
import beast.base.spec.inference.parameter.RealVectorParam;
import beast.base.spec.type.IntScalar;
import beast.base.spec.inference.parameter.*;
import beast.base.spec.type.IntVector;
import beast.base.spec.type.RealScalar;
import beast.base.spec.type.RealVector;
import beast.base.spec.type.Scalar;
import beast.base.spec.type.Simplex;
import beastfx.app.util.FXUtils;
import javafx.geometry.Insets;
import javafx.scene.Node;
Expand All @@ -43,6 +24,10 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IIDInputEditor extends ScalarDistributionInputEditor {

public IIDInputEditor() {
Expand Down Expand Up @@ -118,7 +103,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
List<?> list = (List<?>) m_input.get();
TensorDistribution<?,?> prior1 = (TensorDistribution<?,?>) list.get(itemNr);
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
((BEASTInterface)p1).initAndValidate();
Expand All @@ -139,7 +124,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
List<?> list = (List<?>) m_input.get();
TensorDistribution<?,?> prior1 = (TensorDistribution<?,?>) list.get(itemNr);
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
p1.initAndValidate();
Expand Down Expand Up @@ -273,9 +258,10 @@ protected ComboBox<BeautiSubTemplate> createComboBox() {
Object param = distr.paramInput.get();
Class<?> domain = getParameterDomain(param);
for (BeautiSubTemplate template : tensorTemplates) {
if (isCompatible(domain, templateDomains.get(k++))) {
if (isCompatible(domain, templateDomains.get(k), hasSimplexParam(param, templateInstances.get(k)))) {
comboBox.getItems().add(template);
}
k++;
}

if (comboBox.getItems().size() == 0) {
Expand Down Expand Up @@ -353,12 +339,27 @@ protected void updateItem(BeautiSubTemplate item, boolean empty) {
}


private boolean isCompatible(Class<?> paramDomain, Class<?> templateDomain) {
/**
* Domain range checks in isCompatible() can't see the "elements sum to 1" structural
* constraint of a Simplex, so a Simplex-only template must line up with a
* Simplex-valued param, and a non-Simplex template must not be offered for one.
*/
private boolean hasSimplexParam(Object param, TensorDistribution<?,?> templateInstance) {
Object templateParam = templateInstance == null ? null : templateInstance.getInput("param").get();
boolean paramIsSimplex = param instanceof Simplex;
boolean templateIsSimplex = templateParam instanceof Simplex;
return paramIsSimplex == templateIsSimplex;
}

private boolean isCompatible(Class<?> paramDomain, Class<?> templateDomain, boolean hasSimplexParam) {
if (templateDomain == null) {
// the "no prior" and ScalarDistribution templates should be rejected
return false;
}

if (!hasSimplexParam) {
return false;
}

if (Real.class.isAssignableFrom(paramDomain)) {
// check type first
if (!(Real.class.isAssignableFrom(templateDomain))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
return;
}
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
((BEASTInterface)p1).initAndValidate();
Expand All @@ -188,7 +188,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
return;
}
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
p1.initAndValidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import beast.base.spec.inference.distribution.ScalarDistribution;
import beast.base.spec.inference.distribution.TensorDistribution;
import beast.base.spec.inference.parameter.*;
import beast.base.spec.type.*;
import beast.base.spec.type.IntVector;
import beast.base.spec.type.RealVector;
import beast.base.spec.type.Scalar;
import beast.base.spec.type.Simplex;
import beastfx.app.util.FXUtils;
import javafx.scene.Node;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -98,7 +101,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
List<?> list = (List<?>) m_input.get();
TensorDistribution<?,?> prior1 = (TensorDistribution<?,?>) list.get(itemNr);
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
((BEASTInterface)p1).initAndValidate();
Expand All @@ -119,7 +122,7 @@ public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandO
List<?> list = (List<?>) m_input.get();
TensorDistribution<?,?> prior1 = (TensorDistribution<?,?>) list.get(itemNr);
BEASTInterface p1 = (BEASTInterface) prior1.paramInput.get();
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntScalar.class, doc);
BEASTObjectDialog dlg = new BEASTObjectDialog(p1, p1.getClass(), doc);
if (dlg.showDialog()) {
dlg.accept(p1, doc);
p1.initAndValidate();
Expand Down Expand Up @@ -253,9 +256,10 @@ private ComboBox<BeautiSubTemplate> createComboBox() {
Object param = distr.paramInput.get();
Class<?> domain = getParameterDomain(param);
for (BeautiSubTemplate template : tensorTemplates) {
if (isCompatible(domain, templateDomains.get(k++))) {
if (isCompatible(domain, templateDomains.get(k), hasSimplexParam(param, templateInstances.get(k)))) {
comboBox.getItems().add(template);
}
k++;
}

if (comboBox.getItems().size() == 0) {
Expand Down Expand Up @@ -334,12 +338,27 @@ protected void updateItem(BeautiSubTemplate item, boolean empty) {
}


private boolean isCompatible(Class<?> paramDomain, Class<?> templateDomain) {
/**
* Domain range checks in isCompatible() can't see the "elements sum to 1" structural
* constraint of a Simplex, so a Simplex-only template must line up with a
* Simplex-valued param, and a non-Simplex template must not be offered for one.
*/
private boolean hasSimplexParam(Object param, TensorDistribution<?,?> templateInstance) {
Object templateParam = templateInstance == null ? null : templateInstance.getInput("param").get();
boolean paramIsSimplex = param instanceof Simplex;
boolean templateIsSimplex = templateParam instanceof Simplex;
return paramIsSimplex == templateIsSimplex;
}

private boolean isCompatible(Class<?> paramDomain, Class<?> templateDomain, boolean hasSimplexParam) {
if (templateDomain == null) {
// the "no prior" and ScalarDistribution templates should be rejected
return false;
}

if (!hasSimplexParam) {
return false;
}

if (Real.class.isAssignableFrom(paramDomain)) {
// check type first
if (!(Real.class.isAssignableFrom(templateDomain))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
]]>
</subtemplate>

<!-- OneOnX -->
<subtemplate id='1/X' class='beast.base.inference.distribution.OneOnX' mainid='[top]'>
<![CDATA[
<distr spec="beast.base.inference.distribution.OneOnX"/>
]]>
</subtemplate>

<!-- lognormal -->
<subtemplate id='LogNormal' class='beast.base.spec.inference.distribution.LogNormal' mainid='[top]'
suppressInputs='beast.base.spec.inference.distribution.LogNormal.param'
Expand Down Expand Up @@ -188,6 +181,21 @@
]]>
</subtemplate>

<!-- OneOnX (improper 1/x prior) is removed from the BEAUti distribution list; -->
<!-- use LogUniform as a replacement to a PositiveReal-domain param bounded on [lower, upper]. -->
<subtemplate id='LogUniform' class='beast.base.spec.inference.distribution.LogUniform' mainid='[top]'
suppressInputs='beast.base.spec.inference.distribution.LogUniform.param'
hmc='
LogUniform/lower/=ParametricDistributions/LogUniform/lower/,
LogUniform/upper/=ParametricDistributions/LogUniform/upper/'>
<![CDATA[
<distr spec="beast.base.spec.inference.distribution.LogUniform">
<lower spec="beast.base.spec.inference.parameter.RealScalarParam" domain="PositiveReal" value="1.0E-8" estimate="false"/>
<upper spec="beast.base.spec.inference.parameter.RealScalarParam" domain="PositiveReal" value="1.0E8" estimate="false"/>
</distr>
]]>
</subtemplate>

<!-- Poisson -->
<subtemplate id='Poisson' class='beast.base.spec.inference.distribution.Poisson' mainid='[top]'
suppressInputs='beast.base.spec.inference.distribution.Poisson.param'
Expand All @@ -201,12 +209,17 @@
</subtemplate>

<!-- Dirichlet -->
<!-- The "param" below is hidden from the user (see suppressInputs) and its value is never used. -->
<!-- BEAUti still needs it to recognize Dirichlet as a valid prior for simplex parameters; -->
<!-- without it, Dirichlet would disappear from the prior dropdown. -->
<subtemplate id='Dirichlet' class='beast.base.spec.inference.distribution.Dirichlet' mainid='[top]'
suppressInputs='beast.base.spec.inference.distribution.Dirichlet.param'
hmc='
Dirichlet/alpha/=ParametricDistributions/Dirichlet/mean/,
Dirichlet/offset/=ParametricDistributions/Dirichlet/offset/'>
<![CDATA[
<distr spec="beast.base.spec.inference.distribution.Dirichlet">
<param spec="beast.base.spec.inference.parameter.SimplexParam" dimension="1" value="1.0" estimate="false"/>
<alpha spec="beast.base.spec.inference.parameter.RealVectorParam" domain="PositiveReal" estimate="false">1.0</alpha>
</distr>
]]>
Expand Down
Loading