Create activation function and corresponding inverse function. Args: activation_type: The activation type to create. Returns: The corresponding activation functions and the corresponding inverse function.
(activation_type: ActivationType)
| 30 | |
| 31 | |
| 32 | def create_activation_pair(activation_type: ActivationType) -> ActivationPair: |
| 33 | """Create activation function and corresponding inverse function. |
| 34 | |
| 35 | Args: |
| 36 | activation_type: The activation type to create. |
| 37 | |
| 38 | Returns: |
| 39 | The corresponding activation functions and the corresponding inverse function. |
| 40 | """ |
| 41 | if activation_type == "linear": |
| 42 | return ActivationPair(lambda x: x, lambda x: x) |
| 43 | elif activation_type == "exp": |
| 44 | return ActivationPair(torch.exp, torch.log) |
| 45 | elif activation_type == "sigmoid": |
| 46 | return ActivationPair(torch.sigmoid, inverse_sigmoid) |
| 47 | elif activation_type == "softplus": |
| 48 | return ActivationPair(torch.nn.functional.softplus, inverse_softplus) |
| 49 | elif activation_type == "relu_with_pushback": |
| 50 | return ActivationPair(relu_with_pushback, lambda x: x) |
| 51 | elif activation_type == "hard_sigmoid_with_pushback": |
| 52 | return ActivationPair(hard_sigmoid_with_pushback, lambda x: 6.0 * x - 3.0) |
| 53 | else: |
| 54 | raise ValueError(f"Unsupported activation function: {activation_type}.") |
| 55 | |
| 56 | |
| 57 | def inverse_sigmoid(tensor: torch.Tensor) -> torch.Tensor: |
nothing calls this directly
no test coverage detected