Skip to content

activations

ComplexActivation

1
2
3
ComplexActivation(
    activation: tf.keras.layers.Layer, **kwargs: Any
)

Bases: tf.keras.layers.Layer

Wrapper to apply a given activation to a complex input individually for the real and imaginary part.

Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import DeepSaki as ds
import tensorflow as tf

activation = tf.keras.layers.LeakyReLU(alpha=0.3)

complex_activation = ds.activations.ComplexActivation(activation=activation)
complex_tensor = tf.complex(real=[-1.0,1.0], imag=[-2.0,2.0])
x = complex_activation(complex_tensor)
print(x)
#output: <tf.Tensor: shape=(2,), dtype=complex64, numpy=array([-0.3-0.6j,  1. +2.j ], dtype=complex64)>

Initialize ComplexActivation.

Parameters:

Name Type Description Default
activation tf.keras.layers.Layer

Activation function to complexyfy.

required
kwargs Any

keyword arguments passed to the parent class tf.keras.layers.Layer.

{}
Source code in DeepSaki/activations/complex_valued_activations.py
24
25
26
27
28
29
30
31
32
def __init__(self, activation: tf.keras.layers.Layer, **kwargs: Any) -> None:
    """Initialize ComplexActivation.

    Args:
        activation (tf.keras.layers.Layer): Activation function to complexyfy.
        kwargs: keyword arguments passed to the parent class tf.keras.layers.Layer.
    """
    super(ComplexActivation, self).__init__(**kwargs)
    self.activation = activation

call

1
call(inputs: tf.Tensor) -> tf.Tensor

Splits its intput inputsinto a real and imaginary part, applies activation and constructs a complex number.

Parameters:

Name Type Description Default
inputs tf.Tensor

Input tensor to be activated. Might be a complex or real valued tensor.

required

Returns:

Type Description
tf.Tensor

Complex-valued tensor with activated real and imaginary part.

Source code in DeepSaki/activations/complex_valued_activations.py
34
35
36
37
38
39
40
41
42
43
44
45
def call(self, inputs: tf.Tensor) -> tf.Tensor:
    """Splits its intput `inputs`into a real and imaginary part, applies `activation` and constructs a complex number.

    Args:
        inputs (tf.Tensor): Input tensor to be activated. Might be a complex or real valued tensor.

    Returns:
        Complex-valued tensor with activated real and imaginary part.
    """
    real = self.activation(tf.math.real(inputs))
    imag = self.activation(tf.math.imag(inputs))
    return tf.complex(real, imag)

get_config

1
get_config() -> Dict[str, Any]

Returns configuration of class instance.

Returns:

Type Description
Dict[str, Any]

Dict[str,Any]: Dictionary containing the class' configuration.

Source code in DeepSaki/activations/complex_valued_activations.py
47
48
49
50
51
52
53
54
55
def get_config(self) -> Dict[str, Any]:
    """Returns configuration of class instance.

    Returns:
        Dict[str,Any]: Dictionary containing the class' configuration.
    """
    config = super(ComplexActivation, self).get_config()
    config.update({"activation": self.activation})
    return config