qualia2.functions package

Submodules

qualia2.functions.activation module

class qualia2.functions.activation.BReLU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Bipolar rectified linear unit

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.ELU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Exponential linear unit

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, k=1.0)[source]

calculates forward propagation

class qualia2.functions.activation.Gaussian(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise Gaussian function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.Identity(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Identity function

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.LeakyReLU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Leaky rectified linear unit

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, negative_slope=0.1)[source]

calculates forward propagation

class qualia2.functions.activation.ReLU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Rectified linear unit

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.Sigmoid(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Sigmoid function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.SoftMax(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

SoftMax function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.SoftPlus(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

SoftPlus function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.SoftSign(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

SoftSign function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.activation.Tanhshrink(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise x - Tanh(x) function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

qualia2.functions.array module

class qualia2.functions.array.Concat(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

concatenate given Tensors

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(*args, axis=1)[source]
Args:

*args (tuple(Tensor)): tensors to be concatenated along the given axis.

axis (int): axis to concatenate the Tensors.

class qualia2.functions.array.ListConcat(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

concatenate list of Tensors

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(list)[source]
Args:

list (list(Tensor)): list of Tensors

qualia2.functions.complex module

class qualia2.functions.complex.CMSELoss(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

MSE Loss for complex neural networks

Args:

input (Tensor): output of the network target (Tensor): label of the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = sum((y_n - x_n)^2/2)

Shape:
  • Input: [N, C]

  • Target: [N, C]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.complex.CReLU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.complex.CTanh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise hyperbolic tangent function for complex neural networks

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

qualia2.functions.conv module

class qualia2.functions.conv.Conv1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, ow, x_shape, kernel_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel, bias=None, stride=1, padding=1, dilation=1)[source]

Applies a 2D convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, width]

kernel (Tensor): Kernel with shape of [patch, channel, kernel_width]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (int): Stride of the convolution. Default: 1

padding (int): Padding controls the amount of implicit zero-paddings on both sides for padding number of points for each dimension. Default: 1

dilation (int): Spacing between kernel elements. Default: 1

Returns:

(Tensor): Output tensor will have shape of [batch, patch, out_width]

Shape:
  • Input: [N, in_channels, W]

  • Output: [N, out_channels, W_out]

\(W_out = (W+2*padding-dilation*(kernel_size-1)-1)/stride+1\)

static unfold(x, batch, ow, kernel_shape, stride, dilation)[source]
class qualia2.functions.conv.Conv2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, oh, ow, x_shape, kernel_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel, bias=None, stride=(1, 1), padding=(1, 1), dilation=(1, 1))[source]

Applies a 2D convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, height, width]

kernel (Tensor): Kernel with shape of [patch, channel, kernel_height, kernel_width]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (tuple of int): Stride of the convolution. Default: (1,1)

padding (tuple of int): Padding controls the amount of implicit zero-paddings on both sides for padding number of points for each dimension. Default: (1,1)

dilation (tuple of int): Spacing between kernel elements. Default: (1,1)

Returns:

(Tensor): Output tensor will have shape of [batch, patch, out_height, out_width]

Shape:
  • Input: [N, in_channels, H, W]

  • Output: [N, out_channels, H_out, W_out]

:math:`H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0]+1 ` :math:`W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1]+1 `

static unfold(x, batch, oh, ow, kernel_shape, stride, dilation)[source]
class qualia2.functions.conv.Conv3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, oh, ow, od, x_shape, kernel_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel, bias=None, stride=(1, 1, 1), padding=(1, 1, 1), dilation=(1, 1, 1))[source]

Applies a 3D convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, height, width, depth]

kernel (Tensor): Kernel with shape of [patch, channel, kernel_height, kernel_width, kernel_depth]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (tuple of int): Stride of the convolution. Default: (1,1,1)

padding (tuple of int): Padding controls the amount of implicit zero-paddings on both sides for padding number of points for each dimension. Default: (1,1,1)

dilation (tuple of int): Spacing between kernel elements. Default: (1,1,1)

Returns:

(Tensor): Output tensor will have shape of [batch, patch, out_height, out_width, out_depth]

Shape:
  • Input: [N, in_channels, H, W, D]

  • Output: [N, out_channels, H_out, W_out, D_out]

\(H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0]+1\) \(W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1]+1\) \(D_out = (D+2*padding[2]-dilation[2]*(kernel_size[2]-1)-1)/stride[2]+1\)

static unfold(x, batch, oh, ow, od, kernel_shape, stride, dilation)[source]
class qualia2.functions.conv.ConvTranspose1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, kernel, bias=None, stride=1, padding=1, output_padding=0, dilation=1)[source]

