use of com.amazon.randomcutforest.parkservices.state.threshold.BasicThresholderMapper in project random-cut-forest-by-aws by aws.
the class ThresholdedRandomCutForestMapper method toState.
@Override
public ThresholdedRandomCutForestState toState(ThresholdedRandomCutForest model) {
ThresholdedRandomCutForestState state = new ThresholdedRandomCutForestState();
RandomCutForestMapper randomCutForestMapper = new RandomCutForestMapper();
randomCutForestMapper.setPartialTreeStateEnabled(true);
randomCutForestMapper.setSaveTreeStateEnabled(true);
randomCutForestMapper.setCompressionEnabled(true);
randomCutForestMapper.setSaveCoordinatorStateEnabled(true);
randomCutForestMapper.setSaveExecutorContextEnabled(true);
state.setForestState(randomCutForestMapper.toState(model.getForest()));
BasicThresholderMapper thresholderMapper = new BasicThresholderMapper();
state.setThresholderState(thresholderMapper.toState(model.getThresholder()));
PreprocessorMapper preprocessorMapper = new PreprocessorMapper();
state.setPreprocessorStates(new PreprocessorState[] { preprocessorMapper.toState((Preprocessor) model.getPreprocessor()) });
state.setTriggerFactor(model.getPredictorCorrector().getTriggerFactor());
state.setIgnoreSimilar(model.getPredictorCorrector().isIgnoreSimilar());
state.setIgnoreSimilarFactor(model.getPredictorCorrector().getIgnoreSimilarFactor());
state.setNumberOfAttributors(model.getPredictorCorrector().getNumberOfAttributors());
state.setForestMode(model.getForestMode().name());
state.setTransformMethod(model.getTransformMethod().name());
IRCFComputeDescriptor descriptor = model.getLastAnomalyDescriptor();
state.setLastAnomalyTimeStamp(descriptor.getInternalTimeStamp());
state.setLastAnomalyScore(descriptor.getRCFScore());
state.setLastAnomalyAttribution(new DiVectorMapper().toState(descriptor.getAttribution()));
state.setLastAnomalyPoint(descriptor.getRCFPoint());
state.setLastExpectedPoint(descriptor.getExpectedRCFPoint());
state.setLastRelativeIndex(descriptor.getRelativeIndex());
return state;
}
use of com.amazon.randomcutforest.parkservices.state.threshold.BasicThresholderMapper in project random-cut-forest-by-aws by aws.
the class ThresholdedRandomCutForestMapper method toModel.
@Override
public ThresholdedRandomCutForest toModel(ThresholdedRandomCutForestState state, long seed) {
RandomCutForestMapper randomCutForestMapper = new RandomCutForestMapper();
BasicThresholderMapper thresholderMapper = new BasicThresholderMapper();
PreprocessorMapper preprocessorMapper = new PreprocessorMapper();
RandomCutForest forest = randomCutForestMapper.toModel(state.getForestState());
BasicThresholder thresholder = thresholderMapper.toModel(state.getThresholderState());
Preprocessor preprocessor = preprocessorMapper.toModel(state.getPreprocessorStates()[0]);
ForestMode forestMode = ForestMode.valueOf(state.getForestMode());
TransformMethod transformMethod = TransformMethod.valueOf(state.getTransformMethod());
RCFComputeDescriptor descriptor = new RCFComputeDescriptor(null, 0L);
descriptor.setRCFScore(state.getLastAnomalyScore());
descriptor.setInternalTimeStamp(state.getLastAnomalyTimeStamp());
descriptor.setAttribution(new DiVectorMapper().toModel(state.getLastAnomalyAttribution()));
descriptor.setRCFPoint(state.getLastAnomalyPoint());
descriptor.setExpectedRCFPoint(state.getLastExpectedPoint());
descriptor.setRelativeIndex(state.getLastRelativeIndex());
descriptor.setForestMode(forestMode);
descriptor.setTransformMethod(transformMethod);
descriptor.setImputationMethod(ImputationMethod.valueOf(state.getPreprocessorStates()[0].getImputationMethod()));
PredictorCorrector predictorCorrector = new PredictorCorrector(thresholder);
predictorCorrector.setIgnoreSimilar(state.isIgnoreSimilar());
predictorCorrector.setIgnoreSimilarFactor(state.getIgnoreSimilarFactor());
predictorCorrector.setTriggerFactor(state.getTriggerFactor());
predictorCorrector.setNumberOfAttributors(state.getNumberOfAttributors());
return new ThresholdedRandomCutForest(forestMode, transformMethod, forest, predictorCorrector, preprocessor, descriptor);
}
Aggregations