src.ml_cfexplainer.utils package

Submodules

src.ml_cfexplainer.utils.AE_architecture module

Created on Sun Nov 29 16:52:27 2020

@author: trduong

class src.ml_cfexplainer.utils.AE_architecture.autoencoder(index_age, index_hours, index_workclass, index_education, index_marital_status, index_occupation, index_race, index_gender)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

src.ml_cfexplainer.utils.AE_train module

src.ml_cfexplainer.utils.auto-encoder-train module

src.ml_cfexplainer.utils.blackbox-model-train module

src.ml_cfexplainer.utils.blackboxmodel module

class src.ml_cfexplainer.utils.blackboxmodel.BlackBox(inp_shape)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

src.ml_cfexplainer.utils.calculate_loss module

src.ml_cfexplainer.utils.datagen module

src.ml_cfexplainer.utils.dataloader module

class src.ml_cfexplainer.utils.dataloader.DataLoader(params)[source]

Bases: object

A data interface for public data.

get_features_range()[source]
get_data_type(col)[source]

Infers data type of a feature from the training data.

one_hot_encode_data(data)[source]

One-hot-encodes the data.

normalize_data(df)[source]

Normalizes continuous features to make them fall in the range [0,1].

de_normalize_data(df)[source]

De-normalizes continuous features from [0,1] range to original range.

get_minx_maxx(normalized=True)[source]

Gets the min/max value of features in normalized or de-normalized form.

split_data(data)[source]
get_mads_from_training_data(normalized=False)[source]

Computes Median Absolute Deviation of features.

get_data_params()[source]

Gets all data related params for DiCE.

get_encoded_categorical_feature_indexes()[source]

Gets the column indexes categorical features after one-hot-encoding.

get_indexes_of_features_to_vary(features_to_vary='all')[source]

Gets indexes from feature names of one-hot-encoded data.

from_dummies(data, prefix_sep='_')[source]

Gets the original data from dummy encoded data with k levels.

get_decimal_precisions()[source]

“Gets the precision of continuous features in the data.

get_decoded_data(data)[source]

Gets the original data from dummy encoded data.

prepare_df_for_encoding()[source]

Facilitates prepare_query_instance() function.

prepare_query_instance(query_instance, encode)[source]

Prepares user defined test input for DiCE.

get_dev_data(model_interface, desired_class, filter_threshold=0.5)[source]

Constructs dev data by extracting part of the test data for which finding counterfactuals make sense.

src.ml_cfexplainer.utils.helpers module

src.ml_cfexplainer.utils.preprocess_adult module

src.ml_cfexplainer.utils.vae_model module

class src.ml_cfexplainer.utils.vae_model.CF_VAE(data_size, encoded_size, d)[source]

Bases: torch.nn.modules.module.Module

encoder(x)[source]
decoder(z)[source]
sample_latent_code(mean, logvar)[source]
normal_likelihood(x, mean, logvar, raxis=1)[source]
forward(x, c)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

compute_elbo(x, c, pred_model)[source]
training: bool
class src.ml_cfexplainer.utils.vae_model.AutoEncoder(data_size, encoded_size, d)[source]

Bases: torch.nn.modules.module.Module

encoder(x)[source]
decoder(z)[source]
sample_latent_code(mean, logvar)[source]
normal_likelihood(x, mean, logvar, raxis=1)[source]
forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

Module contents