Search in sources :

Example 6 with IntegerParameter

use of beast.core.parameter.IntegerParameter in project beast2 by CompEvol.

the class PriorInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
    m_bAddButtons = addButtons;
    m_input = input;
    m_beastObject = beastObject;
    this.itemNr = listItemNr;
    Box itemBox = Box.createHorizontalBox();
    Prior prior = (Prior) beastObject;
    String text = prior.getParameterName();
    JLabel label = new JLabel(text);
    Font font = label.getFont();
    Dimension size = new Dimension(font.getSize() * 200 / 13, font.getSize() * 25 / 13);
    label.setMinimumSize(size);
    label.setPreferredSize(size);
    itemBox.add(label);
    List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(prior.distInput, prior, null, doc);
    JComboBox<BeautiSubTemplate> comboBox = new JComboBox<BeautiSubTemplate>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
    comboBox.setName(text + ".distr");
    String id = prior.distInput.get().getID();
    // Log.warning.println("id=" + id);
    id = id.substring(0, id.indexOf('.'));
    for (BeautiSubTemplate template : availableBEASTObjects) {
        if (template.classInput.get() != null && template.shortClassName.equals(id)) {
            comboBox.setSelectedItem(template);
        }
    }
    comboBox.addActionListener(e -> {
        @SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> comboBox1 = (JComboBox<BeautiSubTemplate>) e.getSource();
        List<?> list = (List<?>) m_input.get();
        BeautiSubTemplate template = (BeautiSubTemplate) comboBox1.getSelectedItem();
        // String id = ((BEASTObject) list.get(item)).getID();
        // String partition = BeautiDoc.parsePartition(id);
        PartitionContext context = doc.getContextFor((BEASTInterface) list.get(itemNr));
        Prior prior1 = (Prior) list.get(itemNr);
        try {
            template.createSubNet(context, prior1, prior1.distInput, true);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        sync();
        refreshPanel();
    });
    JPanel panel = new JPanel();
    panel.add(comboBox);
    panel.setMaximumSize(size);
    itemBox.add(panel);
    if (prior.m_x.get() instanceof RealParameter) {
        // add range button for real parameters
        RealParameter p = (RealParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            RealParameter p1 = (RealParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    } else if (prior.m_x.get() instanceof IntegerParameter) {
        // add range button for real parameters
        IntegerParameter p = (IntegerParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            IntegerParameter p1 = (IntegerParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntegerParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    }
    int fontsize = comboBox.getFont().getSize();
    comboBox.setMaximumSize(new Dimension(1024 * fontsize / 13, 24 * fontsize / 13));
    String tipText = getDoc().tipTextMap.get(beastObject.getID());
    // System.out.println(beastObject.getID());
    if (tipText != null) {
        JLabel tipTextLabel = new JLabel(" " + tipText);
        itemBox.add(tipTextLabel);
    }
    itemBox.add(Box.createGlue());
    add(itemBox);
}
Also used : Arrays(java.util.Arrays) JButton(javax.swing.JButton) Input(beast.core.Input) Prior(beast.math.distributions.Prior) Font(java.awt.Font) FontSizeAction(javax.swing.text.StyledEditorKit.FontSizeAction) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) Box(javax.swing.Box) IntegerParameter(beast.core.parameter.IntegerParameter) Dimension(java.awt.Dimension) List(java.util.List) InputEditor(beast.app.draw.InputEditor) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) BEASTInterface(beast.core.BEASTInterface) JComboBox(javax.swing.JComboBox) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) IntegerParameter(beast.core.parameter.IntegerParameter) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) Dimension(java.awt.Dimension) Font(java.awt.Font) Prior(beast.math.distributions.Prior) List(java.util.List)

Example 7 with IntegerParameter

use of beast.core.parameter.IntegerParameter in project MultiTypeTree by tgvaughan.

the class StructuredCoalescentUntypedTree method main.

/**
 * Generates an ensemble of trees from the structured coalescent for testing
 * coloured tree-space samplers.
 *
 * @param argv
 * @throws Exception
 */
