Search in sources :

Example 1 with DoubleCell

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

the class RuleSetToTable method createRow.

/**
 * Creates a row, {@link DataCell} values based on {@code rule} and the other parameters.
 *
 * @param rule A PMML {@link Rule}.
 * @param outcomeType The expected outcome.
 * @param types The types of the input column.
 * @return The cells for the {@code rule}.
 */
private DataCell[] createRow(final Rule rule, final DataType outcomeType, final Map<String, DataType> types, final List<String> scoreValues) {
    List<DataCell> ret = new ArrayList<>();
    boolean usePrecedence = !m_settings.getAdditionalParentheses().getBooleanValue();
    if (m_settings.getSplitRules().getBooleanValue()) {
        ret.add(new StringCell(convertToString(rule.getCondition(), usePrecedence, types)));
        ret.add(convertToExpectedType(rule.getOutcome(), outcomeType));
    } else {
        ret.add(new StringCell(convertToString(rule.getCondition(), usePrecedence, types) + " => " + toString(convertToExpectedType(rule.getOutcome(), outcomeType))));
    }
    if (m_settings.getConfidenceAndWeight().getBooleanValue()) {
        ret.add(toCell(rule.getConfidence()));
        ret.add(toCell(rule.getWeight()));
    }
    if (m_settings.getProvideStatistics().getBooleanValue()) {
        ret.add(toCell(rule.getRecordCount()));
        ret.add(toCell(rule.getNbCorrect()));
    }
    final Map<String, ScoreProbabilityAndRecordCount> scoreDistribution = rule.getScoreDistribution();
    if (m_settings.getScoreTableRecordCount().isEnabled() && m_settings.getScoreTableRecordCount().getBooleanValue()) {
        for (final String value : scoreValues) {
            if (scoreDistribution.containsKey(value)) {
                ret.add(new DoubleCell(scoreDistribution.get(value).getRecordCount()));
            } else {
                ret.add(DataType.getMissingCell());
            }
        }
    }
    if (m_settings.getScoreTableProbability().isEnabled() && m_settings.getScoreTableProbability().getBooleanValue()) {
        for (final String value : scoreValues) {
            if (scoreDistribution.containsKey(value)) {
                final BigDecimal probability = scoreDistribution.get(value).getProbability();
                ret.add(probability == null ? DataType.getMissingCell() : new DoubleCell(probability.doubleValue()));
            } else {
                ret.add(DataType.getMissingCell());
            }
        }
    }
    return ret.toArray(new DataCell[ret.size()]);
}
Also used : StringCell(org.knime.core.data.def.StringCell) ScoreProbabilityAndRecordCount(org.knime.base.node.rules.engine.pmml.PMMLRuleTranslator.ScoreProbabilityAndRecordCount) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) BigDecimal(java.math.BigDecimal)

Example 2 with DoubleCell

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

the class TimeDifferenceNodeModel method getRoundedTimeDifference.

/**
 * @param first the older time
 * @param last the newer time
 * @param g the granularity
 * @return a double cell containing the time difference between the first
 * and the last, already granulated and rounded.
 */
private DoubleCell getRoundedTimeDifference(final long first, final long last, final Granularity g) {
    double diffTime = (last - first) / g.getFactor();
    BigDecimal bd = new BigDecimal(diffTime);
    bd = bd.setScale(m_rounding.getIntValue(), BigDecimal.ROUND_CEILING);
    return new DoubleCell(bd.doubleValue());
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) BigDecimal(java.math.BigDecimal)

Example 3 with DoubleCell

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

the class TSAverageHandler method getMean.

private DataCell getMean() {
    if (m_previous instanceof IntValue) {
        // get an int, create an int
        double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
        return new IntCell((int) Math.round(mean));
    }
    if (m_previous instanceof LongValue) {
        // get an int, create an int
        double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
        return new LongCell(Math.round(mean));
    }
    if (m_previous instanceof DoubleValue) {
        // get an double, create an double
        double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
        return new DoubleCell(mean);
    }
    if (m_previous instanceof DateAndTimeValue) {
        // get an int, create an int
        DateAndTimeValue dataCell1 = (DateAndTimeValue) m_previous;
        DateAndTimeValue dataCell2 = ((DateAndTimeValue) m_next);
        boolean hasDate = dataCell1.hasDate() | dataCell2.hasDate();
        boolean hasTime = dataCell1.hasTime() | dataCell2.hasTime();
        boolean hasMilis = dataCell1.hasMillis() | dataCell2.hasMillis();
        double d = dataCell1.getUTCTimeInMillis() + dataCell2.getUTCTimeInMillis();
        d *= 0.5;
        return new DateAndTimeCell((long) d, hasDate, hasTime, hasMilis);
    }
    return DataType.getMissingCell();
}
Also used : LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) LongValue(org.knime.core.data.LongValue) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue) IntCell(org.knime.core.data.def.IntCell)

