trickster.domain

Categorical feature spaces

Transformations and stats for quantized, categorical, and collection features.

class trickster.domain.categorical.FeatureExpansionSpec(idxs: List[int], expand_fn: Callable, feature_name: str = None, extras: List = None)

Categorical feature expansion specification.

Parameters:
  • idxs – Indexes in a feature vector that correspond to this feature.
  • expand_fn – Expansion funciton.
  • feature_name – Feature name.
  • weights – Feature-wise weights.
class trickster.domain.categorical.Node(src: List, depth: int = 0, feature_extract_fn: Callable = None)

Node in a transformation graph.

Parameters:
  • xRaw example.
  • feature_extract_fn – Feature extraction funcion.
  • depth – Number of hops from the original example.
expand(expansion_specs)

Return the expanded neighbour nodes.

features

Return the feature vector.

trickster.domain.categorical.expand(sample, expansion_specs)

Perform multiple expansions.

Parameters:
Returns:

List of numpy arrays.

trickster.domain.categorical.expand_categorical(sample, feat_idxs)

Expand all values of a single categorical feature.

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_collection(sample, feat_idxs)

Expand all values of a collection of categorical features (set and unset).

Parameters:
  • sample (Numpy array.) – Initial node.
  • feat_idxs (Numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

List of numpy arrays.

trickster.domain.categorical.expand_collection_set(sample, feat_idxs)

Expand all values of a collection of categorical features (set [0,1] to [1,0]).

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_collection_unset(sample, feat_idxs)

Expand all values of a collection of categorical features (unset [1,0] to [0,1]).

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_quantized(sample, feat_idxs)

Get the neighbouring value (shift ‘1’ right and left) in a quantized one-hot feature vector.

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_quantized_decrement(sample, feat_idxs)

Get the neighbouring value (shift ‘1’ left) in a quantized one-hot feature vector.

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_quantized_increase(sample, feat_idxs)

Expand all higher values of a single categorical feature.

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.expand_quantized_increment(sample, feat_idxs)

Get the neighbouring value (shift ‘1’ right) in a quantized one-hot feature vector.

Parameters:
  • sample (numpy array.) – Initial node.
  • feat_idxs (numpy array or list of ints.) – Indexes pointing to transformable features in the sample array.
Returns:

list of numpy arrays.

trickster.domain.categorical.get_feature_coef_importance(X, clf, transformable_feature_idxs)

Get the most important features from the transformable feature set based on classifier parameters.

trickster.domain.categorical.get_feature_diff_importance(difference, transformable_feature_idxs)

Get the most important features from the transformable feature set based on the feature difference between the initial and adversarial example.

trickster.domain.categorical.noop(sample, feat_idxs)

Don’t expand.