use of com.amazon.randomcutforest.tree.BoundingBox in project random-cut-forest-by-aws by aws.
the class ImputeVisitorTest method testMerge.
@Test
public void testMerge() {
float[] otherPoint = new float[] { 99, 100, 101 };
ImputeVisitor other = new ImputeVisitor(otherPoint, 0, new int[0]);
// set other.rank to a small value
NodeView node = mock(NodeView.class);
when(node.getLeafPoint()).thenReturn(new float[] { 0, 0, 0 });
when(node.getLiftedLeafPoint()).thenReturn(new float[] { 0, 0, 0 });
when(node.getBoundingBox()).thenReturn(new BoundingBox(new float[] { 0, 0, 0 }));
other.acceptLeaf(node, 99);
assertTrue(other.getAnomalyRank() < visitor.getAnomalyRank());
other.combine(visitor);
assertArrayEquals(otherPoint, other.getResult().leafPoint);
visitor.combine(other);
assertArrayEquals(otherPoint, visitor.getResult().leafPoint);
}
use of com.amazon.randomcutforest.tree.BoundingBox in project random-cut-forest-by-aws by aws.
the class ImputeVisitorTest method testAcceptLeafEqualsZeroDepth.
@Test
public void testAcceptLeafEqualsZeroDepth() {
float[] point = { queryPoint[0], 2.0f, queryPoint[2] };
INodeView leafNode = mock(NodeView.class);
when(leafNode.getLeafPoint()).thenReturn(point);
when(leafNode.getLiftedLeafPoint()).thenReturn(point);
when(leafNode.getBoundingBox()).thenReturn(new BoundingBox(point, point));
int leafDepth = 0;
int leafMass = 10;
when(leafNode.getMass()).thenReturn(leafMass);
visitor.acceptLeaf(leafNode, leafDepth);
float[] expected = new float[] { -1.0f, 2.0f, 3.0f };
assertArrayEquals(expected, visitor.getResult().leafPoint);
assertEquals(0.0, visitor.getAnomalyRank());
}
use of com.amazon.randomcutforest.tree.BoundingBox in project random-cut-forest-by-aws by aws.
the class ImputeVisitorTest method testAccept.
@Test
public void testAccept() {
float[] point = { queryPoint[0], 2.0f, -111.11f };
INodeView node = mock(NodeView.class);
when(node.getLeafPoint()).thenReturn(point);
when(node.getLiftedLeafPoint()).thenReturn(point);
when(node.getBoundingBox()).thenReturn(new BoundingBox(point, point));
int depth = 100;
int leafMass = 10;
when(node.getMass()).thenReturn(leafMass);
visitor.acceptLeaf(node, depth);
float[] expected = new float[] { -1.0f, 2.0f, 3.0f };
assertArrayEquals(expected, visitor.getResult().leafPoint);
assertEquals(defaultScoreUnseenFunction(depth, leafMass), visitor.getAnomalyRank());
depth--;
IBoundingBoxView boundingBox = node.getBoundingBox().getMergedBox(new float[] { 99.0f, 4.0f, -19.0f });
when(node.getBoundingBox()).thenReturn(boundingBox);
when(node.probailityOfSeparation(any())).thenReturn(CommonUtils.getProbabilityOfSeparation(boundingBox, expected));
when(node.getMass()).thenReturn(leafMass + 2);
double oldRank = visitor.getAnomalyRank();
visitor.accept(node, depth);
assertArrayEquals(expected, visitor.getResult().leafPoint);
double p = CommonUtils.getProbabilityOfSeparation(boundingBox, expected);
double expectedRank = p * defaultScoreUnseenFunction(depth, node.getMass()) + (1 - p) * oldRank;
assertEquals(expectedRank, visitor.getAnomalyRank(), EPSILON);
}
use of com.amazon.randomcutforest.tree.BoundingBox in project random-cut-forest-by-aws by aws.
the class ImputeVisitorTest method testAcceptLeafNotEquals.
@Test
public void testAcceptLeafNotEquals() {
float[] point = { queryPoint[0], 2.0f, -111.11f };
INodeView leafNode = mock(NodeView.class);
when(leafNode.getLeafPoint()).thenReturn(point);
when(leafNode.getLiftedLeafPoint()).thenReturn(point);
when(leafNode.getBoundingBox()).thenReturn(new BoundingBox(point, point));
int leafDepth = 100;
int leafMass = 10;
when(leafNode.getMass()).thenReturn(leafMass);
visitor.acceptLeaf(leafNode, leafDepth);
float[] expected = new float[] { -1.0f, 2.0f, 3.0f };
assertArrayEquals(expected, visitor.getResult().leafPoint);
assertEquals(defaultScoreUnseenFunction(leafDepth, leafMass), visitor.getAnomalyRank());
}
use of com.amazon.randomcutforest.tree.BoundingBox in project random-cut-forest-by-aws by aws.
the class AnomalyScoreVisitorTest method testAcceptLeafNotEquals.
@Test
public void testAcceptLeafNotEquals() {
float[] point = new float[] { 1.0f, 2.0f, 3.0f };
float[] anotherPoint = new float[] { 4.0f, 5.0f, 6.0f };
INodeView leafNode = mock(NodeView.class);
when(leafNode.getLeafPoint()).thenReturn(anotherPoint);
when(leafNode.getBoundingBox()).thenReturn(new BoundingBox(anotherPoint, anotherPoint));
int leafDepth = 100;
AnomalyScoreVisitor visitor = new AnomalyScoreVisitor(point, 2);
visitor.acceptLeaf(leafNode, leafDepth);
double expectedScore = 1.0 / (leafDepth + 1);
assertThat(visitor.getResult(), closeTo(CommonUtils.defaultScalarNormalizerFunction(expectedScore, 2), EPSILON));
assertFalse(visitor.pointInsideBox);
}
Aggregations