Applies a 1D transposed convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, height]

kernel (Tensor): Kernel with shape of [channel, patch, kernel_height]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (tuple of int): Stride of the convolution. Default: 1

padding (tuple of int): Zero-padding added to both sides of the input. Default: 1

output_padding (tuple of int): Zero-padding added to both sides of the output. Default: 0

dilation (tuple of int): Spacing between kernel elements. Default: 1

Shape:
  • Input: [N, in_channels, H]

  • Output: [N, out_channels, H_out]

\(H_out = (H-1)*stride[0]-2*padding[0]+dilation[0]*(kernel_size[0]-1)+1+output_padding[0]\)

Reference:

https://arxiv.org/pdf/1603.07285.pdf

class qualia2.functions.conv.ConvTranspose2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, kernel, bias=None, stride=(1, 1), padding=(1, 1), output_padding=(0, 0), dilation=(1, 1))[source]

Applies a 2D transposed convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, height, width]

kernel (Tensor): Kernel with shape of [channel, patch, kernel_height, kernel_width]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (tuple of int): Stride of the convolution. Default: (1,1)

padding (tuple of int): Zero-padding added to both sides of the input. Default: (1,1)

output_padding (tuple of int): Zero-padding added to both sides of the output. Default: (0,0)

dilation (tuple of int): Spacing between kernel elements. Default: (1,1)

Shape:
  • Input: [N, in_channels, H, W]

  • Output: [N, out_channels, H_out, W_out]

\(H_out = (H-1)*stride[0]-2*padding[0]+dilation[0]*(kernel_size[0]-1)+1+output_padding[0]\) \(W_out = (W-1)*stride[1]-2*padding[1]+dilation[1]*(kernel_size[1]-1)+1+output_padding[1]\)

Reference:

https://arxiv.org/pdf/1603.07285.pdf

class qualia2.functions.conv.ConvTranspose3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, kernel, bias=None, stride=(1, 1, 1), padding=(1, 1, 1), output_padding=(0, 0, 0), dilation=(1, 1, 1))[source]

Applies a 2D transposed convolution over an input signal composed of several input planes.

Args:

x (Tensor): Input tensor with shepe of [batch, channel, height, width, depth]

kernel (Tensor): Kernel with shape of [channel, patch, kernel_height, kernel_width, kernel_depth]

bias (Tensor): Bias with shape of [patch] to add if needed. Default: None

stride (tuple of int): Stride of the convolution. Default: (1,1,1)

padding (tuple of int): Zero-padding added to both sides of the input. Default: (1,1,1)

output_padding (tuple of int): Zero-padding added to both sides of the output. Default: (0,0,0)

dilation (tuple of int): Spacing between kernel elements. Default: (1,1,1)

Shape:
  • Input: [N, in_channels, H, W, D]

  • Output: [N, out_channels, H_out, W_out, D_out]

\(H_out = (H-1)*stride[0]-2*padding[0]+dilation[0]*(kernel_size[0]-1)+1+output_padding[0]\) \(W_out = (W-1)*stride[1]-2*padding[1]+dilation[1]*(kernel_size[1]-1)+1+output_padding[1]\) \(D_out = (D-1)*stride[2]-2*padding[2]+dilation[2]*(kernel_size[2]-1)+1+output_padding[2]\)

Reference:

https://arxiv.org/pdf/1603.07285.pdf

qualia2.functions.distance module

class qualia2.functions.distance.CosineSimilarity(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, b, dim=1, eps=1e-08)[source]

calculates forward propagation

qualia2.functions.dropout module

class qualia2.functions.dropout.Dropout(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, p=0.5, training=True)[source]

During training, randomly zeroes some of the elements of the input tensor with probability p using samples from a Bernoulli distribution. Each channel will be zeroed out independently on every forward call. Args:

x (Tensor): Input tensor with any shepe p (float): probability that randomly zeroes some of the elements of the input tensor training (bool): True if the model is in training

qualia2.functions.linear_algebra module

class qualia2.functions.linear_algebra.Dot(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, b)[source]

calculates forward propagation

class qualia2.functions.linear_algebra.Linear(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, weight, bias=None)[source]

calculates forward propagation

class qualia2.functions.linear_algebra.Tensordot(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, b, axes=1)[source]

calculates forward propagation

qualia2.functions.loss module

