Search in sources :

Example 1 with SimulatedTransductiveScalarScoreVisitor

use of com.amazon.randomcutforest.anomalydetection.SimulatedTransductiveScalarScoreVisitor in project random-cut-forest-by-aws by aws.

the class RandomCutForest method getDynamicSimulatedScore.

/**
 * Similar to above but now the scoring takes in a function of Bounding Box to
 * probabilities (vector over the dimensions); and produces a score af-if the
 * tree were built using that function (when in reality the tree is an RCF).
 * Changing the defaultRCFgVec function to some other function f() will provide
 * a mechanism of dynamic scoring for trees that are built using f() which is
 * the purpose of TransductiveScalarScore visitor. Note that the answer is an
 * MCMC simulation and is not normalized (because the scoring functions are
 * flexible and unknown) and over a small number of trees the errors can be
 * large specially if vecSep is very far from defaultRCFgVec
 *
 * Given the large number of possible sources of distortion, ignoreLeafThreshold
 * is not supported.
 *
 * @param point  point to be scored
 * @param seen   the score function for seen point
 * @param unseen score function for unseen points
 * @param damp   dampening the score for duplicates
 * @param vecSep the function of (BoundingBox) -> array of probabilities
 * @return the simuated score
 */
public double getDynamicSimulatedScore(float[] point, BiFunction<Double, Double, Double> seen, BiFunction<Double, Double, Double> unseen, BiFunction<Double, Double, Double> damp, Function<IBoundingBoxView, double[]> vecSep) {
    if (!isOutputReady()) {
        return 0.0;
    }
    VisitorFactory<Double> visitorFactory = new VisitorFactory<>((tree, y) -> new SimulatedTransductiveScalarScoreVisitor(tree.projectToTree(y), tree.getMass(), seen, unseen, damp, CommonUtils::defaultRCFgVecFunction, vecSep));
    BinaryOperator<Double> accumulator = Double::sum;
    Function<Double, Double> finisher = sum -> sum / numberOfTrees;
    return traverseForest(transformToShingledPoint(point), visitorFactory, accumulator, finisher);
}
Also used : CommonUtils.checkNotNull(com.amazon.randomcutforest.CommonUtils.checkNotNull) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) ParallelForestTraversalExecutor(com.amazon.randomcutforest.executor.ParallelForestTraversalExecutor) Random(java.util.Random) ParallelForestUpdateExecutor(com.amazon.randomcutforest.executor.ParallelForestUpdateExecutor) AbstractForestUpdateExecutor(com.amazon.randomcutforest.executor.AbstractForestUpdateExecutor) IStateCoordinator(com.amazon.randomcutforest.executor.IStateCoordinator) RandomCutTree(com.amazon.randomcutforest.tree.RandomCutTree) CommonUtils.toFloatArray(com.amazon.randomcutforest.CommonUtils.toFloatArray) Neighbor(com.amazon.randomcutforest.returntypes.Neighbor) ConditionalSampleSummarizer(com.amazon.randomcutforest.imputation.ConditionalSampleSummarizer) ImputeVisitor(com.amazon.randomcutforest.imputation.ImputeVisitor) NearNeighborVisitor(com.amazon.randomcutforest.inspect.NearNeighborVisitor) IBoundingBoxView(com.amazon.randomcutforest.tree.IBoundingBoxView) Collector(java.util.stream.Collector) PointStoreCoordinator(com.amazon.randomcutforest.executor.PointStoreCoordinator) AnomalyAttributionVisitor(com.amazon.randomcutforest.anomalydetection.AnomalyAttributionVisitor) OneSidedConvergingDoubleAccumulator(com.amazon.randomcutforest.returntypes.OneSidedConvergingDoubleAccumulator) AnomalyScoreVisitor(com.amazon.randomcutforest.anomalydetection.AnomalyScoreVisitor) AbstractForestTraversalExecutor(com.amazon.randomcutforest.executor.AbstractForestTraversalExecutor) BinaryOperator(java.util.function.BinaryOperator) SequentialForestTraversalExecutor(com.amazon.randomcutforest.executor.SequentialForestTraversalExecutor) List(java.util.List) Math.max(java.lang.Math.max) Optional(java.util.Optional) DensityOutput(com.amazon.randomcutforest.returntypes.DensityOutput) CommonUtils.toDoubleArray(com.amazon.randomcutforest.CommonUtils.toDoubleArray) Precision(com.amazon.randomcutforest.config.Precision) CompactSampler(com.amazon.randomcutforest.sampler.CompactSampler) SamplerPlusTree(com.amazon.randomcutforest.executor.SamplerPlusTree) ShingleBuilder(com.amazon.randomcutforest.util.ShingleBuilder) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SimulatedTransductiveScalarScoreVisitor(com.amazon.randomcutforest.anomalydetection.SimulatedTransductiveScalarScoreVisitor) PointStore(com.amazon.randomcutforest.store.PointStore) DynamicAttributionVisitor(com.amazon.randomcutforest.anomalydetection.DynamicAttributionVisitor) ConvergingAccumulator(com.amazon.randomcutforest.returntypes.ConvergingAccumulator) Config(com.amazon.randomcutforest.config.Config) SimpleInterpolationVisitor(com.amazon.randomcutforest.interpolation.SimpleInterpolationVisitor) InterpolationMeasure(com.amazon.randomcutforest.returntypes.InterpolationMeasure) IPointStore(com.amazon.randomcutforest.store.IPointStore) SequentialForestUpdateExecutor(com.amazon.randomcutforest.executor.SequentialForestUpdateExecutor) ArrayUtils(com.amazon.randomcutforest.util.ArrayUtils) OneSidedConvergingDiVectorAccumulator(com.amazon.randomcutforest.returntypes.OneSidedConvergingDiVectorAccumulator) CommonUtils.checkArgument(com.amazon.randomcutforest.CommonUtils.checkArgument) DynamicScoreVisitor(com.amazon.randomcutforest.anomalydetection.DynamicScoreVisitor) DiVector(com.amazon.randomcutforest.returntypes.DiVector) ITree(com.amazon.randomcutforest.tree.ITree) ConditionalTreeSample(com.amazon.randomcutforest.returntypes.ConditionalTreeSample) ConditionalSampleSummary(com.amazon.randomcutforest.returntypes.ConditionalSampleSummary) Collections(java.util.Collections) IStreamSampler(com.amazon.randomcutforest.sampler.IStreamSampler) SimulatedTransductiveScalarScoreVisitor(com.amazon.randomcutforest.anomalydetection.SimulatedTransductiveScalarScoreVisitor)

