Search in sources :

Example 1 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.

the class FixedMeanRateTest method testFixedMeanRate.

@Test
public void testFixedMeanRate() throws Exception {
    importAlignment("examples/nexus", new File("26.nex"), new File("29.nex"));
    beautiFrame.menuItemWithPath("Mode", "Automatic set fix mean substitution rate flag").click();
    warning("Setting fixed mean rates");
    JTabbedPaneFixture f = beautiFrame.tabbedPane();
    f = f.selectTab("Site Model");
    beautiFrame.checkBox("mutationRate.isEstimated").check();
    beautiFrame.checkBox("FixMeanMutationRate").check();
    warning("link/unlink site models");
    f.selectTab("Partitions");
    beautiFrame.table().selectCells(TableCell.row(0).column(0), TableCell.row(1).column(0));
    beautiFrame.button("Link Site Models").click();
    beautiFrame.button("Unlink Site Models").click();
    // saveFile("/Users/remcobouckaert/tmp", "x.xml");
    makeSureXMLParses();
    DeltaExchangeOperator operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
    int nrOfParameters = operator.parameterInput.get().size();
    if (nrOfParameters != 2) {
        throw new IllegalArgumentException("Expected 2 parameters for deltaExchangeOperator, not " + nrOfParameters);
    }
}
Also used : DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) File(java.io.File) JTabbedPaneFixture(org.fest.swing.fixture.JTabbedPaneFixture) Test(org.junit.Test)

Example 2 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.

the class FixedMeanRateTest method testFixedMeanRateSharedSiteModel.

@Test
public void testFixedMeanRateSharedSiteModel() throws Exception {
    importAlignment("examples/nexus", new File("26.nex"), new File("29.nex"), new File("47.nex"));
    warning("Setting fixed mean rates");
    JTabbedPaneFixture f = beautiFrame.tabbedPane();
    f = f.selectTab("Site Model");
    beautiFrame.checkBox("mutationRate.isEstimated").check();
    // beautiFrame.checkBox("FixMeanMutationRate").check();
    warning("link/unlink site models");
    f.selectTab("Partitions");
    beautiFrame.table().selectCells(TableCell.row(0).column(1), TableCell.row(1).column(1), TableCell.row(2).column(1));
    beautiFrame.button("Link Site Models").click();
    beautiFrame.button("Unlink Site Models").click();
    DeltaExchangeOperator operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
    int nrOfParameters = operator.parameterInput.get().size();
    if (nrOfParameters != 3) {
        throw new IllegalArgumentException("Expected 3 parameters for deltaExchangeOperator, not " + nrOfParameters);
    }
    List<Integer> weights = operator.parameterWeightsInput.get().valuesInput.get();
    Assert.assertEquals(weights.size(), 3);
    Assert.assertEquals(weights.get(0), (Integer) 614);
    Assert.assertEquals(weights.get(1), (Integer) 601);
    Assert.assertEquals(weights.get(2), (Integer) 819);
    beautiFrame.table().selectCells(TableCell.row(0).column(1), TableCell.row(2).column(1));
    beautiFrame.button("Link Site Models").click();
    operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
    nrOfParameters = operator.parameterInput.get().size();
    if (nrOfParameters != 2) {
        throw new IllegalArgumentException("Expected 2 parameters for deltaExchangeOperator, not " + nrOfParameters);
    }
    weights = operator.parameterWeightsInput.get().valuesInput.get();
    Assert.assertEquals(weights.size(), 2);
    Assert.assertEquals(weights.get(0), (Integer) (614 + 819));
    Assert.assertEquals(weights.get(1), (Integer) 601);
    makeSureXMLParses();
}
Also used : DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) File(java.io.File) JTabbedPaneFixture(org.fest.swing.fixture.JTabbedPaneFixture) Test(org.junit.Test)

Example 3 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.

the class SiteModelInputEditor method customConnector.

