Example usage for java.lang Double MIN_VALUE

List of usage examples for java.lang Double MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Double MIN_VALUE.

Prototype

double MIN_VALUE

To view the source code for java.lang Double MIN_VALUE.

Click Source Link

Document

A constant holding the smallest positive nonzero value of type double , 2-1074.

Usage

From source file:ai.susi.mind.SusiTransfer.java

/**
 * A conclusion from choices is done by the application of a function on the choice set.
 * This may be done by i.e. counting the number of choices or extracting a maximum element.
 * @param choices the given set of json objects from the data object of a SusiThought
 * @returnan array of json objects which are the extraction of given choices according to the given mapping
 *//* w w  w . ja v  a  2s  . c  om*/
public JSONArray conclude(JSONArray choices) {
    JSONArray a = new JSONArray();
    if (this.selectionMapping != null && this.selectionMapping.size() == 1) {
        // test if this has an aggregation key: AVG, COUNT, MAX, MIN, SUM
        final String aggregator = this.selectionMapping.keySet().iterator().next();
        final String aggregator_as = this.selectionMapping.get(aggregator);
        if (aggregator.startsWith("COUNT(") && aggregator.endsWith(")")) { // TODO: there should be a special pattern for this to make it more efficient
            return a.put(new JSONObject().put(aggregator_as, choices.length()));
        }
        if (aggregator.startsWith("MAX(") && aggregator.endsWith(")")) {
            final AtomicDouble max = new AtomicDouble(Double.MIN_VALUE);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> max.set(Math.max(max.get(), ((JSONObject) json).getDouble(c))));
            return a.put(new JSONObject().put(aggregator_as, max.get()));
        }
        if (aggregator.startsWith("MIN(") && aggregator.endsWith(")")) {
            final AtomicDouble min = new AtomicDouble(Double.MAX_VALUE);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> min.set(Math.min(min.get(), ((JSONObject) json).getDouble(c))));
            return a.put(new JSONObject().put(aggregator_as, min.get()));
        }
        if (aggregator.startsWith("SUM(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            return a.put(new JSONObject().put(aggregator_as, sum.get()));
        }
        if (aggregator.startsWith("AVG(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            return a.put(new JSONObject().put(aggregator_as, sum.get() / choices.length()));
        }
    }
    if (this.selectionMapping != null && this.selectionMapping.size() == 2) {
        Iterator<String> ci = this.selectionMapping.keySet().iterator();
        String aggregator = ci.next();
        String column = ci.next();
        if (column.indexOf('(') >= 0) {
            String s = aggregator;
            aggregator = column;
            column = s;
        }
        final String aggregator_as = this.selectionMapping.get(aggregator);
        final String column_as = this.selectionMapping.get(column);
        final String column_final = column;
        if (aggregator.startsWith("PERCENT(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(8, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            choices.forEach(json -> a.put(
                    new JSONObject().put(aggregator_as, 100.0d * ((JSONObject) json).getDouble(c) / sum.get())
                            .put(column_as, ((JSONObject) json).get(column_final))));
            return a;
        }
    }
    // this.selectionMapping == null -> extract everything
    for (Object json : choices) {
        JSONObject extraction = this.extract((JSONObject) json);
        if (extraction.length() > 0)
            a.put(extraction);
    }
    return a;
}

From source file:org.loklak.susi.SusiTransfer.java

/**
 * A conclusion from choices is done by the application of a function on the choice set.
 * This may be done by i.e. counting the number of choices or extracting a maximum element.
 * @param choices the given set of json objects from the data object of a SusiThought
 * @returnan array of json objects which are the extraction of given choices according to the given mapping
 *//*from   www  .ja  v  a  2s.c o  m*/
