use of com.amazon.randomcutforest.anomalydetection.DynamicScoreVisitor in project random-cut-forest-by-aws by aws.
the class RandomCutForest method getDynamicScore.
/**
* Score a point using the given scoring functions.
*
* @param point input point being scored
* @param ignoreLeafMassThreshold said threshold
* @param seen the function that applies if input is equal to
* a previously seen sample in a leaf
* @param unseen if the input does not have a match in the
* leaves
* @param damp damping function based on the duplicity of the
* previously seen samples
* @return anomaly score
*/
public double getDynamicScore(float[] point, int ignoreLeafMassThreshold, BiFunction<Double, Double, Double> seen, BiFunction<Double, Double, Double> unseen, BiFunction<Double, Double, Double> damp) {
checkArgument(ignoreLeafMassThreshold >= 0, "ignoreLeafMassThreshold should be greater than or equal to 0");
if (!isOutputReady()) {
return 0.0;
}
VisitorFactory<Double> visitorFactory = new VisitorFactory<>((tree, y) -> new DynamicScoreVisitor(tree.projectToTree(y), tree.getMass(), ignoreLeafMassThreshold, seen, unseen, damp));
BinaryOperator<Double> accumulator = Double::sum;
Function<Double, Double> finisher = sum -> sum / numberOfTrees;
return traverseForest(transformToShingledPoint(point), visitorFactory, accumulator, finisher);
}
use of com.amazon.randomcutforest.anomalydetection.DynamicScoreVisitor in project random-cut-forest-by-aws by aws.
the class RandomCutForest method getApproximateDynamicScore.
/**
* Score a point using the given scoring functions. This method will
* short-circuit before visiting all trees if the scores that are returned from
* a subset of trees appears to be converging to a given value. See
* {@link OneSidedConvergingDoubleAccumulator} for more about convergence.
*
* @param point input point
* @param precision controls early convergence
* @param highIsCritical this is true for the default scoring function.
* If the user wishes to use a different scoring
* function where anomaly scores are low values
* (for example, height in tree) then this should
* be set to false.
* @param ignoreLeafMassThreshold said threshold
* @param seen scoring function when the input matches some
* tuple in the leaves
* @param unseen scoring function when the input is not found
* @param damp dampening function for duplicates which are
* same as input (applies with seen)
* @return the dynamic score under sequential early stopping
*/
public double getApproximateDynamicScore(float[] point, double precision, boolean highIsCritical, int ignoreLeafMassThreshold, BiFunction<Double, Double, Double> seen, BiFunction<Double, Double, Double> unseen, BiFunction<Double, Double, Double> damp) {
checkArgument(ignoreLeafMassThreshold >= 0, "ignoreLeafMassThreshold should be greater than or equal to 0");
if (!isOutputReady()) {
return 0.0;
}
VisitorFactory<Double> visitorFactory = new VisitorFactory<>((tree, y) -> new DynamicScoreVisitor(tree.projectToTree(y), tree.getMass(), ignoreLeafMassThreshold, seen, unseen, damp));
ConvergingAccumulator<Double> accumulator = new OneSidedConvergingDoubleAccumulator(highIsCritical, precision, DEFAULT_APPROXIMATE_DYNAMIC_SCORE_MIN_VALUES_ACCEPTED, numberOfTrees);
Function<Double, Double> finisher = x -> x / accumulator.getValuesAccepted();
return traverseForest(transformToShingledPoint(point), visitorFactory, accumulator, finisher);
}
Aggregations