class qualia2.functions.loss.BinaryCrossEntropy(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Creates a criterion that measures the Binary Cross Entropy between the target and the output

Args:

input (Tensor): output of the network target (Tensor): label of the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = -y_n*log(x_n)-(1-y_n)*log(1-x_n)

Shape:
  • Input: [N, 1]

  • Target: [N, 1]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.loss.CrossEntropy(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

‘Creates a criterion that measures the Cross Entropy between the target and the output

Args:

input (Tensor): output of the network target (Tensor): one-hot representation of label for the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = -sum_over_classes(y_n*log(x_n))

Shape:
  • Input: [N, num_class]

  • Target: [N, num_class]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.loss.HuberLoss(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Args:

input (Tensor): output of the network target (Tensor): label of the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:
l_n = sum((y_n - x_n)^2/2) for |y_n - x_n| < 1

sum(|y_n - x_n|) otherwise

Shape:
  • Input: [N, C]

  • Target: [N, C]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.loss.LogisticBinaryCrossEntropy(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Creates a criterion that measures the Binary Cross Entropy between the target and the logistic of output

Args:

input (Tensor): output of the network target (Tensor): label of the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = y_n*log(1+exp(-x_n))+(1-y_n)*log(1+exp(x_n))

Shape:
  • Input: [N, 1]

  • Target: [N, 1]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.loss.MSELoss(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Args:

input (Tensor): output of the network target (Tensor): label of the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = sum((y_n - x_n)^2/2)

Shape:
  • Input: [N, C]

  • Target: [N, C]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

class qualia2.functions.loss.SoftmaxCrossEntropy(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

‘Creates a criterion that measures the Cross Entropy between the target and the softmax of output

Args:

input (Tensor): output of the network target (Tensor): one-hot representation of label for the dataset reduce (bool): the losses are averaged or summed over observations for each minibatch depending on size_average. size_average (bool): the losses are averaged over each loss element in the batch.

Model:

l_n = -sum_over_classes(y_n*log(softmax(x_n)))

Shape:
  • Input: [N, num_class]

  • Target: [N, num_class]

  • Output: [1] by default

    [N] if not reduce

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, target, reduce=True, size_average=True)[source]

calculates forward propagation

qualia2.functions.normalize module

class qualia2.functions.normalize.BatchNorm(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, mean, std, weight, bias, axis, eps=1e-05)[source]

Applies Batch Normalization for each channel across a batch of data.

Args:

x (Tensor): input tensor. mean (ndarray): running mean of the input tensor. std (ndarray): running std of the input tensor. weight (Tensor): weight to apply. bias (Tensor): bias to apply. axis (list): axis indicates the all the axis in the input except C dimention eps (float): a value added to the denominator for numerical stability.

Shape:
  • Input: [N,C,*]

  • Output: [N,C,*]

qualia2.functions.pool module

class qualia2.functions.pool.AvePool1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_width, ow, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_width=2, stride=2, padding=0, dilation=1)[source]

Applies a 1D average pooling over an input signal composed of several input planes.

Args:

kernel_size (int): the size of the window to take a max over stride (int): the stride of the window. Default value is kernel_size padding (int): implicit zero padding to be added on all three sides dilation (int): a parameter that controls the stride of elements in the window

Shape:
  • Input: [N,C,W]

  • Output: [N,C,W_out]

W_out = (W+2*padding-dilation*(kernel_width-1)-1)/stride + 1

static unfold(x, batch, ow, channel, kernel_width, stride, dilation)[source]
class qualia2.functions.pool.AvePool2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_size, oh, ow, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_size=(2, 2), stride=(2, 2), padding=(0, 0), dilation=(1, 1))[source]

Applies a 2D average pooling over an input signal composed of several input planes.

Args:

kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window

Shape:
  • Input: [N,C,H,W]

  • Output: [N,C,H_out,W_out]

H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1

static unfold(x, batch, oh, ow, channel, kernel_height, kernel_width, stride, dilation)[source]
class qualia2.functions.pool.AvePool3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_size, oh, ow, od, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=(0, 0, 0), dilation=(1, 1, 1))[source]

Applies a 3D max pooling over an input signal composed of several input planes.

Args:

kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window

Shape:
  • Input: [N,C,H,W,D]

  • Output: [N,C,H_out,W_out,D_out]

H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1 D_out = (D+2*padding[2]-dilation[2]*(kernel_size[2]-1)-1)/stride[2] + 1

static unfold(x, batch, oh, ow, od, channel, kernel_height, kernel_width, kernel_depth, stride, dilation)[source]
class qualia2.functions.pool.GlobalAvePool1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x)[source]

Applies a 1D global average pooling over an input signal composed of several input planes.

class qualia2.functions.pool.GlobalAvePool2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x)[source]

Applies a 2D global average pooling over an input signal composed of several input planes.

class qualia2.functions.pool.GlobalAvePool3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x)[source]

Applies a 3D global average pooling over an input signal composed of several input planes.

