use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class LinearInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
for (int i = 0; i < m_numMissing; i++) {
DataCell res;
if (m_previous.isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
if (m_previous instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (m_previous instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
m_values.add(res);
}
m_numMissing = 0;
m_previous = cell;
}
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class RoundDoubleCellFactory method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
DataCell[] newCells = new DataCell[m_colIndexToRound.length];
int noCols = row.getNumCells();
int nextIndexToRound = 0;
int currIndexToRound = -1;
// walk through all columns and round if specified
for (int i = 0; i < noCols; i++) {
// are available).
if (nextIndexToRound < m_colIndexToRound.length) {
currIndexToRound = m_colIndexToRound[nextIndexToRound];
}
// if value needs to be rounded
if (i == currIndexToRound) {
final DataCell outCell;
if (row.getCell(i).isMissing()) {
outCell = DataType.getMissingCell();
} else {
double value = ((DoubleValue) row.getCell(i)).getDoubleValue();
// check for infinity or nan
if (Double.isInfinite(value) || Double.isNaN(value)) {
switch(m_outputType) {
case Double:
// this isn't nice as we shouldn't have NaN and Inf in the input ...
// but that's a problem somewhere else
outCell = new DoubleCell(value);
break;
default:
outCell = new StringCell(new Double(value).toString());
}
} else {
// do not use constructor, see AP-7016
BigDecimal bd = BigDecimal.valueOf(value).stripTrailingZeros();
switch(m_numberMode) {
case DECIMAL_PLACES:
bd = bd.setScale(m_precision, m_roundingMode);
break;
case SIGNIFICANT_FIGURES:
bd = bd.round(new MathContext(m_precision, m_roundingMode));
break;
default:
throw new IllegalStateException();
}
outCell = m_outputType.createCell(bd);
}
}
// increment index of included column indices
newCells[nextIndexToRound++] = outCell;
}
}
return newCells;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class PMCCPortObjectAndSpec method createCorrelationMatrix.
private DataTable createCorrelationMatrix(final DataContainer cont, final ExecutionMonitor mon) throws CanceledExecutionException {
if (!hasData()) {
throw new IllegalStateException("No data available");
}
final int l = m_colNames.length;
for (int i = 0; i < l; i++) {
RowKey key = new RowKey(m_colNames[i]);
DataCell[] cells = new DataCell[l];
for (int j = 0; j < l; j++) {
if (i == j) {
cells[i] = MAX_VALUE_CELL;
} else {
double corr = m_correlations.get(i, j);
if (Double.isNaN(corr)) {
cells[j] = DataType.getMissingCell();
} else {
cells[j] = new DoubleCell(corr);
}
}
}
mon.checkCanceled();
cont.addRowToTable(new DefaultRow(key, cells));
mon.setProgress(i / (double) l, "Added row " + i);
}
cont.close();
return cont.getTable();
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class DomainDialog method takeOverSettings.
/**
* @return an object with domain values set by the user. Or <code>null</code> if settings are invalid. Then, a error
* message box is displayed.
*/
private ColProperty takeOverSettings() {
ColProperty result = new ColProperty();
if (m_colProp.getColumnSpec().getType().isCompatible(StringValue.class)) {
DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), m_colProp.getColumnSpec().getType());
if (m_containsVals != null) {
result.setReadPossibleValuesFromFile(m_containsVals.isSelected());
}
if ((m_containsVals == null) || m_containsVals.isSelected()) {
// if it's null we have a string column
Set<DataCell> pVals = null;
// tranfser possible values
int valCount = m_valueList.getModel().getSize();
pVals = new LinkedHashSet<DataCell>();
for (int i = 0; i < valCount; i++) {
DataCell val = (DataCell) m_valueList.getModel().getElementAt(i);
pVals.add(val);
}
if (pVals.size() > 0) {
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(pVals);
dcsc.setDomain(domainCreator.createDomain());
}
}
result.setColumnSpec(dcsc.createSpec());
} else {
DataType type = m_colProp.getColumnSpec().getType();
DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), type);
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
if (type.equals(IntCell.TYPE)) {
domainCreator.setLowerBound(new IntCell((int) m_lowerBoundField.getValue()));
domainCreator.setUpperBound(new IntCell((int) m_upperBoundField.getValue()));
} else if (type.equals(DoubleCell.TYPE)) {
domainCreator.setLowerBound(new DoubleCell((double) m_lowerBoundField.getValue()));
domainCreator.setUpperBound(new DoubleCell((double) m_upperBoundField.getValue()));
}
dcsc.setDomain(domainCreator.createDomain());
result.setColumnSpec(dcsc.createSpec());
}
return result;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class NumericalAttributeModel method createDataRows.
/**
* {@inheritDoc}
*/
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
if (sortedClassVal == null) {
return;
}
final StringCell attributeCell = new StringCell(getAttributeName());
for (final String classVal : sortedClassVal) {
final List<DataCell> cells = new LinkedList<>();
cells.add(attributeCell);
cells.add(DataType.getMissingCell());
cells.add(new StringCell(classVal));
final NumericalClassValue classValue = m_classValues.get(classVal);
cells.add(new IntCell(classValue.getNoOfNotMissingRows()));
if (!ignoreMissing) {
cells.add(new IntCell(classValue.getNoOfMissingValueRecs()));
}
cells.add(new DoubleCell(classValue.getMean()));
cells.add(new DoubleCell(classValue.getStdDeviation()));
dc.addRowToTable(new DefaultRow(RowKey.createRowKey(rowId.getAndIncrement()), cells.toArray(new DataCell[0])));
}
}
Aggregations