Search in sources :

Example 6 with CompactSampler

use of com.amazon.randomcutforest.sampler.CompactSampler in project random-cut-forest-by-aws by aws.

the class CompactSamplerMapperTest method nonemptySamplerProvider.

public static Stream<Arguments> nonemptySamplerProvider() {
    CompactSampler fullSampler1 = CompactSampler.builder().capacity(sampleSize).timeDecay(lambda).randomSeed(seed).storeSequenceIndexesEnabled(false).build();
    CompactSampler fullSampler2 = CompactSampler.builder().capacity(sampleSize).timeDecay(lambda).randomSeed(seed).storeSequenceIndexesEnabled(true).build();
    Random random = new Random();
    long baseIndex = 10_000;
    for (int i = 0; i < 100; i++) {
        int pointReference = random.nextInt();
        fullSampler1.update(pointReference, baseIndex + i);
        fullSampler2.update(pointReference, baseIndex + i);
    }
    CompactSampler partiallyFullSampler1 = CompactSampler.builder().capacity(sampleSize).timeDecay(lambda).randomSeed(seed).storeSequenceIndexesEnabled(false).build();
    CompactSampler partiallyFullSampler2 = CompactSampler.builder().capacity(sampleSize).timeDecay(lambda).randomSeed(seed).storeSequenceIndexesEnabled(true).build();
    for (int i = 0; i < sampleSize / 2; i++) {
        int pointReference = random.nextInt();
        partiallyFullSampler1.update(pointReference, baseIndex + i);
        partiallyFullSampler2.update(pointReference, baseIndex + i);
    }
    return Stream.of(Arguments.of("full sampler without sequence indexes", fullSampler1), Arguments.of("full sampler with sequence indexes", fullSampler2), Arguments.of("partially full sampler without sequence indexes", partiallyFullSampler1), Arguments.of("partially full sampler with sequence indexes", partiallyFullSampler2));
}
Also used : Random(java.util.Random) CompactSampler(com.amazon.randomcutforest.sampler.CompactSampler)

Example 7 with CompactSampler

use of com.amazon.randomcutforest.sampler.CompactSampler in project random-cut-forest-by-aws by aws.

the class RandomCutForestTest method setUp.

@BeforeEach
public void setUp() {
    dimensions = 2;
    sampleSize = 256;
    numberOfTrees = 10;
    components = new ComponentList<>();
    for (int i = 0; i < numberOfTrees; i++) {
        CompactSampler sampler = mock(CompactSampler.class);
        when(sampler.getCapacity()).thenReturn(sampleSize);
        RandomCutTree tree = mock(RandomCutTree.class);
        components.add(spy(new SamplerPlusTree<>(sampler, tree)));
    }
    updateCoordinator = spy(new PointStoreCoordinator<>(new PointStore.Builder().dimensions(2).capacity(1).build()));
    traversalExecutor = spy(new SequentialForestTraversalExecutor(components));
    updateExecutor = spy(new SequentialForestUpdateExecutor<>(updateCoordinator, components));
    RandomCutForest.Builder<?> builder = RandomCutForest.builder().dimensions(dimensions).numberOfTrees(numberOfTrees).sampleSize(sampleSize);
    forest = spy(new RandomCutForest(builder, updateCoordinator, components, builder.getRandom()));
    Whitebox.setInternalState(forest, "traversalExecutor", traversalExecutor);
    Whitebox.setInternalState(forest, "updateExecutor", updateExecutor);
}
Also used : RandomCutTree(com.amazon.randomcutforest.tree.RandomCutTree) SequentialForestUpdateExecutor(com.amazon.randomcutforest.executor.SequentialForestUpdateExecutor) CompactSampler(com.amazon.randomcutforest.sampler.CompactSampler) SequentialForestTraversalExecutor(com.amazon.randomcutforest.executor.SequentialForestTraversalExecutor) ShingleBuilder(com.amazon.randomcutforest.util.ShingleBuilder) SamplerPlusTree(com.amazon.randomcutforest.executor.SamplerPlusTree) PointStoreCoordinator(com.amazon.randomcutforest.executor.PointStoreCoordinator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CompactSampler (com.amazon.randomcutforest.sampler.CompactSampler)7 RandomCutForest (com.amazon.randomcutforest.RandomCutForest)3 PointStoreCoordinator (com.amazon.randomcutforest.executor.PointStoreCoordinator)3 RandomCutTree (com.amazon.randomcutforest.tree.RandomCutTree)3 Random (java.util.Random)3 ComponentList (com.amazon.randomcutforest.ComponentList)2 Precision (com.amazon.randomcutforest.config.Precision)2 SamplerPlusTree (com.amazon.randomcutforest.executor.SamplerPlusTree)2 CompactSamplerMapper (com.amazon.randomcutforest.state.sampler.CompactSamplerMapper)2 CompactSamplerState (com.amazon.randomcutforest.state.sampler.CompactSamplerState)2 PointStoreMapper (com.amazon.randomcutforest.state.store.PointStoreMapper)2 CompactRandomCutTreeContext (com.amazon.randomcutforest.state.tree.CompactRandomCutTreeContext)2 IPointStore (com.amazon.randomcutforest.store.IPointStore)2 PointStore (com.amazon.randomcutforest.store.PointStore)2 CommonUtils.checkArgument (com.amazon.randomcutforest.CommonUtils.checkArgument)1 CommonUtils.checkNotNull (com.amazon.randomcutforest.CommonUtils.checkNotNull)1 IComponentModel (com.amazon.randomcutforest.IComponentModel)1 Config (com.amazon.randomcutforest.config.Config)1 SequentialForestTraversalExecutor (com.amazon.randomcutforest.executor.SequentialForestTraversalExecutor)1 SequentialForestUpdateExecutor (com.amazon.randomcutforest.executor.SequentialForestUpdateExecutor)1