public JSONArray conclude(JSONArray choices) {
    JSONArray a = new JSONArray();
    if (this.selectionMapping != null && this.selectionMapping.size() == 1) {
        // test if this has an aggregation key: AVG, COUNT, MAX, MIN, SUM
        final String aggregator = this.selectionMapping.keySet().iterator().next();
        final String aggregator_as = this.selectionMapping.get(aggregator);
        if (aggregator.startsWith("COUNT(") && aggregator.endsWith(")")) { // TODO: there should be a special pattern for this to make it more efficient
            return a.put(new JSONObject().put(aggregator_as, choices.length()));
        }
        if (aggregator.startsWith("MAX(") && aggregator.endsWith(")")) {
            final AtomicDouble max = new AtomicDouble(Double.MIN_VALUE);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> max.set(Math.max(max.get(), ((JSONObject) json).getDouble(c))));
            return a.put(new JSONObject().put(aggregator_as, max.get()));
        }
        if (aggregator.startsWith("MIN(") && aggregator.endsWith(")")) {
            final AtomicDouble min = new AtomicDouble(Double.MAX_VALUE);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> min.set(Math.min(min.get(), ((JSONObject) json).getDouble(c))));
            return a.put(new JSONObject().put(aggregator_as, min.get()));
        }
        if (aggregator.startsWith("SUM(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            return a.put(new JSONObject().put(aggregator_as, sum.get()));
        }
        if (aggregator.startsWith("AVG(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(4, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            return a.put(new JSONObject().put(aggregator_as, sum.get() / choices.length()));
        }
    }
    if (this.selectionMapping != null && this.selectionMapping.size() == 2) {
        Iterator<String> ci = this.selectionMapping.keySet().iterator();
        String aggregator = ci.next();
        String column = ci.next();
        if (column.indexOf('(') >= 0) {
            String s = aggregator;
            aggregator = column;
            column = s;
        }
        final String aggregator_as = this.selectionMapping.get(aggregator);
        final String column_as = this.selectionMapping.get(column);
        final String column_final = column;
        if (aggregator.startsWith("PERCENT(") && aggregator.endsWith(")")) {
            final AtomicDouble sum = new AtomicDouble(0.0d);
            String c = aggregator.substring(8, aggregator.length() - 1);
            choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c)));
            choices.forEach(json -> a.put(
                    new JSONObject().put(aggregator_as, 100.0d * ((JSONObject) json).getDouble(c) / sum.get())
                            .put(column_as, ((JSONObject) json).get(column_final))));
            return a;
        }
    }
    for (Object json : choices) {
        JSONObject extraction = this.extract((JSONObject) json);
        if (extraction.length() > 0)
            a.put(extraction);
    }
    return a;
}

From source file:org.opensaas.jaudit.test.BeanTest.java

/**
 * Returns a new Map of default test class to test values types useful in
 * testing getters/setters.//from w  ww .ja v  a 2  s . co m
 * 
 * @return Map of supported types and associated values.
 */
protected static Map<Class<?>, Object[]> newClassToValues() {
    final Map<Class<?>, Object[]> ctov = new HashMap<Class<?>, Object[]>();

    ctov.put(Boolean.class, new Object[] { Boolean.TRUE, Boolean.FALSE, null });
    ctov.put(Boolean.TYPE, new Object[] { Boolean.TRUE, Boolean.FALSE });
    ctov.put(Date.class, new Object[] { new Date(), new Date(0L), new Date(1000L), null });
    ctov.put(Double.class, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE, null });
    ctov.put(Double.TYPE, new Object[] { 0d, Double.MAX_VALUE, Double.MIN_VALUE });
    ctov.put(Integer.class, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, null });
    ctov.put(Integer.TYPE, new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE });
    ctov.put(Long.class, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, null });
    ctov.put(Long.TYPE, new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE });
    ctov.put(String.class, new Object[] { "", " ", "Texas Fight!", UUID.randomUUID().toString(), null });

    return Collections.unmodifiableMap(ctov);
}

From source file:playground.johannes.snowball.Histogram.java

public int getMaxBin() {
    fillBins();//w ww  . jav a  2s.co  m
    double maxVal = Double.MIN_VALUE;
    int maxBin = -1;
    for (int i = 0; i < bins.size(); i++) {
        if (bins.get(i) > maxVal) {
            maxVal = bins.get(i);
            maxBin = i;
        }
    }

    return maxBin;
}

From source file:com.github.rvesse.airline.restrictions.factories.RangeRestrictionFactory.java

