Skip to content

Linear

Description

Info

Parent class: Module

Derived classes: -

This module performs a linear transformation to the input data:

y = xW^T + b

where

x - input feature vector;
y - transformed feature vector;
W - layer weights matrix;
b - layer bias vector.

Initializing

def __init__(self,  insize,  outsize,  wscale=1.0,  useBias=True,  initscheme=None,  name=None,  empty=False,  transpose=False):

Parameters

Parameter Allowed types Description Default
insize int Size of the input vector -
outsize int Size of the input vector -
wscale float Dispersion of random layer weights 1.0
useBias bool Whether to use the bias vector True
initscheme Union[tuple, str] Specifies the layer weights initialization scheme. (see createTensorWithScheme). None -> ("xavier_uniform", "in")
name str Layer name None
empty bool Whether to initialize the matrix of weights and biases False
transpose bool Use of a transposed matrix False

Explanations

-

Examples

Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import Linear

Info

gpuarray is required to properly place the tensor in the GPU

batchsize, insize, outsize = 10, 32, 16
data = gpuarray.to_gpu(np.random.randn(batchsize, insize).astype(np.float32))
print(data.shape)
(10, 32)
linear = Linear(insize, outsize)
print(linear.W.shape)
(32, 16)
linear(data)
print(linear.data.shape)
(10, 16)