use of org.opensearch.ad.ml.HybridThresholdingModel in project anomaly-detection by opensearch-project.
the class ADStatsTests method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
// sampleSize * numberOfTrees has to be larger than 1. Otherwise, RCF reports errors.
rcf = RandomCutForest.builder().dimensions(1).sampleSize(2).numberOfTrees(1).build();
thresholdingModel = new HybridThresholdingModel(1e-8, 1e-5, 200, 10_000, 2, 5_000_000);
List<ModelState<?>> modelsInformation = new ArrayList<>(Arrays.asList(new ModelState<>(rcf, "rcf-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(rcf, "rcf-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f)));
when(modelManager.getAllModels()).thenReturn(modelsInformation);
ModelState<EntityModel> entityModel1 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
ModelState<EntityModel> entityModel2 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
List<ModelState<?>> entityModelsInformation = new ArrayList<>(Arrays.asList(entityModel1, entityModel2));
EntityCache cache = mock(EntityCache.class);
when(cacheProvider.get()).thenReturn(cache);
when(cache.getAllModels()).thenReturn(entityModelsInformation);
IndexUtils indexUtils = mock(IndexUtils.class);
when(indexUtils.getIndexHealthStatus(anyString())).thenReturn("yellow");
when(indexUtils.getNumberOfDocumentsInIndex(anyString())).thenReturn(100L);
clusterStatName1 = "clusterStat1";
clusterStatName2 = "clusterStat2";
nodeStatName1 = "nodeStat1";
nodeStatName2 = "nodeStat2";
Settings settings = Settings.builder().put(MAX_MODEL_SIZE_PER_NODE.getKey(), 10).build();
ClusterService clusterService = mock(ClusterService.class);
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(MAX_MODEL_SIZE_PER_NODE))));
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
statsMap = new HashMap<String, ADStat<?>>() {
{
put(nodeStatName1, new ADStat<>(false, new CounterSupplier()));
put(nodeStatName2, new ADStat<>(false, new ModelsOnNodeSupplier(modelManager, cacheProvider, settings, clusterService)));
put(clusterStatName1, new ADStat<>(true, new IndexStatusSupplier(indexUtils, "index1")));
put(clusterStatName2, new ADStat<>(true, new IndexStatusSupplier(indexUtils, "index2")));
}
};
adStats = new ADStats(statsMap);
}
use of org.opensearch.ad.ml.HybridThresholdingModel in project anomaly-detection by opensearch-project.
the class ModelsOnNodeSupplierTests method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
clock = Clock.systemUTC();
rcf = RandomCutForest.builder().dimensions(1).sampleSize(2).numberOfTrees(1).build();
thresholdingModel = new HybridThresholdingModel(1e-8, 1e-5, 200, 10_000, 2, 5_000_000);
expectedResults = new ArrayList<>(Arrays.asList(new ModelState<>(rcf, "rcf-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(rcf, "rcf-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f)));
when(modelManager.getAllModels()).thenReturn(expectedResults);
ModelState<EntityModel> entityModel1 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
ModelState<EntityModel> entityModel2 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
entityModelsInformation = new ArrayList<>(Arrays.asList(entityModel1, entityModel2));
EntityCache cache = mock(EntityCache.class);
when(cacheProvider.get()).thenReturn(cache);
when(cache.getAllModels()).thenReturn(entityModelsInformation);
}
Aggregations