Typical workflow for radius neighbors - 5.2 English - 68552

AOCL API Guide (68552)

Document ID
68552
Release Date
2025-12-29
Version
5.2 English

The standard way of computing the radius neighbors using AOCL-DA is as follows.

  1. Initialize a aoclda.nearest_neighbors.nearest_neighbors() object with options set in the class constructor.

  2. Fit the nearest neighbors for your training data set using aoclda.nearest_neighbors.nearest_neighbors.fit().

  3. Compute the indices of the neighbors and optionally the corresponding distances using aoclda.nearest_neighbors.nearest_neighbors.radius_neighbors().

  1. Initialize a da_handle with da_handle_type da_handle_nn.

  2. Pass data to the handle using da_nn_classifier_set_training_data_?.

  3. Set the radius of neighbors required and the metric or weights used in radius neighbors using da_options_set_? (see below).

  4. Compute the radius neighbors and optionally the corresponding distances for each data point using da_nn_radius_neighbors_?.

  5. Extract results using da_handle_get_result_?. The following results are available:

    • Number of neighbors for each query point using da_nn_radius_neighbors_count. The size of the output array is equal to the number of query points plus one. The last element contains the total number of neighbors found for all query points and can be used for memory allocation.

    • Indices of neighbors for each query point using da_nn_radius_neighbors_indices_index. The size of the output array is equal to the number of neighbors found for the specific query point.

    • Distances to neighbors for each query point using da_nn_radius_neighbors_distances_index, if available. The size of the output array is equal to the number of neighbors found for the specific query point.

    • Offsets to locate the neighbors for each query point using da_nn_radius_neighbors_offsets. The size of the output array is equal to the number of query points plus one. For query points where no neighbors were found, the offsets will be -1.

    • Indices of neighbors for all query points using da_nn_radius_neighbors_indices. The size of the output array is equal to the total number of neighbors found for all query points.

    • Distances to neighbors for all query points using da_nn_radius_neighbors_distances, if available. The size of the output array is equal to the total number of neighbors found for all query points.

    Note

    We can extract all indices and distances of neighbors for all query points at once using da_nn_radius_neighbors_offsets, da_nn_radius_neighbors_indices and da_nn_radius_neighbors_distances. Otherwise, we can extract the indices and distances of neighbors for a specific query point using da_nn_radius_neighbors_count to find out how much memory to allocate and da_nn_radius_neighbors_indices_index and da_nn_radius_neighbors_distances_index.