public static boolean customConnector(BeautiDoc doc) {
    try {
        DeltaExchangeOperator operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
        if (operator == null) {
            return false;
        }
        List<RealParameter> parameters = operator.parameterInput.get();
        parameters.clear();
        // String weights = "";
        CompoundDistribution likelihood = (CompoundDistribution) doc.pluginmap.get("likelihood");
        boolean hasOneEstimatedRate = false;
        List<String> rateIDs = new ArrayList<>();
        List<Integer> weights = new ArrayList<>();
        for (Distribution d : likelihood.pDistributions.get()) {
            GenericTreeLikelihood treelikelihood = (GenericTreeLikelihood) d;
            Alignment data = treelikelihood.dataInput.get();
            int weight = data.getSiteCount();
            if (data.isAscertained) {
                weight -= data.getExcludedPatternCount();
            }
            if (treelikelihood.siteModelInput.get() instanceof SiteModel) {
                SiteModel siteModel = (SiteModel) treelikelihood.siteModelInput.get();
                RealParameter mutationRate = siteModel.muParameterInput.get();
                // clockRate.m_bIsEstimated.setValue(true, clockRate);
                if (mutationRate.isEstimatedInput.get()) {
                    hasOneEstimatedRate = true;
                    if (rateIDs.indexOf(mutationRate.getID()) == -1) {
                        parameters.add(mutationRate);
                        weights.add(weight);
                        rateIDs.add(mutationRate.getID());
                    } else {
                        int k = rateIDs.indexOf(mutationRate.getID());
                        weights.set(k, weights.get(k) + weight);
                    }
                }
            }
        }
        IntegerParameter weightParameter;
        if (weights.size() == 0) {
            weightParameter = new IntegerParameter();
        } else {
            String weightString = "";
            for (int k : weights) {
                weightString += k + " ";
            }
            weightParameter = new IntegerParameter(weightString);
            weightParameter.setID("weightparameter");
        }
        weightParameter.isEstimatedInput.setValue(false, weightParameter);
        operator.parameterWeightsInput.setValue(weightParameter, operator);
        return hasOneEstimatedRate;
    } catch (Exception e) {
    }
    return false;
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) ArrayList(java.util.ArrayList) RealParameter(beast.core.parameter.RealParameter) SiteModel(beast.evolution.sitemodel.SiteModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompoundDistribution(beast.core.util.CompoundDistribution) Alignment(beast.evolution.alignment.Alignment) CompoundDistribution(beast.core.util.CompoundDistribution) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator)

Example 4 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.

the class SiteModelInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    fixMeanRatesCheckBox = new JCheckBox("Fix mean substitution rate");
    fixMeanRatesCheckBox.setName("FixMeanMutationRate");
    fixMeanRatesCheckBox.setEnabled(!doc.autoUpdateFixMeanSubstRate);
    super.init(input, beastObject, itemNr, isExpandOption, addButtons);
    List<Operator> operators = ((MCMC) doc.mcmc.get()).operatorsInput.get();
    fixMeanRatesCheckBox.addActionListener(e -> {
        JCheckBox averageRatesBox = (JCheckBox) e.getSource();
        doFixMeanRates(averageRatesBox.isSelected());
        if (averageRatesBox.isSelected())
            // set up relative weights
            setUpOperator();
    });
    operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
    if (operator == null) {
        operator = new DeltaExchangeOperator();
        try {
            operator.setID("FixMeanMutationRatesOperator");
            operator.initByName("weight", 2.0, "delta", 0.75);
        } catch (Throwable e1) {
        // ignore initAndValidate exception
        }
        doc.addPlugin(operator);
    }
    fixMeanRatesCheckBox.setSelected(operators.contains(operator));
    Box box = Box.createHorizontalBox();
    box.add(fixMeanRatesCheckBox);
    box.add(Box.createHorizontalGlue());
    fixMeanRatesValidateLabel = new SmallLabel("x", Color.GREEN);
    fixMeanRatesValidateLabel.setVisible(false);
    box.add(fixMeanRatesValidateLabel);
    if (doc.alignments.size() >= 1 && operator != null) {
        JComponent component = (JComponent) getComponents()[0];
        component.add(box);
    }
    setUpOperator();
}
Also used : DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator)

Example 5 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.

the class DeltaExchangeOperatorTest method testKeepsSum.

@Test
public void testKeepsSum() {
    DeltaExchangeOperator operator = new DeltaExchangeOperator();
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    register(operator, "parameter", parameter);
    for (int i = 0; i < 100; ++i) {
        operator.proposal();
    }
    double i = 0;
    for (Double p : parameter.getValues()) {
        i += p;
    }
    assertEquals("The DeltaExchangeOperator should not change the sum of a parameter", i, 4, 0.00001);
}
Also used : RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Aggregations

DeltaExchangeOperator (beast.evolution.operators.DeltaExchangeOperator)9 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)4 IntegerParameter (beast.core.parameter.IntegerParameter)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JTabbedPaneFixture (org.fest.swing.fixture.JTabbedPaneFixture)2 SmallLabel (beast.app.draw.SmallLabel)1 Operator (beast.core.Operator)1 OperatorSchedule (beast.core.OperatorSchedule)1 State (beast.core.State)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 Alignment (beast.evolution.alignment.Alignment)1 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)1 ScaleOperator (beast.evolution.operators.ScaleOperator)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Box (javax.swing.Box)1 JCheckBox (javax.swing.JCheckBox)1