Search in sources :

Example 91 with BufferedDataContainer

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);
}
Also used : Random(java.util.Random) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Covariance(org.apache.commons.math3.stat.correlation.Covariance) BufferedDataTable(org.knime.core.node.BufferedDataTable) Test(org.junit.Test)

Example 92 with BufferedDataContainer

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);
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) Random(java.util.Random) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Covariance(org.apache.commons.math3.stat.correlation.Covariance) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Test(org.junit.Test)

Example 93 with BufferedDataContainer

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Before(org.junit.Before)

Example 94 with BufferedDataContainer

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 95 with BufferedDataContainer

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();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

BufferedDataContainer (org.knime.core.node.BufferedDataContainer)157 BufferedDataTable (org.knime.core.node.BufferedDataTable)96 DefaultRow (org.knime.core.data.def.DefaultRow)93 DataCell (org.knime.core.data.DataCell)88 DataTableSpec (org.knime.core.data.DataTableSpec)88 DataRow (org.knime.core.data.DataRow)80 RowKey (org.knime.core.data.RowKey)38 DoubleCell (org.knime.core.data.def.DoubleCell)37 StringCell (org.knime.core.data.def.StringCell)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)24 ArrayList (java.util.ArrayList)23 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)21 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 IOException (java.io.IOException)15 ExecutionContext (org.knime.core.node.ExecutionContext)15 LinkedHashMap (java.util.LinkedHashMap)14 HashSet (java.util.HashSet)13 IntCell (org.knime.core.data.def.IntCell)13