trickster.linear
¶
Tools for working with linear and linearized models.
-
class
trickster.linear.
LinearGridHeuristic
(problem_ctx, cache_grad=True, weight_vec=None, grid_step=1)¶ Snaps values of a linear heuristic to values on a regular grid.
This is useful when the transformations in the transformation graph have fixed costs.
Parameters: grid_step – Regular grid step. -
__call__
(x)¶ Call self as a function.
-
-
class
trickster.linear.
LinearHeuristic
(problem_ctx, cache_grad=True, weight_vec=None)¶ $$L_p$$ distance to the decision boundary of a binary linear classifier.
Parameters: - cache_grad – Cache the forward gradient norm.
- weight_vec – Feature-wise weights if the $$L_p$$ space is weighted.
-
__call__
(x)¶ Call self as a function.
-
trickster.linear.
create_reduced_linear_classifier
(clf, x, transformable_feature_idxs)¶ Construct a reduced-dimension classifier based on the original one for a given example.
The reduced-dimension classifier should behave the same way as the original one, but operate in a smaller feature space. This is done by fixing the score of the classifier on a static part of
x
, and integrating it into the bias parameter of the reduced classifier.For example, let $$x = [1, 2, 3]$$, weights of the classifier $$w = [1, 1, 1]$$ and bias term $$b = 0$$, and the only transformable feature index is 0. Then the reduced classifier has weights $$w’ = [1]$$, and the bias term incorporates the non-transformable part of $$x$$: $$b’ = -1 cdot 2 + 1 cdot 3$$.
Parameters: - clf – Original logistic regression classifier
- x – An example
- transformable_feature_idxs – List of features that can be changed in the given example.
-
trickster.linear.
dist_to_decision_boundary
(clf, x, target_class, target_confidence, lp_space, inv_feature_weights=None, _grad_norm=None)¶ Compute distance to the decision boundary of a binary linear classifier.
-
trickster.linear.
get_forward_grad
(clf, x, target_class=None)¶ Get the forward gradient of a classifier.
Parameters: - clf – Classifier.
- x – Input.
- target_class – Currently not supported.