use of org.apache.commons.math.random.RandomDataImpl in project knime-core by knime.
the class RFSubsetColumnSampleStrategy method getColumnSampleForTreeNode.
/**
* {@inheritDoc}
*/
@Override
public ColumnSample getColumnSampleForTreeNode(final TreeNodeSignature treeNodeSignature) {
byte[] signature = treeNodeSignature.getSignaturePath();
JDKRandomGenerator generator = new JDKRandomGenerator();
generator.setSeed(m_seed);
int[] newSeed = new int[signature.length];
for (int i = 0; i < signature.length; i++) {
for (int p = 0; p <= signature[i]; p++) {
newSeed[i] = generator.nextInt();
}
}
generator.setSeed(newSeed);
int totalColCount = m_data.getColumns().length;
RandomData rd = new RandomDataImpl(generator);
int[] includes = rd.nextPermutation(totalColCount, m_subsetSize);
Arrays.sort(includes);
return new SubsetColumnSample(m_data, includes);
}
use of org.apache.commons.math.random.RandomDataImpl in project knime-core by knime.
the class RandomBinarySplitEnumerationTest method testFullEnumeration.
/**
* Tests random enumeration on all possible masks. All valid values must be returned, no duplicates
* expected.
*/
@Test
public void testFullEnumeration() {
final int valueCount = 16;
final int validCount = (int) Math.pow(2, valueCount - 1) - 1;
/* Reference enumeration */
final FullBinarySplitEnumeration fullEnum = new FullBinarySplitEnumeration(valueCount);
final HashSet<BigInteger> allAvailableBS = new HashSet<>();
do {
allAvailableBS.add(fullEnum.getValueMask());
} while (fullEnum.next());
/* random enum to test */
RandomBinarySplitEnumeration randomEnum = new RandomBinarySplitEnumeration(valueCount, validCount, new RandomDataImpl());
int i = 0;
do {
BigInteger valueMask = randomEnum.getValueMask();
if (!allAvailableBS.remove(valueMask)) {
Assert.fail("value mask appeared twice: " + valueMask + " (this is iteration " + i + ".)");
}
i++;
} while (randomEnum.next());
if (!allAvailableBS.isEmpty()) {
Assert.fail("Some value masks not returned (" + allAvailableBS.size() + " left)");
}
}
use of org.apache.commons.math.random.RandomDataImpl in project knime-core by knime.
the class TestDataGenerator method createRandomData.
public static RandomData createRandomData() {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(System.currentTimeMillis());
return new RandomDataImpl(randomGenerator);
}
use of org.apache.commons.math.random.RandomDataImpl in project knime-core by knime.
the class TreeEnsembleLearnerConfiguration method createRandomData.
/**
* @param seed
* @return RandomData created from <b>seed</b>
*/
public static RandomData createRandomData(final long seed) {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
return new RandomDataImpl(randomGenerator);
}
use of org.apache.commons.math.random.RandomDataImpl in project knime-core by knime.
the class TreeEnsembleLearnerConfiguration method createRandomData.
/**
* @param seed
* @return RandomData created from <b>seed</b>
*/
public static RandomData createRandomData(final long seed) {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
return new RandomDataImpl(randomGenerator);
}
Aggregations