ceml.backend.tensorflow¶
ceml.backend.tensorflow.costfunctions¶
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTf(**kwds)¶ Bases:
ceml.costfunctions.costfunctions.CostFunctionDifferentiableBase class of differentiable cost functions implemented in tensorflow.
-
grad()¶ Warning
Do not use this method!
Use ‘tf.GradientTape’ for computing the gradient.
- Raises
NotImplementedError –
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.DummyCost(**kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfDummy cost function - always returns zero.
-
score_impl(x)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.L1Cost(x_orig, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfL1 cost function.
-
score_impl(x)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.L2Cost(x_orig, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfL2 cost function.
-
score_impl(x)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.LMadCost(x_orig, mad, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfManhattan distance weighted feature-wise with the inverse median absolute deviation (MAD).
-
score_impl(x)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.NegLogLikelihoodCost(y_target, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfNegative-log-likelihood cost function.
-
score_impl(y)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.RegularizedCost(penalize_input, penalize_output, C=1.0, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfRegularized cost function.
-
score_impl(x)¶ Applying the cost function to a given input.
Abstract method for computing applying the cost function to a given input x.
Note
All derived classes must implement this method.
-
-
class
ceml.backend.tensorflow.costfunctions.costfunctions.SquaredError(y_target, **kwds)¶ Bases:
ceml.backend.tensorflow.costfunctions.costfunctions.CostFunctionDifferentiableTfSquared error cost function.
-
score_impl(y)¶ Computes the loss - squared error.
-
ceml.backend.tensorflow.optimizer¶
-
class
ceml.backend.tensorflow.optimizer.optimizer.TfOptimizer(**kwds)¶ Bases:
ceml.optim.optimizer.OptimizerWrapper for a tensorflow optimization algorithm.
The
TfOptimizerprovides an interface for wrapping an arbitrary tensorflow optimization algorithm (seetf.train.Optimizer) and minimizing a given loss function.-
init(model, loss, x, optim, tol=None, max_iter=1, grad_mask=None)¶ Initializes all parameters.
- Parameters
model (callable or instance of
tf.keras.Model) – The model that is to be used.loss (instance of
ceml.backend.tensorflow.costfunctions.RegularizedCost) – The loss that has to be minimized.x (numpy.ndarray) – The starting value of x - usually this is the original input whose prediction has to be explained..
optim (instance of
tf.train.Optimizer) – Optimizer for minimizing the loss.tol (float, optional) –
Tolerance for termination.
The default is 0.0
max_iter (int, optional) –
Maximum number of iterations.
The default is 1.
grad_mask (numpy.array, optional) –
Mask that is multiplied element wise on top of the gradient - can be used to hold some dimensions constant.
If grad_mask is None, no gradient mask is used.
The default is None.
- Raises
TypeError – If the type of loss or model is not correct.
-