Search in sources :

Example 1 with Weighted

use of com.amazon.randomcutforest.sampler.Weighted 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());
    }
}
Also used : PointStore(com.amazon.randomcutforest.store.PointStore) Weighted(com.amazon.randomcutforest.sampler.Weighted) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

Weighted (com.amazon.randomcutforest.sampler.Weighted)1 PointStore (com.amazon.randomcutforest.store.PointStore)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1