ML Namespace#
Warning
Primarily internal API: it may change or disappear without notice and has no stability, deprecation, backward-compatibility, or input-validation guarantees. Callers must validate inputs and satisfy all memory, stream, and lifetime preconditions. Prefer the supported Python API.
-
namespace ML#
Typedefs
-
using cuda_launch_t = unsigned int#
Integer type expected by CUDA launch configuration (
dim3components, shared-mem size, etc.).Prefer
ML::narrow_cast<ML::cuda_launch_t>(...)over a barenarrow_cast<unsigned int>(...)when the value is destined for a<<<>>>grid/block dimension. This keeps call sites self-documenting and lets us adapt to future CUDA API changes in one place.
-
using solver = raft::linalg::solver#
-
using mg_solver = raft::linalg::solver#
-
typedef paramsTSVDTemplate paramsTSVD#
-
typedef paramsPCATemplate paramsPCA#
-
typedef paramsPCATemplate<mg_solver> paramsPCAMG#
-
typedef paramsTSVDTemplate<mg_solver> paramsTSVDMG#
-
typedef IsolationForestModel<float> IsolationForestF#
-
typedef IsolationForestModel<double> IsolationForestD#
-
typedef RandomForestMetaData<float, int> RandomForestClassifierF#
-
typedef RandomForestMetaData<double, int> RandomForestClassifierD#
-
typedef RandomForestMetaData<float, float> RandomForestRegressorF#
-
typedef RandomForestMetaData<double, double> RandomForestRegressorD#
-
typedef int64_t knn_indices_dense_t#
-
typedef int knn_indices_sparse_t#
Enums
-
enum lr_type#
Values:
-
enumerator OPTIMAL#
-
enumerator CONSTANT#
-
enumerator INVSCALING#
-
enumerator ADAPTIVE#
-
enumerator OPTIMAL#
-
enum CRITERION#
Values:
-
enumerator GINI#
-
enumerator ENTROPY#
-
enumerator MSE#
-
enumerator MAE#
-
enumerator POISSON#
-
enumerator GAMMA#
-
enumerator INVERSE_GAUSSIAN#
-
enumerator CRITERION_END#
-
enumerator GINI#
Functions
- void hdbscan(
- const raft::handle_t &handle,
- const float *X,
- size_t m,
- size_t n,
- ML::distance::DistanceType metric,
- HDBSCAN::Common::HDBSCANParams ¶ms,
- HDBSCAN::Common::hdbscan_output<int64_t, float> &out,
- float *core_dists
Executes HDBSCAN clustering on an mxn-dimensional input array, X.
Note that while the algorithm is generally deterministic and should provide matching results between RAPIDS and the Scikit-learn Contrib versions, the construction of the k-nearest neighbors graph and minimum spanning tree can introduce differences between the two algorithms, especially when several nearest neighbors around a point might have the same distance. While the differences in the minimum spanning trees alone might be subtle, they can (and often will) lead to some points being assigned different cluster labels between the two implementations.
- Parameters:
handle – [in] raft handle for resource reuse
X – [in] array (size m, n) on device in row-major format
m – number of rows in X
n – number of columns in X
metric – distance metric to use
params – struct of configuration hyper-parameters
out – struct of output data and arrays on device
core_dists – array (size m, 1) of core distances
- void build_condensed_hierarchy(
- const raft::handle_t &handle,
- const int64_t *children,
- const float *delta,
- const int64_t *sizes,
- int min_cluster_size,
- int n_leaves,
- HDBSCAN::Common::CondensedHierarchy<int64_t, float> &condensed_tree
- void _extract_clusters(
- const raft::handle_t &handle,
- size_t n_leaves,
- int n_edges,
- int64_t *parents,
- int64_t *children,
- float *lambdas,
- int64_t *sizes,
- int64_t *labels,
- float *probabilities,
- HDBSCAN::Common::CLUSTER_SELECTION_METHOD cluster_selection_method,
- bool allow_single_cluster,
- int64_t max_cluster_size,
- float cluster_selection_epsilon
- void compute_all_points_membership_vectors(
- const raft::handle_t &handle,
- HDBSCAN::Common::CondensedHierarchy<int64_t, float> &condensed_tree,
- HDBSCAN::Common::PredictionData<int64_t, float> &prediction_data,
- const float *X,
- ML::distance::DistanceType metric,
- float *membership_vec,
- size_t batch_size = 4096
- void compute_membership_vector(
- const raft::handle_t &handle,
- HDBSCAN::Common::CondensedHierarchy<int64_t, float> &condensed_tree,
- HDBSCAN::Common::PredictionData<int64_t, float> &prediction_data,
- const float *X,
- const float *points_to_predict,
- size_t n_prediction_points,
- int min_samples,
- ML::distance::DistanceType metric,
- float *membership_vec,
- size_t batch_size = 4096
- void out_of_sample_predict(
- const raft::handle_t &handle,
- HDBSCAN::Common::CondensedHierarchy<int64_t, float> &condensed_tree,
- HDBSCAN::Common::PredictionData<int64_t, float> &prediction_data,
- const float *X,
- int64_t *labels,
- const float *points_to_predict,
- size_t n_prediction_points,
- ML::distance::DistanceType metric,
- int min_samples,
- int64_t *out_labels,
- float *out_probabilities
-
template<checked_target T, checked_source U>
T narrow_cast(U value)# Convert
valueto target typeT, trapping if the value does not fit (negative source with unsigned target, or magnitude exceedingT'srange).Use at sites where an existing API forces a narrowing — e.g. passing a
std::size_tsize to a function that takesint, or storing apair::firstinto anintvariable. The cast itself is preserved; this helper only ensures it doesn’t silently corrupt the value.When
Tis strictly wider thanUthe magnitude check is skipped (no bit-level loss is possible), so a misplacednarrow_cast<std::size_t>(int)on a non-negative value is a freestatic_cast. Sign-loss is still flagged: a negative source with an unsigned target traps regardless of widths, since sign loss is a real correctness bug even on a “widening” conversion.Example:
// Was: int n = m_shape.first; // silent narrow int n = ML::narrow_cast<int>(m_shape.first); // traps if first > INT_MAX
- Template Parameters:
T – target integral type
U – source integral type (deduced)
- Throws:
raft::exception – if
valuecannot be represented inT- Returns:
valueasT
-
template<checked_target T, checked_source U1, checked_source U2, checked_source... Us>
T checked_mul(
)# Multiply two or more integers in target type
T, trapping on overflow or on operands that cannot be represented inT.- Template Parameters:
T – target integral type (typically
std::size_torstd::int64_t)U1 – type of the first factor (deduced)
U2 – type of the second factor (deduced)
Us – types of additional factors (deduced)
- Throws:
raft::exception – on overflow or unrepresentable operand
- Returns:
the product as
T
-
template<checked_target T, checked_source U1, checked_source U2, checked_source... Us>
T checked_add(
)# Add two or more integers in target type
T, trapping on overflow or on operands that cannot be represented inT.
-
template<checked_target T, checked_source U1, checked_source U2>
T checked_sub(
)# Compute
a-bin target typeT, trapping on underflow or on operands that cannot be represented inT.For unsigned
Tthis enforcesa>=b.
-
template<checked_target T, checked_source U1, checked_source U2>
T checked_div(
)# Compute
a/bin target typeT, trapping on divide-by-zero (and on signedINT_MIN / -1overflow for signedT) or on operands that cannot be represented inT.
-
inline rapids_logger::sink_ptr default_sink()#
Returns the default sink for the global logger.
If the environment variable
CUML_DEBUG_LOG_FILEis defined, the default sink is a sink to that file. Otherwise, the default is to dump to stderr.- Returns:
sink_ptr The sink to use
-
inline std::string default_pattern()#
Returns the default log pattern for the global logger.
- Returns:
std::string The default log pattern.
-
inline rapids_logger::logger &default_logger()#
Get the default logger.
- Returns:
logger& The default logger
-
template<typename enum_solver>
inline raft::linalg::paramsTSVD to_raft_params( - const paramsTSVDTemplate<enum_solver> &ml_prms
-
template<typename enum_solver>
inline raft::linalg::paramsPCA to_raft_params( - const paramsPCATemplate<enum_solver> &ml_prms
- void pcaFit(
- const raft::handle_t &handle,
- float *input,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- float *mu,
- float *noise_vars,
- const paramsPCA &prms
- void pcaFit(
- const raft::handle_t &handle,
- double *input,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- double *mu,
- double *noise_vars,
- const paramsPCA &prms
- void pcaFitTransform(
- const raft::handle_t &handle,
- float *input,
- float *trans_input,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- float *mu,
- float *noise_vars,
- const paramsPCA &prms
- void pcaFitTransform(
- const raft::handle_t &handle,
- double *input,
- double *trans_input,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- double *mu,
- double *noise_vars,
- const paramsPCA &prms
- void pcaInverseTransform(
- const raft::handle_t &handle,
- float *trans_input,
- float *components,
- float *singular_vals,
- float *mu,
- float *input,
- const paramsPCA &prms
- void pcaInverseTransform(
- const raft::handle_t &handle,
- double *trans_input,
- double *components,
- double *singular_vals,
- double *mu,
- double *input,
- const paramsPCA &prms
- void pcaTransform(
- const raft::handle_t &handle,
- float *input,
- float *components,
- float *trans_input,
- float *singular_vals,
- float *mu,
- const paramsPCA &prms
- void pcaTransform(
- const raft::handle_t &handle,
- double *input,
- double *components,
- double *trans_input,
- double *singular_vals,
- double *mu,
- const paramsPCA &prms
- void tsvdFit(
- const raft::handle_t &handle,
- float *input,
- float *components,
- float *singular_vals,
- const paramsTSVD &prms
- void tsvdFit(
- const raft::handle_t &handle,
- double *input,
- double *components,
- double *singular_vals,
- const paramsTSVD &prms
- void tsvdInverseTransform(
- const raft::handle_t &handle,
- float *trans_input,
- float *components,
- float *input,
- const paramsTSVD &prms
- void tsvdInverseTransform(
- const raft::handle_t &handle,
- double *trans_input,
- double *components,
- double *input,
- const paramsTSVD &prms
- void tsvdTransform(
- const raft::handle_t &handle,
- float *input,
- float *components,
- float *trans_input,
- const paramsTSVD &prms
- void tsvdTransform(
- const raft::handle_t &handle,
- double *input,
- double *components,
- double *trans_input,
- const paramsTSVD &prms
- void tsvdFitTransform(
- const raft::handle_t &handle,
- float *input,
- float *trans_input,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- const paramsTSVD &prms
- void tsvdFitTransform(
- const raft::handle_t &handle,
- double *input,
- double *trans_input,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- const paramsTSVD &prms
-
template<typename T>
CompactIFForest<T> get_compact_trees( - const raft::handle_t &handle,
- const IsolationForestModel<T> *model
Extract compact tree data from a trained model for export.
Efficiently copies only the used nodes (~400 KB for 100 trees) instead of the full padded storage (~200 MB).
-
double compute_c_normalization(int n)#
Compute c(n) = 2H(n-1) - 2(n-1)/n normalization constant.
-
template<typename T>
void build_treelite_isolation_forest( - TreeliteModelHandle *model_handle,
- const raft::handle_t &handle,
- const IsolationForestModel<T> *forest
Build a Treelite regression forest from a trained Isolation Forest model.
The exported Treelite model predicts average path length across trees. The Isolation Forest anomaly score transform, s(x) = 2^(-E[h(x)] / c(n)), is intentionally applied by callers so exported tree structure stays faithful to the trained isolation trees.
- Parameters:
model_handle – [out] Treelite model handle owned by the caller
handle – [in] RAFT handle for GPU resources
forest – [in] Trained Isolation Forest model
- void fit(
- const raft::handle_t &handle,
- IsolationForestF *forest,
- const float *input,
- size_t n_rows,
- int n_cols,
- const IF_params ¶ms,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
Fit an Isolation Forest model.
- Parameters:
handle – [in] RAFT handle for GPU resources
forest – [out] Model to populate with trained trees
input – [in] Training data, column-major [n_rows × n_cols], device pointer
n_rows – [in] Number of training samples
n_cols – [in] Number of features
params – [in] Hyperparameters (n_estimators, max_samples, max_depth, seed)
verbosity – [in] Logging level
- void fit(
- const raft::handle_t &handle,
- IsolationForestD *forest,
- const double *input,
- size_t n_rows,
- int n_cols,
- const IF_params ¶ms,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
-
template<typename T>
void fit_treelite( - const raft::handle_t &handle,
- TreeliteModelHandle *model_handle,
- const T *input,
- size_t n_rows,
- int n_cols,
- const IF_params ¶ms,
- double *c_normalization,
- int *feature_indices,
- size_t feature_indices_size,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
Fit an Isolation Forest and export it as a Treelite model.
- Parameters:
handle – [in] RAFT handle for GPU resources
model_handle – [out] Treelite model handle owned by the caller
input – [in] Training data, column-major [n_rows × n_cols], device pointer
n_rows – [in] Number of training samples
n_cols – [in] Number of features
params – [in] Hyperparameters (n_estimators, max_samples, max_depth, seed)
c_normalization – [out] Normalization constant c(n) for the trained forest, needed to turn average path lengths into anomaly scores
feature_indices – [out] Host buffer receiving each tree’s sampled feature indices in row-major [n_estimators, resolved max_features] order
feature_indices_size – [in] Number of elements available in feature_indices
verbosity – [in] Logging level
- void score_samples(
- const raft::handle_t &handle,
- const IsolationForestF *forest,
- const float *input,
- size_t n_rows,
- int n_cols,
- float *scores,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
Compute anomaly scores.
Returns scores following the original paper convention (Liu et al. 2008):
Score ≈ 1.0: anomaly (isolated quickly)
Score ≈ 0.5: normal (average isolation depth)
Score ≈ 0.0: very normal (hard to isolate)
- Parameters:
handle – [in] RAFT handle for GPU resources
forest – [in] Trained Isolation Forest model
input – [in] Test data, row-major [n_rows × n_cols], device pointer
n_rows – [in] Number of test samples
n_cols – [in] Number of features (must match training)
scores – [out] Anomaly scores [n_rows], device pointer
verbosity – [in] Logging level
- void score_samples(
- const raft::handle_t &handle,
- const IsolationForestD *forest,
- const double *input,
- size_t n_rows,
- int n_cols,
- double *scores,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- void predict(
- const raft::handle_t &handle,
- const IsolationForestF *forest,
- const float *input,
- size_t n_rows,
- int n_cols,
- int *predictions,
- float threshold = 0.5f,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
Predict anomaly labels.
- Parameters:
handle – [in] RAFT handle for GPU resources
forest – [in] Trained Isolation Forest model
input – [in] Test data, row-major [n_rows × n_cols], device pointer
n_rows – [in] Number of test samples
n_cols – [in] Number of features (must match training)
predictions – [out] Labels [n_rows]: 1 = anomaly, -1 = normal, device pointer
threshold – [in] Score threshold (default 0.5); scores strictly above it are anomalies
verbosity – [in] Logging level
- void predict(
- const raft::handle_t &handle,
- const IsolationForestD *forest,
- const double *input,
- size_t n_rows,
- int n_cols,
- int *predictions,
- double threshold = 0.5,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_metrics set_all_rf_metrics(
- RF_type rf_type,
- float accuracy,
- double mean_abs_error,
- double mean_squared_error,
- double median_abs_error
-
RF_metrics set_rf_metrics_classification(float accuracy)#
- RF_metrics set_rf_metrics_regression(
- double mean_abs_error,
- double mean_squared_error,
- double median_abs_error
-
void print(const RF_metrics rf_metrics)#
- void preprocess_labels(
- int n_rows,
- std::vector<int> &labels,
- std::map<int, int> &labels_map,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- void postprocess_labels(
- int n_rows,
- std::vector<int> &labels,
- std::map<int, int> &labels_map,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
-
template<class T, class L>
void delete_rf_metadata( - RandomForestMetaData<T, L> *forest
-
template<class T, class L>
std::string get_rf_summary_text( - const RandomForestMetaData<T, L> *forest
-
template<class T, class L>
std::string get_rf_detailed_text( - const RandomForestMetaData<T, L> *forest
-
template<class T, class L>
std::string get_rf_json( - const RandomForestMetaData<T, L> *forest
-
template<class T, class L>
void build_treelite_forest( - TreeliteModelHandle *model,
- const RandomForestMetaData<T, L> *forest,
- int num_features
-
template<class T, class L>
void compute_feature_importances( - const RandomForestMetaData<T, L> *forest,
- T *importances
Compute the feature importances of the trained RandomForest model.
- Template Parameters:
T – data type for input data (float or double).
L – data type for labels (int type for classification, T type for regression).
- Parameters:
forest – [in] CPU pointer to RandomForestMetaData
importances – [out] output feature importance scores
- void fit(
- const raft::handle_t &user_handle,
- RandomForestClassifierF *forest,
- float *input,
- int n_rows,
- int n_cols,
- int *labels,
- int n_unique_labels,
- RF_params rf_params,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info,
- bool *bootstrap_masks = nullptr,
- const double *sample_weight = nullptr,
- bool input_row_major = false
- void fit(
- const raft::handle_t &user_handle,
- RandomForestClassifierD *forest,
- double *input,
- int n_rows,
- int n_cols,
- int *labels,
- int n_unique_labels,
- RF_params rf_params,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info,
- bool *bootstrap_masks = nullptr,
- const double *sample_weight = nullptr,
- bool input_row_major = false
-
template<typename T, typename L>
void fit_treelite( - const raft::handle_t &user_handle,
- TreeliteModelHandle *model,
- T *input,
- int n_rows,
- int n_cols,
- L *labels,
- int n_unique_labels,
- RF_params rf_params,
- bool *bootstrap_masks,
- T *feature_importances,
- rapids_logger::level_enum verbosity,
- const double *sample_weight = nullptr,
- bool input_row_major = false
Train a random forest classifier and export it as a Treelite model.
- Parameters:
user_handle – [in] RAFT handle for stream and allocator resources.
model – [out] Treelite model handle populated by training.
input – [in] Training data, column-major by default or row-major when input_row_major is true.
n_rows – [in] Number of rows in input.
n_cols – [in] Number of columns in input.
labels – [in] Training labels.
n_unique_labels – [in] Number of unique classes in labels.
rf_params – [in] Random forest training parameters.
bootstrap_masks – [in] Optional bootstrap masks.
feature_importances – [out] Output feature importances.
verbosity – [in] Logging verbosity.
sample_weight – [in] Optional per-row sample weights.
input_row_major – [in] Whether input is row-major instead of column-major.
- void predict(
- const raft::handle_t &user_handle,
- const RandomForestClassifierF *forest,
- const float *input,
- int n_rows,
- int n_cols,
- int *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- void predict(
- const raft::handle_t &user_handle,
- const RandomForestClassifierD *forest,
- const double *input,
- int n_rows,
- int n_cols,
- int *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_metrics score(
- const raft::handle_t &user_handle,
- const RandomForestClassifierF *forest,
- const int *ref_labels,
- int n_rows,
- const int *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_metrics score(
- const raft::handle_t &user_handle,
- const RandomForestClassifierD *forest,
- const int *ref_labels,
- int n_rows,
- const int *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_params set_rf_params(
- int max_depth,
- int max_leaves,
- float max_features,
- int max_n_bins,
- int min_samples_leaf,
- int min_samples_split,
- float min_impurity_decrease,
- bool bootstrap,
- int n_trees,
- float max_samples,
- uint64_t seed,
- CRITERION split_criterion,
- int cfg_n_streams,
- int max_batch_size
- void fit(
- const raft::handle_t &user_handle,
- RandomForestRegressorF *forest,
- float *input,
- int n_rows,
- int n_cols,
- float *labels,
- RF_params rf_params,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info,
- bool *bootstrap_masks = nullptr,
- const double *sample_weight = nullptr,
- bool input_row_major = false
- void fit(
- const raft::handle_t &user_handle,
- RandomForestRegressorD *forest,
- double *input,
- int n_rows,
- int n_cols,
- double *labels,
- RF_params rf_params,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info,
- bool *bootstrap_masks = nullptr,
- const double *sample_weight = nullptr,
- bool input_row_major = false
-
template<typename T, typename L>
void fit_treelite( - const raft::handle_t &user_handle,
- TreeliteModelHandle *model,
- T *input,
- int n_rows,
- int n_cols,
- L *labels,
- RF_params rf_params,
- bool *bootstrap_masks,
- T *feature_importances,
- rapids_logger::level_enum verbosity,
- const double *sample_weight = nullptr,
- bool input_row_major = false
Train a random forest regressor and export it as a Treelite model.
- Parameters:
user_handle – [in] RAFT handle for stream and allocator resources.
model – [out] Treelite model handle populated by training.
input – [in] Training data, column-major by default or row-major when input_row_major is true.
n_rows – [in] Number of rows in input.
n_cols – [in] Number of columns in input.
labels – [in] Training labels.
rf_params – [in] Random forest training parameters.
bootstrap_masks – [in] Optional bootstrap masks.
feature_importances – [out] Output feature importances.
verbosity – [in] Logging verbosity.
sample_weight – [in] Optional per-row sample weights.
input_row_major – [in] Whether input is row-major instead of column-major.
- void predict(
- const raft::handle_t &user_handle,
- const RandomForestRegressorF *forest,
- const float *input,
- int n_rows,
- int n_cols,
- float *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- void predict(
- const raft::handle_t &user_handle,
- const RandomForestRegressorD *forest,
- const double *input,
- int n_rows,
- int n_cols,
- double *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_metrics score(
- const raft::handle_t &user_handle,
- const RandomForestRegressorF *forest,
- const float *ref_labels,
- int n_rows,
- const float *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- RF_metrics score(
- const raft::handle_t &user_handle,
- const RandomForestRegressorD *forest,
- const double *ref_labels,
- int n_rows,
- const double *predictions,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
- void TSNE_fit(
- const raft::handle_t &handle,
- float *X,
- float *Y,
- int n,
- int p,
- int64_t *knn_indices,
- float *knn_dists,
- TSNEParams ¶ms,
- float *kl_div = nullptr,
- int *n_iter = nullptr
Dimensionality reduction via TSNE using Barnes-Hut, Fourier Interpolation, or naive methods. or brute force O(N^2).
The CUDA implementation is derived from the excellent CannyLabs open source implementation here: CannyLab/tsne-cuda. The CannyLabs code is licensed according to the conditions in cuml/cpp/src/tsne/cannylabs_tsne_license.txt. A full description of their approach is available in their article t-SNE-CUDA: GPU-Accelerated t-SNE and its Applications to Modern Data (https://arxiv.org/abs/1807.11824).
- Parameters:
handle – [in] The GPU handle.
X – [in] The row-major dataset in device memory.
Y – [out] The column-major final embedding in device memory
n – [in] Number of rows in data X.
p – [in] Number of columns in data X.
knn_indices – [in] Array containing nearest neighbors indices.
knn_dists – [in] Array containing nearest neighbors distances.
params – [in] Parameters for TSNE model
kl_div – [out] (optional) KL divergence output
n_iter – [out] (optional) The number of iterations TSNE ran for.
- void TSNE_fit_sparse(
- const raft::handle_t &handle,
- int *indptr,
- int *indices,
- float *data,
- float *Y,
- int nnz,
- int n,
- int p,
- int *knn_indices,
- float *knn_dists,
- TSNEParams ¶ms,
- float *kl_div = nullptr,
- int *n_iter = nullptr
Dimensionality reduction via TSNE using either Barnes Hut O(NlogN) or brute force O(N^2).
The CUDA implementation is derived from the excellent CannyLabs open source implementation here: CannyLab/tsne-cuda. The CannyLabs code is licensed according to the conditions in cuml/cpp/src/tsne/cannylabs_tsne_license.txt. A full description of their approach is available in their article t-SNE-CUDA: GPU-Accelerated t-SNE and its Applications to Modern Data (https://arxiv.org/abs/1807.11824).
- Parameters:
handle – [in] The GPU handle.
indptr – [in] indptr of CSR dataset.
indices – [in] indices of CSR dataset.
data – [in] data of CSR dataset.
Y – [out] The final embedding.
nnz – [in] The number of non-zero entries in the CSR.
n – [in] Number of rows in data X.
p – [in] Number of columns in data X.
knn_indices – [in] Array containing nearest neighbors indices.
knn_dists – [in] Array containing nearest neighbors distances.
params – [in] Parameters for TSNE model
kl_div – [out] (optional) KL divergence output
n_iter – [out] (optional) The number of iterations TSNE ran for.
- void brute_force_knn(
- const raft::handle_t &handle,
- std::vector<float*> &input,
- std::vector<int> &sizes,
- int D,
- float *search_items,
- int n,
- int64_t *res_I,
- float *res_D,
- int k,
- bool rowMajorIndex = false,
- bool rowMajorQuery = false,
- ML::distance::DistanceType metric = ML::distance::DistanceType::L2Expanded,
- float metric_arg = 2.0f,
- std::vector<int64_t> *translations = nullptr
Flat C++ API function to perform a brute force knn on a series of input arrays and combine the results into a single output array for indexes and distances.
- Parameters:
handle – [in] RAFT handle
input – [in] vector of pointers to the input arrays
sizes – [in] vector of sizes of input arrays
D – [in] the dimensionality of the arrays
search_items – [in] array of items to search of dimensionality D
n – [in] number of rows in search_items
res_I – [out] the resulting index array of size n * k
res_D – [out] the resulting distance array of size n * k
k – [in] the number of nearest neighbors to return
rowMajorIndex – [in] are the index arrays in row-major order?
rowMajorQuery – [in] are the query arrays in row-major order?
metric – [in] distance metric to use. Euclidean (L2) is used by default
metric_arg – [in] the value of
pfor Minkowski (l-p) distances. This is ignored if the metric_type is not Minkowski.translations – [in] translation ids for indices when index rows represent non-contiguous partitions
- void rbc_build_index(
- const raft::handle_t &handle,
- std::uintptr_t &rbc_index,
- float *X,
- int64_t n_rows,
- int64_t n_cols,
- ML::distance::DistanceType metric
- void rbc_knn_query(
- const raft::handle_t &handle,
- const std::uintptr_t &rbc_index,
- uint32_t k,
- const float *search_items,
- uint32_t n_search_items,
- int64_t dim,
- int64_t *out_inds,
- float *out_dists
- void rbc_radius_neighbors_graph(
- const raft::handle_t &handle,
- const std::uintptr_t &rbc_index,
- const float *query,
- int64_t n_query,
- int64_t dim,
- float radius,
- int64_t *adj_indptr,
- int64_t *adj_indices = nullptr,
- int64_t nnz = 0
Perform a radius neighbors query on the fit index.
A single query requires two calls to this API:
The first call should pass adj_indices=nullptr and nnz=0. This will fill in adj_indptr, letting you get the size needed for adj_indices.
The second call should pass adj_indices and nnz, an array of size nnz=adj_indptr[-1]. This will fill in adj_indices.
- Parameters:
handle – [in] RAFT handle
rbc_index – [in] the fit RBC index
query – [in] the query points as a C-contiguous array
n_query – [in] number of rows in the query
dim – [in] number of columns in the query
radius – [in] the neighborhood radius
adj_indptr – [out] the indptr array in output CSR adjacency matrix, of shape n_query + 1.
adj_indices – [out] the indices array in the output CSR adjacency matrix, of shape adj_indptr[-1]. Should be NULL on the first call.
nnz – [in] the number of elements in adj_indices, or 0 on the first call.
-
void rbc_free_index(std::uintptr_t rbc_index)#
Free the RBC index.
- Parameters:
rbc_index – [in] pointer to the index to free
- void approx_knn_build_index(
- raft::handle_t &handle,
- knnIndex *index,
- knnIndexParam *params,
- ML::distance::DistanceType metric,
- float metricArg,
- float *index_array,
- int n,
- int D
Flat C++ API function to build an approximate nearest neighbors index from an index array and a set of parameters.
- Parameters:
handle – [in] RAFT handle
index – [out] index to be built
params – [in] parametrization of the index to be built
metric – [in] distance metric to use. Euclidean (L2) is used by default
metricArg – [in] metric argument
index_array – [in] the index array to build the index with
n – [in] number of rows in the index array
D – [in] the dimensionality of the index array
- void approx_knn_search(
- raft::handle_t &handle,
- float *distances,
- int64_t *indices,
- knnIndex *index,
- int k,
- float *query_array,
- int n
Flat C++ API function to perform an approximate nearest neighbors search from previously built index and a query array.
- Parameters:
handle – [in] RAFT handle
distances – [out] distances of the nearest neighbors toward their query point
indices – [out] indices of the nearest neighbors
index – [in] index to perform a search with
k – [in] the number of nearest neighbors to search for
query_array – [in] the query to perform a search with
n – [in] number of rows in the query array
- void knn_classify(
- raft::handle_t &handle,
- int *out,
- int64_t *knn_indices,
- std::vector<int*> &y,
- size_t n_index_rows,
- size_t n_query_rows,
- int k,
- float *sample_weight = nullptr
Flat C++ API function to perform a knn classification using a given a vector of label arrays. This supports multilabel classification by classifying on multiple label arrays. Note that each label is classified independently, as is done in scikit-learn.
- Parameters:
handle – [in] RAFT handle
out – [out] output array on device (size n_samples * size of y vector)
knn_indices – [in] index array on device resulting from knn query (size n_samples * k)
y – [in] vector of label arrays on device vector size is number of (size n_samples)
n_index_rows – [in] number of vertices in index (eg. size of each y array)
n_query_rows – [in] number of samples in knn_indices
k – [in] number of nearest neighbors in knn_indices
sample_weight – [in] optional pre-computed weight array on device (size n_samples * k). If nullptr, uniform weights are used.
- void knn_regress(
- raft::handle_t &handle,
- float *out,
- int64_t *knn_indices,
- std::vector<float*> &y,
- size_t n_index_rows,
- size_t n_query_rows,
- int k,
- float *sample_weight = nullptr
Flat C++ API function to perform a knn regression using a given a vector of label arrays. This supports multilabel regression by classifying on multiple label arrays. Note that each label is classified independently, as is done in scikit-learn.
- Parameters:
handle – [in] RAFT handle
out – [out] output array on device (size n_samples)
knn_indices – [in] array on device of knn indices (size n_samples * k)
y – [in] array of labels on device (size n_samples)
n_index_rows – [in] number of vertices in index (eg. size of each y array)
n_query_rows – [in] number of samples in knn_indices and out
k – [in] number of nearest neighbors in knn_indices
sample_weight – [in] optional pre-computed weight array on device (size n_samples * k). If nullptr, uniform weights are used.
- void knn_regress(
- raft::handle_t &handle,
- double *out,
- int64_t *knn_indices,
- std::vector<double*> &y,
- size_t n_index_rows,
- size_t n_query_rows,
- int k,
- float *sample_weight = nullptr
- void knn_class_proba(
- raft::handle_t &handle,
- std::vector<float*> &out,
- int64_t *knn_indices,
- std::vector<int*> &y,
- size_t n_index_rows,
- size_t n_query_rows,
- int k,
- float *sample_weight = nullptr
Flat C++ API function to compute knn class probabilities using a vector of device arrays containing discrete class labels. Note that the output is a vector, which is.
- Parameters:
handle – [in] RAFT handle
out – [out] vector of output arrays on device. vector size = n_outputs. Each array should have size(n_samples, n_classes)
knn_indices – [in] array on device of knn indices (size n_samples * k)
y – [in] array of labels on device (size n_samples)
n_index_rows – [in] number of labels in y
n_query_rows – [in] number of rows in knn_indices and out
k – [in] number of nearest neighbors in knn_indices
sample_weight – [in] optional pre-computed weight array on device (size n_samples * k). If nullptr, uniform weights are used.
- int divide_by_mask_build_index(
- const raft::handle_t &handle,
- const bool *d_mask,
- int *d_index,
- int batch_size
Batch division by mask step 1: build an index of the position of each series in its new batch and measure the size of each sub-batch
- Parameters:
handle – [in] cuML handle
d_mask – [in] Boolean mask
d_index – [out] Index of each series in its new batch
batch_size – [in] Batch size
- Returns:
The number of ‘true’ series in the mask
- void divide_by_mask_execute(
- const raft::handle_t &handle,
- const float *d_in,
- const bool *d_mask,
- const int *d_index,
- float *d_out0,
- float *d_out1,
- int batch_size,
- int n_obs
Batch division by mask step 2: create both sub-batches from the mask and index
- Parameters:
handle – [in] cuML handle
d_in – [in] Input batch. Each series is a contiguous chunk
d_mask – [in] Boolean mask
d_index – [in] Index of each series in its new batch
d_out0 – [out] The sub-batch for the ‘false’ members
d_out1 – [out] The sub-batch for the ‘true’ members
batch_size – [in] Batch size
n_obs – [in] Number of data points per series
- void divide_by_mask_execute(
- const raft::handle_t &handle,
- const double *d_in,
- const bool *d_mask,
- const int *d_index,
- double *d_out0,
- double *d_out1,
- int batch_size,
- int n_obs
- void divide_by_mask_execute(
- const raft::handle_t &handle,
- const int *d_in,
- const bool *d_mask,
- const int *d_index,
- int *d_out0,
- int *d_out1,
- int batch_size,
- int n_obs
- void divide_by_min_build_index(
- const raft::handle_t &handle,
- const float *d_matrix,
- int *d_batch,
- int *d_index,
- int *h_size,
- int batch_size,
- int n_sub
Batch division by minimum value step 1: build an index of which sub-batch each series belongs to, an index of the position of each series in its new batch, and measure the size of each sub-batch
- Parameters:
handle – [in] cuML handle
d_matrix – [in] Matrix of the values to minimize Shape: (batch_size, n_sub)
d_batch – [out] Which sub-batch each series belongs to
d_index – [out] Index of each series in its new batch
h_size – [out] Size of each sub-batch (host)
batch_size – [in] Batch size
n_sub – [in] Number of sub-batches
- void divide_by_min_build_index(
- const raft::handle_t &handle,
- const double *d_matrix,
- int *d_batch,
- int *d_index,
- int *h_size,
- int batch_size,
- int n_sub
- void divide_by_min_execute(
- const raft::handle_t &handle,
- const float *d_in,
- const int *d_batch,
- const int *d_index,
- float **hd_out,
- int batch_size,
- int n_sub,
- int n_obs
Batch division by minimum value step 2: create all the sub-batches
- Parameters:
handle – [in] cuML handle
d_in – [in] Input batch. Each series is a contiguous chunk
d_batch – [in] Which sub-batch each series belongs to
d_index – [in] Index of each series in its new sub-batch
hd_out – [out] Host array of pointers to device arrays of each sub-batch
batch_size – [in] Batch size
n_sub – [in] Number of sub-batches
n_obs – [in] Number of data points per series
- void divide_by_min_execute(
- const raft::handle_t &handle,
- const double *d_in,
- const int *d_batch,
- const int *d_index,
- double **hd_out,
- int batch_size,
- int n_sub,
- int n_obs
- void divide_by_min_execute(
- const raft::handle_t &handle,
- const int *d_in,
- const int *d_batch,
- const int *d_index,
- int **hd_out,
- int batch_size,
- int n_sub,
- int n_obs
- void build_division_map(
- const raft::handle_t &handle,
- const int *const *hd_id,
- const int *h_size,
- int *d_id_to_pos,
- int *d_id_to_model,
- int batch_size,
- int n_sub
Build a map to associate each batch member with a model and index in the associated sub-batch
- Parameters:
handle – [in] cuML handle
hd_id – [in] Host array of pointers to device arrays containing the indices of the members of each sub-batch
h_size – [in] Host array containing the size of each sub-batch
d_id_to_pos – [out] Device array containing the position of each member in its new sub-batch
d_id_to_model – [out] Device array associating each member with its sub-batch
batch_size – [in] Batch size
n_sub – [in] Number of sub-batches
- void merge_series(
- const raft::handle_t &handle,
- const float *const *hd_in,
- const int *d_id_to_pos,
- const int *d_id_to_sub,
- float *d_out,
- int batch_size,
- int n_sub,
- int n_obs
Merge multiple sub-batches into one batch according to the maps that associate each id in the unique batch to a sub-batch and a position in this sub-batch.
- Parameters:
handle – [in] cuML handle
hd_in – [in] Host array of pointers to device arrays containing the sub-batches
d_id_to_pos – [in] Device array containing the position of each member in its new sub-batch
d_id_to_sub – [in] Device array associating each member with its sub-batch
d_out – [out] Output merged batch
batch_size – [in] Batch size
n_sub – [in] Number of sub-batches
n_obs – [in] Number of observations (or forecasts) per series
- void merge_series(
- const raft::handle_t &handle,
- const double *const *hd_in,
- const int *d_id_to_pos,
- const int *d_id_to_sub,
- double *d_out,
- int batch_size,
- int n_sub,
- int n_obs
- void pack(
- raft::handle_t &handle,
- const ARIMAParams<double> ¶ms,
- const ARIMAOrder &order,
- int batch_size,
- double *param_vec
Pack separate parameter arrays into a compact array
- Parameters:
handle – [in] cuML handle
params – [in] Parameter structure
order – [in] ARIMA order
batch_size – [in] Batch size
param_vec – [out] Compact parameter array
- void unpack(
- raft::handle_t &handle,
- ARIMAParams<double> ¶ms,
- const ARIMAOrder &order,
- int batch_size,
- const double *param_vec
Unpack a compact array into separate parameter arrays
- Parameters:
handle – [in] cuML handle
params – [out] Parameter structure
order – [in] ARIMA order
batch_size – [in] Batch size
param_vec – [in] Compact parameter array
- bool detect_missing(
- raft::handle_t &handle,
- const double *d_y,
- int n_elem
Detect missing observations in a time series
- Parameters:
handle – [in] cuML handle
d_y – [in] Time series
n_elem – [in] Total number of elements in the dataset
- void batched_diff(
- raft::handle_t &handle,
- double *d_y_diff,
- const double *d_y,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order
Compute the differenced series (seasonal and/or non-seasonal differences)
- Parameters:
handle – [in] cuML handle
d_y_diff – [out] Differenced series
d_y – [in] Original series
batch_size – [in] Batch size
n_obs – [in] Number of observations
order – [in] ARIMA order
- void batched_loglike(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_y,
- const double *d_exog,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order,
- const double *d_params,
- double *loglike,
- bool trans = true,
- bool host_loglike = true,
- LoglikeMethod method = MLE,
- int truncate = 0
Compute the loglikelihood of the given parameter on the given time series in a batched context.
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_y – [in] Series to fit: shape = (n_obs, batch_size) and expects column major data layout. (device)
d_exog – [in] Exogenous variables: shape = (n_obs, n_exog * batch_size) and expects column major data layout. (device)
batch_size – [in] Number of time series
n_obs – [in] Number of observations in a time series
order – [in] ARIMA hyper-parameters
d_params – [in] Parameters to evaluate grouped by series: [mu0, ar.., ma.., mu1, ..] (device)
loglike – [out] Log-Likelihood of the model per series
trans – [in] Run
jones_transformon params.host_loglike – [in] Whether loglike is a host pointer
method – [in] Whether to use sum-of-squares or Kalman filter
truncate – [in] For CSS, start the sum-of-squares after a given number of observations
- void batched_loglike(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_y,
- const double *d_exog,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order,
- const ARIMAParams<double> ¶ms,
- double *loglike,
- bool trans = true,
- bool host_loglike = true,
- LoglikeMethod method = MLE,
- int truncate = 0,
- int fc_steps = 0,
- double *d_fc = nullptr,
- const double *d_exog_fut = nullptr,
- double level = 0,
- double *d_lower = nullptr,
- double *d_upper = nullptr
Compute the loglikelihood of the given parameter on the given time series in a batched context.
Note
: this overload should be used when the parameters are already unpacked to avoid useless packing / unpacking
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_y – [in] Series to fit: shape = (n_obs, batch_size) and expects column major data layout. (device)
d_exog – [in] Exogenous variables: shape = (n_obs, n_exog * batch_size) and expects column major data layout. (device)
batch_size – [in] Number of time series
n_obs – [in] Number of observations in a time series
order – [in] ARIMA hyper-parameters
params – [in] ARIMA parameters (device)
loglike – [out] Log-Likelihood of the model per series
trans – [in] Run
jones_transformon params.host_loglike – [in] Whether loglike is a host pointer
method – [in] Whether to use sum-of-squares or Kalman filter
truncate – [in] For CSS, start the sum-of-squares after a given number of observations
fc_steps – [in] Number of steps to forecast
d_fc – [in] Array to store the forecast
d_exog_fut – [in] Future values of exogenous variables Shape (fc_steps, n_exog * batch_size) (col-major, device)
level – [in] Confidence level for prediction intervals. 0 to skip the computation. Else 0 < level < 1
d_lower – [out] Lower limit of the prediction interval
d_upper – [out] Upper limit of the prediction interval
- void batched_loglike_grad(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_y,
- const double *d_exog,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order,
- const double *d_x,
- double *d_grad,
- double h,
- bool trans = true,
- LoglikeMethod method = MLE,
- int truncate = 0
Compute the gradient of the log-likelihood
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_y – [in] Series to fit: shape = (n_obs, batch_size) and expects column major data layout. (device)
d_exog – [in] Exogenous variables: shape = (n_obs, n_exog * batch_size) and expects column major data layout. (device)
batch_size – [in] Number of time series
n_obs – [in] Number of observations in a time series
order – [in] ARIMA hyper-parameters
d_x – [in] Parameters grouped by series
d_grad – [out] Gradient to compute
h – [in] Finite-differencing step size
trans – [in] Run
jones_transformon paramsmethod – [in] Whether to use sum-of-squares or Kalman filter
truncate – [in] For CSS, start the sum-of-squares after a given number of observations
- void predict(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_y,
- const double *d_exog,
- const double *d_exog_fut,
- int batch_size,
- int n_obs,
- int start,
- int end,
- const ARIMAOrder &order,
- const ARIMAParams<double> ¶ms,
- double *d_y_p,
- bool pre_diff = true,
- double level = 0,
- double *d_lower = nullptr,
- double *d_upper = nullptr
Batched in-sample and out-of-sample prediction of a time-series given all the model parameters
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_y – [in] Batched Time series to predict. Shape: (num_samples, batch size) (device)
d_exog – [in] Exogenous variables. Shape = (n_obs, n_exog * batch_size) (device)
d_exog_fut – [in] Future values of exogenous variables Shape: (end - n_obs, batch_size) (device)
batch_size – [in] Total number of batched time series
n_obs – [in] Number of samples per time series (all series must be identical)
start – [in] Index to start the prediction
end – [in] Index to end the prediction (excluded)
order – [in] ARIMA hyper-parameters
params – [in] ARIMA parameters (device)
d_y_p – [out] Prediction output (device)
pre_diff – [in] Whether to use pre-differencing
level – [in] Confidence level for prediction intervals. 0 to skip the computation. Else 0 < level < 1
d_lower – [out] Lower limit of the prediction interval
d_upper – [out] Upper limit of the prediction interval
- void information_criterion(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_y,
- const double *d_exog,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order,
- const ARIMAParams<double> ¶ms,
- double *ic,
- int ic_type
Compute an information criterion (AIC, AICc, BIC)
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_y – [in] Series to fit: shape = (n_obs, batch_size) and expects column major data layout. (device)
d_exog – [in] Exogenous variables. Shape = (n_obs, n_exog * batch_size) (device)
batch_size – [in] Total number of batched time series
n_obs – [in] Number of samples per time series (all series must be identical)
order – [in] ARIMA hyper-parameters
params – [in] ARIMA parameters (device)
ic – [out] Array where to write the information criteria Shape: (batch_size) (device)
ic_type – [in] Type of information criterion wanted. 0: AIC, 1: AICc, 2: BIC
- void estimate_x0(
- raft::handle_t &handle,
- ARIMAParams<double> ¶ms,
- const double *d_y,
- const double *d_exog,
- int batch_size,
- int n_obs,
- const ARIMAOrder &order,
- bool missing
Provide initial estimates to ARIMA parameters mu, AR, and MA
- Parameters:
handle – [in] cuML handle
params – [in] ARIMA parameters (device)
d_y – [in] Series to fit: shape = (n_obs, batch_size) and expects column major data layout. (device)
d_exog – [in] Exogenous variables. Shape = (n_obs, n_exog * batch_size) (device)
batch_size – [in] Total number of batched time series
n_obs – [in] Number of samples per time series (all series must be identical)
order – [in] ARIMA hyper-parameters
missing – [in] Are there missing observations?
- void batched_kalman_filter(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const double *d_ys,
- const double *d_exog,
- int nobs,
- const ARIMAParams<double> ¶ms,
- const ARIMAOrder &order,
- int batch_size,
- double *d_loglike,
- double *d_pred,
- int fc_steps = 0,
- double *d_fc = nullptr,
- const double *d_exog_fut = nullptr,
- double level = 0,
- double *d_lower = nullptr,
- double *d_upper = nullptr
An ARIMA specialized batched kalman filter to evaluate ARMA parameters and provide the resulting prediction as well as loglikelihood fit.
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
d_ys – [in] Batched time series Shape (nobs, batch_size) (col-major, device)
d_exog – [in] Batched exogenous variables Shape (nobs, n_exog * batch_size) (col-major, device)
nobs – [in] Number of samples per time series
params – [in] ARIMA parameters (device)
order – [in] ARIMA hyper-parameters
batch_size – [in] Number of series making up the batch
d_loglike – [out] Resulting log-likelihood (per series) (device)
d_pred – [out] Predictions shape=(nobs-d-s*D, batch_size) (device)
fc_steps – [in] Number of steps to forecast
d_fc – [in] Array to store the forecast
d_exog_fut – [in] Future values of exogenous variables Shape (fc_steps, n_exog * batch_size) (col-major, device)
level – [in] Confidence level for prediction intervals. 0 to skip the computation. Else 0 < level < 1
d_lower – [out] Lower limit of the prediction interval
d_upper – [out] Upper limit of the prediction interval
- void batched_jones_transform(
- raft::handle_t &handle,
- const ARIMAMemory<double> &arima_mem,
- const ARIMAOrder &order,
- int batch_size,
- bool isInv,
- const double *h_params,
- double *h_Tparams
Convenience function for batched “jones transform” used in ARIMA to ensure certain properties of the AR and MA parameters (takes host array and returns host array)
- Parameters:
handle – [in] cuML handle
arima_mem – [in] Pre-allocated temporary memory
order – [in] ARIMA hyper-parameters
batch_size – [in] Number of time series analyzed.
isInv – [in] Do the inverse transform?
h_params – [in] ARIMA parameters by batch (mu, ar, ma) (host)
h_Tparams – [out] Transformed ARIMA parameters (expects pre-allocated array of size (p+q)*batch_size) (host)
-
inline void PUSH_RANGE(const char *name, cudaStream_t stream)#
Synchronize CUDA stream and push a named nvtx range.
- Deprecated:
Use new raft::common::nvtx::push_range from <raft/core/nvtx.hpp>
- Parameters:
name – range name
stream – stream to synchronize
-
inline void POP_RANGE(cudaStream_t stream)#
Synchronize CUDA stream and pop the latest nvtx range.
- Deprecated:
Use new raft::common::nvtx::pop_range from <raft/core/nvtx.hpp>
- Parameters:
stream – stream to synchronize
-
inline void PUSH_RANGE(const char *name)#
Push a named nvtx range.
- Deprecated:
Use new raft::common::nvtx::push_range from <raft/core/nvtx.hpp>
- Parameters:
name – range name
-
inline void POP_RANGE()#
Pop the latest range
- Deprecated:
Use new raft::common::nvtx::pop_range from <raft/core/nvtx.hpp>
-
template<typename T>
inline void col_ref( - const SimpleDenseMat<T> &mat,
- SimpleVec<T> &mask_vec,
- int c
-
template<typename T>
inline void col_slice( - const SimpleDenseMat<T> &mat,
- SimpleDenseMat<T> &mask_mat,
- int c_from,
- int c_to
-
template<typename T>
std::ostream &operator<<( - std::ostream &os,
- const SimpleDenseMat<T> &mat
-
template<typename T, typename I = int>
inline void check_csr( - const SimpleSparseMat<T, I> &mat,
- cudaStream_t stream
-
template<typename T, typename I = int>
std::ostream &operator<<( - std::ostream &os,
- const SimpleSparseMat<T, I> &mat
-
inline int get_device(const void *ptr)#
-
inline cudaMemoryType memory_type(const void *p)#
-
inline bool is_device_or_managed_type(const void *p)#
-
template<typename T, int ALIGN = 256>
struct ARIMAMemory# - #include <arima_common.h>
Structure to manage ARIMA temporary memory allocations
Note
The user is expected to give a preallocated buffer to the constructor, and ownership is not transferred to this struct! The buffer must be allocated as long as the object lives, and deallocated afterwards.
Public Functions
- inline ARIMAMemory(
- const ARIMAOrder &order,
- int batch_size,
- int n_obs,
- char *in_buf
Constructor to create pointers from buffer
- Parameters:
order – [in] ARIMA order
batch_size – [in] Number of series in the batch
n_obs – [in] Length of the series
in_buf – [in] Pointer to the temporary memory buffer. Ownership is retained by the caller
Public Static Functions
- static inline size_t compute_size(
- const ARIMAOrder &order,
- int batch_size,
- int n_obs
Static method to get the size of the required buffer allocation
- Parameters:
order – [in] ARIMA order
batch_size – [in] Number of series in the batch
n_obs – [in] Length of the series
- Returns:
Buffer size in bytes
-
struct ARIMAOrder#
- #include <arima_common.h>
Structure to hold the ARIMA order (makes it easier to pass as an argument)
-
template<typename DataT>
struct ARIMAParams# - #include <arima_common.h>
Structure to hold the parameters (makes it easier to pass as an argument)
Note
: the qualifier const applied to this structure will only guarantee that the pointers are not changed, but the user can still modify the arrays when using the pointers directly!
Public Functions
- inline void allocate(
- const ARIMAOrder &order,
- int batch_size,
- cudaStream_t stream,
- bool tr = false
Allocate all the parameter device arrays
- Template Parameters:
AllocatorT – Type of allocator used
- Parameters:
order – [in] ARIMA order
batch_size – [in] Batch size
stream – [in] CUDA stream
tr – [in] Whether these are the transformed parameters
- inline void deallocate(
- const ARIMAOrder &order,
- int batch_size,
- cudaStream_t stream,
- bool tr = false
Deallocate all the parameter device arrays
- Template Parameters:
AllocatorT – Type of allocator used
- Parameters:
order – [in] ARIMA order
batch_size – [in] Batch size
stream – [in] CUDA stream
tr – [in] Whether these are the transformed parameters
- void pack(
- const ARIMAOrder &order,
- int batch_size,
- DataT *param_vec,
- cudaStream_t stream
Pack the separate parameter arrays into a unique parameter vector
- Parameters:
order – [in] ARIMA order
batch_size – [in] Batch size
param_vec – [out] Linear array of all parameters grouped by batch [mu, ar, ma, sar, sma, sigma2] (device)
stream – [in] CUDA stream
- void unpack(
- const ARIMAOrder &order,
- int batch_size,
- const DataT *param_vec,
- cudaStream_t stream
Unpack a parameter vector into separate arrays of parameters.
- Parameters:
order – [in] ARIMA order
batch_size – [in] Batch size
param_vec – [in] Linear array of all parameters grouped by batch [mu, ar, ma, sar, sma, sigma2] (device)
stream – [in] CUDA stream
-
template<typename T>
struct CompactIFForest# - #include <isolation_forest.hpp>
Compact tree data returned by get_compact_trees(). Contains all used nodes concatenated, with per-tree metadata.
-
struct IF_params#
- #include <isolation_forest.hpp>
Isolation Forest hyperparameters.
Public Members
-
int n_estimators = 100#
Number of isolation trees.
-
int max_samples = 256#
Samples per tree (default 256).
-
int max_depth = -1#
Max depth (-1 = auto: ceil(log2(max_samples))).
-
int max_features = -1#
Features sampled per tree (-1 = all features).
-
bool bootstrap = false#
If true, sample rows with replacement.
-
uint64_t seed = 0#
Random seed.
-
int n_estimators = 100#
-
template<typename T>
struct IFNodeCompact# - #include <isolation_forest.hpp>
Compact node representation (matches internal IFNode layout).
Internal nodes: feature_idx >= 0, threshold is split value Leaf nodes: feature_idx = -1, threshold stores pre-computed path length
-
template<class T>
struct IsolationForestModel# - #include <isolation_forest.hpp>
Trained Isolation Forest model.
Public Members
-
int n_features = 0#
Number of features in training data.
-
int n_features_per_tree = 0#
Features sampled per tree.
-
int n_samples_per_tree = 0#
Samples used per tree (for c(n) calculation).
-
double c_normalization = 0#
Precomputed c(n) normalization constant.
-
int max_nodes_per_tree = 0#
Allocated node capacity per tree.
-
rmm::device_buffer global_feature_indices#
Optional per-tree sampled feature ids.
-
rmm::device_buffer global_nodes#
Device memory for global-memory IFNode array.
-
rmm::device_buffer global_tree_offsets#
Per-tree base offset in global_nodes.
-
rmm::device_buffer global_tree_n_nodes#
Per-tree used node counts.
-
rmm::device_buffer global_tree_max_depth#
Per-tree max depth metadata.
-
int n_features = 0#
-
struct IVFParam : public ML::knnIndexParam#
- #include <knn.hpp>
Subclassed by ML::IVFFlatParam, ML::IVFPQParam
-
template<typename value_idx, typename value_t>
struct knn_graph# - #include <common.hpp>
Simple container for KNN graph properties
- Template Parameters:
value_idx –
value_t –
-
struct knnIndex#
- #include <knn.hpp>
-
struct knnIndexParam#
- #include <knn.hpp>
Subclassed by ML::IVFParam
-
template<typename T>
struct manifold_dense_inputs_t : public ML::manifold_inputs_t<T># - #include <common.hpp>
Dense input to manifold learning algorithms
- Template Parameters:
T –
-
template<typename T>
struct manifold_inputs_t# - #include <common.hpp>
Base struct for representing inputs to manifold learning algorithms.
- Template Parameters:
T –
Subclassed by ML::manifold_dense_inputs_t< T >, ML::manifold_sparse_inputs_t< value_idx, T >
-
template<typename value_idx, typename value_t>
struct manifold_precomputed_knn_inputs_t : public ML::manifold_inputs_t<value_t># - #include <common.hpp>
Precomputed KNN graph input to manifold learning algorithms
- Template Parameters:
value_idx –
value_t –
-
template<typename value_idx, typename T>
struct manifold_sparse_inputs_t : public ML::manifold_inputs_t<T># - #include <common.hpp>
Sparse CSR input to manifold learning algorithms
- Template Parameters:
value_idx –
T –
-
template<typename Dtype>
struct OptimParams# - #include <holtwinters_params.h>
-
class params#
- #include <params.hpp>
Subclassed by ML::paramsSolver
-
template<typename enum_solver = solver>
class paramsPCATemplate : public ML::paramsTSVDTemplate<solver># - #include <params.hpp>
structure for pca parameters. Ref: http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
- Param n_components:
Number of components to keep. if n_components is not set all components are kept:
- Param copy:
If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.
- Param whiten:
When True (False by default) the components_ vectors are multiplied by the square root of n_samples and then divided by the singular values to ensure uncorrelated outputs with unit component-wise variances.
- Param algorithm:
the solver to be used in PCA.
- Param tol:
Tolerance for singular values computed by the Jacobi solver
- Param n_iterations:
Number of iterations for the power method computed by the Jacobi solver
- Param verbose:
0: no error message printing, 1: print error messages
-
class paramsSolver : public ML::params#
- #include <params.hpp>
Subclassed by ML::paramsTSVDTemplate< mg_solver >, ML::paramsTSVDTemplate< solver >, ML::paramsTSVDTemplate< enum_solver >
-
template<typename enum_solver = solver>
class paramsTSVDTemplate : public ML::paramsSolver# - #include <params.hpp>
-
template<typename T>
class pinned_host_vector# - #include <pinned_host_vector.hpp>
-
template<class T, class L>
struct RandomForestMetaData# - #include <randomforest.hpp>
Public Members
-
int n_features = 0#
Number of features in the training data.
-
int n_features = 0#
-
struct RF_metrics#
- #include <randomforest.hpp>
-
struct RF_params#
- #include <randomforest.hpp>
Public Members
-
int n_trees#
Number of decision trees in the random forest.
-
bool bootstrap#
Control bootstrapping. If bootstrapping is set to true, bootstrapped samples are used for building each tree. Bootstrapped sampling is done by randomly drawing round(max_samples * n_samples) number of samples with replacement. More on bootstrapping: https://en.wikipedia.org/wiki/Bootstrap_aggregating If bootstrapping is set to false, whole dataset is used to build each tree.
-
float max_samples#
Ratio of dataset rows used while fitting each tree.
-
uint64_t seed#
Decision tree training hyper parameter struct. random seed
-
int n_streams#
Number of concurrent GPU streams for parallel tree building. Each stream is independently managed by CPU thread. N streams need N times RF workspace.
-
int n_trees#
-
template<typename T>
struct SimpleDenseMat : public ML::SimpleMat<T># - #include <dense.hpp>
Subclassed by ML::SimpleMatOwning< T >, ML::SimpleVec< T >
Public Functions
- inline virtual void gemmb(
- const raft::handle_t &handle,
- const T alpha,
- const SimpleDenseMat<T> &A,
- const bool transA,
- const bool transB,
- const T beta,
- SimpleDenseMat<T> &C,
- cudaStream_t stream
GEMM assigning to C where
thisrefers to B.C <- alpha * A^transA * (*this)^transB + beta * C
-
template<typename T>
struct SimpleMat# - #include <base.hpp>
Subclassed by ML::SimpleDenseMat< T >, ML::SimpleSparseMat< T, I >
Public Functions
- virtual void gemmb(
- const raft::handle_t &handle,
- const T alpha,
- const SimpleDenseMat<T> &A,
- const bool transA,
- const bool transB,
- const T beta,
- SimpleDenseMat<T> &C,
- cudaStream_t stream
GEMM assigning to C where
thisrefers to B.C <- alpha * A^transA * (*this)^transB + beta * C
-
template<typename T>
struct SimpleMatOwning : public ML::SimpleDenseMat<T># - #include <dense.hpp>
-
template<typename T, typename I = int>
struct SimpleSparseMat : public ML::SimpleMat<T># - #include <sparse.hpp>
Sparse matrix in CSR format.
Note, we use cuSPARSE to manimulate matrices, and it guarantees:
row_ids[m] == nnz
cols are sorted within rows.
However, when the data comes from the outside, we cannot guarantee that.
Public Functions
- inline virtual void gemmb(
- const raft::handle_t &handle,
- const T alpha,
- const SimpleDenseMat<T> &A,
- const bool transA,
- const bool transB,
- const T beta,
- SimpleDenseMat<T> &C,
- cudaStream_t stream
GEMM assigning to C where
thisrefers to B.C <- alpha * A^transA * (*this)^transB + beta * C
-
template<typename T>
struct SimpleVec : public ML::SimpleDenseMat<T># - #include <dense.hpp>
Subclassed by ML::SimpleVecOwning< T >
-
struct TSNEParams#
- #include <tsne.h>
-
class UMAPParams#
- #include <umapparams.h>
Public Members
-
int n_neighbors = 15#
The number of neighbors to use to approximate geodesic distance. Larger numbers induce more global estimates of the manifold that can miss finer detail, while smaller values will focus on fine manifold structure to the detriment of the larger picture.
-
int n_components = 2#
Number of features in the final embedding
-
int n_epochs = 0#
Number of epochs to use in the training of the embedding.
-
float learning_rate = 1.0#
Initial learning rate for the embedding optimization
-
float min_dist = 0.1#
The effective minimum distance between embedded points. Smaller values will result in a more clustered/clumped embedding where nearby points on the manifold are drawn closer together, while larger values will result on a more even dispersal of points. The value should be set relative to the
spreadvalue, which determines the scale at which embedded points will be spread out.
-
float spread = 1.0#
The effective scale of embedded points. In combination with
min_distthis determines how clustered/clumped the embedded points are.
-
float set_op_mix_ratio = 1.0#
Interpolate between (fuzzy) union and intersection as the set operation used to combine local fuzzy simplicial sets to obtain a global fuzzy simplicial sets. Both fuzzy set operations use the product t-norm. The value of this parameter should be between 0.0 and 1.0; a value of 1.0 will use a pure fuzzy union, while 0.0 will use a pure fuzzy intersection.
-
float local_connectivity = 1.0#
The local connectivity required — i.e. the number of nearest neighbors that should be assumed to be connected at a local level. The higher this value the more connected the manifold becomes locally. In practice this should be not more than the local intrinsic dimension of the manifold.
-
float repulsion_strength = 1.0#
Weighting applied to negative samples in low dimensional embedding optimization. Values higher than one will result in greater weight being given to negative samples.
-
int negative_sample_rate = 5#
The number of negative samples to select per positive sample in the optimization process. Increasing this value will result in greater repulsive force being applied, greater optimization cost, but slightly more accuracy.
-
float transform_queue_size = 4.0#
For transform operations (embedding new points using a trained model_ this will control how aggressively to search for nearest neighbors. Larger values will result in slower performance but more accurate nearest neighbor evaluation.
-
rapids_logger::level_enum verbosity = rapids_logger::level_enum::info#
Control logging level during algorithm execution
-
float a = -1.0#
More specific parameters controlling the embedding. If None these values are set automatically as determined by
min_distandspread.
-
float b = -1.0#
More specific parameters controlling the embedding. If None these values are set automatically as determined by
min_distandspread.
-
float initial_alpha = 1.0#
Initial learning rate for SGD
-
int init = 1#
Embedding initializer algorithm 0 = random layout 1 = spectral layout
-
int target_n_neighbors = -1#
The number of nearest neighbors to use to construct the target simplicial set. If set to -1, use the n_neighbors value.
-
bool force_serial_epochs = false#
If true, optimization epochs will be executed with reduced GPU parallelism. This is commonly useful for deterministic runs with random_state set, and may also be enabled to avoid outliers for spectral initialization. This may slow the optimization step. Use this to resolve rare edge cases where the default heuristics do not trigger.
-
bool deterministic = true#
Whether should we use deterministic algorithm. This should be set to true if random_state is provided, otherwise it’s false. When it’s true, cuml will have higher memory usage but produce stable numeric output.
-
int n_neighbors = 15#
-
namespace CD#
-
namespace opg#
Functions
- int fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &labels,
- float *coef,
- float *intercept,
- bool fit_intercept,
- int epochs,
- float alpha,
- float l1_ratio,
- bool shuffle,
- float tol,
- bool verbose
performs MNMG fit operation for the ridge regression
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] vector holding all partitions for that rank
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
coef – [out] learned regression coefficients
intercept – [out] intercept value
fit_intercept – [in] fit intercept or not
epochs – [in] number of epochs
alpha – [in] ridge parameter
l1_ratio – [in] l1 ratio
shuffle – [in] whether to shuffle the data
tol – [in] tolerance for early stopping during fitting
verbose – [in]
- Returns:
n_iter: the number of solver iterations run
- int fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &labels,
- double *coef,
- double *intercept,
- bool fit_intercept,
- int epochs,
- double alpha,
- double l1_ratio,
- bool shuffle,
- double tol,
- bool verbose
- void predict(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- size_t n_parts,
- MLCommon::Matrix::Data<float> **input,
- size_t n_rows,
- size_t n_cols,
- float *coef,
- float intercept,
- MLCommon::Matrix::Data<float> **preds,
- bool verbose
performs MNMG prediction for OLS
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
n_rows – [in] number of rows of input data
n_cols – [in] number of cols of input data
coef – [in] OLS coefficients
intercept – [in] the fit intercept
preds – [out] predictions
verbose – [in]
-
namespace opg#
-
namespace Datasets#
Unnamed Group
- void make_arima(
- const raft::handle_t &handle,
- float *out,
- int batch_size,
- int n_obs,
- ARIMAOrder order,
- float scale = 1.0f,
- float noise_scale = 0.2f,
- float intercept_scale = 1.0f,
- uint64_t seed = 0ULL
Generates a dataset of time series by simulating an ARIMA process of a given order.
- Parameters:
handle – [in] cuML handle
out – [out] Generated time series
batch_size – [in] Batch size
n_obs – [in] Number of observations per series
order – [in] ARIMA order
scale – [in] Scale used to draw the starting values
noise_scale – [in] Scale used to draw the residuals
intercept_scale – [in] Scale used to draw the intercept
seed – [in] Seed for the random number generator
- void make_arima(
- const raft::handle_t &handle,
- double *out,
- int batch_size,
- int n_obs,
- ARIMAOrder order,
- double scale = 1.0,
- double noise_scale = 0.2,
- double intercept_scale = 1.0,
- uint64_t seed = 0ULL
Functions
- void make_regression(
- const raft::handle_t &handle,
- float *out,
- float *values,
- int64_t n_rows,
- int64_t n_cols,
- int64_t n_informative,
- float *coef = nullptr,
- int64_t n_targets = 1LL,
- float bias = 0.0f,
- int64_t effective_rank = -1LL,
- float tail_strength = 0.5f,
- float noise = 0.0f,
- bool shuffle = true,
- uint64_t seed = 0ULL
GPU-equivalent of sklearn.datasets.make_regression as documented at: https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_regression.html.
- Parameters:
handle – [in] cuML handle
out – [out] Row-major (samples, features) matrix to store the problem data
values – [out] Row-major (samples, targets) matrix to store the values for the regression problem
n_rows – [in] Number of samples
n_cols – [in] Number of features
n_informative – [in] Number of informative features (non-zero coefficients)
coef – [out] Row-major (features, targets) matrix to store the coefficients used to generate the values for the regression problem. If nullptr is given, nothing will be written
n_targets – [in] Number of targets (generated values per sample)
bias – [in] A scalar that will be added to the values
effective_rank – [in] The approximate rank of the data matrix (used to create correlations in the data). -1 is the code to use well-conditioned data
tail_strength – [in] The relative importance of the fat noisy tail of the singular values profile if effective_rank is not -1
noise – [in] Standard deviation of the gaussian noise applied to the output
shuffle – [in] Shuffle the samples and the features
seed – [in] Seed for the random number generator
- void make_regression(
- const raft::handle_t &handle,
- double *out,
- double *values,
- int64_t n_rows,
- int64_t n_cols,
- int64_t n_informative,
- double *coef = nullptr,
- int64_t n_targets = 1LL,
- double bias = 0.0,
- int64_t effective_rank = -1LL,
- double tail_strength = 0.5,
- double noise = 0.0,
- bool shuffle = true,
- uint64_t seed = 0ULL
- void make_regression(
- const raft::handle_t &handle,
- float *out,
- float *values,
- int n_rows,
- int n_cols,
- int n_informative,
- float *coef = nullptr,
- int n_targets = 1LL,
- float bias = 0.0f,
- int effective_rank = -1LL,
- float tail_strength = 0.5f,
- float noise = 0.0f,
- bool shuffle = true,
- uint64_t seed = 0ULL
- void make_regression(
- const raft::handle_t &handle,
- double *out,
- double *values,
- int n_rows,
- int n_cols,
- int n_informative,
- double *coef = nullptr,
- int n_targets = 1LL,
- double bias = 0.0,
- int effective_rank = -1LL,
- double tail_strength = 0.5,
- double noise = 0.0,
- bool shuffle = true,
- uint64_t seed = 0ULL
-
namespace Dbscan#
-
namespace detail#
Functions
-
template<checked_target T, checked_source U>
T widen_or_fail( - U value,
- char const *op
Widen
valuetoT, trapping if the source value cannot be represented inT.
- inline void cuml_rf_allreduce_validation_status(
- const raft::handle_t &handle,
- const int *local_status,
- int *global_status
- inline void cuml_rf_allreduce_oob_stats(
- const raft::handle_t &handle,
- const double *local_stats,
- double *global_stats,
- std::size_t count
-
template<checked_target T, checked_source U>
-
namespace distance#
Enums
-
enum class DistanceType#
Values:
-
enumerator L2Expanded#
-
enumerator L2SqrtExpanded#
-
enumerator CosineExpanded#
-
enumerator L1#
-
enumerator L2Unexpanded#
-
enumerator L2SqrtUnexpanded#
-
enumerator InnerProduct#
-
enumerator Linf#
-
enumerator Canberra#
-
enumerator LpUnexpanded#
-
enumerator CorrelationExpanded#
-
enumerator JaccardExpanded#
-
enumerator HellingerExpanded#
-
enumerator Haversine#
-
enumerator BrayCurtis#
-
enumerator JensenShannon#
-
enumerator HammingUnexpanded#
-
enumerator KLDivergence#
-
enumerator RusselRaoExpanded#
-
enumerator DiceExpanded#
-
enumerator BitwiseHamming#
-
enumerator Precomputed#
-
enumerator L2Expanded#
-
enum class DistanceType#
-
namespace DT#
Typedefs
-
typedef TreeMetaDataNode<float, int> TreeClassifierF#
-
typedef TreeMetaDataNode<double, int> TreeClassifierD#
-
typedef TreeMetaDataNode<float, float> TreeRegressorF#
-
typedef TreeMetaDataNode<double, double> TreeRegressorD#
Functions
- void set_tree_params(
- DecisionTreeParams ¶ms,
- int cfg_max_depth = -1,
- int cfg_max_leaves = -1,
- float cfg_max_features = 1.0f,
- int cfg_max_n_bins = 128,
- int cfg_min_samples_leaf = 1,
- int cfg_min_samples_split = 2,
- float cfg_min_impurity_decrease = 0.0f,
- CRITERION cfg_split_criterion = CRITERION_END,
- int cfg_max_batch_size = 4096
Set all DecisionTreeParams members.
- Parameters:
params – [inout] update with tree parameters
cfg_max_depth – [in] maximum tree depth; default -1
cfg_max_leaves – [in] maximum leaves; default -1
cfg_max_features – [in] maximum number of features; default 1.0f
cfg_max_n_bins – [in] maximum number of bins; default 128
cfg_min_samples_leaf – [in] min. rows in each leaf node; default 1
cfg_min_samples_split – [in] min. rows needed to split an internal node; default 2
cfg_min_impurity_decrease – [in] split a node only if its reduction in impurity is more than this value
cfg_split_criterion – [in] split criterion; default CRITERION_END, i.e., GINI for classification or MSE for regression
cfg_max_batch_size – [in] Maximum number of nodes that can be processed in a batch. This is used only for batched-level algo. Default value 4096.
-
template<class T, class L>
std::string get_tree_summary_text( - const TreeMetaDataNode<T, L> *tree
Obtain high-level tree information.
- Template Parameters:
T – data type for input data (float or double).
L – data type for labels (int type for classification, T type for regression).
- Parameters:
tree – [in] CPU pointer to TreeMetaDataNode
- Returns:
High-level tree information as string
-
template<class T, class L>
std::string get_tree_text( - const TreeMetaDataNode<T, L> *tree
Obtain detailed tree information.
- Template Parameters:
T – data type for input data (float or double).
L – data type for labels (int type for classification, T type for regression).
- Parameters:
tree – [in] CPU pointer to TreeMetaDataNode
- Returns:
Detailed tree information as string
-
template<class T, class L>
std::string get_tree_json( - const TreeMetaDataNode<T, L> *tree
Export tree as a JSON string.
- Template Parameters:
T – data type for input data (float or double).
L – data type for labels (int type for classification, T type for regression).
- Parameters:
tree – [in] CPU pointer to TreeMetaDataNode
- Returns:
Tree structure as JSON stsring
-
template<typename DataT, typename LabelT>
struct Dataset# - #include <dataset.h>
Public Members
-
const double *sample_weight#
optional input sample weights
-
std::int64_t n_rows#
total rows in dataset
-
std::int64_t n_cols#
total cols in dataset
-
std::int64_t row_stride#
row stride in input data elements
-
std::int64_t col_stride#
column stride in input data elements
-
std::int64_t n_sampled_rows#
total sampled rows in dataset
-
std::int64_t n_sampled_cols#
total sampled cols in dataset
-
std::int64_t *row_ids#
indices of sampled rows
-
int num_outputs#
Number of classes or regression outputs
-
const double *sample_weight#
-
struct DecisionTreeParams#
- #include <decisiontree.hpp>
Public Members
-
int max_depth#
Maximum tree depth. Set to INT32_MAX for unlimited depth (i.e., until leaves are pure or other stopping criteria are met).
-
int max_leaves#
Maximum leaf nodes per tree. Soft constraint. Unlimited, If
-1.
-
float max_features#
Ratio of number of features (columns) to consider per node split.
-
int max_n_bins#
maximum number of bins used by the split algorithm per feature.
-
int min_samples_leaf#
The minimum number of samples (rows) in each leaf node.
-
int min_samples_split#
The minimum number of samples (rows) needed to split an internal node.
-
CRITERION split_criterion#
Node split criterion. GINI and Entropy for classification, MSE for regression.
-
float min_impurity_decrease = 0.0f#
Minimum impurity decrease required for splitting a node. If the impurity decrease is below this value, node is leafed out. Default is 0.0
-
int max_batch_size#
Maximum number of nodes that can be processed in a given batch. This is used only for batched-level algo
-
int max_depth#
-
template<typename DataT>
struct Quantiles# - #include <quantiles.h>
-
template<typename T>
class TreeliteType#
-
template<>
class TreeliteType<double># - #include <treelite_util.h>
-
template<>
class TreeliteType<float># - #include <treelite_util.h>
-
template<>
class TreeliteType<int># - #include <treelite_util.h>
-
template<>
class TreeliteType<uint32_t># - #include <treelite_util.h>
-
template<class T, class L>
struct TreeMetaDataNode# - #include <decisiontree.hpp>
-
typedef TreeMetaDataNode<float, int> TreeClassifierF#
-
namespace Explainer#
Typedefs
-
using TreePathHandle = std::variant<std::shared_ptr<TreePathInfo<float>>, std::shared_ptr<TreePathInfo<double>>>#
-
using FloatPointer = std::variant<float*, double*>#
Functions
- void kernel_dataset(
- const raft::handle_t &handle,
- float *X,
- int nrows_X,
- int ncols,
- float *background,
- int nrows_background,
- float *dataset,
- float *observation,
- int *nsamples,
- int len_nsamples,
- int maxsample,
- uint64_t seed = 0ULL
Generates samples of dataset for kernel shap algorithm.
Kernel distributes exact part of the kernel shap dataset Each block scatters the data of a row of
observationsinto the (number of rows of background) indataset, based on the row ofX. So, given: background = [[0, 1, 2], [3, 4, 5]] observation = [100, 101, 102] X = [[1, 0, 1], [0, 1, 1]]dataset (output): [[100, 1, 102], [100, 4, 102] [0, 101, 102], [3, 101, 102]] The first thread of each block calculates the sampling of
kentries ofobservationto scatter intodataset. Afterwards each block scatters the data of a row ofXinto the (number of rows of background) indataset. So, given: background = [[0, 1, 2, 3], [5, 6, 7, 8]] observation = [100, 101, 102, 103] nsamples = [3, 2]X (output) [[1, 0, 1, 1], [0, 1, 1, 0]]
dataset (output): [[100, 1, 102, 103], [100, 6, 102, 103] [0, 101, 102, 3], [5, 101, 102, 8]]
- Parameters:
handle – [in] cuML handle
X – [inout] generated data [on device] 1-0 (row major)
nrows_X – [in] number of rows in X
ncols – [in] number of columns in X, background and dataset
background – [in] background data [on device]
nrows_background – [in] number of rows in background dataset
dataset – [out] generated data [on device] observation=background (row major)
observation – [in] row to scatter
nsamples – [in] vector with number of entries that are randomly sampled
len_nsamples – [in] number of entries to be sampled
maxsample – [in] size of the biggest sampled observation
seed – [in] Seed for the random number generator
- void permutation_shap_dataset(
- const raft::handle_t &handle,
- float *dataset,
- const float *background,
- int nrows_bg,
- int ncols,
- const float *row,
- int *idx,
- bool row_major
Generates a dataset by tiling the
backgroundmatrix intoout, while adding a forward and backward permutation pass of the observationrowon the positions defined byidx. Example:background = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] idx = [2, 0, 1] row = [100, 101, 102] output: [[ 0, 1, 2] [ 3, 4, 5] [ 6, 7, 8] [ 0, 1, 102] [ 3, 4, 102] [ 6, 7, 102] [100, 1, 102] [100, 4, 102] [100, 7, 102] [100, 101, 102] [100, 101, 102] [100, 101, 102] [100, 101, 2] [100, 101, 5] [100, 101, 8] [ 0, 101, 2] [ 3, 101, 5] [ 6, 101, 8] [ 0, 1, 2] [ 3, 4, 5] [ 6, 7, 8]]
- Parameters:
handle – [in] cuML handle
dataset – [out] generated data in either row major or column major format, depending on the
row_majorparameter [on device] [dim = (2 * ncols * nrows_bg + nrows_bg) * ncols]background – [in] background data [on device] [dim = ncols * nrows_bg]
nrows_bg – [in] number of rows in background dataset
ncols – [in] number of columns
row – [in] row to scatter in a permutated fashion [dim = ncols]
idx – [in] permutation indexes [dim = ncols]
row_major – [in] boolean to generate either row or column major data
- void shap_main_effect_dataset(
- const raft::handle_t &handle,
- float *dataset,
- const float *background,
- int nrows_bg,
- int ncols,
- const float *row,
- int *idx,
- bool row_major
Generates a dataset by tiling the
backgroundmatrix intoout, while adding a forward and backward permutation pass of the observationrowon the positions defined byidx. Example:background = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] idx = [2, 0, 1] row = [100, 101, 102] output: [[ 0, 1, 2] [ 3, 4, 5] [ 6, 7, 8] [ 0, 1, 102] [ 3, 4, 102] [ 6, 7, 102] [100, 1, 2] [100, 4, 5] [100, 7, 8] [ 0, 101, 2] [ 3, 101, 5] [ 6, 101, 8]]
- Parameters:
handle – [in] cuML handle
dataset – [out] generated data [on device] [dim = (2 * ncols * nrows_bg + nrows_bg) * ncols]
background – [in] background data [on device] [dim = ncols * nrows_bg]
nrows_bg – [in] number of rows in background dataset
ncols – [in] number of columns
row – [in] row to scatter in a permutated fashion [dim = ncols]
idx – [in] permutation indexes [dim = ncols]
row_major – [in] boolean to generate either row or column major data
- void update_perm_shap_values(
- const raft::handle_t &handle,
- float *shap_values,
- const float *y_hat,
- const int ncols,
- const int *idx
Function that aggregates averages of the averatge of results of the model called with the permutation dataset, to estimate the SHAP values. It is equivalent to the Python code: for i,ind in enumerate(idx): shap_values[ind] += y_hat[i + 1] - y_hat[i] for i,ind in enumerate(idx): shap_values[ind] += y_hat[i + ncols] - y_hat[i + ncols + 1]
- Parameters:
handle – [in] cuML handle
shap_values – [out] Array where the results are aggregated [dim = ncols]
y_hat – [in] Results to use for the aggregation [dim = ncols + 1]
ncols – [in] number of columns
idx – [in] permutation indexes [dim = ncols]
-
TreePathHandle extract_path_info(TreeliteModelHandle model)#
- void gpu_treeshap(
- TreePathHandle path_info,
- const FloatPointer data,
- std::size_t n_rows,
- std::size_t n_cols,
- FloatPointer out_preds,
- std::size_t out_preds_size
- void gpu_treeshap_interventional(
- TreePathHandle path_info,
- const FloatPointer data,
- std::size_t n_rows,
- std::size_t n_cols,
- const FloatPointer background_data,
- std::size_t background_n_rows,
- std::size_t background_n_cols,
- FloatPointer out_preds,
- std::size_t out_preds_size
- void gpu_treeshap_interactions(
- TreePathHandle path_info,
- const FloatPointer data,
- std::size_t n_rows,
- std::size_t n_cols,
- FloatPointer out_preds,
- std::size_t out_preds_size
- void gpu_treeshap_taylor_interactions(
- TreePathHandle path_info,
- const FloatPointer data,
- std::size_t n_rows,
- std::size_t n_cols,
- FloatPointer out_preds,
- std::size_t out_preds_size
-
template<typename T>
class TreePathInfo#
-
using TreePathHandle = std::variant<std::shared_ptr<TreePathInfo<float>>, std::shared_ptr<TreePathInfo<double>>>#
-
namespace GLM#
Functions
-
template<typename T, typename I = int>
void qnFit( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X,
- bool X_col_major,
- T *y,
- I N,
- I D,
- I C,
- T *w0,
- T *f,
- int *num_iters,
- T *sample_weight = nullptr,
- T svr_eps = 0
Fit a GLM using quasi newton methods.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X – device pointer to a contiguous feature matrix of dimension [N, D]
X_col_major – true if X is stored column-major
y – device pointer to label vector of length N
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)w0 – device pointer of size (D + (fit_intercept ? 1 : 0)) * C with initial point, overwritten by final result.
f – host pointer holding the final objective value
num_iters – host pointer holding the actual number of iterations taken
sample_weight – device pointer to sample weight vector of length n_rows (nullptr for uniform weights)
svr_eps – epsilon parameter for svr
-
template<typename T, typename I = int>
void qnFitSparse( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X_values,
- I *X_cols,
- I *X_row_ids,
- I X_nnz,
- T *y,
- I N,
- I D,
- I C,
- T *w0,
- T *f,
- int *num_iters,
- T *sample_weight = nullptr,
- T svr_eps = 0
Fit a GLM using quasi newton methods.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X_values – feature matrix values (CSR format), length = X_nnz
X_cols – feature matrix columns (CSR format), length = X_nnz, range = [0, … D-1]
X_row_ids – feature matrix compressed row ids (CSR format), length = N + 1, range = [0, … X_nnz]
X_nnz – number of non-zero entries in the feature matrix (CSR format)
y – device pointer to label vector of length N
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)w0 – device pointer of size (D + (fit_intercept ? 1 : 0)) * C with initial point, overwritten by final result.
f – host pointer holding the final objective value
num_iters – host pointer holding the actual number of iterations taken
sample_weight – device pointer to sample weight vector of length n_rows (nullptr for uniform weights)
svr_eps – epsilon parameter for svr
-
template<typename T, typename I = int>
void qnDecisionFunction( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X,
- bool X_col_major,
- I N,
- I D,
- I C,
- T *coefs,
- T *scores
Obtain the confidence scores of samples.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X – device pointer to a contiguous feature matrix of dimension [N, D]
X_col_major – true if X is stored column-major
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)coefs – device pointer to model coefficients. Length D if fit_intercept == false else D+1
scores – device pointer to confidence scores of length N (for binary logistic: [0,1], for multinomial: [0,…,C-1])
-
template<typename T, typename I = int>
void qnDecisionFunctionSparse( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X_values,
- I *X_cols,
- I *X_row_ids,
- I X_nnz,
- I N,
- I D,
- I C,
- T *coefs,
- T *scores
Obtain the confidence scores of samples.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X_values – feature matrix values (CSR format), length = X_nnz
X_cols – feature matrix columns (CSR format), length = X_nnz, range = [0, … D-1]
X_row_ids – feature matrix compressed row ids (CSR format), length = N + 1, range = [0, … X_nnz]
X_nnz – number of non-zero entries in the feature matrix (CSR format)
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)coefs – device pointer to model coefficients. Length D if fit_intercept == false else D+1
scores – device pointer to confidence scores of length N (for binary logistic: [0,1], for multinomial: [0,…,C-1])
-
template<typename T, typename I = int>
void qnPredict( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X,
- bool X_col_major,
- I N,
- I D,
- I C,
- T *coefs,
- T *preds
Predict a GLM using quasi newton methods.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X – device pointer to a contiguous feature matrix of dimension [N, D]
X_col_major – true if X is stored column-major
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)coefs – device pointer to model coefficients. Length D if fit_intercept == false else D+1
preds – device pointer to predictions of length N (for binary logistic: [0,1], for multinomial: [0,…,C-1])
-
template<typename T, typename I = int>
void qnPredictSparse( - const raft::handle_t &cuml_handle,
- const qn_params ¶ms,
- T *X_values,
- I *X_cols,
- I *X_row_ids,
- I X_nnz,
- I N,
- I D,
- I C,
- T *coefs,
- T *preds
Predict a GLM using quasi newton methods.
- Parameters:
cuml_handle – reference to raft::handle_t object
params – model parameters
X_values – feature matrix values (CSR format), length = X_nnz
X_cols – feature matrix columns (CSR format), length = X_nnz, range = [0, … D-1]
X_row_ids – feature matrix compressed row ids (CSR format), length = N + 1, range = [0, … X_nnz]
X_nnz – number of non-zero entries in the feature matrix (CSR format)
N – number of examples
D – number of features
C – number of outputs (number of classes or
1for regression)coefs – device pointer to model coefficients. Length D if fit_intercept == false else D+1
preds – device pointer to predictions of length N (for binary logistic: [0,1], for multinomial: [0,…,C-1])
-
namespace opg#
Functions
- void preProcessData(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &labels,
- float *mu_input,
- float *mu_labels,
- bool fit_intercept,
- cudaStream_t *streams,
- int n_streams,
- bool verbose
- void preProcessData(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &labels,
- double *mu_input,
- double *mu_labels,
- bool fit_intercept,
- cudaStream_t *streams,
- int n_streams,
- bool verbose
- void postProcessData(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &labels,
- float *coef,
- float *intercept,
- float *mu_input,
- float *mu_labels,
- bool fit_intercept,
- cudaStream_t *streams,
- int n_streams,
- bool verbose
- void postProcessData(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &labels,
- double *coef,
- double *intercept,
- double *mu_input,
- double *mu_labels,
- bool fit_intercept,
- cudaStream_t *streams,
- int n_streams,
- bool verbose
-
template<typename T>
std::vector<T> getUniquelabelsMG( - const raft::handle_t &handle,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<T>*> &labels
Calculate unique class labels across multiple GPUs in a multi-node environment.
- Parameters:
handle – [in] the internal cuml handle object
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
- Returns:
host vector that stores the distinct labels
-
template<typename T>
void qnFit( - raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<T>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<T>*> &labels,
- T *coef,
- const qn_params &pams,
- bool X_col_major,
- bool standardization,
- int n_classes,
- T *f,
- int *num_iters
performs MNMG fit operation for the logistic regression using quasi newton methods
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] vector holding all partitions for that rank
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
coef – [out] learned coefficients
pams – [in] model parameters
X_col_major – [in] true if X is stored column-major
standardization – [in] whether to standardize the dataset before training
n_classes – [in] number of outputs (number of classes or
1for regression)f – [out] host pointer holding the final objective value
num_iters – [out] host pointer holding the actual number of iterations taken
-
template<typename T, typename I>
void qnFitSparse( - raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<T>*> &input_values,
- I *input_cols,
- I *input_row_ids,
- I X_nnz,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<T>*> &labels,
- T *coef,
- const qn_params &pams,
- bool standardization,
- int n_classes,
- T *f,
- int *num_iters
support sparse vectors (Compressed Sparse Row format) for MNMG logistic regression fit using quasi newton methods
- Parameters:
handle – [in] the internal cuml handle object
input_values – [in] vector holding non-zero values of all partitions for that rank
input_cols – [in] vector holding column indices of non-zero values of all partitions for that rank
input_row_ids – [in] vector holding row pointers of non-zero values of all partitions for that rank
X_nnz – [in] the number of non-zero values of that rank
standardization – [in] whether to standardize the dataset before training
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
coef – [out] learned coefficients
pams – [in] model parameters
n_classes – [in] number of outputs (number of classes or
1for regression)f – [out] host pointer holding the final objective value
num_iters – [out] host pointer holding the actual number of iterations taken
-
template<typename T, typename I = int>
-
namespace graph_build_params#
-
struct nn_descent_params_umap#
- #include <umapparams.h>
Arguments for using nn descent as the knn build algorithm. graph_degree must be larger than or equal to n_neighbors. Increasing graph_degree and max_iterations may result in better accuracy. Smaller termination threshold means stricter convergence criteria for nn descent and may take longer to converge.
-
struct graph_build_params#
- #include <umapparams.h>
Parameters for knn graph building in UMAP. [Hint1]: the ratio of overlap_factor / n_clusters determines device memory usage. Approximately (overlap_factor / n_clusters) * num_rows_in_entire_data number of rows will be put on device memory at once. E.g. between (overlap_factor / n_clusters) = 2/10 and 2/20, the latter will use less device memory. [Hint2]: larger overlap_factor results in better accuracy of the final all-neighbors knn graph. E.g. While using similar amount of device memory, (overlap_factor / n_clusters) = 4/20 will have better accuracy than 2/10 at the cost of performance. [Hint3]: for overlap_factor, start with 2, and gradually increase (2->3->4 …) for better accuracy [Hint4]: for n_clusters, start with 4, and gradually increase(4->8->16 …) for less GPU memory usage. This is independent from overlap_factor as long as overlap_factor < n_clusters
Public Members
-
size_t overlap_factor = 2#
Number of clusters each data point is assigned to. Only valid when n_clusters > 1.
-
size_t n_clusters = 1#
Number of clusters to split the data into when building the knn graph. Increasing this will use less device memory at the cost of accuracy. When using n_clusters > 1, is is required that the data is put on host (refer to data_on_host argument for fit_transform). The default value (n_clusters=1) will place the entire data on device memory.
-
size_t overlap_factor = 2#
-
struct nn_descent_params_umap#
-
namespace HDBSCAN#
-
namespace Common#
Enums
Functions
- void generate_prediction_data(
- const raft::handle_t &handle,
- CondensedHierarchy<int64_t, float> &condensed_tree,
- int64_t *labels,
- int64_t *inverse_label_map,
- int n_selected_clusters,
- PredictionData<int64_t, float> &prediction_data
-
template<typename value_idx, typename value_t>
class CondensedHierarchy# - #include <hdbscan.hpp>
The Condensed hierarchicy is represented by an edge list with parents as the source vertices, children as the destination, with attributes for the cluster size and lambda value.
- Template Parameters:
value_idx –
value_t –
Public Functions
-
CondensedHierarchy(const raft::handle_t &handle_, size_t n_leaves_)#
Constructs an empty condensed hierarchy object which requires condense() to be called in order to populate the state.
- Parameters:
handle_ –
n_leaves_ –
- CondensedHierarchy(
- const raft::handle_t &handle_,
- size_t n_leaves_,
- int n_edges_,
- value_idx *parents_,
- value_idx *children_,
- value_t *lambdas_,
- value_idx *sizes_
Constructs a condensed hierarchy object with existing arrays which already contain a condensed hierarchy.
- Parameters:
handle_ –
n_leaves_ –
n_edges_ –
parents_ –
children_ –
lambdas_ –
sizes_ –
- CondensedHierarchy(
- const raft::handle_t &handle_,
- size_t n_leaves_,
- int n_edges_,
- int n_clusters_,
- rmm::device_uvector<value_idx> &&parents_,
- rmm::device_uvector<value_idx> &&children_,
- rmm::device_uvector<value_t> &&lambdas_,
- rmm::device_uvector<value_idx> &&sizes_
Constructs a condensed hierarchy object by moving rmm::device_uvector. Used to construct cluster trees
- Parameters:
handle_ –
n_leaves_ –
n_edges_ –
n_clusters_ –
parents_ –
children_ –
lambdas_ –
sizes_ –
- void condense(
- value_idx *full_parents,
- value_idx *full_children,
- value_t *full_lambdas,
- value_idx *full_sizes,
- value_idx size = -1
To maintain a high level of parallelism, the output from Condense::build_condensed_hierarchy() is sparse (the cluster nodes inside any collapsed subtrees will be 0).
This function converts the sparse form to a dense form and renumbers the cluster nodes into a topological sort order. The renumbering reverses the values in the parent array since root has the largest value in the single-linkage tree. Then, it makes the combined parent and children arrays monotonic. Finally all of the arrays of the dendrogram are sorted by parent->children->sizes (e.g. topological). The root node will always have an id of 0 and the largest cluster size.
Ths single-linkage tree dendrogram is a binary tree and parents/children can be found with simple indexing arithmetic but the condensed tree no longer has this property and so the tree now relies on either special indexing or the topological ordering for efficient traversal.
-
class RobustSingleLinkageParams#
- #include <hdbscan.hpp>
Subclassed by ML::HDBSCAN::Common::HDBSCANParams
-
class HDBSCANParams : public ML::HDBSCAN::Common::RobustSingleLinkageParams#
- #include <hdbscan.hpp>
-
template<typename value_idx, typename value_t>
class robust_single_linkage_output# - #include <hdbscan.hpp>
Container object for output information common between robust single linkage variants.
- Template Parameters:
value_idx –
value_t –
Subclassed by ML::HDBSCAN::Common::hdbscan_output< value_idx, value_t >
Public Functions
- inline robust_single_linkage_output(
- const raft::handle_t &handle_,
- int n_leaves_,
- value_idx *labels_,
- value_idx *children_,
- value_idx *sizes_,
- value_t *deltas_,
- value_idx *mst_src_,
- value_idx *mst_dst_,
- value_t *mst_weights_
Construct output object with empty device arrays of known size.
- Parameters:
handle_ – raft handle for ordering cuda operations
n_leaves_ – number of data points
labels_ – labels array on device (size n_leaves)
children_ – dendrogram src/dst array (size n_leaves - 1, 2)
sizes_ – dendrogram cluster sizes array (size n_leaves - 1)
deltas_ – dendrogram distances array (size n_leaves - 1)
mst_src_ – min spanning tree source array (size n_leaves - 1)
mst_dst_ – min spanning tree destination array (size n_leaves - 1)
mst_weights_ – min spanninng tree distances array (size n_leaves - 1)
-
inline void set_n_clusters(int n_clusters_)#
The number of clusters is set by the algorithm once it is known.
- Parameters:
n_clusters_ – number of resulting clusters
-
template<typename value_idx, typename value_t>
class hdbscan_output : public ML::HDBSCAN::Common::robust_single_linkage_output<value_idx, value_t># - #include <hdbscan.hpp>
Plain old container object to consolidate output arrays. This object is intentionally kept simple and straightforward in order to ease its use in the Python layer. For this reason, the MST arrays and renumbered dendrogram array, as well as its aggregated distances/cluster sizes, are kept separate. The condensed hierarchy is computed and populated in a separate object because its size is not known ahead of time. An RMM device vector is held privately and stabilities initialized explicitly since that size is also not known ahead of time.
- Template Parameters:
value_idx –
value_t –
Public Functions
-
inline void set_n_clusters(int n_clusters_)#
Once n_clusters is known, the stabilities array can be initialized.
- Parameters:
n_clusters_ –
-
template<typename value_idx, typename value_t>
class PredictionData# - #include <hdbscan.hpp>
Container object for computing and storing intermediate information needed later for computing membership vectors and approximate predict. Users are only expected to create an instance of this object, the hdbscan method will do the rest.
- Template Parameters:
value_idx –
value_t –
Public Functions
- void allocate(
- const raft::handle_t &handle,
- value_idx n_exemplars_,
- value_idx n_selected_clusters_,
- value_idx n_edges_
Resizes the buffers in the PredictionData object.
- Parameters:
handle – [in] raft handle for resource reuse
n_exemplars_ – [in] number of exemplar points
n_selected_clusters_ – [in] number of selected clusters in the final clustering
n_edges_ – [in] number of edges in the condensed hierarchy
-
namespace graph_build_params#
-
struct nn_descent_params_hdbscan#
- #include <hdbscan.hpp>
Arguments for using nn descent as the knn build algorithm. graph_degree must be larger than or equal to min_samples+1. Increasing graph_degree and max_iterations may result in better accuracy. Smaller termination threshold means stricter convergence criteria for nn descent and may take longer to converge.
-
struct graph_build_params#
- #include <hdbscan.hpp>
Parameters for knn graph building in HDBSCAN. Enables building the mutual reachability graph on datasets larger than device memory by:
Partitioning the dataset into overlapping clusters,
Computing local KNN graphs within each cluster, and
Merging the local graphs into a single global graph.
Guidelines for choosing parameters:
the ratio of overlap_factor / n_clusters determines device memory usage. Approximately (overlap_factor / n_clusters) * num_rows_in_entire_data number of rows will be put on device memory at once. E.g. between (overlap_factor / n_clusters) = 2/10 and 2/20, the latter will use less device memory.
larger overlap_factor results in better accuracy of the final all-neighbors knn graph. E.g. While using similar amount of device memory, (overlap_factor / n_clusters) = 4/20 will have better accuracy than 2/10 at the cost of performance.
for overlap_factor, start with 2, and gradually increase (2->3->4 …) for better accuracy
for n_clusters, start with 4, and gradually increase(4->8->16 …) for less GPU memory usage. This is independent from overlap_factor as long as overlap_factor < n_clusters
Public Members
-
size_t overlap_factor = 2#
Number of clusters each data point is assigned to. Only valid when n_clusters > 1.
-
size_t n_clusters = 1#
Number of clusters to split the data into when building the knn graph. Increasing this will use less device memory at the cost of accuracy. When using n_clusters > 1, is is required that the data is put on host (refer to data_on_host argument for fit_transform). The default value (n_clusters=1) will place the entire data on device memory.
-
struct nn_descent_params_hdbscan#
-
namespace HELPER#
Functions
- void compute_core_dists(
- const raft::handle_t &handle,
- const float *X,
- float *core_dists,
- size_t m,
- size_t n,
- ML::distance::DistanceType metric,
- int min_samples
Compute the core distances for each point in the training matrix.
- Parameters:
handle – [in] raft handle for resource reuse
X – [in] array (size m, n) on device in row-major format
core_dists – [out] array (size m, 1) of core distances
m – number of rows in X
n – number of columns in X
metric – distance metric to use
min_samples – minimum number of samples to use for computing core distances
- void compute_inverse_label_map(
- const raft::handle_t &handle,
- HDBSCAN::Common::CondensedHierarchy<int64_t, float> &condensed_tree,
- size_t n_leaves,
- HDBSCAN::Common::CLUSTER_SELECTION_METHOD cluster_selection_method,
- rmm::device_uvector<int64_t> &inverse_label_map,
- bool allow_single_cluster,
- int64_t max_cluster_size,
- float cluster_selection_epsilon
Compute the map from final, normalize labels to the labels in the CondensedHierarchy.
- Parameters:
handle – [in] raft handle for resource reuse
condensed_tree – [in] the Condensed Hierarchy object
n_leaves – [in] number of leaves in the input data
cluster_selection_method – [in] cluster selection method
inverse_label_map – [out] rmm::device_uvector of size 0. It will be resized during the computation
allow_single_cluster – [in] allow single cluster
max_cluster_size – [in] max cluster size
cluster_selection_epsilon – [in] cluster selection epsilon
-
namespace Common#
-
namespace HoltWinters#
Functions
- void buffer_size(
- int n,
- int batch_size,
- int frequency,
- int *start_leveltrend_len,
- int *start_season_len,
- int *components_len,
- int *error_len,
- int *leveltrend_coef_shift,
- int *season_coef_shift
Provides buffer sizes for HoltWinters algorithm
- Parameters:
n – [in] n_samples in time-series
batch_size – [in] number of time-series in X
frequency – [in] number of periods in a season of the time-series
start_leveltrend_len – [out] pointer which will hold the length of the level/trend array buffers
start_season_len – [out] pointer which will hold the length of the seasonal array buffer
components_len – [out] pointer which will hold the length of all three components
error_len – [out] pointer which will hold the length of the SSE Error
leveltrend_coef_shift – [out] pointer which will hold the offset to level/trend arrays
season_coef_shift – [out] pointer which will hold the offset to season array
- void fit(
- const raft::handle_t &handle,
- int n,
- int batch_size,
- int frequency,
- int start_periods,
- ML::SeasonalType seasonal,
- float epsilon,
- float *data,
- float *level_d,
- float *trend_d,
- float *season_d,
- float *error_d
Fits a HoltWinters model
- Parameters:
handle – [in] cuml handle to use across the algorithm
n – [in] n_samples in time-series
batch_size – [in] number of time-series in X
frequency – [in] number of periods in a season of the time-series
start_periods – [in] number of seasons to be used for seasonal seed values
seasonal – [in] type of seasonal component (ADDITIVE or MULTIPLICATIVE)
epsilon – [in] the error tolerance value for optimization
data – [in] device pointer to the data to fit on
level_d – [out] device pointer to array which will hold level components
trend_d – [out] device pointer to array which will hold trend components
season_d – [out] device pointer to array which will hold season components
error_d – [out] device pointer to array which will hold training SSE error
- void fit(
- const raft::handle_t &handle,
- int n,
- int batch_size,
- int frequency,
- int start_periods,
- ML::SeasonalType seasonal,
- double epsilon,
- double *data,
- double *level_d,
- double *trend_d,
- double *season_d,
- double *error_d
- void forecast(
- const raft::handle_t &handle,
- int n,
- int batch_size,
- int frequency,
- int h,
- ML::SeasonalType seasonal,
- float *level_d,
- float *trend_d,
- float *season_d,
- float *forecast_d
Forecasts future points from fitted HoltWinters model
- Parameters:
handle – [in] cuml handle to use across the algorithm
n – [in] n_samples in time-series
batch_size – [in] number of time-series in X
frequency – [in] number of periods in a season of the time-series
h – [in] number of future points to predict in the time-series
seasonal – [in] type of seasonal component (ADDITIVE or MULTIPLICATIVE)
level_d – [out] device pointer to array which holds level components
trend_d – [out] device pointer to array which holds trend components
season_d – [out] device pointer to array which holds season components
forecast_d – [out] device pointer to array which will hold the forecast points
- void forecast(
- const raft::handle_t &handle,
- int n,
- int batch_size,
- int frequency,
- int h,
- ML::SeasonalType seasonal,
- double *level_d,
- double *trend_d,
- double *season_d,
- double *forecast_d
-
namespace Internals#
-
class Callback#
- #include <callback.hpp>
Subclassed by ML::Internals::GraphBasedDimRedCallback
-
class Callback#
-
namespace KDE#
Enums
Functions
-
template<typename T>
void score_samples( - raft::resources const &handle,
- const T *query,
- const T *train,
- const T *weights,
- T *output,
- std::int64_t n_query,
- std::int64_t n_train,
- std::int64_t n_features,
- T bandwidth,
- T sum_weights,
- DensityKernelType kernel,
- ML::distance::DistanceType metric,
- T metric_arg
Compute normalized log-density scores for query samples.
The query and training arrays must be dense row-major (C-contiguous) device arrays with shapes
(n_query, n_features)and(n_train, n_features), respectively.- Template Parameters:
T – floating point type, either float or double
- Parameters:
handle – [in] raft resources used to launch work
query – [in] device pointer to query samples in row-major order
train – [in] device pointer to training samples in row-major order
weights – [in] optional device pointer to sample weights of length
n_train, or nullptr for uniform weightsoutput – [out] device pointer to log-density scores of length
n_queryn_query – [in] number of query samples
n_train – [in] number of training samples
n_features – [in] number of features per sample
bandwidth – [in] positive KDE bandwidth
sum_weights – [in] sum of
weights, orn_trainwhen weights is nullkernel – [in] density kernel to evaluate
metric – [in] distance metric used between query and training samples
metric_arg – [in] metric-specific argument, such as p for Minkowski
-
template<typename T>
-
namespace kmeans#
Functions
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *X,
- int n_samples,
- int n_features,
- const float *sample_weight,
- float *centroids,
- float &inertia,
- int &n_iter
Compute k-means clustering for each sample in the input.
- Parameters:
handle – [in] The handle to the cuML library context that manages the CUDA resources.
params – [in] Parameters for KMeans model.
X – [in] Training instances to cluster, in row-major format. May or may not be device accessible.
n_samples – [in] Number of samples in the input X.
n_features – [in] Number of features or the dimensions of each sample.
sample_weight – [in] The weights for each observation in X. If non-null, sample_weight must have the same memory residency as X.
centroids – [inout] [in] When init is InitMethod::Array, use centroids as the initial cluster centers [out] Otherwise, generated centroids from the kmeans algorithm is stored at the address pointed by ‘centroids’.
centroidsmust always be device accessible.inertia – [out] Sum of squared distances of samples to their closest cluster center.
n_iter – [out] Number of iterations run.
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *X,
- int n_samples,
- int n_features,
- const double *sample_weight,
- double *centroids,
- double &inertia,
- int &n_iter
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *X,
- int64_t n_samples,
- int64_t n_features,
- const float *sample_weight,
- float *centroids,
- float &inertia,
- int64_t &n_iter
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *X,
- int64_t n_samples,
- int64_t n_features,
- const double *sample_weight,
- double *centroids,
- double &inertia,
- int64_t &n_iter
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *const *X_parts,
- const int64_t *n_samples_parts,
- int64_t n_parts,
- int64_t n_features,
- const float *const *sample_weight_parts,
- float *centroids,
- float &inertia,
- int64_t &n_iter
Multi-GPU / out-of-core k-means fit over multiple local data partitions.
Each rank (e.g. each Dask worker) supplies its local training data as an array of
n_partspartitions. All partitions on a given rank must share the same residency. The distributed reduction across ranks is performed via the NCCL communicator that must be initialized onhandle.- Parameters:
handle – [in] cuML handle with NCCL comms initialized.
params – [in] Parameters for the KMeans model. For host-resident partitions the host-to-device batch size is read from
params.device_buffer_samples.X_parts – [in] Array of
n_partspointers to the local row-major partitions (all host- or all device-resident). Partitionihas shape [n_samples_parts[i],n_features].n_samples_parts – [in] Array of
n_partsper-partition row counts.n_parts – [in] Number of local partitions on this rank.
n_features – [in] Number of features (shared by all partitions).
sample_weight_parts – [in] Optional array of
n_partspointers to the per-partition weight vectors (matching the residency ofX_parts), ornullptrfor uniform weights.centroids – [inout] Device matrix [n_clusters x n_features].
inertia – [out] Sum of squared distances to closest center.
n_iter – [out] Number of iterations run.
- void fit(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *const *X_parts,
- const int64_t *n_samples_parts,
- int64_t n_parts,
- int64_t n_features,
- const double *const *sample_weight_parts,
- double *centroids,
- double &inertia,
- int64_t &n_iter
- void predict(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *centroids,
- const float *X,
- int n_samples,
- int n_features,
- const float *sample_weight,
- bool normalize_weights,
- int *labels,
- float &inertia
Predict the closest cluster each sample in X belongs to.
- Parameters:
handle – [in] The handle to the cuML library context that manages the CUDA resources.
params – [in] Parameters for KMeans model.
centroids – [in] Cluster centroids. It must be noted that the data must be in row-major format and stored in device accessible location.
X – [in] New data to predict.
n_samples – [in] Number of samples in the input X.
n_features – [in] Number of features or the dimensions of each sample in ‘X’ (value should be same as the dimension for each cluster centers in ‘centroids’).
sample_weight – [in] The weights for each observation in X.
normalize_weights – [in] True if the weights should be normalized
labels – [out] Index of the cluster each sample in X belongs to.
inertia – [out] Sum of squared distances of samples to their closest cluster center.
- void predict(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *centroids,
- const double *X,
- int n_samples,
- int n_features,
- const double *sample_weight,
- bool normalize_weights,
- int *labels,
- double &inertia
- void predict(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *centroids,
- const float *X,
- int64_t n_samples,
- int64_t n_features,
- const float *sample_weight,
- bool normalize_weights,
- int64_t *labels,
- float &inertia
- void predict(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *centroids,
- const double *X,
- int64_t n_samples,
- int64_t n_features,
- const double *sample_weight,
- bool normalize_weights,
- int64_t *labels,
- double &inertia
- void transform(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *centroids,
- const float *X,
- int n_samples,
- int n_features,
- float *X_new
Transform X to a cluster-distance space.
- Parameters:
handle – [in] The handle to the cuML library context that manages the CUDA resources.
params – [in] Parameters for KMeans model.
centroids – [in] Cluster centroids. It must be noted that the data must be in row-major format and stored in device accessible location.
X – [in] Training instances to cluster. It must be noted that the data must be in row-major format and stored in device accessible location.
n_samples – [in] Number of samples in the input X.
n_features – [in] Number of features or the dimensions of each sample in ‘X’ (it should be same as the dimension for each cluster centers in ‘centroids’).
X_new – [out] X transformed in the new space..
- void transform(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *centroids,
- const double *X,
- int n_samples,
- int n_features,
- double *X_new
- void transform(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const float *centroids,
- const float *X,
- int64_t n_samples,
- int64_t n_features,
- float *X_new
- void transform(
- const raft::handle_t &handle,
- const KMeansParams ¶ms,
- const double *centroids,
- const double *X,
- int64_t n_samples,
- int64_t n_features,
- double *X_new
- inline cuvs::cluster::kmeans::params to_cuvs(
- KMeansParams const &config
-
struct KMeansParams#
- #include <kmeans_params.hpp>
-
namespace KNN#
-
namespace opg#
Functions
- void knn(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<int64_t>*> *out_I,
- std::vector<MLCommon::Matrix::floatData_t*> *out_D,
- std::vector<MLCommon::Matrix::floatData_t*> &idx_data,
- MLCommon::Matrix::PartDescriptor &idx_desc,
- std::vector<MLCommon::Matrix::floatData_t*> &query_data,
- MLCommon::Matrix::PartDescriptor &query_desc,
- bool rowMajorIndex,
- bool rowMajorQuery,
- int k,
- size_t batch_size,
- bool verbose
Performs a multi-node multi-GPU KNN.
- Parameters:
handle – [in] the raft::handle_t to use for managing resources
out_I – [out] vector of output index partitions. size should match the number of local input partitions.
out_D – [out] vector of output distance partitions. size should match the number of local input partitions.
idx_data – [in] vector of local indices to query
idx_desc – [in] describes how the index partitions are distributed across the ranks.
query_data – [in] vector of local query partitions
query_desc – [in] describes how the query partitions are distributed across the cluster.
rowMajorIndex – [in] boolean indicating whether the index is row major.
rowMajorQuery – [in] boolean indicating whether the query is row major.
k – [in] the number of neighbors to query
batch_size – [in] the max number of rows to broadcast at a time
verbose – [in] print extra logging info
- void knn_classify(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<int>*> *out,
- std::vector<std::vector<float*>> *probas,
- std::vector<MLCommon::Matrix::floatData_t*> &idx_data,
- MLCommon::Matrix::PartDescriptor &idx_desc,
- std::vector<MLCommon::Matrix::floatData_t*> &query_data,
- MLCommon::Matrix::PartDescriptor &query_desc,
- std::vector<std::vector<int*>> &y,
- std::vector<int*> &uniq_labels,
- std::vector<int> &n_unique,
- bool rowMajorIndex = false,
- bool rowMajorQuery = false,
- bool probas_only = false,
- int k = 10,
- size_t batch_size = 1 << 15,
- bool verbose = false
Performs a multi-node multi-GPU KNN classify.
- Parameters:
handle – [in] the raft::handle_t to use for managing resources
out – [out] vector of output labels partitions. size should match the number of local input partitions.
probas – [in] (optional) pointer to a vector containing arrays of probabilities
idx_data – [in] vector of local indices to query
idx_desc – [in] describes how the index partitions are distributed across the ranks.
query_data – [in] vector of local query partitions
query_desc – [in] describes how the query partitions are distributed across the cluster.
y – [in] vector of vector of label arrays. for multilabel classification, each element in the vector is a different “output” array of labels corresponding to the i’th output. size should match the number of local input partitions.
uniq_labels – [in] vector of the sorted unique labels for each array in y
n_unique – [in] vector of sizes for each array in uniq_labels
rowMajorIndex – [in] boolean indicating whether the index is row major.
rowMajorQuery – [in] boolean indicating whether the query is row major.
probas_only – [in] return probas instead of performing complete knn_classify
k – [in] the number of neighbors to query
batch_size – [in] the max number of rows to broadcast at a time
verbose – [in] print extra logging info
- void knn_regress(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> *out,
- std::vector<MLCommon::Matrix::floatData_t*> &idx_data,
- MLCommon::Matrix::PartDescriptor &idx_desc,
- std::vector<MLCommon::Matrix::floatData_t*> &query_data,
- MLCommon::Matrix::PartDescriptor &query_desc,
- std::vector<std::vector<float*>> &y,
- bool rowMajorIndex,
- bool rowMajorQuery,
- int k,
- int n_outputs,
- size_t batch_size,
- bool verbose
Performs a multi-node multi-GPU KNN regress.
- Parameters:
handle – [in] the raft::handle_t to use for managing resources
out – [out] vector of output partitions. size should match the number of local input partitions.
idx_data – [in] vector of local indices to query
idx_desc – [in] describes how the index partitions are distributed across the ranks.
query_data – [in] vector of local query partitions
query_desc – [in] describes how the query partitions are distributed across the cluster.
y – [in] vector of vector of output arrays. for multi-output regression, each element in the vector is a different “output” array corresponding to the i’th output. size should match the number of local input partitions.
rowMajorIndex – [in] boolean indicating whether the index is row major.
rowMajorQuery – [in] boolean indicating whether the query is row major.
k – [in] the number of neighbors to query
n_outputs – [in] number of outputs
batch_size – [in] the max number of rows to broadcast at a time
verbose – [in] print extra logging info
-
namespace opg#
-
namespace linkage#
Functions
- void single_linkage(
- const raft::handle_t &handle,
- const float *X,
- int n_rows,
- int n_cols,
- size_t n_clusters,
- ML::distance::DistanceType metric,
- int *children,
- int *labels,
- bool use_knn = false,
- int c = 15
Computes single-linkage hierarchical clustering on a dense input feature matrix and outputs the labels, dendrogram, and minimum spanning tree.
- Parameters:
handle – [in] raft handle to encapsulate expensive resources
X – [in] dense feature matrix on device, C contiguous
n_rows – [in] number of rows in X
n_cols – [in] number of columns in X
n_clusters – [in] the number of clusters to fit.
metric – [in] distance metric to use. Must be supported by the dense pairwise distances API.
children – [out] the output dendrogram, shape=(n_rows - 1, 2), C contiguous
labels – [out] the output labels, shape=(n_rows,)
use_knn – [in] whether to construct a knn graph instead of the full n^2 pairwise distance matrix. This can be faster for very large datasets or in cases where lower memory usage is required.
c – [in] tunes the number of neighbors when
use_knnis true, wheren_neighbors=log(n_rows) + c.
-
namespace matrix#
Enums
Functions
- inline cuvs::distance::kernels::KernelParams to_cuvs(
- KernelParams const &config
-
struct KernelParams#
- #include <kernel_params.hpp>
-
namespace Metrics#
Unnamed Group
- double adjusted_rand_index(
- const raft::handle_t &handle,
- const int64_t *y,
- const int64_t *y_hat,
- const int64_t n
Calculates the “adjusted rand index”
This metric is the corrected-for-chance version of the rand index
- Parameters:
handle – raft::handle_t
y – Array of response variables of the first clustering classifications
y_hat – Array of response variables of the second clustering classifications
n – Number of elements in y and y_hat
- Returns:
: The adjusted rand index value
- double adjusted_rand_index(
- const raft::handle_t &handle,
- const int *y,
- const int *y_hat,
- const int n
Functions
- float r2_score_py(
- const raft::handle_t &handle,
- float *y,
- float *y_hat,
- int n
Calculates the “Coefficient of Determination” (R-Squared) score normalizing the sum of squared errors by the total sum of squares with single precision.
This score indicates the proportionate amount of variation in an expected response variable is explained by the independent variables in a linear regression model. The larger the R-squared value, the more variability is explained by the linear regression model.
- Parameters:
handle – raft::handle_t
y – Array of ground-truth response variables
y_hat – Array of predicted response variables
n – Number of elements in y and y_hat
- Returns:
: The R-squared value.
- double r2_score_py(
- const raft::handle_t &handle,
- double *y,
- double *y_hat,
- int n
Calculates the “Coefficient of Determination” (R-Squared) score normalizing the sum of squared errors by the total sum of squares with double precision.
This score indicates the proportionate amount of variation in an expected response variable is explained by the independent variables in a linear regression model. The larger the R-squared value, the more variability is explained by the linear regression model.
- Parameters:
handle – raft::handle_t
y – Array of ground-truth response variables
y_hat – Array of predicted response variables
n – Number of elements in y and y_hat
- Returns:
: The R-squared value.
- double rand_index(
- const raft::handle_t &handle,
- double *y,
- double *y_hat,
- int n
Calculates the “rand index”
This metric is a measure of similarity between two data clusterings.
- Parameters:
handle – raft::handle_t
y – Array of response variables of the first clustering classifications
y_hat – Array of response variables of the second clustering classifications
n – Number of elements in y and y_hat
- Returns:
: The rand index value
- double silhouette_score(
- const raft::handle_t &handle,
- double *y,
- int nRows,
- int nCols,
- int *labels,
- int nLabels,
- double *silScores,
- ML::distance::DistanceType metric
Calculates the “Silhouette Score”
The Silhouette Coefficient is calculated using the mean intra-cluster distance (a) and the mean nearest-cluster distance (b) for each sample. The Silhouette Coefficient for a sample is (b - a) / max(a, b). To clarify, b is the distance between a sample and the nearest cluster that the sample is not a part of. Note that Silhouette Coefficient is only defined if number of labels is 2 <= n_labels <= n_samples - 1.
- Parameters:
handle – raft::handle_t
y – Array of data samples with dimensions (nRows x nCols)
nRows – number of data samples
nCols – number of features
labels – Array containing labels for every data sample (1 x nRows)
nLabels – number of Labels
metric – the numerical value that maps to the type of distance metric to be used in the calculations
silScores – Array that is optionally taken in as input if required to be populated with the silhouette score for every sample (1 x nRows), else nullptr is passed
- double kl_divergence(
- const raft::handle_t &handle,
- const double *y,
- const double *y_hat,
- int n
Calculates the “Kullback-Leibler Divergence”
The KL divergence tells us how well the probability distribution Q approximates the probability distribution P It is often also used as a ‘distance metric’ between two probability distributions (not symmetric)
- Parameters:
handle – raft::handle_t
y – Array of probabilities corresponding to distribution P
y_hat – Array of probabilities corresponding to distribution Q
n – Number of elements in y and y_hat
- Returns:
: The KL Divergence value
- float kl_divergence(
- const raft::handle_t &handle,
- const float *y,
- const float *y_hat,
- int n
Calculates the “Kullback-Leibler Divergence”
The KL divergence tells us how well the probability distribution Q approximates the probability distribution P It is often also used as a ‘distance metric’ between two probability distributions (not symmetric)
- Parameters:
handle – raft::handle_t
y – Array of probabilities corresponding to distribution P
y_hat – Array of probabilities corresponding to distribution Q
n – Number of elements in y and y_hat
- Returns:
: The KL Divergence value
- double entropy(
- const raft::handle_t &handle,
- const int *y,
- const int n,
- const int lower_class_range,
- const int upper_class_range
Calculates the “entropy” of a labelling
This metric is a measure of the purity/polarity of the clustering
- Parameters:
handle – raft::handle_t
y – Array of response variables of the clustering
n – Number of elements in y
lower_class_range – the lowest value in the range of classes
upper_class_range – the highest value in the range of classes
- Returns:
: The entropy value of the clustering
- double mutual_info_score(
- const raft::handle_t &handle,
- const int *y,
- const int *y_hat,
- const int n,
- const int lower_class_range,
- const int upper_class_range
Calculates the “Mutual Information score” between two clusters
Mutual Information is a measure of the similarity between two labels of the same data.
- Parameters:
handle – raft::handle_t
y – Array of response variables of the first clustering classifications
y_hat – Array of response variables of the second clustering classifications
n – Number of elements in y and y_hat
lower_class_range – the lowest value in the range of classes
upper_class_range – the highest value in the range of classes
- Returns:
: The mutual information score
- double homogeneity_score(
- const raft::handle_t &handle,
- const int *y,
- const int *y_hat,
- const int n,
- const int lower_class_range,
- const int upper_class_range
Calculates the “homogeneity score” between two clusters
A clustering result satisfies homogeneity if all of its clusters contain only data points which are members of a single class.
- Parameters:
handle – raft::handle_t
y – truth labels
y_hat – predicted labels
n – Number of elements in y and y_hat
lower_class_range – the lowest value in the range of classes
upper_class_range – the highest value in the range of classes
- Returns:
: The homogeneity score
- double completeness_score(
- const raft::handle_t &handle,
- const int *y,
- const int *y_hat,
- const int n,
- const int lower_class_range,
- const int upper_class_range
Calculates the “completeness score” between two clusters
A clustering result satisfies completeness if all the data points that are members of a given class are elements of the same cluster.
- Parameters:
handle – raft::handle_t
y – truth labels
y_hat – predicted labels
n – Number of elements in y and y_hat
lower_class_range – the lowest value in the range of classes
upper_class_range – the highest value in the range of classes
- Returns:
: The completeness score
- double v_measure(
- const raft::handle_t &handle,
- const int *y,
- const int *y_hat,
- const int n,
- const int lower_class_range,
- const int upper_class_range,
- double beta
Calculates the “v-measure” between two clusters
v-measure is the harmonic mean between the homogeneity and completeness scores of 2 cluster classifications
- Parameters:
handle – raft::handle_t
y – truth labels
y_hat – predicted labels
n – Number of elements in y and y_hat
lower_class_range – the lowest value in the range of classes
upper_class_range – the highest value in the range of classes
beta – Ratio of weight attributed to homogeneity vs completeness
- Returns:
: The v-measure
- float accuracy_score_py(
- const raft::handle_t &handle,
- const int *predictions,
- const int *ref_predictions,
- int n
Calculates the “accuracy” between two input numpy arrays/ cudf series
The accuracy metric is used to calculate the accuracy of the predict labels predict labels
- Parameters:
handle – raft::handle_t
predictions – predicted labels
ref_predictions – truth labels
n – Number of elements in y and y_hat
- Returns:
: The accuracy
- void pairwise_distance(
- const raft::handle_t &handle,
- const double *x,
- const double *y,
- double *dist,
- int m,
- int n,
- int k,
- ML::distance::DistanceType metric,
- bool isRowMajor = true,
- double metric_arg = 2.0
Calculates the ij pairwise distances between two input arrays of double type.
- Parameters:
handle – raft::handle_t
x – pointer to the input data samples array (mRows x kCols)
y – pointer to the second input data samples array. Can use the same pointer as x (nRows x kCols)
dist – output pointer where the results will be stored (mRows x nCols)
m – number of rows in x
n – number of rows in y
k – number of cols in x and y (must be the same)
metric – the distance metric to use for the calculation
isRowMajor – specifies whether the x and y data pointers are row (C type array) or col (F type array) major
metric_arg – the value of
pfor Minkowski (l-p) distances.
- void pairwise_distance(
- const raft::handle_t &handle,
- const float *x,
- const float *y,
- float *dist,
- int m,
- int n,
- int k,
- ML::distance::DistanceType metric,
- bool isRowMajor = true,
- float metric_arg = 2.0f
Calculates the ij pairwise distances between two input arrays of float type.
- Parameters:
handle – raft::handle_t
x – pointer to the input data samples array (mRows x kCols)
y – pointer to the second input data samples array. Can use the same pointer as x (nRows x kCols)
dist – output pointer where the results will be stored (mRows x nCols)
m – number of rows in x
n – number of rows in y
k – number of cols in x and y (must be the same)
metric – the distance metric to use for the calculation
isRowMajor – specifies whether the x and y data pointers are row (C type array) or col (F type array) major
metric_arg – the value of
pfor Minkowski (l-p) distances.
- void pairwiseDistance_sparse(
- const raft::handle_t &handle,
- double *x,
- double *y,
- double *dist,
- int x_nrows,
- int y_nrows,
- int n_cols,
- int x_nnz,
- int y_nnz,
- int *x_indptr,
- int *y_indptr,
- int *x_indices,
- int *y_indices,
- ML::distance::DistanceType metric,
- float metric_arg
- void pairwiseDistance_sparse(
- const raft::handle_t &handle,
- float *x,
- float *y,
- float *dist,
- int x_nrows,
- int y_nrows,
- int n_cols,
- int x_nnz,
- int y_nnz,
- int *x_indptr,
- int *y_indptr,
- int *x_indices,
- int *y_indices,
- ML::distance::DistanceType metric,
- float metric_arg
-
template<typename math_t, ML::distance::DistanceType distance_type>
double trustworthiness_score( - const raft::handle_t &h,
- const math_t *X,
- math_t *X_embedded,
- int n,
- int m,
- int d,
- int n_neighbors,
- int batchSize = 512
Compute the trustworthiness score.
- Parameters:
h – Raft handle
X – Data in original dimension
X_embedded – Data in target dimension (embedding)
n – Number of samples
m – Number of features in high/original dimension
d – Number of features in low/embedded dimension
n_neighbors – Number of neighbors considered by trustworthiness score
batchSize – Batch size
- Template Parameters:
distance_type – Distance type to consider
- Returns:
Trustworthiness score
-
namespace Batched#
Functions
- float silhouette_score(
- const raft::handle_t &handle,
- float *X,
- int n_rows,
- int n_cols,
- int *y,
- int n_labels,
- float *scores,
- int chunk,
- ML::distance::DistanceType metric
Calculates Batched “Silhouette Score” by tiling the pairwise distance matrix to remove use of quadratic memory
The Silhouette Coefficient is calculated using the mean intra-cluster distance (a) and the mean nearest-cluster distance (b) for each sample. The Silhouette Coefficient for a sample is (b - a) / max(a, b). To clarify, b is the distance between a sample and the nearest cluster that the sample is not a part of. Note that Silhouette Coefficient is only defined if number of labels is 2 <= n_labels <= n_samples - 1.
- Parameters:
handle – [in] raft::handle_t
X – [in] Array of data samples with dimensions (n_rows x n_cols)
n_rows – [in] number of data samples
n_cols – [in] number of features
y – [in] Array containing labels for every data sample (1 x n_rows)
n_labels – [in] number of Labels
metric – [in] the numerical value that maps to the type of distance metric to be used in the calculations
chunk – [in] the row-wise chunk size on which the pairwise distance matrix is tiled
scores – [out] Array that is optionally taken in as input if required to be populated with the silhouette score for every sample (1 x nRows), else nullptr is passed
- double silhouette_score(
- const raft::handle_t &handle,
- double *X,
- int n_rows,
- int n_cols,
- int *y,
- int n_labels,
- double *scores,
- int chunk,
- ML::distance::DistanceType metric
-
namespace OLS#
-
namespace opg#
Functions
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &labels,
- float *coef,
- float *intercept,
- bool fit_intercept,
- int algo,
- bool verbose
performs MNMG fit operation for the ridge regression
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] vector holding all partitions for that rank
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
coef – [out] learned regression coefficients
intercept – [out] intercept value
fit_intercept – [in] fit intercept or not
algo – [in] which algorithm is used for OLS. 0 is for SVD, 1 is for eig.
verbose – [in]
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &labels,
- double *coef,
- double *intercept,
- bool fit_intercept,
- int algo,
- bool verbose
- void predict(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- size_t n_parts,
- MLCommon::Matrix::Data<float> **input,
- size_t n_rows,
- size_t n_cols,
- float *coef,
- float intercept,
- MLCommon::Matrix::Data<float> **preds,
- bool verbose
performs MNMG prediction for OLS
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
n_rows – [in] number of rows of input data
n_cols – [in] number of cols of input data
coef – [in] OLS coefficients
intercept – [in] the fit intercept
preds – [out] predictions
verbose – [in]
-
namespace opg#
-
namespace PCA#
-
namespace opg#
Functions
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- float *mu,
- float *noise_vars,
- paramsPCAMG prms,
- bool verbose = false
performs MNMG fit operation for the pca
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] input data
input_desc – [in] descriptor for input data
components – [out] principal components of the input data
explained_var – [out] explained var
explained_var_ratio – [out] the explained var ratio
singular_vals – [out] singular values of the data
mu – [out] mean of every column in input
noise_vars – [out] variance of the noise
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- double *mu,
- double *noise_vars,
- paramsPCAMG prms,
- bool verbose = false
- void fit_transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::floatData_t **input,
- MLCommon::Matrix::floatData_t **trans_input,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- float *mu,
- float *noise_vars,
- paramsPCAMG prms,
- bool verbose
performs MNMG fit and transform operation for the pca
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
trans_input – [out] transformed input data
components – [out] principal components of the input data
explained_var – [out] explained var
explained_var_ratio – [out] the explained var ratio
singular_vals – [out] singular values of the data
mu – [out] mean of every column in input
noise_vars – [out] variance of the noise
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void fit_transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::doubleData_t **input,
- MLCommon::Matrix::doubleData_t **trans_input,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- double *mu,
- double *noise_vars,
- paramsPCAMG prms,
- bool verbose
- void transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<float> **input,
- float *components,
- MLCommon::Matrix::Data<float> **trans_input,
- float *singular_vals,
- float *mu,
- paramsPCAMG prms,
- bool verbose
performs MNMG transform operation for the pca
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
components – [in] principal components of the input data
trans_input – [out] transformed input data
singular_vals – [in] singular values of the data
mu – [in] mean of every column in input
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<double> **input,
- double *components,
- MLCommon::Matrix::Data<double> **trans_input,
- double *singular_vals,
- double *mu,
- paramsPCAMG prms,
- bool verbose
- void inverse_transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<float> **trans_input,
- float *components,
- MLCommon::Matrix::Data<float> **input,
- float *singular_vals,
- float *mu,
- paramsPCAMG prms,
- bool verbose
performs MNMG inverse transform operation for the pca
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
trans_input – [in] transformed input data
components – [in] principal components of the input data
input – [out] input data
singular_vals – [in] singular values of the data
mu – [in] mean of every column in input
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
-
namespace opg#
-
namespace Ridge#
-
namespace opg#
Functions
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &labels,
- float *alpha,
- int n_alpha,
- float *coef,
- float *intercept,
- bool fit_intercept,
- int algo,
- bool verbose
performs MNMG fit operation for the ridge regression
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] vector holding all partitions for that rank
input_desc – [in] PartDescriptor object for the input
labels – [in] labels data
alpha – [in] ridge parameter
n_alpha – [in] number of ridge parameters. Only one parameter is supported right now.
coef – [out] learned regression coefficients
intercept – [out] intercept value
fit_intercept – [in] fit intercept or not
algo – [in] the algorithm to use for fitting
verbose – [in]
- void fit(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &labels,
- double *alpha,
- int n_alpha,
- double *coef,
- double *intercept,
- bool fit_intercept,
- int algo,
- bool verbose
- void predict(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- size_t n_parts,
- MLCommon::Matrix::Data<float> **input,
- size_t n_rows,
- size_t n_cols,
- float *coef,
- float intercept,
- MLCommon::Matrix::Data<float> **preds,
- bool verbose
performs MNMG prediction for OLS
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
n_rows – [in] number of rows of input data
n_cols – [in] number of cols of input data
coef – [in] OLS coefficients
intercept – [in] the fit intercept
preds – [out] predictions
verbose – [in]
-
namespace opg#
-
namespace Solver#
Functions
- void sgdFit(
- raft::handle_t &handle,
- float *input,
- int n_rows,
- int n_cols,
- float *labels,
- float *coef,
- float *intercept,
- bool fit_intercept,
- int batch_size,
- int epochs,
- int lr_type,
- float eta0,
- float power_t,
- int loss,
- int penalty,
- float alpha,
- float l1_ratio,
- bool shuffle,
- float tol,
- int n_iter_no_change
- void sgdFit(
- raft::handle_t &handle,
- double *input,
- int n_rows,
- int n_cols,
- double *labels,
- double *coef,
- double *intercept,
- bool fit_intercept,
- int batch_size,
- int epochs,
- int lr_type,
- double eta0,
- double power_t,
- int loss,
- int penalty,
- double alpha,
- double l1_ratio,
- bool shuffle,
- double tol,
- int n_iter_no_change
- void sgdPredict(
- raft::handle_t &handle,
- const float *input,
- int n_rows,
- int n_cols,
- const float *coef,
- float intercept,
- float *preds,
- int loss
- void sgdPredict(
- raft::handle_t &handle,
- const double *input,
- int n_rows,
- int n_cols,
- const double *coef,
- double intercept,
- double *preds,
- int loss
- void sgdPredictBinaryClass(
- raft::handle_t &handle,
- const float *input,
- int n_rows,
- int n_cols,
- const float *coef,
- float intercept,
- float *preds,
- int loss
- void sgdPredictBinaryClass(
- raft::handle_t &handle,
- const double *input,
- int n_rows,
- int n_cols,
- const double *coef,
- double intercept,
- double *preds,
- int loss
- int cdFit(
- raft::handle_t &handle,
- float *input,
- int n_rows,
- int n_cols,
- float *labels,
- float *coef,
- float *intercept,
- bool fit_intercept,
- int epochs,
- int loss,
- float alpha,
- float l1_ratio,
- bool shuffle,
- float tol,
- float *sample_weight = nullptr
Fits a linear, lasso, and elastic-net regression model using Coordinate Descent solver.
i.e. finds coefficients that minimize the following loss function:
f(coef) = 1/2 * || labels - input * coef ||^2
1/2 * alpha * (1 - l1_ratio) * ||coef||^2
alpha * l1_ratio * ||coef||_1
- Parameters:
handle – Reference of raft::handle_t
input – pointer to an array in column-major format (size of n_rows, n_cols)
n_rows – n_samples or rows in input
n_cols – n_features or columns in X
labels – pointer to an array for labels (size of n_rows)
coef – pointer to an array for coefficients (size of n_cols). This will be filled with coefficients once the function is executed.
intercept – pointer to a scalar for intercept. This will be filled once the function is executed
fit_intercept – boolean parameter to control if the intercept will be fitted or not
epochs – Maximum number of iterations that solver will run
loss – enum to use different loss functions. Only linear regression loss functions is supported right now
alpha – L1 parameter
l1_ratio – ratio of alpha will be used for L1. (1 - l1_ratio) * alpha will be used for L2
shuffle – boolean parameter to control whether coordinates will be picked randomly or not
tol – tolerance to stop the solver
sample_weight – device pointer to sample weight vector of length n_rows (nullptr or uniform weights) This vector is modified during the computation
- Returns:
n_iter Number of iterations the solver ran for.
- int cdFit(
- raft::handle_t &handle,
- double *input,
- int n_rows,
- int n_cols,
- double *labels,
- double *coef,
- double *intercept,
- bool fit_intercept,
- int epochs,
- int loss,
- double alpha,
- double l1_ratio,
- bool shuffle,
- double tol,
- double *sample_weight = nullptr
- void cdPredict(
- raft::handle_t &handle,
- const float *input,
- int n_rows,
- int n_cols,
- const float *coef,
- float intercept,
- float *preds,
- int loss
- void cdPredict(
- raft::handle_t &handle,
- const double *input,
- int n_rows,
- int n_cols,
- const double *coef,
- double intercept,
- double *preds,
- int loss
-
template<typename math_t>
void initShuffle(
)#
-
namespace Lars#
Functions
-
template<typename math_t, typename idx_t>
void larsFit( - const raft::handle_t &handle,
- math_t *X,
- idx_t n_rows,
- idx_t n_cols,
- const math_t *y,
- math_t *beta,
- idx_t *active_idx,
- math_t *alphas,
- idx_t *n_active,
- math_t *Gram = nullptr,
- int max_iter = 500,
- math_t *coef_path = nullptr,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::off,
- idx_t ld_X = 0,
- idx_t ld_G = 0,
- math_t eps = -1
Train a regressor using LARS method.
- Parameters:
handle – RAFT handle
X – device array of training vectors in column major format, size [n_rows * n_cols]. Note that the columns of X will be permuted if the Gram matrix is not specified. It is expected that X is normalized so that each column has zero mean and unit variance.
n_rows – number of training samples
n_cols – number of feature columns
y – device array of the regression targets, size [n_rows]. y should be normalized to have zero mean.
beta – device array of regression coefficients, has to be allocated on entry, size [max_iter]
active_idx – device array containing the indices of active variables. Must be allocated on entry. Size [max_iter]
alphas – the maximum correlation along the regularization path are returned here. Must be a device array allocated on entry Size [max_iter].
n_active – host pointer to return the number of active elements, scalar.
Gram – device array containing Gram matrix (X.T * X). Can be nullptr. Size [n_cols * ld_G]
max_iter – maximum number of iterations, this equals with the maximum number of coefficients returned. max_iter <= n_cols.
coef_path – coefficients along the regularization path are returned here. Must be nullptr, or a device array already allocated on entry. Size [max_iter * max_iter].
verbosity – verbosity level
ld_X – leading dimension of X (stride of columns, ld_X >= n_rows).
ld_G – leading dimension of G (ld_G >= n_cols)
eps – numeric parameter for Cholesky rank one update
-
template<typename math_t, typename idx_t>
void larsPredict( - const raft::handle_t &handle,
- const math_t *X,
- idx_t n_rows,
- idx_t n_cols,
- idx_t ld_X,
- const math_t *beta,
- idx_t n_active,
- idx_t *active_idx,
- math_t intercept,
- math_t *preds
Predict with LARS regressor.
- Parameters:
handle – RAFT handle
X – device array of training vectors in column major format, size [n_rows * n_cols].
n_rows – number of training samples
n_cols – number of feature columns
ld_X – leading dimension of X (stride of columns)
beta – device array of regression coefficients, size [n_active]
n_active – the number of regression coefficients
active_idx – device array containing the indices of active variables. Only these columns of X will be used for prediction, size [n_active].
intercept –
preds – device array to store the predictions, size [n_rows]. Must be allocated on entry.
-
template<typename math_t, typename idx_t>
-
namespace Sparse#
Functions
- void brute_force_knn(
- raft::handle_t &handle,
- const int *idx_indptr,
- const int *idx_indices,
- const float *idx_data,
- size_t idx_nnz,
- int n_idx_rows,
- int n_idx_cols,
- const int *query_indptr,
- const int *query_indices,
- const float *query_data,
- size_t query_nnz,
- int n_query_rows,
- int n_query_cols,
- int *output_indices,
- float *output_dists,
- int k,
- size_t batch_size_index = DEFAULT_BATCH_SIZE,
- size_t batch_size_query = DEFAULT_BATCH_SIZE,
- ML::distance::DistanceType metric = ML::distance::DistanceType::L2Expanded,
- float metricArg = 0
Variables
-
int DEFAULT_BATCH_SIZE = 1 << 16#
-
namespace SpectralClustering#
Functions
- void fit_predict(
- raft::resources const &handle,
- params config,
- raft::device_matrix_view<float, int, raft::row_major> dataset,
- raft::device_vector_view<int, int> labels
Perform spectral clustering on input dataset by constructing a k-nearest neighbors graph.
- Parameters:
handle – [in] cuML resources handle
config – [in] Parameters for spectral clustering
dataset – [in] Input dataset (row-major)
labels – [out] Cluster labels for each sample
- void fit_predict(
- raft::resources const &handle,
- params config,
- raft::device_coo_matrix_view<float, int, int, int> connectivity_graph,
- raft::device_vector_view<int, int> labels
Perform spectral clustering on a precomputed connectivity graph using COO sparse matrix view.
- Parameters:
handle – [in] cuML resources handle
config – [in] Parameters for spectral clustering
connectivity_graph – [in] COO sparse matrix view of the connectivity graph
labels – [out] Cluster labels for each sample
- void fit_predict(
- raft::resources const &handle,
- params config,
- raft::device_vector_view<int, int> rows,
- raft::device_vector_view<int, int> cols,
- raft::device_vector_view<float, int> vals,
- raft::device_vector_view<int, int> labels
Perform spectral clustering on a precomputed connectivity graph using separate vector views for COO components.
- Parameters:
handle – [in] cuML resources handle
config – [in] Parameters for spectral clustering
rows – [in] Row indices of the COO sparse matrix
cols – [in] Column indices of the COO sparse matrix
vals – [in] Values of the COO sparse matrix
labels – [out] Cluster labels for each sample
-
struct params#
- #include <spectral_clustering.hpp>
Spectral clustering parameters.
Public Members
-
int n_clusters#
Number of clusters to find.
-
int n_components#
Number of eigenvectors to use.
-
int n_init#
Number of times to run k-means with different seeds.
-
int n_neighbors#
Number of neighbors for kNN graph construction.
-
float eigen_tol#
Tolerance for the eigensolver.
-
uint64_t seed#
Random seed for reproducibility.
-
int n_clusters#
-
namespace SpectralEmbedding#
Functions
- void transform(
- raft::resources const &handle,
- ML::SpectralEmbedding::params config,
- raft::device_matrix_view<float, int, raft::row_major> dataset,
- raft::device_matrix_view<float, int, raft::col_major> embedding
- void transform(
- raft::resources const &handle,
- ML::SpectralEmbedding::params config,
- raft::device_coo_matrix_view<float, int, int, int64_t> connectivity_graph,
- raft::device_matrix_view<float, int, raft::col_major> embedding
- void transform(
- raft::resources const &handle,
- ML::SpectralEmbedding::params config,
- raft::device_vector_view<int, int64_t> rows,
- raft::device_vector_view<int, int64_t> cols,
- raft::device_vector_view<float, int64_t> vals,
- raft::device_matrix_view<float, int, raft::col_major> embedding
-
struct params#
- #include <spectral_embedding.hpp>
Parameters for spectral embedding algorithm.
Public Members
-
int n_components#
The number of components to reduce the data to.
-
int n_neighbors#
The number of neighbors to use for the nearest neighbors graph.
-
bool norm_laplacian#
Whether to normalize the Laplacian matrix.
-
bool drop_first#
Whether to drop the first eigenvector.
-
std::optional<uint64_t> seed = std::nullopt#
Random seed for reproducibility.
-
int n_components#
-
namespace Stationarity#
Functions
- void kpss_test(
- const raft::handle_t &handle,
- const float *d_y,
- bool *results,
- int batch_size,
- int n_obs,
- int d,
- int D,
- int s,
- float pval_threshold
Perform the KPSS stationarity test on the data differenced according to the given order.
- Parameters:
handle – [in] cuML handle
d_y – [in] Input data (column-major, series in columns)
results – [out] Boolean device array to store the results
batch_size – [in] Batch size
n_obs – [in] Number of observations
d – [in] Order of simple differencing
D – [out] Order of seasonal differencing
s – [in] Seasonal period if D > 0 (else unused)
pval_threshold – [in] P-value threshold above which a series is considered stationary
- void kpss_test(
- const raft::handle_t &handle,
- const double *d_y,
- bool *results,
- int batch_size,
- int n_obs,
- int d,
- int D,
- int s,
- double pval_threshold
-
namespace SVM#
Enums
Functions
-
template<typename math_t>
int svcFit( - const raft::handle_t &handle,
- math_t *input,
- int n_rows,
- int n_cols,
- math_t *labels,
- const SvmParameter ¶m,
- ML::matrix::KernelParams &kernel_params,
- SvmModel<math_t> &model,
- const math_t *sample_weight
Fit a support vector classifier to the training data.
Each row of the input data stores a feature vector. We use the SMO method to fit the SVM.
The output device buffers in model shall be unallocated on entry.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – [in] the cuML handle
input – [in] device pointer for the input data in column major format. Size n_rows x n_cols.
n_rows – [in] number of rows
n_cols – [in] number of columns
labels – [in] device pointer for the labels. Size [n_rows].
param – [in] parameters for training
kernel_params – [in] parameters for the kernel function
model – [out] parameters of the trained model
sample_weight – [in] optional sample weights, size [n_rows]
- Returns:
n_iter: the number of solver iterations run during fitting
-
template<typename math_t>
int svcFitSparse( - const raft::handle_t &handle,
- int *indptr,
- int *indices,
- math_t *data,
- int n_rows,
- int n_cols,
- int nnz,
- math_t *labels,
- const SvmParameter ¶m,
- ML::matrix::KernelParams &kernel_params,
- SvmModel<math_t> &model,
- const math_t *sample_weight
Fit a support vector classifier to the training data.
Each row of the input data stores a feature vector. We use the SMO method to fit the SVM.
The output device buffers in model shall be unallocated on entry.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – [in] the cuML handle
indptr – [in] device pointer for CSR row positions. Size [n_rows + 1].
indices – [in] device pointer for CSR column indices. Size [nnz].
data – [in] device pointer for the CSR data. Size [nnz].
n_rows – [in] number of rows
n_cols – [in] number of columns
nnz – [in] number of stored entries.
labels – [in] device pointer for the labels. Size [n_rows].
param – [in] parameters for training
kernel_params – [in] parameters for the kernel function
model – [out] parameters of the trained model
sample_weight – [in] optional sample weights, size [n_rows]
- Returns:
n_iter: the number of solver iterations run during fitting
-
template<typename math_t>
void svcPredict( - const raft::handle_t &handle,
- math_t *input,
- int n_rows,
- int n_cols,
- ML::matrix::KernelParams &kernel_params,
- const SvmModel<math_t> &model,
- math_t *preds,
- math_t buffer_size,
- bool predict_class
Predict classes or decision function value for samples in input.
We evaluate the decision function f(x_i). Depending on the parameter predict_class, we either return f(x_i) or the label corresponding to sign(f(x_i)).
The predictions are calculated according to the following formulas:
\[ f(x_i) = \sum_{j=1}^n_support K(x_i, x_j) * dual_coefs[j] + b) \]pred(x_i) = label[sign(f(x_i))], if predict_class==true, or pred(x_i) = f(x_i), if predict_class==false.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – the cuML handle
input – [in] device pointer for the input data in column major format, size [n_rows x n_cols].
n_rows – [in] number of rows (input vectors)
n_cols – [in] number of columns (features)
kernel_params – [in] parameters for the kernel function
model – [in] SVM model parameters
preds – [out] device pointer to store the predicted class labels. Size [n_rows]. Should be allocated on entry.
buffer_size – [in] size of temporary buffer in MiB
predict_class – [in] whether to predict class label (true), or just return the decision function value (false)
-
template<typename math_t>
void svcPredictSparse( - const raft::handle_t &handle,
- int *indptr,
- int *indices,
- math_t *data,
- int n_rows,
- int n_cols,
- int nnz,
- ML::matrix::KernelParams &kernel_params,
- const SvmModel<math_t> &model,
- math_t *preds,
- math_t buffer_size,
- bool predict_class
Predict classes or decision function value for samples in input.
We evaluate the decision function f(x_i). Depending on the parameter predict_class, we either return f(x_i) or the label corresponding to sign(f(x_i)).
The predictions are calculated according to the following formulas:
\[ f(x_i) = \sum_{j=1}^n_support K(x_i, x_j) * dual_coefs[j] + b) \]pred(x_i) = label[sign(f(x_i))], if predict_class==true, or pred(x_i) = f(x_i), if predict_class==falsee.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – the cuML handle
indptr – [in] device pointer for CSR row positions. Size [n_rows + 1].
indices – [in] device pointer for CSR column indices. Size [nnz].
data – [in] device pointer for the CSR data. Size [nnz].
n_rows – [in] number of rows
n_cols – [in] number of columns
nnz – [in] number of stored entries.
kernel_params – [in] parameters for the kernel function
model – [in] SVM model parameters
preds – [out] device pointer to store the predicted class labels. Size [n_rows]. Should be allocated on entry.
buffer_size – [in] size of temporary buffer in MiB
predict_class – [in] whether to predict class label (true), or just return the decision function value (false)
-
template<typename math_t>
void svmFreeBuffers(
)# Deallocate device buffers in the SvmModel struct.
- Parameters:
handle – [in] cuML handle
m – [inout] SVM model parameters
-
template<typename math_t>
int svrFit( - const raft::handle_t &handle,
- math_t *X,
- int n_rows,
- int n_cols,
- math_t *y,
- const SvmParameter ¶m,
- ML::matrix::KernelParams &kernel_params,
- SvmModel<math_t> &model,
- const math_t *sample_weight
Fit a support vector regressor to the training data.
Each row of the input data stores a feature vector.
The output buffers in model shall be unallocated on entry.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – [in] the cuML handle
X – [in] device pointer for the input data in column major format. Size n_rows x n_cols.
n_rows – [in] number of rows
n_cols – [in] number of columns
y – [in] device pointer for target values. Size [n_rows].
param – [in] parameters for training
kernel_params – [in] parameters for the kernel function
model – [out] parameters of the trained model
sample_weight – [in] optional sample weights, size [n_rows]
- Returns:
n_iter: the number of solver iterations run during fitting
-
template<typename math_t>
int svrFitSparse( - const raft::handle_t &handle,
- int *indptr,
- int *indices,
- math_t *data,
- int n_rows,
- int n_cols,
- int nnz,
- math_t *y,
- const SvmParameter ¶m,
- ML::matrix::KernelParams &kernel_params,
- SvmModel<math_t> &model,
- const math_t *sample_weight
Fit a support vector regressor to the training data.
Each row of the input data stores a feature vector.
The output buffers in model shall be unallocated on entry.
- Template Parameters:
math_t – floating point type
- Parameters:
handle – [in] the cuML handle
indptr – [in] device pointer for CSR row positions. Size [n_rows + 1].
indices – [in] device pointer for CSR column indices. Size [nnz].
data – [in] device pointer for the CSR data. Size [nnz].
n_rows – [in] number of rows
n_cols – [in] number of columns
nnz – [in] number of stored entries.
y – [in] device pointer for target values. Size [n_rows].
param – [in] parameters for training
kernel_params – [in] parameters for the kernel function
model – [out] parameters of the trained model
sample_weight – [in] optional sample weights, size [n_rows]
- Returns:
n_iter: the number of solver iterations run during fitting
-
template<typename math_t>
class SmoSolver# - #include <smosolver.h>
Solve the quadratic optimization problem using two level decomposition and Sequential Minimal Optimization (SMO).
The general decomposition idea by Osuna is to choose q examples from all the training examples, and solve the QP problem for this subset (discussed in section 11.2 by Joachims [1]). SMO is the extreme case where we choose q=2.
Here we follow [2] and [3] and use two level decomposition. First we set q_1=1024, and solve the QP sub-problem for that (let’s call it QP1). This is the outer iteration, implemented in SmoSolver::Solve.
To solve QP1, we use another decomposition, specifically the SMO (q_2 = 2), which is implemented in SmoBlockSolve.
References:
[1] Joachims, T. Making large-scale support vector machine learning practical. In B. Scholkopf, C. Burges, & A. Smola (Eds.), Advances in kernel methods: Support vector machines. Cambridge, MA: MIT Press (1998)
[2] J. Vanek et al. A GPU-Architecture Optimized Hierarchical Decomposition Algorithm for Support VectorMachine Training, IEEE Transactions on Parallel and Distributed Systems, vol 28, no 12, 3330, (2017)
[3] Z. Wen et al. ThunderSVM: A Fast SVM Library on GPUs and CPUs, Journal of Machine Learning Research, 19, 1-5 (2018)
Public Functions
-
template<typename MatrixViewType>
void Solve( - MatrixViewType matrix,
- int n_rows,
- int n_cols,
- math_t *y,
- const math_t *sample_weight,
- math_t **dual_coefs,
- int *n_support,
- SupportStorage<math_t> *support_matrix,
- int **idx,
- math_t *b,
- int max_iter = -1,
- int max_outer_iter = -1,
- int max_inner_iter = 10000
Solve the quadratic optimization problem.
The output arrays (dual_coefs, support_matrix, idx) will be allocated on the device, they should be unallocated on entry.
- Parameters:
matrix – [in] training vectors in matrix format(MLCommon::Matrix::Matrix), size [n_rows x * n_cols]
n_rows – [in] number of rows (training vectors)
n_cols – [in] number of columns (features)
y – [in] labels (values +/-1), size [n_rows]
sample_weight – [in] device array of sample weights (or nullptr if not applicable)
dual_coefs – [out] size [n_support] on exit
n_support – [out] number of support vectors
support_matrix – [out] support vectors in matrix format, size [n_support, n_cols]
idx – [out] the original training set indices of the support vectors, size [n_support]
b – [out] scalar constant for the decision function
max_iter – [in] maximum number of total iterations (default -1 for no limit)
max_outer_iter – [in] maximum number of outer iteration (default 100 * n_rows)
max_inner_iter – [in] maximum number of inner iterations (default 10000)
- void UpdateF( )#
Update the f vector after a block solve step.
\[ f_i = f_i + \sum_{k\in WS} K_{i,k} * \Delta \alpha_k, \]where i = [0..n_train-1], WS is the set of workspace indices, and \(K_{i,k}\) is the kernel function evaluated for training vector x_i and workspace vector x_k.- Parameters:
f – size [n_train]
n_rows –
delta_alpha – size [n_ws]
n_ws –
cacheTile – kernel function evaluated for the following set K[X,x_ws], size [n_rows, n_ws]
- void Initialize( )#
Initialize the problem to solve.
Both SVC and SVR are solved as a classification problem. The optimization target (W) does not appear directly in the SMO formulation, only its derivative through f (optimality indicator vector):
\[ f_i = y_i \frac{\partial W }{\partial \alpha_i}. \]The f_i values are initialized here, and updated at every solver iteration when alpha changes. The update step is the same for SVC and SVR, only the init step differs.
Additionally, we zero init the dual coefficients (alpha), and initialize class labels for SVR.
- Parameters:
y – [inout] on entry class labels or target values, on exit device pointer to class labels
sample_weight – [in] sample weights (can be nullptr, otherwise device array of size [n_rows])
n_rows – [in]
n_cols – [in]
-
void SvcInit(const math_t *y)#
Initialize Support Vector Classification.
We would like to maximize the following quantity
\[ W(\mathbf{\alpha}) = -\mathbf{\alpha}^T \mathbf{1} + \frac{1}{2} \mathbf{\alpha}^T Q \mathbf{\alpha}, \]We initialize f as:
\[ f_i = y_i \frac{\partial W(\mathbf{\alpha})}{\partial \alpha_i} = -y_i + y_j \alpha_j K(\mathbf{x}_i, \mathbf{x}_j) \]- Parameters:
y – [in] device pointer of class labels size [n_rows]
-
void SvrInit(const math_t *yr, int n_rows, math_t *yc, math_t *f)#
Initializes the solver for epsilon-SVR.
For regression we are optimizing the following quantity
\[W(\alpha^+, \alpha^-) = \epsilon \sum_{i=1}^l (\alpha_i^+ + \alpha_i^-) - \sum_{i=1}^l yc_i (\alpha_i^+ - \alpha_i^-) + \frac{1}{2} \sum_{i,j=1}^l (\alpha_i^+ - \alpha_i^-)(\alpha_j^+ - \alpha_j^-) K(\bm{x}_i, \bm{x}_j) \]Then \( f_i = y_i \frac{\partial W(\alpha}{\partial \alpha_i} \) \( = yc_i*epsilon - yr_i \)
Additionally we set class labels for the training vectors.
References: [1] B. Schölkopf et. al (1998): New support vector algorithms, NeuroCOLT2 Technical Report Series, NC2-TR-1998-031, Section 6 [2] A.J. Smola, B. Schölkopf (2004): A tutorial on support vector regression, Statistics and Computing 14, 199–222 [3] Orchel M. (2011) Support Vector Regression as a Classification Problem with a Priori Knowledge in the Form of Detractors, Man-Machine Interactions 2. Advances in Intelligent and Soft Computing, vol 103
- Parameters:
yr – [in] device pointer with values for regression, size [n_rows]
n_rows – [in]
yc – [out] device pointer to classes associated to the dual coefficients, size [n_rows*2]
f – [out] device pointer f size [n_rows*2]
-
template<typename math_t>
struct SupportStorage# - #include <svm_model.h>
-
template<typename math_t>
class SVC# - #include <svc.hpp>
C-Support Vector Classification.
This is a Scikit-Learn like wrapper around the stateless C++ functions. See Issue #456 for general discussion about stateful Sklearn like wrappers.
The classifier will be fitted using the SMO algorithm in dual space.
The decision function takes the following form
\[ sign\left( \sum_{i=1}^{N_{support}} y_i \alpha_i K(x_i,x) + b \right), \]where \(x_i\) are the support vectors, and \( y_i \alpha_i \) are the dual coordinates.The penalty parameter C limits the values of the dual coefficients
\[ 0 <= \alpha <= C \]Public Functions
- SVC(
- raft::handle_t &handle,
- math_t C = 1,
- math_t tol = 1.0e-3,
- ML::matrix::KernelParams kernel_params = ML::matrix::KernelParams{ML::matrix::KernelType::LINEAR, 3, 1, 0},
- math_t cache_size = 200,
- int max_iter = -1,
- int nochange_steps = 1000,
- rapids_logger::level_enum verbosity = rapids_logger::level_enum::info
Constructs a support vector classifier.
- Parameters:
handle – cuML handle
C – penalty term
tol – tolerance to stop fitting
kernel_params – parameters for kernels
cache_size – size of kernel cache in device memory (MiB)
max_iter – maximum number of outer iterations in SmoSolver
nochange_steps – number of steps with no change wrt convergence
verbosity – verbosity level for logging messages during execution
- void fit( )#
Fit a support vector classifier to the training data.
Each row of the input data stores a feature vector. We use the SMO method to fit the SVM.
- Parameters:
input – device pointer for the input data in column major format. Size n_rows x n_cols.
n_rows – number of rows
n_cols – number of columns
labels – device pointer for the labels. Size n_rows.
sample_weight – [in] optional sample weights, size [n_rows]
-
void predict(math_t *input, int n_rows, int n_cols, math_t *preds)#
Predict classes for samples in input.
- Parameters:
input – [in] device pointer for the input data in column major format, size [n_rows x n_cols].
n_rows – [in] number of vectors
n_cols – [in] number of features
preds – [out] device pointer to store the predicted class labels. Size [n_rows]. Should be allocated on entry.
- void decisionFunction( )#
Calculate decision function value for samples in input.
- Parameters:
input – [in] device pointer for the input data in column major format, size [n_rows x n_cols].
n_rows – [in] number of vectors
n_cols – [in] number of features
preds – [out] device pointer to store the decision function value Size [n_rows]. Should be allocated on entry.
-
template<typename math_t>
struct SvmModel# - #include <svm_model.h>
Parameters that describe a trained SVM model. All pointers are device pointers.
Public Members
-
int n_support#
Number of support vectors.
-
int n_cols#
Number of features.
-
math_t *dual_coefs#
Non-zero dual coefficients ( dual_coef[i] = \( y_i \alpha_i \)). Size [n_support].
-
SupportStorage<math_t> support_matrix#
Support vector storage - can contain either CSR or dense.
-
int *support_idx#
Indices (from the training set) of the support vectors, size [n_support].
-
int n_classes#
Number of classes found in the input labels
-
int n_support#
-
struct SvmParameter#
- #include <svm_parameter.h>
Numerical input parameters for an SVM.
There are several parameters that control how long we train. The training stops if:
max_outer_iter outer iterations are reached. If you pass -1, then max_diff = 100 * n_rows
max_iter total iterations are reached. Pass -1 for no limit on total iterations.
the diff becomes less the tol
the diff is changing less then 0.001*tol in nochange_steps consecutive outer iterations.
-
template<typename math_t>
class WorkingSet# - #include <workingset.h>
Working set selection for the SMO algorithm.
The working set is a subset of the training vectors, by default it has 1024 elements. At every outer iteration in SmoSolver::Solve, we select a different working set, and optimize the dual coefficients for the working set.
The vectors are selected based on the f values, which is the difference between the target label and the decision function value.
Public Functions
- inline WorkingSet(
- const raft::handle_t &handle,
- cudaStream_t stream,
- int n_rows = 0,
- int n_ws = 0,
- SvmType svmType = C_SVC
Manage a working set.
- Parameters:
handle – cuml handle implementation
stream – cuda stream for working set operations
n_rows – number of training vectors
n_ws – number of elements in the working set (default 1024)
svmType – classification or regression
-
inline void SetSize(int n_train, int n_ws = 0)#
Set the size of the working set and allocate buffers accordingly.
- Parameters:
n_train – number of training vectors
n_ws – working set size (default min(1024, n_train))
-
inline int GetSize()#
Return the size of the working set.
-
inline int *GetIndices()#
Return a device pointer to the the working set indices.
The returned array is owned by WorkingSet.
- void SimpleSelect( )#
Select new elements for a working set.
Here we follow the working set selection strategy by Joachims [1], we select n training instances as:
select n/2 element of upper set, where f is largest
select n/2 from lower set, where f is smallest
The difference compared to Joachims’ strategy is that we can already have some elements selected by a different strategy, therefore we select only n = n_ws - n_already_selected.
References: [1] Joachims, T. (1998). Making large-scale support vector machine learning practical. In B. Scholkopf, C. Burges, & A. Smola (Eds.), Advances in kernel methods: Support vector machines. Cambridge, MA: MIT Press
- Parameters:
f – optimality indicator vector, size [n_train]
alpha – dual coefficients, size [n_train]
y – target labels (+/- 1)
C – penalty parameter vector size [n_train]
n_already_selected –
- inline void Select( )#
Select working set indices.
To avoid training vectors oscillating in and out of the working set, we keep half of the previous working set, and fill new elements only to the other half.
We can have a FIFO retention policy, or we can consider the time (=ws_priority) a vector already spent in the ws. References: [1] Z. Wen et al. ThunderSVM: A Fast SVM Library on GPUs and CPUs, Journal of Machine Learning Research, 19, 1-5 (2018)
- Parameters:
f – optimality indicator vector, size [n_train]
alpha – dual coefficients, size [n_train]
y – class labels, size [n_train]
C – penalty parameter vector, size [n_train]
-
int PrioritySelect(math_t *alpha, const math_t *C, int nc)#
Select elements from the previous working set based on their priority.
We sort the old working set based on their priority in ascending order, and then select nc elements from free, and then lower/upper bound vectors. For details see [2].
See Issue #946.
References: [2] T Serafini, L Zanni: On the Working Set selection in grad. projection based decomposition techniques for Support Vector Machines DOI: 10.1080/10556780500140714
- Parameters:
alpha – [in] device vector of dual coefficients, size [n_train]
C – [in] penalty parameter
nc – [in] number of elements to select
Public Members
-
bool FIFO_strategy = true#
Workspace selection strategy, note that only FIFO is tested so far
-
namespace linear#
Functions
-
template<typename T>
int fit( - const raft::handle_t &handle,
- const Params ¶ms,
- const std::size_t nRows,
- const std::size_t nCols,
- const int nClasses,
- const T *classes,
- const T *X,
- const T *y,
- const T *sampleWeight,
- T *w
Fit a linear SVM model.
- Parameters:
handle – [in] the cuML handle.
params – [in] the model parameters.
nRows – [in] the number of input samples.
nCols – [in] the number of feature dimensions.
nClasses – [in] the number of input classes, or 0 for a regression problem.
classes – [in] the unique input classes, shape=(nClasses,), or nullptr for a regression problem.
X – [in] the training data, shape=(nRows, nCols), F-contiguous
y – [in] the target data, shape=(nRows,)
sampleWeight – [in] non-negative weights for the training data, shape=(nRows,), or nullptr if unweighted.
w – [out] the fitted weights, shape=(nCoefs, nCols) or (nCoefs + 1, nCols + 1) if
fit_intercept=true, where nCoefs = 1 for regression or if nClasses = 2, and nClasses otherwise. F-contiguous.
- Returns:
n_iter: the maximum number of iterations run across all classes.
-
struct Params#
- #include <linear.hpp>
Public Types
Public Members
-
bool fit_intercept = true#
Whether to fit the bias term.
-
bool penalized_intercept = false#
When true, the bias term is treated the same way as other data features. Enabling this feature forces an extra copying the input data X.
-
int max_iter = 1000#
Maximum number of iterations for the underlying QN solver.
-
int linesearch_max_iter = 100#
Maximum number of linesearch (inner loop) iterations for the underlying QN solver.
-
int lbfgs_memory = 5#
Number of vectors approximating the hessian for the underlying QN solver (l-bfgs).
-
rapids_logger::level_enum verbose = rapids_logger::level_enum::off#
Triggers extra output when greater than zero.
-
double C = 1.0#
The constant scaling factor of the main term in the loss function. (You can also think of that as the inverse factor of the penalty term).
-
double grad_tol = 0.0001#
The threshold on the gradient for the underlying QN solver.
-
double change_tol = 0.00001#
The threshold on the function change for the underlying QN solver.
-
double epsilon = 0.0#
The epsilon-sensitivity parameter (applicable to the SVM-regression (SVR) loss functions).
-
bool fit_intercept = true#
-
template<typename T>
-
template<typename math_t>
-
namespace TSVD#
-
namespace opg#
Functions
- void fit(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::floatData_t **input,
- float *components,
- float *singular_vals,
- paramsTSVDMG &prms,
- bool verbose = false
performs MNMG fit operation for the tsvd
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
components – [out] principal components of the input data
singular_vals – [out] singular values of the data
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void fit(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::doubleData_t **input,
- double *components,
- double *singular_vals,
- paramsTSVDMG &prms,
- bool verbose = false
- void fit_transform(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<float>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<float>*> &trans_data,
- MLCommon::Matrix::PartDescriptor &trans_desc,
- float *components,
- float *explained_var,
- float *explained_var_ratio,
- float *singular_vals,
- paramsTSVDMG &prms,
- bool verbose
performs MNMG fit and transform operation for the tsvd.
- Parameters:
handle – [in] the internal cuml handle object
input_data – [in] input data
input_desc – [in] input descriptor for data
trans_data – [out] transformed input data
trans_desc – [out] transformed input data descriptor
components – [out] principal components of the input data
explained_var – [out] explained var
explained_var_ratio – [out] the explained var ratio
singular_vals – [out] singular values of the data
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void fit_transform(
- raft::handle_t &handle,
- std::vector<MLCommon::Matrix::Data<double>*> &input_data,
- MLCommon::Matrix::PartDescriptor &input_desc,
- std::vector<MLCommon::Matrix::Data<double>*> &trans_data,
- MLCommon::Matrix::PartDescriptor &trans_desc,
- double *components,
- double *explained_var,
- double *explained_var_ratio,
- double *singular_vals,
- paramsTSVDMG &prms,
- bool verbose
- void transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<float> **input,
- float *components,
- MLCommon::Matrix::Data<float> **trans_input,
- paramsTSVDMG &prms,
- bool verbose
performs MNMG transform operation for the tsvd.
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
input – [in] input data
components – [in] principal components of the input data
trans_input – [out] transformed input data
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
- void transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<double> **input,
- double *components,
- MLCommon::Matrix::Data<double> **trans_input,
- paramsTSVDMG &prms,
- bool verbose
- void inverse_transform(
- raft::handle_t &handle,
- MLCommon::Matrix::RankSizePair **rank_sizes,
- std::uint32_t n_parts,
- MLCommon::Matrix::Data<float> **trans_input,
- float *components,
- MLCommon::Matrix::Data<float> **input,
- paramsTSVDMG &prms,
- bool verbose
performs MNMG inverse transform operation for the output.
- Parameters:
handle – [in] the internal cuml handle object
rank_sizes – [in] includes all the partition size information for the rank
n_parts – [in] number of partitions
trans_input – [in] transformed input data
components – [in] principal components of the input data
input – [out] input data
prms – [in] data structure that includes all the parameters from input size to algorithm
verbose – [in]
-
namespace opg#
-
namespace UMAP#
Functions
-
void find_ab(const raft::handle_t &handle, UMAPParams *params)#
Returns the simplical set to be consumed by the ML::UMAP::refine function.
- Parameters:
handle – [in] raft::handle_t
params – [out] pointer to ML::UMAPParams object of which the a and b parameters will be updated
- std::unique_ptr<raft::sparse::COO<float, int>> get_graph(
- const raft::handle_t &handle,
- float *X,
- float *y,
- int n,
- int d,
- int64_t *knn_indices,
- float *knn_dists,
- UMAPParams *params
Returns the simplical set to be consumed by the ML::UMAP::refine function.
- Parameters:
handle – [in] raft::handle_t
X – [in] pointer to input array
y – [in] pointer to labels array
n – [in] n_samples of input array
d – [in] n_features of input array
knn_indices – [in] pointer to knn_indices (optional)
knn_dists – [in] pointer to knn_dists (optional)
params – [in] pointer to ML::UMAPParams object
- Returns:
: simplical set as a unique pointer to a raft::sparse::COO object
- void refine(
- const raft::handle_t &handle,
- float *X,
- int n,
- int d,
- raft::sparse::COO<float, int> *graph,
- UMAPParams *params,
- float *embeddings
Performs a UMAP fit on existing embeddings without reinitializing them, which enables iterative fitting without callbacks.
- Parameters:
handle – [in] raft::handle_t
X – [in] pointer to input array
n – [in] n_samples of input array
d – [in] n_features of input array
graph – [in] pointer to raft::sparse::COO object computed using ML::UMAP::get_graph
params – [in] pointer to ML::UMAPParams object
embeddings – [out] pointer to current embedding with shape n * n_components, stores updated embeddings on executing refine
- void init_and_refine(
- const raft::handle_t &handle,
- float *X,
- int n,
- int d,
- raft::sparse::COO<float, int> *graph,
- UMAPParams *params,
- float *embeddings
Initializes embeddings and performs a UMAP fit on them, which enables iterative fitting without callbacks.
- Parameters:
handle – [in] raft::handle_t
X – [in] pointer to input array
n – [in] n_samples of input array
d – [in] n_features of input array
graph – [in] pointer to raft::sparse::COO object computed using ML::UMAP::get_graph
params – [in] pointer to ML::UMAPParams object
embeddings – [out] pointer to current embedding with shape n * n_components, stores updated embeddings on executing refine
- void fit(
- const raft::handle_t &handle,
- float *X,
- float *y,
- int n,
- int d,
- int64_t *knn_indices,
- float *knn_dists,
- UMAPParams *params,
- std::unique_ptr<rmm::device_buffer> &embeddings,
- raft::host_coo_matrix<float, int, int, uint64_t> &graph,
- float *sigmas = nullptr,
- float *rhos = nullptr
Dense fit
- Parameters:
handle – [in] raft::handle_t
X – [in] pointer to input array
y – [in] pointer to labels array
n – [in] n_samples of input array
d – [in] n_features of input array
knn_indices – [in] pointer to knn_indices of input (optional)
knn_dists – [in] pointer to knn_dists of input (optional)
params – [in] pointer to ML::UMAPParams object
embeddings – [out] unique_ptr to device_buffer that will be allocated and filled with embeddings
graph – [out] pointer to fuzzy simplicial set graph
sigmas – [out] optional output array for per-point sigma values (size n, device memory)
rhos – [out] optional output array for per-point rho values (size n, device memory)
- void fit_sparse(
- const raft::handle_t &handle,
- int *indptr,
- int *indices,
- float *data,
- size_t nnz,
- float *y,
- int n,
- int d,
- int *knn_indices,
- float *knn_dists,
- UMAPParams *params,
- std::unique_ptr<rmm::device_buffer> &embeddings,
- raft::host_coo_matrix<float, int, int, uint64_t> &graph
Sparse fit
- Parameters:
handle – [in] raft::handle_t
indptr – [in] pointer to index pointer array of input array
indices – [in] pointer to index array of input array
data – [in] pointer to data array of input array
nnz – [in] pointer to data array of input array
y – [in] pointer to labels array
n – [in] n_samples of input array
d – [in] n_features of input array
knn_indices – [in] pointer to knn_indices of input (optional)
knn_dists – [in] pointer to knn_dists of input (optional)
params – [in] pointer to ML::UMAPParams object
embeddings – [out] unique_ptr to device_buffer that will be allocated and filled with embeddings
graph – [out] pointer to fuzzy simplicial set graph
- void transform(
- const raft::handle_t &handle,
- float *X,
- int n,
- int d,
- float *orig_X,
- int orig_n,
- float *embedding,
- int embedding_n,
- UMAPParams *params,
- float *transformed
Dense transform
- Parameters:
handle – [in] raft::handle_t
X – [in] pointer to input array to be inferred
n – [in] n_samples of input array to be inferred
d – [in] n_features of input array to be inferred
orig_X – [in] pointer to original training array
orig_n – [in] number of rows in original training array
embedding – [in] pointer to embedding created during training
embedding_n – [in] number of rows in embedding created during training
params – [in] pointer to ML::UMAPParams object
transformed – [out] pointer to embedding produced through projection
- void transform_sparse(
- const raft::handle_t &handle,
- int *indptr,
- int *indices,
- float *data,
- size_t nnz,
- int n,
- int d,
- int *orig_x_indptr,
- int *orig_x_indices,
- float *orig_x_data,
- size_t orig_nnz,
- int orig_n,
- float *embedding,
- int embedding_n,
- UMAPParams *params,
- float *transformed
Sparse transform
- Parameters:
handle – [in] raft::handle_t
indptr – [in] pointer to index pointer array of input array to be inferred
indices – [in] pointer to index array of input array to be inferred
data – [in] pointer to data array of input array to be inferred
nnz – [in] number of stored values of input array to be inferred
n – [in] n_samples of input array
d – [in] n_features of input array
orig_x_indptr – [in] pointer to index pointer array of original training array
orig_x_indices – [in] pointer to index array of original training array
orig_x_data – [in] pointer to data array of original training array
orig_nnz – [in] number of stored values of original training array
orig_n – [in] number of rows in original training array
embedding – [in] pointer to embedding created during training
embedding_n – [in] number of rows in embedding created during training
params – [in] pointer to ML::UMAPParams object
transformed – [out] pointer to embedding produced through projection
- void inverse_transform(
- const raft::handle_t &handle,
- float *inv_transformed,
- int n,
- int n_features,
- float *orig_X,
- int orig_n,
- int *graph_rows,
- int *graph_cols,
- float *graph_vals,
- int nnz,
- float *sigmas,
- float *rhos,
- UMAPParams *params,
- int n_epochs
Inverse transform - optimize layout in original space
- Parameters:
handle – [in] raft::handle_t
inv_transformed – [inout] pointer to initial inverse-transformed positions (will be optimized in-place)
n – [in] number of points to inverse transform
n_features – [in] number of features in original space
orig_X – [in] pointer to original training data
orig_n – [in] number of rows in original training data
graph_rows – [in] row indices of the inverse transform graph (COO format)
graph_cols – [in] column indices of the inverse transform graph (COO format)
graph_vals – [in] edge weights of the inverse transform graph
nnz – [in] number of edges in the graph
sigmas – [in] per-point sigma values from fuzzy simplicial set
rhos – [in] per-point rho values from fuzzy simplicial set
params – [in] pointer to ML::UMAPParams object
n_epochs – [in] number of optimization epochs
-
void find_ab(const raft::handle_t &handle, UMAPParams *params)#
-
using cuda_launch_t = unsigned int#