Search in sources :

Example 91 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class MeanAbsoluteDeviationOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    final double[] cells = super.getCells().getElements();
    if (cells.length == 0) {
        return DataType.getMissingCell();
    }
    final Mean mean = new Mean();
    double meanValue = mean.evaluate(cells);
    for (int i = 0; i < cells.length; i++) {
        cells[i] = Math.abs(meanValue - cells[i]);
    }
    meanValue = mean.evaluate(cells);
    return new DoubleCell(meanValue);
}
Also used : Mean(org.apache.commons.math3.stat.descriptive.moment.Mean) DoubleCell(org.knime.core.data.def.DoubleCell)

Example 92 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class QuantileOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    final double[] cells = super.getCells().getElements();
    if (cells.length == 0) {
        return DataType.getMissingCell();
    }
    double quantile = m_settings.getFunctionModel().getDoubleValue();
    EstimationType estType = Percentile.EstimationType.valueOf(m_settings.getEstimationModel().getStringValue());
    double evaluate = estType.evaluate(cells, quantile * 100, new KthSelector());
    return new DoubleCell(evaluate);
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) KthSelector(org.apache.commons.math3.util.KthSelector) EstimationType(org.apache.commons.math3.stat.descriptive.rank.Percentile.EstimationType)

Example 93 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class ExpressionFactoryTest method testColumnRef.

/**
 * Test method for {@link ExpressionFactory#columnRef(DataTableSpec, java.lang.String)} .
 */
@Test
public void testColumnRef() {
    final DefaultRow row0 = new DefaultRow(new RowKey("0"), new IntCell(3));
    final DefaultRow row1 = new DefaultRow(new RowKey("1"), new IntCell(3), new DoubleCell(3.14159));
    final DefaultRow row2 = new DefaultRow(new RowKey("1"), new DoubleCell(3.14159), new StringCell("Hi"));
    final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
    assertEquals(row0.getCell(0), firstVal.getValue());
    assertEquals(row1.getCell(0), m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Num").evaluate(row0, null).getValue());
    final ExpressionValue secondVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Pi").evaluate(row1, null);
    assertEquals(row1.getCell(1), secondVal.getValue());
    final ExpressionValue thirdVal = m_factory.columnRef(new DataTableSpec(new String[] { "Pi", "Greeting" }, new DataType[] { DoubleCell.TYPE, StringCell.TYPE }), "Greeting").evaluate(row2, null);
    assertEquals(row2.getCell(1), thirdVal.getValue());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Example 94 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class MissingValuePanel method getSettings.

/**
 * Get the settings currently entered in the dialog.
 *
 * @return the current settings
 */
public ColSetting getSettings() {
    int method;
    if (m_nothingButton.isSelected()) {
        method = ColSetting.METHOD_NO_HANDLING;
    } else if (m_removeButton.isSelected()) {
        method = ColSetting.METHOD_IGNORE_ROWS;
    } else if (m_fixButton != null && m_fixButton.isSelected()) {
        method = ColSetting.METHOD_FIX_VAL;
        DataCell cell;
        switch(m_setting.getType()) {
            case ColSetting.TYPE_INT:
                Object value = ((JFormattedTextField) m_fixText).getValue();
                cell = new IntCell(((Number) value).intValue());
                break;
            case ColSetting.TYPE_DOUBLE:
                value = ((JFormattedTextField) m_fixText).getValue();
                cell = new DoubleCell(((Number) value).doubleValue());
                break;
            case ColSetting.TYPE_STRING:
                value = ((JComboBox) m_fixText).getEditor().getItem();
                cell = new StringCell(value.toString());
                break;
            default:
                throw new RuntimeException("You shouldn't have come here.");
        }
        m_setting.setFixCell(cell);
    } else if (m_maxButton != null && m_maxButton.isSelected()) {
        method = ColSetting.METHOD_MAX;
    } else if (m_minButton != null && m_minButton.isSelected()) {
        method = ColSetting.METHOD_MIN;
    } else if (m_meanButton != null && m_meanButton.isSelected()) {
        method = ColSetting.METHOD_MEAN;
    } else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
        method = ColSetting.METHOD_MOST_FREQUENT;
    } else {
        assert false : "One button must be selected.";
        method = ColSetting.METHOD_NO_HANDLING;
    }
    m_setting.setMethod(method);
    return m_setting;
}
Also used : JComboBox(javax.swing.JComboBox) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) JFormattedTextField(javax.swing.JFormattedTextField) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 95 with DoubleCell

use of org.knime.core.data.def.DoubleCell in project knime-core by knime.

the class Rule2DPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
protected void updatePaintModel() {
    super.updatePaintModel();
    if (m_rules != null) {
        Rule2DDrawingPane drawingPane = getDrawingPane();
        drawingPane.setOriginalRuleTable(m_rules);
        String xName = getXColName();
        String yName = getYColName();
        int xIdx = -1;
        int yIdx = -1;
        if (xName != null && yName != null) {
            xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
            yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
        }
        if (xIdx >= 0 && yIdx >= 0) {
            Coordinate x = getColHeader().getCoordinate();
            Coordinate y = getRowHeader().getCoordinate();
            // check if the coordinates are valid
            if (x == null || y == null) {
                return;
            }
            // calculate the coordinates of the rules here
            // List<DataRow> rows = new ArrayList<DataRow>();
            DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col1 = creator.createSpec();
            creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col2 = creator.createSpec();
            DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
            DataContainer rows = new DataContainer(spec);
            for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
                DataRow currRow = itr.next();
                DataCell[] newCells = new DataCell[2];
                for (int cell = 0; cell < currRow.getNumCells(); cell++) {
                    // if (!m_rules.getDataTableSpec().getColumnSpec(cell)
                    // .getType().isCompatible(
                    // FuzzyIntervalValue.class)) {
                    // continue;
                    // }
                    Rectangle rect = calculateDrawingRectangle();
                    double a;
                    double b;
                    double c;
                    double d;
                    if (cell == xIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            // normalize xValues
                            a = getXmin();
                            b = getXmin();
                            c = getXmax();
                            d = getXmax();
                        } else {
                            // normalize xValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
                        double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
                        double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
                        double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
                        newCells[0] = newInterval;
                    }
                    if (cell == yIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            a = getYmin();
                            b = getYmin();
                            c = getYmax();
                            d = getYmax();
                        } else {
                            // normalize yValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
                        double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
                        double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
                        double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
                        newCells[1] = newInterval;
                    }
                }
                // create new row out of the normalized cells
                rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
            }
            rows.close();
            drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
        }
        super.updatePaintModel();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) FuzzyIntervalCell(org.knime.core.data.def.FuzzyIntervalCell) DataContainer(org.knime.core.data.container.DataContainer) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

DoubleCell (org.knime.core.data.def.DoubleCell)189 DataCell (org.knime.core.data.DataCell)129 IntCell (org.knime.core.data.def.IntCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)66 StringCell (org.knime.core.data.def.StringCell)65 DataRow (org.knime.core.data.DataRow)57 DataTableSpec (org.knime.core.data.DataTableSpec)55 ArrayList (java.util.ArrayList)42 DataColumnSpec (org.knime.core.data.DataColumnSpec)42 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)41 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)39 RowKey (org.knime.core.data.RowKey)37 DoubleValue (org.knime.core.data.DoubleValue)35 BufferedDataTable (org.knime.core.node.BufferedDataTable)28 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)22 DataType (org.knime.core.data.DataType)20 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 Point (java.awt.Point)12