Example 4 with DoubleCell

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

the class TSLinearHandler method getLinearInterpolation.

private DataCell getLinearInterpolation(final double stepnumber, final double stepcount) {
    if (m_previous instanceof DoubleValue || m_previous instanceof IntValue || m_previous instanceof LongValue) {
        double prev = ((DoubleValue) m_previous).getDoubleValue();
        double next = ((DoubleValue) m_next).getDoubleValue();
        double lin = prev + 1.0 * stepnumber / (1.0 * stepcount) * (next - prev);
        if (m_previous instanceof IntValue) {
            // get an int, create an int
            return new IntCell((int) Math.round(lin));
        }
        if (m_previous instanceof LongValue) {
            // get an long, create an long
            return new LongCell(Math.round(lin));
        }
        return new DoubleCell(lin);
    }
    if (m_previous instanceof DateAndTimeValue) {
        // get an int, create an int
        DateAndTimeValue dataCell1 = (DateAndTimeValue) m_previous;
        DateAndTimeValue dataCell2 = ((DateAndTimeValue) m_next);
        boolean hasDate = dataCell1.hasDate() | dataCell2.hasDate();
        boolean hasTime = dataCell1.hasTime() | dataCell2.hasTime();
        boolean hasMilis = dataCell1.hasMillis() | dataCell2.hasMillis();
        double prev = dataCell1.getUTCTimeInMillis();
        double next = dataCell2.getUTCTimeInMillis();
        double d = prev + stepnumber / stepcount * (next - prev);
        return new DateAndTimeCell((long) d, hasDate, hasTime, hasMilis);
    }
    return DataType.getMissingCell();
}
Also used : LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) LongValue(org.knime.core.data.LongValue) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue) IntCell(org.knime.core.data.def.IntCell)

Example 5 with DoubleCell

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

the class StringManipulationVariableNodeModel method calculate.

/**
 * @throws CompilationFailedException
 * @throws InstantiationException
 * @throws Exception
 */
private void calculate() throws InvalidSettingsException, CompilationFailedException, InstantiationException {
    if (m_settings == null || m_settings.getExpression() == null) {
        throw new InvalidSettingsException("No expression has been set.");
    }
    JavaScriptingSettings settings = m_settings.createJavaScriptingSettings();
    settings.setInputAndCompile(new DataTableSpec());
    // calculate the result
    ColumnCalculator cc = new ColumnCalculator(settings, this);
    DataCell calculate = null;
    try {
        calculate = cc.calculate(new DefaultRow(new RowKey(""), new DataCell[] {}));
    } catch (NoSuchElementException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    String newVariableName;
    Map<String, FlowVariable> inputFlowVariables = getAvailableInputFlowVariables();
    if (m_settings.isReplace()) {
        newVariableName = m_settings.getColName();
        CheckUtils.checkSettingNotNull(inputFlowVariables.get(newVariableName), "Can't replace input variable '%s' -- it does not exist in the input", newVariableName);
    } else {
        newVariableName = new UniqueNameGenerator(inputFlowVariables.keySet()).newName(m_settings.getColName());
    }
    // convert and push result as flow variable
    CheckUtils.checkSetting(!calculate.isMissing(), "Calculation returned missing value");
    Class<? extends DataCell> cellType = calculate.getClass();
    if (cellType.equals(IntCell.class)) {
        pushFlowVariableInt(newVariableName, ((IntCell) calculate).getIntValue());
    } else if (cellType.equals(DoubleCell.class)) {
        pushFlowVariableDouble(newVariableName, ((DoubleCell) calculate).getDoubleValue());
    } else if (cellType.equals(StringCell.class)) {
        pushFlowVariableString(newVariableName, ((StringCell) calculate).getStringValue());
    } else {
        throw new RuntimeException("Invalid variable class: " + cellType);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColumnCalculator(org.knime.ext.sun.nodes.script.calculator.ColumnCalculator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

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