protected RangeRestriction createDoubleRange(Annotation annotation) {
    DoubleRange sRange = (DoubleRange) annotation;
    return new RangeRestriction(
            sRange.min() != Double.MIN_VALUE || !sRange.minInclusive() ? Double.valueOf(sRange.min()) : null,
            sRange.minInclusive(),//from   w w  w  . j  a v a2s. co m
            sRange.max() != Double.MAX_VALUE || !sRange.maxInclusive() ? Double.valueOf(sRange.max()) : null,
            sRange.maxInclusive(), DOUBLE_COMPARATOR);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithScatterPlot.java

public void addDataRedBlueHeatmap(double[] xValues, double[] yValues, double[] zValues, int numShades) {
    int numPoints = xValues.length;
    double minZ = Double.MAX_VALUE;
    double maxZ = Double.MIN_VALUE;
    for (double zValue : zValues) {
        if (zValue < minZ)
            minZ = zValue;/* w ww  .  j  a  va  2s . c  om*/
        if (zValue > maxZ)
            maxZ = zValue;
    }

    double zRange = maxZ - minZ;

    for (int j = 0; j < numShades; j++) {
        double minZValThisGroup = minZ + j * zRange / numShades;
        double maxZValThisGroup = minZ + (j + 1) * zRange / numShades;
        int red = (255 / numShades) * j;
        int blue = 255 - (255 / numShades) * j;
        Color color = new Color(blue, 10, red);

        java.util.List<Float> thisGroupX = new ArrayList<Float>();
        java.util.List<Float> thisGroupY = new ArrayList<Float>();

        for (int k = 0; k < numPoints; k++) {
            if (zValues[k] <= maxZValThisGroup && zValues[k] >= minZValThisGroup) {
                thisGroupX.add((float) xValues[k]);
                thisGroupY.add((float) yValues[k]);
                //if (Double.isNaN(xValues[k]) || Double.isInfinite(xValues[k]) ||
                //        Double.isNaN(yValues[k]) || Double.isInfinite(yValues[k]))System.err.println(xValues[k] + " , " + yValues[k]);
            }
        }
        addData(thisGroupX, thisGroupY, "" + minZValThisGroup);
        //            setSeriesColor(j, color);
        //                setPointSize(3);
    }

}

From source file:com.musicg.api.DetectionApi.java

protected void normalizeSpectrogramData(double[][] spectrogramData) {

    // normalization of absoultSpectrogram
    // set max and min amplitudes
    double maxAmp = Double.MIN_VALUE;
    double minAmp = Double.MAX_VALUE;
    for (int i = 0; i < spectrogramData.length; i++) {
        for (int j = 0; j < spectrogramData[i].length; j++) {
            if (spectrogramData[i][j] > maxAmp) {
                maxAmp = spectrogramData[i][j];
            } else if (spectrogramData[i][j] < minAmp) {
                minAmp = spectrogramData[i][j];
            }//from  w  w  w. j  a v a2 s.  c  o m
        }
    }
    // end set max and min amplitudes

    // normalization
    // avoiding divided by zero
    double minValidAmp = 0.00000000001F;
    if (minAmp == 0) {
        minAmp = minValidAmp;
    }

    double diff = Math.log10(maxAmp / minAmp); // perceptual difference
    for (int i = 0; i < spectrogramData.length; i++) {
        for (int j = 0; j < spectrogramData[i].length; j++) {
            if (spectrogramData[i][j] < minValidAmp) {
                spectrogramData[i][j] = 0;
            } else {
                spectrogramData[i][j] = (Math.log10(spectrogramData[i][j] / minAmp)) / diff;
            }
        }
    }
    // end normalization
}

From source file:au.org.ala.delta.intkey.ui.DefineButtonDialog.java

public DefineButtonDialog(Frame owner, boolean modal) {
    super(owner, modal);
    setPreferredSize(new Dimension(500, 430));

    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(DefineButtonDialog.class);
    resourceMap.injectFields(this);
    ActionMap actionMap = Application.getInstance().getContext().getActionMap(DefineButtonDialog.class, this);

    setTitle(title);//www. jav a  2 s  . c  om

    _okButtonPressed = false;

    _pnlButtons = new JPanel();
    getContentPane().add(_pnlButtons, BorderLayout.SOUTH);

    _btnOk = new JButton();
    _btnOk.setAction(actionMap.get("DefineButtonDialog_OK"));
    _pnlButtons.add(_btnOk);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("DefineButtonDialog_Cancel"));
    _pnlButtons.add(_btnCancel);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("DefineButtonDialog_Help"));
    _btnHelp.setEnabled(false);
    _pnlButtons.add(_btnHelp);

    _pnlMain = new JPanel();
    getContentPane().add(_pnlMain, BorderLayout.CENTER);
    _pnlMain.setLayout(new BorderLayout(5, 0));

    _pnlButtonProperties = new JPanel();
    _pnlButtonProperties.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(
            new EtchedBorder(EtchedBorder.LOWERED, null, null), new EmptyBorder(5, 5, 5, 5))));
    _pnlMain.add(_pnlButtonProperties, BorderLayout.NORTH);
    GridBagLayout gbl__pnlButtonProperties = new GridBagLayout();
    gbl__pnlButtonProperties.columnWidths = new int[] { 475, 0 };
    gbl__pnlButtonProperties.rowHeights = new int[] { 14, 23, 14, 20, 14, 20, 14, 0, 23, 23, 23, 23, 0 };
    gbl__pnlButtonProperties.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl__pnlButtonProperties.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, Double.MIN_VALUE };
    _pnlButtonProperties.setLayout(gbl__pnlButtonProperties);

    _lblEnterNameOf = new JLabel(enterFileNameCaption);
    _lblEnterNameOf.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc__lblEnterNameOf = new GridBagConstraints();
    gbc__lblEnterNameOf.anchor = GridBagConstraints.WEST;
    gbc__lblEnterNameOf.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterNameOf.gridx = 0;
    gbc__lblEnterNameOf.gridy = 0;
    _pnlButtonProperties.add(_lblEnterNameOf, gbc__lblEnterNameOf);

    _pnlFile = new JPanel();
    GridBagConstraints gbc__pnlFile = new GridBagConstraints();
    gbc__pnlFile.fill = GridBagConstraints.HORIZONTAL;
    gbc__pnlFile.insets = new Insets(0, 0, 5, 0);
    gbc__pnlFile.gridx = 0;
    gbc__pnlFile.gridy = 1;
    _pnlButtonProperties.add(_pnlFile, gbc__pnlFile);
    _pnlFile.setLayout(new BorderLayout(0, 0));

    _txtFldFileName = new JTextField();
    _pnlFile.add(_txtFldFileName, BorderLayout.CENTER);
    _txtFldFileName.setColumns(10);

    _btnBrowse = new JButton();
    _btnBrowse.setAction(actionMap.get("DefineButtonDialog_Browse"));
    _pnlFile.add(_btnBrowse, BorderLayout.EAST);

    _lblEnterTheCommands = new JLabel(enterCommandsCaption);
    _lblEnterTheCommands.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc__lblEnterTheCommands = new GridBagConstraints();
    gbc__lblEnterTheCommands.anchor = GridBagConstraints.WEST;
    gbc__lblEnterTheCommands.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterTheCommands.gridx = 0;
    gbc__lblEnterTheCommands.gridy = 2;
    _pnlButtonProperties.add(_lblEnterTheCommands, gbc__lblEnterTheCommands);

    _txtFldCommands = new JTextField();
    GridBagConstraints gbc__txtFldCommands = new GridBagConstraints();
    gbc__txtFldCommands.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldCommands.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldCommands.gridx = 0;
    gbc__txtFldCommands.gridy = 3;
    _pnlButtonProperties.add(_txtFldCommands, gbc__txtFldCommands);
    _txtFldCommands.setColumns(10);

    _lblEnterBriefHelp = new JLabel(enterBriefHelpCaption);
    _lblEnterBriefHelp.setAlignmentY(Component.TOP_ALIGNMENT);
    GridBagConstraints gbc__lblEnterBriefHelp = new GridBagConstraints();
    gbc__lblEnterBriefHelp.anchor = GridBagConstraints.NORTHWEST;
    gbc__lblEnterBriefHelp.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterBriefHelp.gridx = 0;
    gbc__lblEnterBriefHelp.gridy = 4;
    _pnlButtonProperties.add(_lblEnterBriefHelp, gbc__lblEnterBriefHelp);

    _txtFldBriefHelp = new JTextField();
    GridBagConstraints gbc__txtFldBriefHelp = new GridBagConstraints();
    gbc__txtFldBriefHelp.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldBriefHelp.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldBriefHelp.gridx = 0;
    gbc__txtFldBriefHelp.gridy = 5;
    _pnlButtonProperties.add(_txtFldBriefHelp, gbc__txtFldBriefHelp);
    _txtFldBriefHelp.setColumns(10);

    _lblEnterMoreDetailed = new JLabel(enterDetailedHelpCaption);
    GridBagConstraints gbc__lblEnterMoreDetailed = new GridBagConstraints();
    gbc__lblEnterMoreDetailed.anchor = GridBagConstraints.WEST;
    gbc__lblEnterMoreDetailed.insets = new Insets(0, 0, 5, 0);
    gbc__lblEnterMoreDetailed.gridx = 0;
    gbc__lblEnterMoreDetailed.gridy = 6;
    _pnlButtonProperties.add(_lblEnterMoreDetailed, gbc__lblEnterMoreDetailed);

    _txtFldDetailedHelp = new JTextField();
    GridBagConstraints gbc__txtFldDetailedHelp = new GridBagConstraints();
    gbc__txtFldDetailedHelp.insets = new Insets(0, 0, 5, 0);
    gbc__txtFldDetailedHelp.fill = GridBagConstraints.HORIZONTAL;
    gbc__txtFldDetailedHelp.gridx = 0;
    gbc__txtFldDetailedHelp.gridy = 7;
    _pnlButtonProperties.add(_txtFldDetailedHelp, gbc__txtFldDetailedHelp);
    _txtFldDetailedHelp.setColumns(10);

    _chckbxEnableOnlyIfUsedCharacters = new JCheckBox(enableOnlyIfUsedCaption);
    GridBagConstraints gbc__chckbxEnableOnlyIf = new GridBagConstraints();
    gbc__chckbxEnableOnlyIf.anchor = GridBagConstraints.WEST;
    gbc__chckbxEnableOnlyIf.insets = new Insets(0, 0, 5, 0);
    gbc__chckbxEnableOnlyIf.gridx = 0;
    gbc__chckbxEnableOnlyIf.gridy = 8;
    _pnlButtonProperties.add(_chckbxEnableOnlyIfUsedCharacters, gbc__chckbxEnableOnlyIf);

    _rdbtnEnableInAll = new JRadioButton(enableInAllModesCaption);
    GridBagConstraints gbc__rdbtnEnableInAll = new GridBagConstraints();
    gbc__rdbtnEnableInAll.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInAll.insets = new Insets(0, 0, 5, 0);
    gbc__rdbtnEnableInAll.gridx = 0;
    gbc__rdbtnEnableInAll.gridy = 9;
    _pnlButtonProperties.add(_rdbtnEnableInAll, gbc__rdbtnEnableInAll);

    _rdbtnEnableInNormal = new JRadioButton(enableInNormalModeCaption);
    GridBagConstraints gbc__rdbtnEnableInNormal = new GridBagConstraints();
    gbc__rdbtnEnableInNormal.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInNormal.insets = new Insets(0, 0, 5, 0);
    gbc__rdbtnEnableInNormal.gridx = 0;
    gbc__rdbtnEnableInNormal.gridy = 10;
    _pnlButtonProperties.add(_rdbtnEnableInNormal, gbc__rdbtnEnableInNormal);

    _rdbtnEnableInAdvanced = new JRadioButton(enableInAdvancedModeCaption);
    GridBagConstraints gbc__rdbtnEnableInAdvanced = new GridBagConstraints();
    gbc__rdbtnEnableInAdvanced.anchor = GridBagConstraints.WEST;
    gbc__rdbtnEnableInAdvanced.gridx = 0;
    gbc__rdbtnEnableInAdvanced.gridy = 11;
    _pnlButtonProperties.add(_rdbtnEnableInAdvanced, gbc__rdbtnEnableInAdvanced);

    _pnlSpaceRemoveAll = new JPanel();
    _pnlSpaceRemoveAll.setBorder(new EmptyBorder(0, 10, 0, 0));
    _pnlMain.add(_pnlSpaceRemoveAll, BorderLayout.SOUTH);
    _pnlSpaceRemoveAll.setLayout(new BoxLayout(_pnlSpaceRemoveAll, BoxLayout.Y_AXIS));

    _chckbxInsertASpace = new JCheckBox(insertSpaceCaption);
    _chckbxInsertASpace.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _insertSpace = !_insertSpace;

            if (_insertSpace) {
                _removeAllButtons = false;
                _chckbxRemoveAllButtons.setSelected(false);
            }

            updateButtonPropertyControls();
        }
    });
    _pnlSpaceRemoveAll.add(_chckbxInsertASpace);

    _chckbxRemoveAllButtons = new JCheckBox(removeAllCaption);
    _chckbxRemoveAllButtons.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _removeAllButtons = !_removeAllButtons;

            if (_removeAllButtons) {
                _insertSpace = false;
                _chckbxInsertASpace.setSelected(false);
            }

            updateButtonPropertyControls();
        }
    });
    _pnlSpaceRemoveAll.add(_chckbxRemoveAllButtons);

    _pnlButtonProperties.setEnabled(false);

    ButtonGroup btnGroup = new ButtonGroup();
    btnGroup.add(_rdbtnEnableInAll);
    btnGroup.add(_rdbtnEnableInNormal);
    btnGroup.add(_rdbtnEnableInAdvanced);

    _rdbtnEnableInAll.setSelected(true);
}

