hessQuik.activations¶
hessQuik Activation Function¶
- class hessQuikActivationFunction(*args: Any, **kwargs: Any)[source]¶
Bases:
Module
Base class for all hessQuik activation functions.
- forward(x: torch.Tensor, do_gradient: bool = False, do_Hessian: bool = False, forward_mode: bool = True) Tuple[torch.Tensor, Optional[torch.Tensor], Optional[torch.Tensor]] [source]¶
Applies a pointwise activation function to the incoming data.
- Parameters:
x (torch.Tensor) – input into the activation function. \((*)\) where \(*\) means any shape.
do_gradient (bool, optional) – If set to
True
, the gradient will be computed during the forward call. Default:False
do_Hessian (bool, optional) – If set to
True
, the Hessian will be computed during the forward call. Default:False
forward_mode (bool, optional) – If set to
False
, the derivatives will be computed in backward mode. Default:True
- Returns:
sigma (torch.Tensor) - value of activation function at input x, same size as x
dsigma (torch.Tensor or
None
) - first derivative of activation function at input x, same size as xd2sigma (torch.Tensor or
None
) - second derivative of activation function at input x, same size as x
- backward(do_Hessian: bool = False) Tuple[torch.Tensor, Optional[torch.Tensor]] [source]¶
Computes derivatives of activation function evaluated at x in backward mode.
Calls self.compute_derivatives without inputs, stores necessary variables in self.ctx.
Inherited by all subclasses.
- compute_derivatives(*args, do_Hessian: bool = False) Tuple[torch.Tensor, Optional[torch.Tensor]] [source]¶
- Parameters:
args (torch.Tensor) – variables needed to compute derivatives
do_Hessian (bool, optional) – If set to
True
, the Hessian will be computed during the forward call. Default:False
- Returns:
dsigma (torch.Tensor or
None
) - first derivative of activation function at input x, same size as xd2sigma (torch.Tensor or
None
) - second derivative of activation function at input x, same size as x
AntiTanh¶
- class antiTanhActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the antiderivative of the hyperbolic tangent activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.antiTanhActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)
Identity¶
- class identityActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the identity activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.identityActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)
Quadratic¶
- class quadraticActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the quadratic activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.quadraticActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)
Sigmoid¶
- class sigmoidActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the sigmoid activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.sigmoidActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)
Softplus¶
- class softplusActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the softplus activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.softplusActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)
- __init__(beta: float = 1.0, threshold: float = 20.0) None [source]¶
- Parameters:
beta (float) – parameter affecting steepness of the softplus function. Default: 1.0
threshold (float) – parameter for numerical stability. Uses identity function when \(\beta x > threshold\)
Tanh¶
- class tanhActivation(*args: Any, **kwargs: Any)[source]¶
Bases:
hessQuikActivationFunction
Applies the hyperbolic tangent activation function to each entry of the incoming data.
Examples:
>>> import hessQuik.activations as act >>> act_func = act.tanhActivation() >>> x = torch.randn(10, 4) >>> sigma, dsigma, d2sigma = act_func(x, do_gradient=True, do_Hessian=True)