class qualia2.functions.pool.MaxPool1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_width, argmax, ow, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_width=2, stride=2, padding=0, dilation=1, return_indices=False)[source]

Applies a 1D max pooling over an input signal composed of several input planes.

Args:

kernel_size (int): the size of the window to take a max over stride (int): the stride of the window. Default value is kernel_size padding (int): implicit zero padding to be added on all three sides dilation (int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.

Shape:
  • Input: [N,C,W]

  • Output: [N,C,W_out]

W_out = (W+2*padding-dilation*(kernel_width-1)-1)/stride + 1

static unfold(x, batch, ow, channel, kernel_width, stride, dilation)[source]
class qualia2.functions.pool.MaxPool2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_size, argmax, oh, ow, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_size=(2, 2), stride=(2, 2), padding=(0, 0), dilation=(1, 1), return_indices=False)[source]

Applies a 2D max pooling over an input signal composed of several input planes.

Args:

kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.

Shape:
  • Input: [N,C,H,W]

  • Output: [N,C,H_out,W_out]

H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1

static unfold(x, batch, oh, ow, channel, kernel_height, kernel_width, stride, dilation)[source]
class qualia2.functions.pool.MaxPool3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static fold(delta, kernel_size, argmax, oh, ow, od, x_shape, padded_shape, stride, dilation)[source]
static forward(x, kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=(0, 0, 0), dilation=(1, 1, 1), return_indices=False)[source]

Applies a 3D max pooling over an input signal composed of several input planes.

Args:

kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window return_indices (bool): if True, will return the max indices along with the outputs.

Shape:
  • Input: [N,C,H,W,D]

  • Output: [N,C,H_out,W_out,D_out]

H_out = (H+2*padding[0]-dilation[0]*(kernel_size[0]-1)-1)/stride[0] + 1 W_out = (W+2*padding[1]-dilation[1]*(kernel_size[1]-1)-1)/stride[1] + 1 D_out = (D+2*padding[2]-dilation[2]*(kernel_size[2]-1)-1)/stride[2] + 1

static unfold(x, batch, oh, ow, od, channel, kernel_height, kernel_width, kernel_depth, stride, dilation)[source]
class qualia2.functions.pool.MaxUnpool1d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, indices, kernel_size=2, stride=2, padding=0, dilation=1)[source]

Computes a partial inverse of MaxPool2d. Args:

x (Tensor): the input Tensor to invertc indices (ndarray): the indices given out by MaxPool2d kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window

Shape:
  • Input: [N,C,W]

  • Output: [N,C,W_out]

W_out = (W-1)*stride+dilation*(kernel_size-1)+1-2*padding

class qualia2.functions.pool.MaxUnpool2d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, indices, kernel_size=(2, 2), stride=(2, 2), padding=(0, 0), dilation=(1, 1))[source]

Computes a partial inverse of MaxPool2d. Args:

x (Tensor): the input Tensor to invertc indices (ndarray): the indices given out by MaxPool2d kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window

Shape:
  • Input: [N,C,H,W]

  • Output: [N,C,H_out,W_out]

H_out = (H-1)*stride[0]+dilation[0]*(kernel_size[0]-1)+1-2*padding[0] W_out = (W-1)*stride[1]+dilation[1]*(kernel_size[1]-1)+1-2*padding[1]

