speechbrain.nnet.complex_networks.c_ops module

This library implements different operations needed by complex-

valued architectures. This work is inspired by: “Deep Complex Networks” from Trabelsi C. et al.

Authors
  • Titouan Parcollet 2020

Summary

Functions:

affect_conv_init

Applies the weight initialization function given to the parameters.

affect_init

Applies the weight initialization function given to the parameters.

check_complex_input

Check the complex-valued shape for a linear layer.

complex_conv_op

Applies a complex convolution to the incoming data.

complex_init

Returns a matrice of complex numbers initialized as described in: "Deep Complex Networks", Trabelsi C.

complex_linear_op

Applies a complex linear transformation to the incoming data.

get_conjugate

Returns the conjugate (z = r - xi) of the input complex numbers.

get_imag

Returns the imaginary components of the complex-valued input.

get_real

Returns the real components of the complex-valued input.

multi_mean

Performs torch.mean over multiple dimensions of input.

unitary_init

Returns a matrice of unitary complex numbers.

Reference

speechbrain.nnet.complex_networks.c_ops.check_complex_input(input_shape)[source]

Check the complex-valued shape for a linear layer.

Parameters:

input_shape (tuple) – Expected shape of the input.

speechbrain.nnet.complex_networks.c_ops.get_real(input, input_type='linear', channels_axis=1)[source]

Returns the real components of the complex-valued input.

Parameters:
  • input (torch.Tensor) – Input tensor.

  • input_type (str,) – (convolution, linear) (default “linear”)

  • channels_axis (int.) – Default 1.

speechbrain.nnet.complex_networks.c_ops.get_imag(input, input_type='linear', channels_axis=1)[source]

Returns the imaginary components of the complex-valued input.

Parameters:
  • input (torch.Tensor) – Input tensor.

  • input_type (str,) – (convolution, linear) (default “linear”)

  • channels_axis (int.) – Default 1.

speechbrain.nnet.complex_networks.c_ops.get_conjugate(input, input_type='linear', channels_axis=1)[source]

Returns the conjugate (z = r - xi) of the input complex numbers.

Parameters:
  • input (torch.Tensor) – Input tensor

  • input_type (str,) – (convolution, linear) (default “linear”)

  • channels_axis (int.) – Default 1.

speechbrain.nnet.complex_networks.c_ops.complex_linear_op(input, real_weight, imag_weight, bias)[source]

Applies a complex linear transformation to the incoming data.

Parameters:
  • input (torch.Tensor) – Complex input tensor to be transformed.

  • real_weight (torch.Parameter) – Real part of the quaternion weight matrix of this layer.

  • imag_weight (torch.Parameter) – First imaginary part of the quaternion weight matrix of this layer.

  • bias (torch.Parameter) –

speechbrain.nnet.complex_networks.c_ops.complex_conv_op(input, real_weight, imag_weight, bias, stride, padding, dilation, conv1d)[source]

Applies a complex convolution to the incoming data.

Parameters:
  • input (torch.Tensor) – Complex input tensor to be transformed.

  • conv1d (bool) – If true, a 1D convolution operation will be applied. Otherwise, a 2D convolution is called.

  • real_weight (torch.Parameter) – Real part of the quaternion weight matrix of this layer.

  • imag_weight (torch.Parameter) – First imaginary part of the quaternion weight matrix of this layer.

  • bias (torch.Parameter) –

  • stride (int) – Stride factor of the convolutional filters.

  • padding (int) – Amount of padding. See torch.nn documentation for more information.

  • dilation (int) – Dilation factor of the convolutional filters.

speechbrain.nnet.complex_networks.c_ops.unitary_init(in_features, out_features, kernel_size=None, criterion='glorot')[source]

Returns a matrice of unitary complex numbers.

Parameters:
  • in_features (int) – Number of real values of the input layer (quaternion // 4).

  • out_features (int) – Number of real values of the output layer (quaternion // 4).

  • kernel_size (int) – Kernel_size for convolutional layers (ex: (3,3)).

  • criterion (str) – (glorot, he) (default “glorot”).

speechbrain.nnet.complex_networks.c_ops.complex_init(in_features, out_features, kernel_size=None, criterion='glorot')[source]

Returns a matrice of complex numbers initialized as described in: “Deep Complex Networks”, Trabelsi C. et al.

Parameters:
  • in_features (int) – Number of real values of the input layer (quaternion // 4).

  • out_features (int) – Number of real values of the output layer (quaternion // 4).

  • kernel_size (int) – Kernel_size for convolutional layers (ex: (3,3)).

  • criterion (str) – (glorot, he) (default “glorot”)

speechbrain.nnet.complex_networks.c_ops.affect_init(real_weight, imag_weight, init_func, criterion)[source]

Applies the weight initialization function given to the parameters.

Parameters:
  • real_weight (torch.Parameters) –

  • imag_weight (torch.Parameters) –

  • init_func (function) – (unitary_init, complex_init)

  • criterion (str) – (glorot, he)

speechbrain.nnet.complex_networks.c_ops.affect_conv_init(real_weight, imag_weight, kernel_size, init_func, criterion)[source]

Applies the weight initialization function given to the parameters. This is specifically written for convolutional layers.

Parameters:
  • real_weight (torch.Parameters) –

  • imag_weight (torch.Parameters) –

  • kernel_size (int) –

  • init_func (function) – (unitary_init, complex_init)

  • criterion (str) – (glorot, he)

speechbrain.nnet.complex_networks.c_ops.multi_mean(input, axes, keepdim=False)[source]

Performs torch.mean over multiple dimensions of input.