Search in sources :

Example 6 with PointStore

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

Example 7 with PointStore

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());
}
Also used : PointStore(com.amazon.randomcutforest.store.PointStore) PointStoreCoordinator(com.amazon.randomcutforest.executor.PointStoreCoordinator)

Example 8 with PointStore

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());
}
Also used : PointStore(com.amazon.randomcutforest.store.PointStore) PointStoreSmall(com.amazon.randomcutforest.store.PointStoreSmall) Test(org.junit.jupiter.api.Test)

Aggregations

PointStore (com.amazon.randomcutforest.store.PointStore)8 Random (java.util.Random)5 PointStoreCoordinator (com.amazon.randomcutforest.executor.PointStoreCoordinator)4 ComponentList (com.amazon.randomcutforest.ComponentList)3 RandomCutForest (com.amazon.randomcutforest.RandomCutForest)3 CompactSampler (com.amazon.randomcutforest.sampler.CompactSampler)3 Weighted (com.amazon.randomcutforest.sampler.Weighted)3 CompactSamplerMapper (com.amazon.randomcutforest.state.sampler.CompactSamplerMapper)3 CompactSamplerState (com.amazon.randomcutforest.state.sampler.CompactSamplerState)3 PointStoreMapper (com.amazon.randomcutforest.state.store.PointStoreMapper)3 CompactRandomCutTreeContext (com.amazon.randomcutforest.state.tree.CompactRandomCutTreeContext)3 IPointStore (com.amazon.randomcutforest.store.IPointStore)3 RandomCutTree (com.amazon.randomcutforest.tree.RandomCutTree)3 ArrayList (java.util.ArrayList)3 CommonUtils.checkArgument (com.amazon.randomcutforest.CommonUtils.checkArgument)2 CommonUtils.checkNotNull (com.amazon.randomcutforest.CommonUtils.checkNotNull)2 IComponentModel (com.amazon.randomcutforest.IComponentModel)2 Config (com.amazon.randomcutforest.config.Config)2 Precision (com.amazon.randomcutforest.config.Precision)2 SamplerPlusTree (com.amazon.randomcutforest.executor.SamplerPlusTree)2