use of com.amazon.randomcutforest.store.PointStore in project random-cut-forest-by-aws by aws.
the class RandomCutTreeTest method testUpdatesOnSmallBoundingBox.
@Test
public void testUpdatesOnSmallBoundingBox() {
// verifies on small bounding boxes random cuts and tree updates are functional
PointStore pointStoreFloat = new PointStore.Builder().indexCapacity(10).capacity(10).currentStoreCapacity(10).dimensions(1).build();
RandomCutTree tree = RandomCutTree.builder().random(rng).pointStoreView(pointStoreFloat).build();
List<Weighted<double[]>> points = new ArrayList<>();
points.add(new Weighted<>(new double[] { 48.08 }, 0, 1L));
points.add(new Weighted<>(new double[] { 48.08001 }, 0, 2L));
pointStoreFloat.add(toFloatArray(points.get(0).getValue()), 0);
pointStoreFloat.add(toFloatArray(points.get(1).getValue()), 1);
tree.addPoint(0, points.get(0).getSequenceIndex());
tree.addPoint(1, points.get(1).getSequenceIndex());
assertNotEquals(pointStoreFloat.get(0)[0], pointStoreFloat.get(1)[0]);
for (int i = 0; i < 10000; i++) {
Weighted<double[]> point = points.get(i % points.size());
tree.deletePoint(i % points.size(), point.getSequenceIndex());
tree.addPoint(i % points.size(), point.getSequenceIndex());
}
}
use of com.amazon.randomcutforest.store.PointStore in project random-cut-forest-by-aws by aws.
the class RandomCutForestMapperTest method assertCompactForestEquals.
public void assertCompactForestEquals(RandomCutForest forest, RandomCutForest forest2) {
assertEquals(forest.getDimensions(), forest2.getDimensions());
assertEquals(forest.getSampleSize(), forest2.getSampleSize());
assertEquals(forest.getOutputAfter(), forest2.getOutputAfter());
assertEquals(forest.getNumberOfTrees(), forest2.getNumberOfTrees());
assertEquals(forest.getTimeDecay(), forest2.getTimeDecay());
assertEquals(forest.isStoreSequenceIndexesEnabled(), forest2.isStoreSequenceIndexesEnabled());
assertEquals(forest.isCompact(), forest2.isCompact());
assertEquals(forest.getPrecision(), forest2.getPrecision());
assertEquals(forest.getBoundingBoxCacheFraction(), forest2.getBoundingBoxCacheFraction());
assertEquals(forest.isCenterOfMassEnabled(), forest2.isCenterOfMassEnabled());
assertEquals(forest.isParallelExecutionEnabled(), forest2.isParallelExecutionEnabled());
assertEquals(forest.getThreadPoolSize(), forest2.getThreadPoolSize());
PointStoreCoordinator coordinator = (PointStoreCoordinator) forest.getUpdateCoordinator();
PointStoreCoordinator coordinator2 = (PointStoreCoordinator) forest2.getUpdateCoordinator();
PointStore store = (PointStore) coordinator.getStore();
PointStore store2 = (PointStore) coordinator2.getStore();
assertArrayEquals(store.getRefCount(), store2.getRefCount());
assertArrayEquals(store.getStore(), store2.getStore());
assertEquals(store.getCapacity(), store2.getCapacity());
assertEquals(store.size(), store2.size());
}
use of com.amazon.randomcutforest.store.PointStore in project random-cut-forest-by-aws by aws.
the class PointStoreMapperTest method testRoundTrip.
@Test
public void testRoundTrip() {
int dimensions = 2;
int capacity = 4;
PointStore store = new PointStoreSmall(dimensions, capacity);
float[] point1 = { 1.1f, -22.2f };
int index1 = store.add(point1, 1);
float[] point2 = { 3.3f, -4.4f };
int index2 = store.add(point2, 2);
float[] point3 = { 10.1f, 100.1f };
int index3 = store.add(point3, 3);
PointStore store2 = mapper.toModel(mapper.toState(store));
assertEquals(capacity, store2.getCapacity());
assertEquals(3, store2.size());
assertEquals(dimensions, store2.getDimensions());
assertArrayEquals(store.getStore(), store2.getStore());
}
Aggregations