Search in sources :

Example 1 with ShingleBuilder

use of com.amazon.randomcutforest.util.ShingleBuilder in project random-cut-forest-by-aws by aws.

the class RandomCutForestShingledFunctionalTest method oneTimeSetUp.

@BeforeAll
public static void oneTimeSetUp() {
    numberOfTrees = 100;
    sampleSize = 256;
    dimensions = 2;
    randomSeed = 123;
    shingleSize = 3;
    shingleBuilder = new ShingleBuilder(dimensions, shingleSize);
    forest = RandomCutForest.builder().numberOfTrees(numberOfTrees).sampleSize(sampleSize).dimensions(shingleBuilder.getShingledPointSize()).randomSeed(randomSeed).centerOfMassEnabled(true).storeSequenceIndexesEnabled(true).build();
    dataSize = 10_000;
    baseMu = 0.0;
    baseSigma = 1.0;
    anomalyMu = 5.0;
    anomalySigma = 1.5;
    transitionToAnomalyProbability = 0.01;
    transitionToBaseProbability = 0.4;
    NormalMixtureTestData generator = new NormalMixtureTestData(baseMu, baseSigma, anomalyMu, anomalySigma, transitionToAnomalyProbability, transitionToBaseProbability);
    double[][] data = generator.generateTestData(dataSize, dimensions);
    for (int i = 0; i < dataSize; i++) {
        shingleBuilder.addPoint(data[i]);
        if (shingleBuilder.isFull()) {
            forest.update(shingleBuilder.getShingle());
        }
    }
}
Also used : ShingleBuilder(com.amazon.randomcutforest.util.ShingleBuilder) NormalMixtureTestData(com.amazon.randomcutforest.testutils.NormalMixtureTestData) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ShingleBuilder

use of com.amazon.randomcutforest.util.ShingleBuilder in project random-cut-forest-by-aws by aws.

the class SimpleRunner method prepareAlgorithm.

/**
 * Set up the internal RandomCutForest instance and line transformer.
 *
 * @param dimensions The number of dimensions in the input data.
 */
protected void prepareAlgorithm(int dimensions) {
    pointBuffer = new double[dimensions];
    shingleBuilder = new ShingleBuilder(dimensions, argumentParser.getShingleSize(), argumentParser.getShingleCyclic());
    shingleBuffer = new double[shingleBuilder.getShingledPointSize()];
    RandomCutForest forest = RandomCutForest.builder().numberOfTrees(argumentParser.getNumberOfTrees()).sampleSize(argumentParser.getSampleSize()).dimensions(shingleBuilder.getShingledPointSize()).timeDecay(argumentParser.getTimeDecay()).randomSeed(argumentParser.getRandomSeed()).build();
    algorithm = algorithmInitializer.apply(forest);
}
Also used : ShingleBuilder(com.amazon.randomcutforest.util.ShingleBuilder) RandomCutForest(com.amazon.randomcutforest.RandomCutForest)

Example 3 with ShingleBuilder

use of com.amazon.randomcutforest.util.ShingleBuilder in project random-cut-forest-by-aws by aws.

the class RandomCutForestTest method testExrapolateBasicWithShingleBuilder.

@Test
public void testExrapolateBasicWithShingleBuilder() {
    doNothing().when(forest).extrapolateBasicCyclic(any(float[].class), anyInt(), anyInt(), anyInt(), any(float[].class), any(int[].class));
    doNothing().when(forest).extrapolateBasicSliding(any(float[].class), anyInt(), anyInt(), any(float[].class), any(int[].class));
    ShingleBuilder shingleBuilder = new ShingleBuilder(1, 2, true);
    int horizon = 3;
    forest.extrapolateBasic(shingleBuilder, horizon);
    verify(forest, times(1)).extrapolateBasicCyclic(any(float[].class), eq(horizon), eq(1), eq(0), any(float[].class), any(int[].class));
    shingleBuilder = new ShingleBuilder(1, 2, false);
    forest.extrapolateBasic(shingleBuilder, horizon);
    verify(forest, times(1)).extrapolateBasicSliding(any(float[].class), eq(horizon), eq(1), any(float[].class), any(int[].class));
}
Also used : ShingleBuilder(com.amazon.randomcutforest.util.ShingleBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

ShingleBuilder (com.amazon.randomcutforest.util.ShingleBuilder)3 RandomCutForest (com.amazon.randomcutforest.RandomCutForest)1 NormalMixtureTestData (com.amazon.randomcutforest.testutils.NormalMixtureTestData)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1