public static void main(String[] argv) throws Exception {
    // Set up migration model.
    RealParameter rateMatrix = new RealParameter();
    rateMatrix.initByName("value", "0.05", "dimension", "12");
    RealParameter popSizes = new RealParameter();
    popSizes.initByName("value", "7.0", "dimension", "4");
    SCMigrationModel migrationModel = new SCMigrationModel();
    migrationModel.initByName("rateMatrix", rateMatrix, "popSizes", popSizes);
    // Specify leaf types:
    IntegerParameter leafTypes = new IntegerParameter();
    leafTypes.initByName("value", "0 0 0");
    // Generate ensemble:
    int reps = 1000000;
    double[] heights = new double[reps];
    long startTime = System.currentTimeMillis();
    StructuredCoalescentUntypedTree sctree;
    sctree = new StructuredCoalescentUntypedTree();
    for (int i = 0; i < reps; i++) {
        if (i % 1000 == 0)
            System.out.format("%d reps done\n", i);
        sctree.initByName("migrationModel", migrationModel, "leafTypes", leafTypes, "nTypes", 4);
        heights[i] = sctree.getRoot().getHeight();
    }
    long time = System.currentTimeMillis() - startTime;
    System.out.printf("E[T] = %1.4f +/- %1.4f\n", DiscreteStatistics.mean(heights), DiscreteStatistics.stdev(heights) / Math.sqrt(reps));
    System.out.printf("V[T] = %1.4f\n", DiscreteStatistics.variance(heights));
    System.out.printf("Took %1.2f seconds\n", time / 1000.0);
    try (PrintStream outStream = new PrintStream("heights.txt")) {
        outStream.println("h c");
        for (int i = 0; i < reps; i++) outStream.format("%g\n", heights[i]);
    }
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) PrintStream(java.io.PrintStream) RealParameter(beast.core.parameter.RealParameter)

Example 8 with IntegerParameter

use of beast.core.parameter.IntegerParameter in project bacter by tgvaughan.

the class SkylinePopulationFunctionTest method test3.

@Test
public void test3() throws Exception {
    SkylinePopulationFunction skyline = new SkylinePopulationFunction();
    skyline.initByName("acg", acg, "popSizes", new RealParameter("1.0 1.0 5.0 1.0"), "groupSizes", new IntegerParameter("0"), "piecewiseLinear", true);
    for (double t = 0.0; t < 10; t += 0.01) assertTrue(Math.abs(t - skyline.getInverseIntensity(skyline.getIntensity(t))) < 1e-14);
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) RealParameter(beast.core.parameter.RealParameter) Test(org.junit.Test)

Example 9 with IntegerParameter

use of beast.core.parameter.IntegerParameter in project bacter by tgvaughan.

the class SkylinePopulationFunctionTest method test4.

@Test
public void test4() throws Exception {
    SkylinePopulationFunction skyline = new SkylinePopulationFunction();
    skyline.initByName("acg", acg, "popSizes", new RealParameter("1.0 1.0 5.0 1.0"), "groupSizes", new IntegerParameter("0"), "piecewiseLinear", true);
    for (CFEventList.Event cfEvent : acg.getCFEvents()) {
        double t = cfEvent.getHeight();
        assertTrue(Math.abs(t - skyline.getInverseIntensity(skyline.getIntensity(t))) < 1e-14);
    }
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) CFEventList(bacter.CFEventList) RealParameter(beast.core.parameter.RealParameter) Test(org.junit.Test)

Example 10 with IntegerParameter

use of beast.core.parameter.IntegerParameter in project bacter by tgvaughan.

the class SkylinePopulationFunctionTest method test2.

@Test
public void test2() throws Exception {
    SkylinePopulationFunction skyline = new SkylinePopulationFunction();
    skyline.initByName("acg", acg, "popSizes", new RealParameter("5.0 1.0 5.0 1.0"), "groupSizes", new IntegerParameter("0 0 0 0"));
    for (CFEventList.Event cfEvent : acg.getCFEvents()) {
        double t = cfEvent.getHeight();
        assertTrue(Math.abs(t - skyline.getInverseIntensity(skyline.getIntensity(t))) < 1e-14);
    }
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) CFEventList(bacter.CFEventList) RealParameter(beast.core.parameter.RealParameter) Test(org.junit.Test)

Aggregations

IntegerParameter (beast.core.parameter.IntegerParameter)31 RealParameter (beast.core.parameter.RealParameter)23 Test (org.junit.Test)13 State (beast.core.State)6 SCMigrationModel (beast.evolution.tree.SCMigrationModel)4 TypeSet (beast.evolution.tree.TypeSet)4 PrintStream (java.io.PrintStream)4 CFEventList (bacter.CFEventList)3 Function (beast.core.Function)3 MCMC (beast.core.MCMC)3 Operator (beast.core.Operator)3 StructuredCoalescentTreeDensity (multitypetree.distributions.StructuredCoalescentTreeDensity)3 MultiTypeTreeStatLogger (multitypetree.util.MultiTypeTreeStatLogger)3 ConversionGraph (bacter.ConversionGraph)2 BooleanParameter (beast.core.parameter.BooleanParameter)2 Alignment (beast.evolution.alignment.Alignment)2 DeltaExchangeOperator (beast.evolution.operators.DeltaExchangeOperator)2 MultiTypeTreeFromNewick (beast.evolution.tree.MultiTypeTreeFromNewick)2 BEASTObjectDialog (beast.app.draw.BEASTObjectDialog)1 InputEditor (beast.app.draw.InputEditor)1