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());
}
}
}
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);
}
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));
}
Aggregations