Classes | |
class | TreePathInfo |
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) |
void | kernel_dataset (const raft::handle_t &handle, float *X, int nrows_X, int ncols, double *background, int nrows_background, double *dataset, double *observation, int *nsamples, int len_nsamples, int maxsample, uint64_t seed=0ULL) |
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) |
void | permutation_shap_dataset (const raft::handle_t &handle, double *dataset, const double *background, int nrows_bg, int ncols, const double *row, int *idx, bool row_major) |
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) |
void | shap_main_effect_dataset (const raft::handle_t &handle, double *dataset, const double *background, int nrows_bg, int ncols, const double *row, int *idx, bool row_major) |
void | update_perm_shap_values (const raft::handle_t &handle, float *shap_values, const float *y_hat, const int ncols, const int *idx) |
void | update_perm_shap_values (const raft::handle_t &handle, double *shap_values, const double *y_hat, const int ncols, const int *idx) |
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) |
using ML::Explainer::FloatPointer = typedef std::variant<float*, double*> |
using ML::Explainer::TreePathHandle = typedef std::variant<std::shared_ptr<TreePathInfo<float> >, std::shared_ptr<TreePathInfo<double> >> |
TreePathHandle ML::Explainer::extract_path_info | ( | TreeliteModelHandle | model | ) |
void ML::Explainer::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 ML::Explainer::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 ML::Explainer::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 ML::Explainer::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 | ||
) |
void ML::Explainer::kernel_dataset | ( | const raft::handle_t & | handle, |
float * | X, | ||
int | nrows_X, | ||
int | ncols, | ||
double * | background, | ||
int | nrows_background, | ||
double * | dataset, | ||
double * | observation, | ||
int * | nsamples, | ||
int | len_nsamples, | ||
int | maxsample, | ||
uint64_t | seed = 0ULL |
||
) |
void ML::Explainer::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.
[in] | handle | cuML handle |
[in,out] | X | generated data [on device] 1-0 (row major) |
[in] | nrows_X | number of rows in X |
[in] | ncols | number of columns in X, background and dataset |
[in] | background | background data [on device] |
[in] | nrows_background | number of rows in background dataset |
[out] | dataset | generated data [on device] observation=background (row major) |
[in] | observation | row to scatter |
[in] | nsamples | vector with number of entries that are randomly sampled |
[in] | len_nsamples | number of entries to be sampled |
[in] | maxsample | size of the biggest sampled observation |
[in] | seed | Seed for the random number generator |
Kernel distrubutes exact part of the kernel shap dataset Each block scatters the data of a row of observations
into the (number of rows of background) in dataset
, based on the row of X
. 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 k
entries of observation
to scatter into dataset
. Afterwards each block scatters the data of a row of X
into the (number of rows of background) in dataset
. 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]]
void ML::Explainer::permutation_shap_dataset | ( | const raft::handle_t & | handle, |
double * | dataset, | ||
const double * | background, | ||
int | nrows_bg, | ||
int | ncols, | ||
const double * | row, | ||
int * | idx, | ||
bool | row_major | ||
) |
void ML::Explainer::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 background
matrix into out
, while adding a forward and backward permutation pass of the observation row
on the positions defined by idx
. 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]]
[in] | handle | cuML handle |
[out] | dataset | generated data in either row major or column major format, depending on the row_major parameter [on device] [dim = (2 * ncols * nrows_bg + nrows_bg) * ncols] |
[in] | background | background data [on device] [dim = ncols * nrows_bg] |
[in] | nrows_bg | number of rows in background dataset |
[in] | ncols | number of columns |
[in] | row | row to scatter in a permutated fashion [dim = ncols] |
[in] | idx | permutation indexes [dim = ncols] |
[in] | row_major | boolean to generate either row or column major data |
void ML::Explainer::shap_main_effect_dataset | ( | const raft::handle_t & | handle, |
double * | dataset, | ||
const double * | background, | ||
int | nrows_bg, | ||
int | ncols, | ||
const double * | row, | ||
int * | idx, | ||
bool | row_major | ||
) |
void ML::Explainer::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 background
matrix into out
, while adding a forward and backward permutation pass of the observation row
on the positions defined by idx
. 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]]
[in] | handle | cuML handle |
[out] | dataset | generated data [on device] [dim = (2 * ncols * nrows_bg + nrows_bg) * ncols] |
[in] | background | background data [on device] [dim = ncols * nrows_bg] |
[in] | nrows_bg | number of rows in background dataset |
[in] | ncols | number of columns |
[in] | row | row to scatter in a permutated fashion [dim = ncols] |
[in] | idx | permutation indexes [dim = ncols] |
[in] | row_major | boolean to generate either row or column major data |
void ML::Explainer::update_perm_shap_values | ( | const raft::handle_t & | handle, |
double * | shap_values, | ||
const double * | y_hat, | ||
const int | ncols, | ||
const int * | idx | ||
) |
void ML::Explainer::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]
[in] | handle | cuML handle |
[out] | shap_values | Array where the results are aggregated [dim = ncols] |
[in] | y_hat | Results to use for the aggregation [dim = ncols + 1] |
[in] | ncols | number of columns |
[in] | idx | permutation indexes [dim = ncols] |