use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class PolyRegLearnerNodeModel method getCellFactory.
private CellFactory getCellFactory(final int dependentIndex) {
final int degree = m_settings.getDegree();
return new CellFactory() {
@Override
public DataCell[] getCells(final DataRow row) {
double sum = m_betas[0];
int betaCount = 1;
double y = 0;
for (int col = 0; col < row.getNumCells(); col++) {
if ((col == dependentIndex || m_colSelected[col]) && row.getCell(col).isMissing()) {
switch(m_settings.getMissingValueHandling()) {
case ignore:
return new DataCell[] { DataType.getMissingCell(), DataType.getMissingCell() };
case fail:
throw new IllegalStateException("Should failed earlier!");
default:
throw new UnsupportedOperationException("Not supported missing handling strategy: " + m_settings.getMissingValueHandling());
}
}
if ((col != dependentIndex) && m_colSelected[col]) {
final double value = ((DoubleValue) row.getCell(col)).getDoubleValue();
double poly = 1;
for (int d = 1; d <= degree; d++) {
poly *= value;
sum += m_betas[betaCount++] * poly;
}
} else if (col == dependentIndex) {
y = ((DoubleValue) row.getCell(col)).getDoubleValue();
}
}
double err = Math.abs(sum - y);
m_squaredError += err * err;
return new DataCell[] { new DoubleCell(sum), new DoubleCell(err) };
}
@Override
public DataColumnSpec[] getColumnSpecs() {
DataColumnSpecCreator crea = new DataColumnSpecCreator("PolyReg prediction", DoubleCell.TYPE);
DataColumnSpec col1 = crea.createSpec();
crea = new DataColumnSpecCreator("Prediction Error", DoubleCell.TYPE);
DataColumnSpec col2 = crea.createSpec();
return new DataColumnSpec[] { col1, col2 };
}
@Override
public void setProgress(final int curRowNr, final int rowCount, final RowKey lastKey, final ExecutionMonitor execMon) {
// do nothing
}
};
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class FuzzyBasisFunctionPredictorRow method computeActivation.
/**
* Returns the compute activation of this input vector.
*
* @param row input pattern
* @return membership degree
*/
@Override
public double computeActivation(final DataRow row) {
assert (m_mem.length == row.getNumCells());
// sets degree to maximum
double degree = 1.0;
// overall cells in the vector
for (int i = 0; i < m_mem.length; i++) {
DataCell cell = row.getCell(i);
if (cell.isMissing()) {
continue;
}
// gets cell at index i
double value = ((DoubleValue) cell).getDoubleValue();
// act in current dimension
double act = m_mem[i].getActivation(value);
if (i == 0) {
degree = act;
continue;
}
// calculates the new (minimum) degree using norm index
degree = Norm.NORMS[m_norm].computeTNorm(degree, act);
assert (0.0 <= degree && degree <= 1.0);
}
// returns membership degree
return degree;
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class MinkowskiDist method calcDistance.
/**
* Calculates the distance between two data rows based on the
* Minkowski distance.
*
* @param firstDataRow the first data row used to calculate the distance
* @param secondDataRow the second data row used to calculate the distance
* @param includedCols the columns to include into the calculation
*
* @return the distance of the two rows
*/
public double calcDistance(final DataRow firstDataRow, final DataRow secondDataRow, final int[] includedCols) {
double sumPowDist = 0;
for (int i : includedCols) {
// skip not included cells
DataCell x = firstDataRow.getCell(i);
DataCell y = secondDataRow.getCell(i);
if (!x.isMissing() && x instanceof DoubleValue && !y.isMissing() && y instanceof DoubleValue) {
DoubleValue clusterValue = (DoubleValue) firstDataRow.getCell(i);
DoubleValue rowValue = (DoubleValue) secondDataRow.getCell(i);
double dist = Math.abs(clusterValue.getDoubleValue() - rowValue.getDoubleValue());
sumPowDist += Math.pow(dist, m_p);
}
}
return Math.pow(sumPowDist, (double) 1 / (double) m_p);
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class ClusterNodeModel method findClosestPrototypeFor.
private int findClosestPrototypeFor(final DataRow row, final double[][] clusters) {
// find closest cluster center
// closest cluster so far
int winner = -1;
// best distance
double winnerDistance = Double.MAX_VALUE;
for (int c = 0; c < m_nrOfClusters.getIntValue(); c++) {
double distance = 0.0;
int pos = 0;
for (int i = 0; i < m_dimension; i++) {
DataCell currentCell = row.getCell(i);
if (!m_ignoreColumn[i]) {
if (!currentCell.isMissing()) {
assert currentCell.getType().isCompatible(DoubleValue.class);
double d = (clusters[c][pos] - ((DoubleValue) (currentCell)).getDoubleValue());
if (!Double.isNaN(d)) {
distance += d * d;
}
} else {
// missing
distance += 0.0;
}
pos++;
}
}
if (distance < winnerDistance) {
// found closer cluster
// make it new winner
winner = c;
winnerDistance = distance;
}
}
// for all clusters (find closest one)
return winner;
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class PMMLSimpleSetPredicate method evaluate.
/**
* {@inheritDoc}
*/
@Override
public Boolean evaluate(final DataRow row, final DataTableSpec spec) {
cacheSpec(spec);
assert getPreviousIndex() != -1;
DataCell cell = row.getCell(getPreviousIndex());
if (cell.isMissing()) {
return null;
}
if (m_arrayType == PMMLArrayType.STRING) {
return m_op.evaluate(cell.toString(), m_values);
} else {
Double a = ((DoubleValue) cell).getDoubleValue();
return m_op.evaluate(a, m_doubleValues);
}
}
Aggregations