use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class AbstractHistogramPlotter method updateBinWidth.
/**
* Updates ONLY the width of the bins.
* @param binWidth the new bin width
*/
protected void updateBinWidth(final int binWidth) {
final AbstractHistogramVizModel vizModel = getHistogramVizModel();
if (vizModel == null) {
LOGGER.debug("VizModel was null");
return;
}
if (!vizModel.setBinWidth(binWidth)) {
return;
}
final Dimension drawingSpace = vizModel.getDrawingSpace();
if (drawingSpace == null) {
throw new IllegalStateException("Drawing space must not be null");
}
final double drawingWidth = drawingSpace.getWidth();
final double drawingHeight = drawingSpace.getHeight();
final Coordinate xCoordinates = getXCoordinate();
final Coordinate aggrCoordinate = getAggregationCoordinate();
final int baseLine = (int) (drawingHeight - aggrCoordinate.calculateMappedValue(new DoubleCell(0), drawingHeight));
final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
final int newBinWidth = vizModel.getBinWidth();
final List<Color> barElementColors = vizModel.getRowColors();
final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
for (final BinDataModel bin : vizModel.getBins()) {
final DataCell captionCell = bin.getXAxisCaptionCell();
final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
// subtract half of the bar width from the start position to place
// the middle point of the bar on the mapped coordinate position
final int xCoord = (int) (labelCoord - (newBinWidth / 2.0));
bin.updateBinWidth(xCoord, newBinWidth, barElementColors, aggrColumns, baseLine, calculator);
}
// if only the bar width changes we don't need to update the properties
// since the bar width change is triggered by the property component
// itself
drawingPane.setHistogramVizModel(vizModel, false);
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class BoxPlotter method updateOutliers.
/**
* Sets the outliers as dotinfo to the scatterplotter drawing pane to
* make them selectable and hilite-able.
* @param yCoordinate the corresponding y coordinate.
* @param box the box (column).
* @return the mapped outliers for this column.
*/
protected List<DotInfo> updateOutliers(final Coordinate yCoordinate, final Box box) {
int height = getDrawingPaneDimension().height - OFFSET;
List<DotInfo> dotList = new ArrayList<DotInfo>();
int x = box.getX();
String colName = box.getColumnName();
// the mild outliers
Map<Double, Set<RowKey>> mildOutliers = ((BoxPlotDataProvider) getDataProvider()).getMildOutliers().get(colName);
for (Map.Entry<Double, Set<RowKey>> entry : mildOutliers.entrySet()) {
double value = entry.getKey();
for (RowKey key : entry.getValue()) {
int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
dot.setXDomainValue(new StringCell(colName));
dot.setYDomainValue(new DoubleCell(value));
dot.setShape(ShapeFactory.getShape(ShapeFactory.CIRCLE));
dotList.add(dot);
}
}
// the extreme outliers
Map<Double, Set<RowKey>> extremeOutliers = ((BoxPlotDataProvider) getDataProvider()).getExtremeOutliers().get(colName);
for (Map.Entry<Double, Set<RowKey>> entry : extremeOutliers.entrySet()) {
double value = entry.getKey();
for (RowKey key : entry.getValue()) {
int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
dot.setShape(ShapeFactory.getShape(ShapeFactory.CROSS));
dot.setXDomainValue(new StringCell(colName));
dot.setYDomainValue(new DoubleCell(value));
dotList.add(dot);
}
}
return dotList;
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class Normalizer3NodeModel method calculate.
/**
* New normalized {@link org.knime.core.data.DataTable} is created depending on the mode.
*/
/**
* @param inData The input data.
* @param exec For BufferedDataTable creation and progress.
* @return the result of the calculation
* @throws Exception If the node calculation fails for any reason.
*/
protected CalculationResult calculate(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable inTable = (BufferedDataTable) inData[0];
DataTableSpec inSpec = inTable.getSpec();
// extract selected numeric columns
String[] includedColumns = getIncludedComlumns(inSpec);
Normalizer2 ntable = new Normalizer2(inTable, includedColumns);
long rowcount = inTable.size();
ExecutionContext prepareExec = exec.createSubExecutionContext(0.3);
AffineTransTable outTable;
boolean fixDomainBounds = false;
switch(m_config.getMode()) {
case MINMAX:
fixDomainBounds = true;
outTable = ntable.doMinMaxNorm(m_config.getMax(), m_config.getMin(), prepareExec);
break;
case Z_SCORE:
outTable = ntable.doZScoreNorm(prepareExec);
break;
case DECIMALSCALING:
outTable = ntable.doDecimalScaling(prepareExec);
break;
default:
throw new InvalidSettingsException("No mode set");
}
if (outTable.getErrorMessage() != null) {
// something went wrong, report and throw an exception
throw new Exception(outTable.getErrorMessage());
}
if (ntable.getErrorMessage() != null) {
// something went wrong during initialization, report.
setWarningMessage(ntable.getErrorMessage());
}
DataTableSpec modelSpec = FilterColumnTable.createFilterTableSpec(inSpec, includedColumns);
AffineTransConfiguration configuration = outTable.getConfiguration();
DataTableSpec spec = outTable.getDataTableSpec();
// the same transformation, which is not guaranteed to snap to min/max)
if (fixDomainBounds) {
DataColumnSpec[] newColSpecs = new DataColumnSpec[spec.getNumColumns()];
for (int i = 0; i < newColSpecs.length; i++) {
newColSpecs[i] = spec.getColumnSpec(i);
}
for (int i = 0; i < includedColumns.length; i++) {
int index = spec.findColumnIndex(includedColumns[i]);
DataColumnSpecCreator creator = new DataColumnSpecCreator(newColSpecs[index]);
DataColumnDomainCreator domCreator = new DataColumnDomainCreator(newColSpecs[index].getDomain());
domCreator.setLowerBound(new DoubleCell(m_config.getMin()));
domCreator.setUpperBound(new DoubleCell(m_config.getMax()));
creator.setDomain(domCreator.createDomain());
newColSpecs[index] = creator.createSpec();
}
spec = new DataTableSpec(spec.getName(), newColSpecs);
}
ExecutionMonitor normExec = exec.createSubProgress(.7);
BufferedDataContainer container = exec.createDataContainer(spec);
long count = 1;
for (DataRow row : outTable) {
normExec.checkCanceled();
normExec.setProgress(count / (double) rowcount, "Normalizing row no. " + count + " of " + rowcount + " (\"" + row.getKey() + "\")");
container.addRowToTable(row);
count++;
}
container.close();
return new CalculationResult(container.getTable(), modelSpec, configuration);
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class LinearInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
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 * (getNumMissing() + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.def.DoubleCell in project knime-core by knime.
the class AverageInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
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 + next) / 2);
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
Aggregations