Aggregations

CommonUtils.checkArgument (com.amazon.randomcutforest.CommonUtils.checkArgument)1 CommonUtils.checkNotNull (com.amazon.randomcutforest.CommonUtils.checkNotNull)1 CommonUtils.toDoubleArray (com.amazon.randomcutforest.CommonUtils.toDoubleArray)1 CommonUtils.toFloatArray (com.amazon.randomcutforest.CommonUtils.toFloatArray)1 AnomalyAttributionVisitor (com.amazon.randomcutforest.anomalydetection.AnomalyAttributionVisitor)1 AnomalyScoreVisitor (com.amazon.randomcutforest.anomalydetection.AnomalyScoreVisitor)1 DynamicAttributionVisitor (com.amazon.randomcutforest.anomalydetection.DynamicAttributionVisitor)1 DynamicScoreVisitor (com.amazon.randomcutforest.anomalydetection.DynamicScoreVisitor)1 SimulatedTransductiveScalarScoreVisitor (com.amazon.randomcutforest.anomalydetection.SimulatedTransductiveScalarScoreVisitor)1 Config (com.amazon.randomcutforest.config.Config)1 Precision (com.amazon.randomcutforest.config.Precision)1 AbstractForestTraversalExecutor (com.amazon.randomcutforest.executor.AbstractForestTraversalExecutor)1 AbstractForestUpdateExecutor (com.amazon.randomcutforest.executor.AbstractForestUpdateExecutor)1 IStateCoordinator (com.amazon.randomcutforest.executor.IStateCoordinator)1 ParallelForestTraversalExecutor (com.amazon.randomcutforest.executor.ParallelForestTraversalExecutor)1 ParallelForestUpdateExecutor (com.amazon.randomcutforest.executor.ParallelForestUpdateExecutor)1 PointStoreCoordinator (com.amazon.randomcutforest.executor.PointStoreCoordinator)1 SamplerPlusTree (com.amazon.randomcutforest.executor.SamplerPlusTree)1 SequentialForestTraversalExecutor (com.amazon.randomcutforest.executor.SequentialForestTraversalExecutor)1 SequentialForestUpdateExecutor (com.amazon.randomcutforest.executor.SequentialForestUpdateExecutor)1