use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class CovarianceMatrixCalculatorTest method computeCovarianceOfRandomData.
/**
* Computes a set of random double
*
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
@Test
public void computeCovarianceOfRandomData() throws InvalidSettingsException, CanceledExecutionException {
long currentTimeMillis = System.currentTimeMillis();
System.out.println("Mahalanobis test random seed: " + currentTimeMillis);
final Random random = new Random(currentTimeMillis);
double[][] data = new double[TEST_TABLE_SIZE][];
BufferedDataContainer inTableCont = generateData(random, data, SPEC_4);
inTableCont.close();
BufferedDataTable inTable = inTableCont.getTable();
// test the covariance matrix computation
CovarianceMatrixCalculator covMatrixCalculator = new CovarianceMatrixCalculator(SPEC_4, SPEC_4.getColumnNames());
BufferedDataContainer covDataContainer = m_exec.createDataContainer(covMatrixCalculator.getResultSpec());
RealMatrix covMatrixUnderTest = covMatrixCalculator.computeCovarianceMatrix(m_exec, inTable, covDataContainer);
covDataContainer.close();
Covariance covariance = new Covariance(data);
RealMatrix referenceCovarianceMatrix = covariance.getCovarianceMatrix();
BufferedDataTable covTableUnderTest = covDataContainer.getTable();
assertCovarianceMatrixEquality(covMatrixUnderTest, referenceCovarianceMatrix, covTableUnderTest, SPEC_4, true);
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class CovarianceMatrixCalculatorTest method computeCovarianceOfRandomDataWithMissingValues.
/**
* Tests the covariance computation on data with missing values
*
* @throws InvalidSettingsException
* @throws CanceledExecutionException
*/
@Test
public void computeCovarianceOfRandomDataWithMissingValues() throws InvalidSettingsException, CanceledExecutionException {
long currentTimeMillis = System.currentTimeMillis();
System.out.println("Mahalanobis test random seed: " + currentTimeMillis);
final Random random = new Random(47);
double[][] data = new double[10][];
BufferedDataContainer inTableCont = generateData(random, data, SPEC_2);
// add two rows with missing values, at the end both should be ignored
DataCell[] row = new DataCell[2];
row[0] = new DoubleCell(random.nextDouble());
row[1] = DataType.getMissingCell();
inTableCont.addRowToTable(new DefaultRow(new RowKey("Missing!1"), row));
row[1] = new DoubleCell(random.nextDouble());
row[0] = DataType.getMissingCell();
inTableCont.addRowToTable(new DefaultRow(new RowKey("Missing!2"), row));
inTableCont.close();
BufferedDataTable inTable = inTableCont.getTable();
// As the missing row should be ignored the test the covariance matrix computation should be the same
CovarianceMatrixCalculator covMatrixCalculator = new CovarianceMatrixCalculator(SPEC_2, SPEC_2.getColumnNames());
BufferedDataContainer covDataContainer = m_exec.createDataContainer(covMatrixCalculator.getResultSpec());
RealMatrix covMatrixUnderTest = covMatrixCalculator.computeCovarianceMatrix(m_exec, inTable, covDataContainer);
covDataContainer.close();
Covariance covariance = new Covariance(data);
RealMatrix referenceCovarianceMatrix = covariance.getCovarianceMatrix();
BufferedDataTable covTableUnderTest = covDataContainer.getTable();
// The diagonal is the variance which also changes considering missing values...
// but we check only the part of the covariance matrix at the top right triangle.
assertCovarianceMatrixEquality(covMatrixUnderTest, referenceCovarianceMatrix, covTableUnderTest, SPEC_2, false);
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class StatisticCalculatorTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator(FEATURE1, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(FEATURE2, DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator(STRING_FEATURE, StringCell.TYPE).createSpec() };
DataTableSpec spec = new DataTableSpec(colSpecs);
final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(spec);
int i = 0;
// values second row : miss,1,1,1,3,4,5,8 mean: 3
// values 3rd row : miss,miss,A,B,E,F,G,H,Z mean: F
container.addRowToTable(creatRow(i++, 1, 1d, "A"));
container.addRowToTable(creatRow(i++, 1, 1d, "Z"));
container.addRowToTable(creatRow(i++, 2, 3d, "B"));
container.addRowToTable(creatRow(i++, 2, 5d, "G"));
container.addRowToTable(creatRow(i++, 2, 1d, "E"));
container.addRowToTable(creatRow(i++, 6, 4d, "F"));
container.addRowToTable(creatRow(i++, 7, null, "H"));
container.addRowToTable(creatRow(i++, 8, null, null));
container.addRowToTable(creatRow(i++, 8, 8d, null));
container.close();
testTable = container.getTable();
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class BlobsInSetCellPartiallySingletonsWorkflowTest method createBDT.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable createBDT(final ExecutionContext exec) {
DataType t = ListCell.getCollectionType(DataType.getType(DataCell.class));
BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Sequence", t).createSpec()));
LargeBlobCell singleton = new LargeBlobCell("singleton", LargeBlobCell.SIZE_OF_CELL);
for (int i = 0; i < ROW_COUNT; i++) {
String s = "someName_" + i;
// every other a ordinary string cell
Collection<DataCell> cells = new ArrayList<DataCell>();
for (int j = 0; j < 4; j++) {
String val = "Row_" + i + "; Cell index " + j;
switch(j) {
case 0:
cells.add(singleton);
break;
case 1:
case 3:
cells.add(new StringCell(val));
break;
case 2:
cells.add(new LargeBlobCell(val, LargeBlobCell.SIZE_OF_CELL));
break;
default:
fail("invalid index");
}
}
ListCell cell = CollectionCellFactory.createListCell(cells);
c.addRowToTable(new DefaultRow(s, cell));
}
c.close();
return c.getTable();
}
use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.
the class OneBlobManyTimesInTableWorkflowTest method createBDT.
/**
* {@inheritDoc}
*/
@Override
public BufferedDataTable createBDT(final ExecutionContext exec) {
BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Blobs", LargeBlobCell.TYPE).createSpec()));
LargeBlobCell cell = new LargeBlobCell("This is a big cell", LargeBlobCell.SIZE_OF_CELL);
for (int i = 0; i < ROW_COUNT; i++) {
String s = "someName_" + i;
c.addRowToTable(new DefaultRow(s, cell));
}
c.close();
return c.getTable();
}
Aggregations