Search in sources :

Example 6 with FeatureManager

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

the class CronTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ThreadPool threadPool = mock(ThreadPool.class);
    ClusterService clusterService = mock(ClusterService.class);
    localNodeID = "foo";
    when(clusterService.localNode()).thenReturn(new DiscoveryNode(localNodeID, buildNewFakeTransportAddress(), Version.CURRENT));
    when(clusterService.getClusterName()).thenReturn(new ClusterName("test"));
    TransportService transportService = mock(TransportService.class);
    ActionFilters actionFilters = mock(ActionFilters.class);
    NodeStateManager tarnsportStatemanager = mock(NodeStateManager.class);
    ModelManager modelManager = mock(ModelManager.class);
    FeatureManager featureManager = mock(FeatureManager.class);
    CacheProvider cacheProvider = mock(CacheProvider.class);
    EntityCache entityCache = mock(EntityCache.class);
    EntityColdStarter entityColdStarter = mock(EntityColdStarter.class);
    when(cacheProvider.get()).thenReturn(entityCache);
    ADTaskManager adTaskManager = mock(ADTaskManager.class);
    action = new CronTransportAction(threadPool, clusterService, transportService, actionFilters, tarnsportStatemanager, modelManager, featureManager, cacheProvider, entityColdStarter, adTaskManager);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) EntityCache(org.opensearch.ad.caching.EntityCache) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) ModelManager(org.opensearch.ad.ml.ModelManager) CacheProvider(org.opensearch.ad.caching.CacheProvider) NodeStateManager(org.opensearch.ad.NodeStateManager) ClusterService(org.opensearch.cluster.service.ClusterService) EntityColdStarter(org.opensearch.ad.ml.EntityColdStarter) TransportService(org.opensearch.transport.TransportService) ADTaskManager(org.opensearch.ad.task.ADTaskManager) ClusterName(org.opensearch.cluster.ClusterName) FeatureManager(org.opensearch.ad.feature.FeatureManager) Before(org.junit.Before)

Example 7 with FeatureManager

use of org.opensearch.ad.feature.FeatureManager 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

FeatureManager (org.opensearch.ad.feature.FeatureManager)7 ModelManager (org.opensearch.ad.ml.ModelManager)5 Before (org.junit.Before)4 NodeStateManager (org.opensearch.ad.NodeStateManager)4 CacheProvider (org.opensearch.ad.caching.CacheProvider)4 EntityCache (org.opensearch.ad.caching.EntityCache)4 IntegerSensitiveSingleFeatureLinearUniformInterpolator (org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator)3 LinearUniformInterpolator (org.opensearch.ad.dataprocessor.LinearUniformInterpolator)3 SingleFeatureLinearUniformInterpolator (org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator)3 SearchFeatureDao (org.opensearch.ad.feature.SearchFeatureDao)3 CheckpointWriteWorker (org.opensearch.ad.ratelimit.CheckpointWriteWorker)3 AnomalyDetectorSettings (org.opensearch.ad.settings.AnomalyDetectorSettings)3 ClusterService (org.opensearch.cluster.service.ClusterService)3 Settings (org.opensearch.common.settings.Settings)3 HashSet (java.util.HashSet)2 ActionFilters (org.opensearch.action.support.ActionFilters)2 ADCircuitBreakerService (org.opensearch.ad.breaker.ADCircuitBreakerService)2 EntityColdStarter (org.opensearch.ad.ml.EntityColdStarter)2 ADTaskManager (org.opensearch.ad.task.ADTaskManager)2 ClusterName (org.opensearch.cluster.ClusterName)2