Nearest Neighbors
- kerch.method.knn(dists: Tensor, observations: Tensor, num: int = 1) Tensor[source]
For each distance
dists, returns the average of thenumsmallest corresponding observations.- Parameters:
dists (torch.Tensor [num_points, num_observations]) – coefficients used in the knn.
observations (torch.Tensor [num_observations, dim_observations]) – observation corresponding to each weight dimension.
num (int, optional) – number of nearest neighbors. Defaults to 1.
- Returns:
KNN
- Return type:
torch.Tensor [num_points, dim_observations]
- kerch.method.kernel_knn(domain: Tensor, observations: Tensor, num: int = 1, kernel_type: str = 'rbf', **kwargs) Tensor[source]
For each coefficient, returns the average of the
numgreatest corresponding kernel values on the domain. The kernel is defined as inkerch.kernel.factory().- Parameters:
domain (torch.Tensor [num_observations, dim_domain]) – domain corresponding to each observation.
observations (torch.Tensor [num_observations, dim_observations]) – observation corresponding to each domain entry.
num (int, optional) – number of nearest neighbors. Defaults to 1.
kernel_type (str, optional) – Type of kernel chosen. For the possible choices, please refer to the Factory Type column of the Kernel Module documentation. Defaults to
kerch.DEFAULT_KERNEL_TYPE.**kwargs (dict, optional) – Arguments to be passed to the kernel constructor, such as sample or sigma. If an argument is passed that does not exist (e.g. sigma to a linear kernel), it will just be neglected. For the default values, please refer to the default values of the requested kernel.
- Returns:
KNN
- Return type:
torch.Tensor [num_points, dim_observations]