From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.NetworkLikelihoodFromGTT.java

protected double findOptimalBranchLength(final Network<Object> speciesNetwork,
        final Map<String, List<String>> species2alleles, final List distinctTrees, final List gtCorrespondence,
        final Set<String> singleAlleleSpecies) {
    boolean continueRounds = true; // keep trying to improve network
    for (NetNode<Object> node : speciesNetwork.dfs()) {
        for (NetNode<Object> parent : node.getParents()) {
            node.setParentDistance(parent, 1.0);
            if (node.isNetworkNode()) {
                node.setParentProbability(parent, 0.5);
            }/*from   ww w. j  ava2 s.c o  m*/
        }
    }

    Set<NetNode> node2ignoreForBL = findEdgeHavingNoBL(speciesNetwork, singleAlleleSpecies);
    double initalProb = computeProbabilityForCached(speciesNetwork, distinctTrees, species2alleles,
            gtCorrespondence);
    if (_printDetails)
        System.out.println(speciesNetwork.toString() + " : " + initalProb);

    final Container<Double> lnGtProbOfSpeciesNetwork = new Container<Double>(initalProb); // records the GTProb of the network at all times

    int roundIndex = 0;
    for (; roundIndex < _maxRounds && continueRounds; roundIndex++) {
        /*
        * Prepare a random ordering of network edge examinations each of which attempts to change a branch length or hybrid prob to improve the GTProb score.
        */
        double lnGtProbLastRound = lnGtProbOfSpeciesNetwork.getContents();
        List<Proc> assigmentActions = new ArrayList<Proc>(); // store adjustment commands here.  Will execute them one by one later.

        for (final NetNode<Object> parent : edu.rice.cs.bioinfo.programs.phylonet.structs.network.util.Networks
                .postTraversal(speciesNetwork)) {

            for (final NetNode<Object> child : parent.getChildren()) {
                if (node2ignoreForBL.contains(child)) {
                    continue;
                }

                assigmentActions.add(new Proc() {
                    public void execute() {

                        UnivariateFunction functionToOptimize = new UnivariateFunction() {
                            public double value(double suggestedBranchLength) {
                                double incumbentBranchLength = child.getParentDistance(parent);

                                child.setParentDistance(parent, suggestedBranchLength);

                                double lnProb = updateProbabilityForCached(speciesNetwork, distinctTrees,
                                        gtCorrespondence, child, parent);
                                //System.out.println(speciesNetwork + ": " + lnProb);
                                if (lnProb > lnGtProbOfSpeciesNetwork.getContents()) // did improve, keep change
                                {
                                    lnGtProbOfSpeciesNetwork.setContents(lnProb);

                                } else // didn't improve, roll back change
                                {
                                    child.setParentDistance(parent, incumbentBranchLength);
                                }
                                return lnProb;
                            }
                        };
                        BrentOptimizer optimizer = new BrentOptimizer(_Brent1, _Brent2); // very small numbers so we control when brent stops, not brent.

                        try {
                            optimizer.optimize(_maxTryPerBranch, functionToOptimize, GoalType.MAXIMIZE,
                                    Double.MIN_VALUE, _maxBranchLength);
                        } catch (TooManyEvaluationsException e) // _maxAssigmentAttemptsPerBranchParam exceeded
                        {
                        }

                        updateProbabilityForCached(speciesNetwork, distinctTrees, gtCorrespondence, child,
                                parent);
                        if (_printDetails)
                            System.out.println(
                                    speciesNetwork.toString() + " : " + lnGtProbOfSpeciesNetwork.getContents());

                    }
                });
            }
        }

        for (final NetNode<Object> child : speciesNetwork.getNetworkNodes()) // find every hybrid node
        {

            Iterator<NetNode<Object>> hybridParents = child.getParents().iterator();
            final NetNode hybridParent1 = hybridParents.next();
            final NetNode hybridParent2 = hybridParents.next();

            assigmentActions.add(new Proc() {
                public void execute() {
                    UnivariateFunction functionToOptimize = new UnivariateFunction() {
                        public double value(double suggestedProb) {
                            double incumbentHybridProbParent1 = child.getParentProbability(hybridParent1);

                            child.setParentProbability(hybridParent1, suggestedProb);
                            child.setParentProbability(hybridParent2, 1.0 - suggestedProb);

                            double lnProb = updateProbabilityForCached(speciesNetwork, distinctTrees,
                                    gtCorrespondence, child, null);
                            //System.out.println(speciesNetwork + ": " + lnProb);
                            if (lnProb > lnGtProbOfSpeciesNetwork.getContents()) // change improved GTProb, keep it
                            {

                                lnGtProbOfSpeciesNetwork.setContents(lnProb);
                            } else // change did not improve, roll back
                            {

                                child.setParentProbability(hybridParent1, incumbentHybridProbParent1);
                                child.setParentProbability(hybridParent2, 1.0 - incumbentHybridProbParent1);
                            }
                            return lnProb;
                        }
                    };
                    BrentOptimizer optimizer = new BrentOptimizer(_Brent1, _Brent2); // very small numbers so we control when brent stops, not brent.

                    try {
                        if (child.getName().equals("Y"))
                            optimizer.optimize(_maxTryPerBranch, functionToOptimize, GoalType.MAXIMIZE, 0.6,
                                    0.8);
                        else
                            optimizer.optimize(_maxTryPerBranch, functionToOptimize, GoalType.MAXIMIZE, 0, 1.0);
                    } catch (TooManyEvaluationsException e) // _maxAssigmentAttemptsPerBranchParam exceeded
                    {
                    }
                    updateProbabilityForCached(speciesNetwork, distinctTrees, gtCorrespondence, child, null);
                    if (_printDetails)
                        System.out.println(
                                speciesNetwork.toString() + " : " + lnGtProbOfSpeciesNetwork.getContents());
                }
            });

        }

        // add hybrid probs to hybrid edges
        Collections.shuffle(assigmentActions);

        for (Proc assigment : assigmentActions) // for each change attempt, perform attempt
        {
            assigment.execute();
        }
        if (_printDetails) {
            System.out.println("Round end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            System.out
                    .println(speciesNetwork.toString() + "\n" + lnGtProbOfSpeciesNetwork.getContents() + "\n");
        }
        if (((double) lnGtProbOfSpeciesNetwork.getContents()) == lnGtProbLastRound) // if no improvement was made wrt to last around, stop trying to find a better assignment
        {
            continueRounds = false;
        } else if (lnGtProbOfSpeciesNetwork.getContents() > lnGtProbLastRound) // improvement was made, ensure it is large enough wrt to improvement threshold to continue searching
        {

            double improvementPercentage = Math.pow(Math.E,
                    (lnGtProbOfSpeciesNetwork.getContents() - lnGtProbLastRound)) - 1.0; // how much did we improve over last round
            if (improvementPercentage < _improvementThreshold) // improved, but not enough to keep searching
            {
                continueRounds = false;
            }
        } else {
            throw new IllegalStateException("Should never have decreased prob.");
        }
    }
    //System.out.println("\n" + lnGtProbOfSpeciesNetwork.getContents() + ": " + speciesNetwork);
    return lnGtProbOfSpeciesNetwork.getContents();
}

From source file:edu.txstate.dmlab.clusteringwiki.cluster.KMeansClusterer.java

/**
 * Cluster a set of documentsToCluster provided as an array of indexes within the
 * term document matrix/*from w w w  . j  av a 2s  .c o m*/
 * @param docs
 * @return
 */
public List<ICluster> levelCluster(ICluster parent, int[] docs) {
    if (docs == null) { //cluster all docs
        return levelCluster(parent);
    }
    documentsToCluster = docs;

    setNumClusters();
    //choose initial cluster seeds
    String parentId = parent.getId();
    List<IClusterDocument> seeds = chooseSeeds(parentId);
    //create clusters and assign initial centroids/seeds
    List<ICluster> clusters = new ArrayList<ICluster>();
    for (int i = 0; i < numClusters; i++) {
        KMeansCluster cluster = new KMeansCluster(getNextClusterId(), context, parent);
        clusters.add(cluster);
    }
    //initial cluster assignments
    int numDocs = docs.length;
    int bestCluster;
    int currentCluster;
    double similarity;
    double maxSimilarity;
    // For every document d, find the cluster j whose centroid is 
    // most similar, assign d to cluster j.
    for (int i = 0; i < numDocs; i++) {
        bestCluster = 0;
        maxSimilarity = Double.MIN_VALUE;
        IClusterDocument d = allDocs.get(docs[i]);
        for (int j = 0; j < numClusters; j++) {
            similarity = seeds.get(j).computeSimilarity(d);
            if (Double.compare(similarity, maxSimilarity) > 0) {
                bestCluster = j;
                maxSimilarity = similarity;
            }
        }
        for (ICluster cluster : clusters)
            cluster.removeDocument(docs[i]);
        clusters.get(bestCluster).addDocument(docs[i]);
    }

    // Repeat until termination conditions are satisfied
    int iteration = 0;
    for (;;) {
        // For every cluster, re-compute the centroid based on the
        // current member documentsToCluster.
        for (int j = 0; j < numClusters; j++) {
            ((KMeansCluster) clusters.get(j)).computeCentroid();
        }
        // For every document d, find the cluster i whose centroid is 
        // most similar, assign d to cluster i. (If a document is 
        // equally similar from all centroids, then just dump it into 
        // cluster 0).
        int numChanged = 0;
        for (int i = 0; i < numDocs; i++) {
            bestCluster = 0;
            currentCluster = -1;
            maxSimilarity = Double.MIN_VALUE;
            IClusterDocument d = allDocs.get(docs[i]);
            for (int j = 0; j < numClusters; j++) {
                similarity = ((KMeansCluster) clusters.get(j)).getSimilarity(d);
                if (Double.compare(similarity, maxSimilarity) > 0) {
                    bestCluster = j;
                    maxSimilarity = similarity;
                }
                if (clusters.get(j).contains(docs[i]))
                    currentCluster = j;
            }
            //if another cluster is better
            if (bestCluster != currentCluster) {
                clusters.get(currentCluster).removeDocument(docs[i]);
                clusters.get(bestCluster).addDocument(docs[i]);
                numChanged++;
            }
        }
        iteration++;
        if (iteration > maxIterations || numChanged == 0)
            break;
    }

    //set cluster labels
    for (int j = 0; j < numClusters; j++) {
        ICluster c = clusters.get(j);
        c.deduceLabel();
        if (c.getLabel().equals("") && c.getDocuments() == null) {
            //if empty cluster, trim
            clusters.remove(j);
            j--;
            numClusters--;
        }
    }

    return clusters;

}