use of com.amazon.randomcutforest.anomalydetection.DynamicAttributionVisitor in project random-cut-forest-by-aws by aws.
the class RandomCutForest method getApproximateDynamicAttribution.
/**
* Atrribution for dynamic sequential scoring; getL1Norm() should agree with
* getDynamicScoringSequential
*
* @param point input
* @param precision parameter to stop early stopping
* @param highIsCritical are high values anomalous (otherwise low
* values are anomalous)
* @param ignoreLeafMassThreshold we ignore leaves with mass equal/below *
* threshold
* @param seen function for scoring points that have been
* seen before
* @param unseen function for scoring points not seen in tree
* @param newDamp dampening function based on duplicates
* @return attribution DiVector of the score
*/
public DiVector getApproximateDynamicAttribution(float[] point, double precision, boolean highIsCritical, int ignoreLeafMassThreshold, BiFunction<Double, Double, Double> seen, BiFunction<Double, Double, Double> unseen, BiFunction<Double, Double, Double> newDamp) {
if (!isOutputReady()) {
return new DiVector(dimensions);
}
VisitorFactory<DiVector> visitorFactory = new VisitorFactory<>((tree, y) -> new DynamicAttributionVisitor(y, tree.getMass(), ignoreLeafMassThreshold, seen, unseen, newDamp), (tree, x) -> x.lift(tree::liftFromTree));
ConvergingAccumulator<DiVector> accumulator = new OneSidedConvergingDiVectorAccumulator(dimensions, highIsCritical, precision, DEFAULT_APPROXIMATE_DYNAMIC_SCORE_MIN_VALUES_ACCEPTED, numberOfTrees);
Function<DiVector, DiVector> finisher = vector -> vector.scale(1.0 / accumulator.getValuesAccepted());
return traverseForest(transformToShingledPoint(point), visitorFactory, accumulator, finisher);
}
use of com.amazon.randomcutforest.anomalydetection.DynamicAttributionVisitor in project random-cut-forest-by-aws by aws.
the class RandomCutForest method getDynamicAttribution.
/**
* Same as above, but for dynamic scoring. See the params of
* getDynamicScoreParallel
*
* @param point point to be scored
* @param ignoreLeafMassThreshold said threshold
* @param seen score function for seen points
* @param unseen score function for unseen points
* @param newDamp dampening function for duplicates in the seen
* function
* @return dynamic scoring attribution DiVector
*/
public DiVector getDynamicAttribution(float[] point, int ignoreLeafMassThreshold, BiFunction<Double, Double, Double> seen, BiFunction<Double, Double, Double> unseen, BiFunction<Double, Double, Double> newDamp) {
if (!isOutputReady()) {
return new DiVector(dimensions);
}
VisitorFactory<DiVector> visitorFactory = new VisitorFactory<>((tree, y) -> new DynamicAttributionVisitor(tree.projectToTree(y), tree.getMass(), ignoreLeafMassThreshold, seen, unseen, newDamp), (tree, x) -> x.lift(tree::liftFromTree));
BinaryOperator<DiVector> accumulator = DiVector::addToLeft;
Function<DiVector, DiVector> finisher = x -> x.scale(1.0 / numberOfTrees);
return traverseForest(transformToShingledPoint(point), visitorFactory, accumulator, finisher);
}
Aggregations