Search in sources :

Example 6 with SearchFeatureDao

use of org.opensearch.ad.feature.SearchFeatureDao in project anomaly-detection by opensearch-project.

the class ModelManagerTests method getEmptyStateFullSamples.

@Test
public void getEmptyStateFullSamples() {
    SearchFeatureDao searchFeatureDao = mock(SearchFeatureDao.class);
    SingleFeatureLinearUniformInterpolator singleFeatureLinearUniformInterpolator = new IntegerSensitiveSingleFeatureLinearUniformInterpolator();
    LinearUniformInterpolator interpolator = new LinearUniformInterpolator(singleFeatureLinearUniformInterpolator);
    NodeStateManager stateManager = mock(NodeStateManager.class);
    featureManager = new FeatureManager(searchFeatureDao, interpolator, clock, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.TRAIN_SAMPLE_TIME_RANGE_IN_HOURS, AnomalyDetectorSettings.MIN_TRAIN_SAMPLES, AnomalyDetectorSettings.MAX_SHINGLE_PROPORTION_MISSING, AnomalyDetectorSettings.MAX_IMPUTATION_NEIGHBOR_DISTANCE, AnomalyDetectorSettings.PREVIEW_SAMPLE_RATE, AnomalyDetectorSettings.MAX_PREVIEW_SAMPLES, AnomalyDetectorSettings.HOURLY_MAINTENANCE, threadPool, AnomalyDetectorPlugin.AD_THREAD_POOL_NAME);
    CheckpointWriteWorker checkpointWriteQueue = mock(CheckpointWriteWorker.class);
    entityColdStarter = new EntityColdStarter(clock, threadPool, stateManager, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE, AnomalyDetectorSettings.NUM_TREES, AnomalyDetectorSettings.TIME_DECAY, numMinSamples, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, interpolator, searchFeatureDao, AnomalyDetectorSettings.THRESHOLD_MIN_PVALUE, featureManager, settings, AnomalyDetectorSettings.HOURLY_MAINTENANCE, checkpointWriteQueue, AnomalyDetectorSettings.MAX_COLD_START_ROUNDS);
    modelManager = spy(new ModelManager(checkpointDao, clock, numTrees, numSamples, rcfTimeDecay, numMinSamples, thresholdMinPvalue, minPreviewSize, modelTtl, checkpointInterval, entityColdStarter, featureManager, memoryTracker));
    ModelState<EntityModel> state = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(false).sampleSize(numMinSamples).build());
    EntityModel model = state.getModel();
    assertTrue(!model.getTrcf().isPresent());
    ThresholdingResult result = modelManager.getAnomalyResultForEntity(new double[] { -1 }, state, "", null, shingleSize);
    // model outputs scores
    assertTrue(result.getRcfScore() != 0);
    // added the sample to score since our model is empty
    assertEquals(0, model.getSamples().size());
}
Also used : SearchFeatureDao(org.opensearch.ad.feature.SearchFeatureDao) NodeStateManager(org.opensearch.ad.NodeStateManager) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) CheckpointWriteWorker(org.opensearch.ad.ratelimit.CheckpointWriteWorker) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) LinearUniformInterpolator(org.opensearch.ad.dataprocessor.LinearUniformInterpolator) FeatureManager(org.opensearch.ad.feature.FeatureManager) Test(org.junit.Test)

Aggregations

SearchFeatureDao (org.opensearch.ad.feature.SearchFeatureDao)6 ActionListener (org.opensearch.action.ActionListener)4 ADTaskManager (org.opensearch.ad.task.ADTaskManager)4 Before (org.junit.Before)3 IntegerSensitiveSingleFeatureLinearUniformInterpolator (org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator)3 LinearUniformInterpolator (org.opensearch.ad.dataprocessor.LinearUniformInterpolator)3 SingleFeatureLinearUniformInterpolator (org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator)3 FeatureManager (org.opensearch.ad.feature.FeatureManager)3 AnomalyDetectionIndices (org.opensearch.ad.indices.AnomalyDetectionIndices)3 CheckpointWriteWorker (org.opensearch.ad.ratelimit.CheckpointWriteWorker)3 ClusterService (org.opensearch.cluster.service.ClusterService)3 Clock (java.time.Clock)2 GetRequest (org.opensearch.action.get.GetRequest)2 GetResponse (org.opensearch.action.get.GetResponse)2 NodeStateManager (org.opensearch.ad.NodeStateManager)2 AnomalyDetectorSettings (org.opensearch.ad.settings.AnomalyDetectorSettings)2 ClusterSettings (org.opensearch.common.settings.ClusterSettings)2 ThresholdedRandomCutForestMapper (com.amazon.randomcutforest.parkservices.state.ThresholdedRandomCutForestMapper)1 ThresholdedRandomCutForestState (com.amazon.randomcutforest.parkservices.state.ThresholdedRandomCutForestState)1 V1JsonToV2StateConverter (com.amazon.randomcutforest.serialize.json.v1.V1JsonToV2StateConverter)1