use of org.knime.base.node.mine.treeensemble2.sample.row.DefaultRowSample in project knime-core by knime.
the class RootDescendantDataMembershipsTest method testCreateChildDataMemberships.
@Test
public void testCreateChildDataMemberships() {
TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
TestDataGenerator dataGen = new TestDataGenerator(config);
TreeData data = dataGen.createTennisData();
DefaultDataIndexManager indexManager = new DefaultDataIndexManager(data);
int nrRows = data.getNrRows();
RowSample rowSample = new DefaultRowSample(nrRows);
RootDataMemberships rootMemberships = new RootDataMemberships(rowSample, data, indexManager);
BitSet firstHalf = new BitSet(nrRows);
firstHalf.set(0, nrRows / 2);
DataMemberships firstHalfChildMemberships = rootMemberships.createChildMemberships(firstHalf);
assertThat(firstHalfChildMemberships, instanceOf(BitSetDescendantDataMemberships.class));
BitSetDescendantDataMemberships bitSetFirstHalfChildMemberships = (BitSetDescendantDataMemberships) firstHalfChildMemberships;
assertEquals(firstHalf, bitSetFirstHalfChildMemberships.getBitSet());
BitSet firstQuarter = new BitSet(nrRows);
firstQuarter.set(0, nrRows / 4);
DataMemberships firstQuarterGrandChild = firstHalfChildMemberships.createChildMemberships(firstQuarter);
assertThat(firstQuarterGrandChild, instanceOf(BitSetDescendantDataMemberships.class));
BitSetDescendantDataMemberships bitSetFirstQuarterGrandChild = (BitSetDescendantDataMemberships) firstQuarterGrandChild;
assertEquals(firstQuarter, bitSetFirstQuarterGrandChild.getBitSet());
}
use of org.knime.base.node.mine.treeensemble2.sample.row.DefaultRowSample in project knime-core by knime.
the class RootDescendantDataMembershipsTest method testGetColumnMemberships.
@Test
public void testGetColumnMemberships() {
TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
TestDataGenerator dataGen = new TestDataGenerator(config);
TreeData data = dataGen.createTennisData();
DefaultDataIndexManager indexManager = new DefaultDataIndexManager(data);
int nrRows = data.getNrRows();
RowSample rowSample = new DefaultRowSample(nrRows);
RootDataMemberships rootMemberships = new RootDataMemberships(rowSample, data, indexManager);
ColumnMemberships rootColMem = rootMemberships.getColumnMemberships(0);
assertThat(rootColMem, instanceOf(IntArrayColumnMemberships.class));
assertEquals(nrRows, rootColMem.size());
int[] expectedOriginalIndices = new int[] { 0, 1, 7, 8, 10, 2, 6, 11, 12, 3, 4, 5, 9, 13 };
for (int i = 0; rootColMem.next(); i++) {
// in this case originalIndex and indexInDataMemberships are the same
assertEquals(expectedOriginalIndices[i], rootColMem.getIndexInDataMemberships());
assertEquals(expectedOriginalIndices[i], rootColMem.getIndexInDataMemberships());
assertEquals(i, rootColMem.getIndexInColumn());
}
BitSet lastHalf = new BitSet(nrRows);
lastHalf.set(nrRows / 2, nrRows);
DataMemberships lastHalfChild = rootMemberships.createChildMemberships(lastHalf);
ColumnMemberships childColMem = lastHalfChild.getColumnMemberships(0);
assertThat(childColMem, instanceOf(DescendantColumnMemberships.class));
assertEquals(nrRows / 2, childColMem.size());
expectedOriginalIndices = new int[] { 7, 8, 10, 11, 12, 9, 13 };
int[] expectedIndexInColumn = new int[] { 2, 3, 4, 7, 8, 12, 13 };
int[] expectedIndexInDataMemberships = new int[] { 7, 8, 10, 11, 12, 9, 13 };
for (int i = 0; childColMem.next(); i++) {
assertEquals(expectedOriginalIndices[i], childColMem.getOriginalIndex());
assertEquals(expectedIndexInColumn[i], childColMem.getIndexInColumn());
assertEquals(expectedIndexInDataMemberships[i], childColMem.getIndexInDataMemberships());
}
}
Aggregations