class qualia2.functions.pool.MaxUnpool3d(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(x, indices, kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=(0, 0, 0), dilation=(1, 1, 1))[source]

Computes a partial inverse of MaxPool2d. Args:

x (Tensor): the input Tensor to invertc indices (ndarray): the indices given out by MaxPool2d kernel_size (tuple of int): the size of the window to take a max over stride (tuple of int): the stride of the window. Default value is kernel_size padding (tuple of int): implicit zero padding to be added on all three sides dilation (tuple of int): a parameter that controls the stride of elements in the window

Shape:
  • Input: Input: [N,C,H,W,D]

  • Output: [N,C,H_out,W_out,D_out]

H_out = (H-1)*stride[0]+dilation[0]*(kernel_size[0]-1)+1-2*padding[0] W_out = (W-1)*stride[1]+dilation[1]*(kernel_size[1]-1)+1-2*padding[1] D_out = (D-1)*stride[2]+dilation[2]*(kernel_size[2]-1)+1-2*padding[2]

qualia2.functions.recurrent module

class qualia2.functions.recurrent.GRU(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x, h, weight_x, weight_h, bias_x, bias_h, num_layers)[source]
Shape:
  • x: [seq_len, N, input_size]

  • h: [num_layers, N, hidden_size]

  • Output: [seq_len, N, hidden_size]

  • Hidden: [num_layers, N, hidden_size]

class qualia2.functions.recurrent.GRUCell(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dh_next)[source]

calculates gradients for backpropagation

static forward(x, h, weight_x, weight_h, bias_x, bias_h)[source]
Shape:
  • x: [N, input_size]

  • h: [N, hidden_size]

  • weight_x: [input_size, 3*hidden_size]

  • weight_h: [hidden_size, 3*hidden_size]

  • bias_x: [3*hidden_size]

  • bias_h: [3*hidden_size]

  • Output: [N, hidden_size]

class qualia2.functions.recurrent.LSTM(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x, h, c, weight_x, weight_h, bias_x, bias_h, num_layers)[source]
Shape:
  • x: [seq_len, N, input_size]

  • h: [num_layers, N, hidden_size]

  • c: [num_layers, N, hidden_size]

  • Output: [seq_len, N, hidden_size]

  • Hidden_h: [num_layers, N, hidden_size]

  • Hidden_c: [num_layers, N, hidden_size]

class qualia2.functions.recurrent.LSTMCell(output_shape_h, output_shape_c, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

backward(dh_next, dc_next=None)[source]

executes backpropagation

calc_grad(dh_next, dc_next)[source]

calculates gradients for backpropagation

static forward(x, h, c, weight_x, weight_h, bias_x, bias_h)[source]
Shape:
  • x: [N, input_size]

  • h: [N, hidden_size]

  • c: [N, hidden_size]

  • weight_x: [input_size, 4*hidden_size]

  • weight_h: [hidden_size, 4*hidden_size]

  • bias_x: [4*hidden_size]

  • bias_h: [4*hidden_size]

  • Output_h: [N, hidden_size]

  • Output_c: [N, hidden_size]

class qualia2.functions.recurrent.RNN(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

static forward(x, h, weight_x, weight_h, bias_x, bias_h, num_layers)[source]
Shape:
  • x: [seq_len, N, input_size]

  • h: [num_layers, N, hidden_size]

  • Output: [seq_len, N, hidden_size]

  • Hidden: [num_layers, N, hidden_size]

class qualia2.functions.recurrent.RNNCell(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dh_next)[source]

calculates gradients for backpropagation

static forward(x, h, weight_x, weight_h, bias_x, bias_h)[source]
Shape:
  • x: [N, input_size]

  • h: [N, hidden_size]

  • weight_x: [input_size, hidden_size]

  • weight_h: [hidden_size, hidden_size]

  • bias_x: [hidden_size]

  • bias_h: [hidden_size]

  • Output: [N, hidden_size]

qualia2.functions.sparse module

class qualia2.functions.sparse.Embedding(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, weight, vocab_size)[source]
Args:

input (Tensor): Long Tensor containing indices into the embedding matrix weight (Tensor): The embedding matrix with number of rows equal to the maximum possible index + 1, and number of columns equal to the embedding size vocab_size (int):

qualia2.functions.trigonometric module

class qualia2.functions.trigonometric.Arccos(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse-cosine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Arccosh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse of hyperbolic cosine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Arcsin(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse-sine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Arcsinh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse of hyperbolic sine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Arctan(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse-tangent function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Arctanh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise inverse of hyperbolic tangent function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Cos(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise cosine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Cosh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise hyperbolic cosine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Sin(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise sine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Sinc(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Sinh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise hyperbolic sine function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Tan(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise tangent function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.trigonometric.Tanh(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

Elementwise hyperbolic tangent function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

qualia2.functions.ufunc module

class qualia2.functions.ufunc.Amax(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, axis=1)[source]

calculates forward propagation

class qualia2.functions.ufunc.Amin(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, axis=1)[source]

calculates forward propagation

class qualia2.functions.ufunc.Cbrt(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.ufunc.Exp(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.ufunc.Log(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.ufunc.Log10(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.ufunc.Maximum(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, other)[source]

calculates forward propagation

class qualia2.functions.ufunc.Mean(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, axis=1)[source]

calculates forward propagation

class qualia2.functions.ufunc.Minimum(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(input, other)[source]

calculates forward propagation

class qualia2.functions.ufunc.Sqrt(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a)[source]

calculates forward propagation

class qualia2.functions.ufunc.Sum(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, axis=1)[source]

calculates forward propagation

qualia2.functions.vision module

class qualia2.functions.vision.Upsample(output_shape, *args, **kwargs)[source]

Bases: qualia2.autograd.Function

calc_grad(dx)[source]

calculates gradients for backpropagation

static forward(a, scale_factor=2, mode='nearest')[source]

calculates forward propagation

Module contents