注意

RAFT 中的向量搜索和聚类算法正在迁移到名为 cuVS 的新向量搜索专用库。在此迁移期间,我们将继续支持 RAFT 中的向量搜索算法,但在 RAPIDS 24.06(六月)版本后将不再更新它们。我们计划在 RAPIDS 24.10(十月)版本完成迁移,并在 24.12(十二月)版本中将它们完全从 RAFT 中移除。

聚类模型评分#

调整兰德指数 (Adjusted Rand Index)#

#include <raft/stats/adjusted_rand_index.cuh>

namespace raft::stats

template<typename value_t, typename math_t, typename idx_t>
double adjusted_rand_index(raft::resources const &handle, raft::device_vector_view<const value_t, idx_t> first_cluster_array, raft::device_vector_view<const value_t, idx_t> second_cluster_array)#

计算调整兰德指数的函数。

模板参数:
  • value_t – 输入标签数组的数据类型

  • math_t – 用于计算组合数 n 选 r 的整型数据类型

  • idx_t – 矩阵范围的索引类型。

参数:
  • handle[in] raft 句柄。

  • first_cluster_array[in] 类别的数组

  • second_cluster_array[in] 类别的数组

返回值:

调整兰德指数

完整性评分 (Completeness Score)#

#include <raft/stats/completeness_score.cuh>

namespace raft::stats

template<typename value_t, typename idx_t>
double completeness_score(raft::resources const &handle, raft::device_vector_view<const value_t, idx_t> truth_cluster_array, raft::device_vector_view<const value_t, idx_t> pred_cluster_array, value_t lower_label_range, value_t upper_label_range)#

计算两个聚类之间完整性评分的函数。

模板参数:
  • value_t – 数据类型

  • idx_t – 矩阵范围的索引类型。

参数:
  • handle[in] raft 句柄。

  • truth_cluster_array[in] 类型为 value_t 的真实类别数组

  • pred_cluster_array[in] 类型为 value_t 的预测类别数组

  • lower_label_range[in] 标签范围的下界

  • upper_label_range[in] 标签范围的上界

返回值:

聚类完整性评分

聚类离散度 (Cluster Dispersion)#

#include <raft/stats/dispersion.cuh>

namespace raft::stats

template<typename value_t, typename idx_t>
value_t cluster_dispersion(raft::resources const &handle, raft::device_matrix_view<const value_t, idx_t, raft::row_major> centroids, raft::device_vector_view<const idx_t, idx_t> cluster_sizes, std::optional<raft::device_vector_view<value_t, idx_t>> global_centroid, const idx_t n_points)#

计算聚类离散度指标。这对于自动查找改进此指标的 ‘k’(在 kmeans 中)非常有用。聚类离散度指标定义为聚类中心与全局中心之间平方距离之和的平方根。

模板参数:
  • value_t – 数据类型

  • idx_t – 索引类型

参数:
  • handle[in] raft 句柄

  • centroids[in] 聚类中心。假定为行主序,维度为 (n_clusters x dim)

  • cluster_sizes[in] 数据集中属于每个聚类的点数。长度为 n_clusters

  • global_centroid[out] 计算所有聚类中心的全局加权中心。长度为 dim。使用 std::nullopt 不返回它。

  • n_points[in] 数据集中的点数

返回值:

聚类离散度值

兰德指数 (Rand Index)#

#include <raft/stats/rand_index.cuh>

namespace raft::stats

template<typename value_t, typename idx_t>
double rand_index(raft::resources const &handle, raft::device_vector_view<const value_t, idx_t> first_cluster_array, raft::device_vector_view<const value_t, idx_t> second_cluster_array)#

计算兰德指数的函数 更多关于兰德指数的信息

模板参数:
  • value_t – 数据类型

  • idx_t – 索引类型

参数:
  • handle[in] raft 句柄

  • first_cluster_array[in] 类型为 value_t 的类别数组

  • second_cluster_array[in] 类型为 value_t 的类别数组

返回值:

: 兰德指数值。

轮廓系数 (Silhouette Score)#

#include <raft/stats/silhouette_score.cuh>

namespace raft::stats

template<typename value_t, typename label_t, typename idx_t>
value_t silhouette_score(raft::resources const &handle, raft::device_matrix_view<const value_t, idx_t, raft::row_major> X_in, raft::device_vector_view<const label_t, idx_t> labels, std::optional<raft::device_vector_view<value_t, idx_t>> silhouette_score_per_sample, idx_t n_unique_labels, raft::distance::DistanceType metric = raft::distance::DistanceType::L2Unexpanded)#

计算给定数据集及其聚类结果的平均轮廓系数的主函数

模板参数:
  • value_t – 数据样本的类型

  • label_t – 标签的类型

  • idx_t – 索引类型

参数:
  • handle[in] 用于管理昂贵资源的 raft 句柄

  • X_in[in] 输入矩阵数据,采用行主序格式 (nRows x nCols)

  • labels[in] 指向包含每个数据样本标签的数组的指针(长度: nRows)

  • silhouette_score_per_sample[out] 可选数组,填充了每个样本的轮廓系数(长度: nRows)

  • n_unique_labels[in] 标签数组中唯一标签的数量

  • metric[in] 映射到计算中使用的距离指标类型的数值

返回值:

: 轮廓系数。

template<typename value_t, typename label_t, typename idx_t>
value_t silhouette_score_batched(raft::resources const &handle, raft::device_matrix_view<const value_t, idx_t, raft::row_major> X, raft::device_vector_view<const label_t, idx_t> labels, std::optional<raft::device_vector_view<value_t, idx_t>> silhouette_score_per_sample, idx_t n_unique_labels, idx_t batch_size, raft::distance::DistanceType metric = raft::distance::DistanceType::L2Unexpanded)#

计算给定数据集及其聚类结果的平均轮廓系数的函数

模板参数:
  • value_t – 数据样本的类型

  • label_t – 标签的类型

  • idx_t – 索引类型

参数:
  • handle[in] 用于管理昂贵资源的 raft 句柄

  • X[in] 输入矩阵数据,采用行主序格式 (nRows x nCols)

  • labels[in] 指向包含每个数据样本标签的数组的指针(长度: nRows)

  • silhouette_score_per_sample[out] 可选数组,填充了每个样本的轮廓系数(长度: nRows)

  • n_unique_labels[in] 标签数组中唯一标签的数量

  • batch_size[in] 每批样本数

  • metric[in] 映射到计算中使用的距离指标类型的数值

返回值:

: 轮廓系数。

V 度量 (V Measure)#

#include <raft/stats/v_measure.cuh>

namespace raft::stats

template<typename value_t, typename idx_t>
double v_measure(raft::resources const &handle, raft::device_vector_view<const value_t, idx_t> truth_cluster_array, raft::device_vector_view<const value_t, idx_t> pred_cluster_array, value_t lower_label_range, value_t upper_label_range, double beta = 1.0)#

计算两个聚类之间 V 度量的函数。

模板参数:
  • value_t – 数据类型

  • idx_t – 用于寻址的整数类型

参数:
  • handle[in] raft 句柄

  • truth_cluster_array[in] 类型为 T 的真实类别数组

  • pred_cluster_array[in] 类型为 T 的预测类别数组

  • lower_label_range[in] 标签范围的下界

  • upper_label_range[in] 标签范围的上界

  • beta[in] v_measure 参数

返回值:

两个聚类之间的 V 度量