Search in sources :

Example 6 with Neighbor

use of com.amazon.randomcutforest.returntypes.Neighbor in project random-cut-forest-by-aws by aws.

the class NearNeighborVisitorTest method acceptLeafNearTimestampsDisabled.

@Test
public void acceptLeafNearTimestampsDisabled() {
    float[] leafPoint = new float[] { 8.8f, 9.9f, -5.5f };
    INodeView leafNode = mock(NodeView.class);
    when(leafNode.getLiftedLeafPoint()).thenReturn(Arrays.copyOf(leafPoint, leafPoint.length));
    when(leafNode.getLeafPoint()).thenReturn(Arrays.copyOf(leafPoint, leafPoint.length));
    assertEquals(0, leafNode.getSequenceIndexes().size());
    int depth = 12;
    visitor.acceptLeaf(leafNode, depth);
    Optional<Neighbor> optional = visitor.getResult();
    assertTrue(optional.isPresent());
    Neighbor neighbor = optional.get();
    assertNotSame(leafPoint, neighbor.point);
    assertArrayEquals(toDoubleArray(leafPoint), neighbor.point);
    assertEquals(Math.sqrt(3 * 1.1 * 1.1), neighbor.distance, EPSILON);
    assertTrue(neighbor.sequenceIndexes.isEmpty());
}
Also used : Neighbor(com.amazon.randomcutforest.returntypes.Neighbor) INodeView(com.amazon.randomcutforest.tree.INodeView) Test(org.junit.jupiter.api.Test)

Aggregations

Neighbor (com.amazon.randomcutforest.returntypes.Neighbor)6 Test (org.junit.jupiter.api.Test)5 INodeView (com.amazon.randomcutforest.tree.INodeView)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2