deepensemble.layers

Layers

Dense Layer

class deepensemble.layers.dense.Dense(n_input=None, n_output=None, activation=None)[source]

Typical Layer of MLP.

\[Layer(x) = activation(Wx + b)\]

where \(x \in \mathbb{R}^{n_{output}}\), \(W \in \mathbb{R}^{n_{output} \times n_{input}}\) and \(b \in \mathbb{R}^{n_{output}}\).

Parameters:

n_input : int or tuple[]

Dimension of input.

n_output : int or tuple[]

Dimension of output.

activation : callback

Activation function.

output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample

prob : bool

Flag for changing behavior of some layers.

Returns:

theano.tensor.matrix

Returns the output layers according to above equation:

\[Layer(x) = activation(Wx + b)\]

Convolutional Layers

class deepensemble.layers.conv.ConvolutionBase(num_filters, filter_size, input_shape=None, stride=1, pad=0, untie_biases=False, filter_flip=True, non_linearity=<function ActivationFunctions.linear at 0x7f9b55a35f28>)[source]

Convolution Layer Class Base-

Parameters:

num_filters : int

Number of filters.

filter_size : int or tuple[]

The tuple has the filter size.

input_shape : tuple[]

The tuple has the batch size, num input feature maps and input data size.

stride : int

pad : int

untie_biases : bool

filter_flip : bool

non_linearity : callable

convolution(x)[source]

Compute the convolution.

get_dim_conv()[source]

Gets dimension convolution.

Returns:

int

Returns dimension of convolution.

get_shape_W()[source]

Gets shape weights of layer.

get_shape_b()[source]

Gets shape bias of layer.

Returns:

int

Returns number of filters.

output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample

prob : bool

No used.

Returns:

theano.tensor.matrix

Returns the output layers.

set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.

class deepensemble.layers.conv.Convolution1D(num_filters, filter_size, input_shape=None, stride=1, pad=0, untie_biases=False, filter_flip=True, non_linearity=<function ActivationFunctions.linear at 0x7f9b55a35f28>)[source]

Convolution 1D Layer.

convolution(_input)[source]

Convolution 1D Function.

Parameters:

_input : theano.tensor

Input sample.

Returns:

theano.tensor

Returns convolution 1D.

class deepensemble.layers.conv.Convolution2D(num_filters, filter_size, input_shape=None, stride=(1, 1), pad=(0, 0), untie_biases=False, filter_flip=True, non_linearity=<function ActivationFunctions.linear at 0x7f9b55a35f28>)[source]

Convolution 2D Layer.

convolution(_input, _conv=<function conv2d at 0x7f9b57dda048>)[source]

Convolution 2D Function.

Parameters:

_input : theano.tensor

Input sample.

_conv : theano.Op

Convolution function.

Returns:

theano.tensor

Returns convolution 1D.

deepensemble.layers.conv.conv1d_mc0(_input, filters, image_shape=None, filter_shape=None, border_mode='valid', subsample=(1, ), filter_flip=True)[source]

Generate convolution 1D using conv2d with width == 1.

Parameters:

_input : theano.tensor.shared

Input layer.

filters : theano.tensor.shared

Filters.

image_shape : tuple[]

Shape of image or array with 1D signals.

filter_shape : tuple[]

Shape of filters.

border_mode : tuple[] or int

Border mode.

subsample

Subsample.

filter_flip

Filter flip.

Returns:

theano.tensor

Returns convolution 1D.

Pool Layers

class deepensemble.layers.pool.PoolBase(pool_size, input_shape=None, output_shape=None, stride=1, pad=0, ignore_border=True, mode='max')[source]

Pool Base Layer

Parameters:

pool_size : int or tuple[]

stride : int or tuple[]

pad : int or tuple[]

ignore_border : bool

mode : str

Attributes

_pool_size (int or tuple[])
_stride (int or tuple[])
_pad (int or tuple[])
_ignore_border (ignore_border)
_mode (mode)
class deepensemble.layers.pool.Pool1D(pool_size, input_shape=None, output_shape=None, stride=1, pad=0, ignore_border=True, mode='max')[source]

Pool 1D Layer.

output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample

prob : bool

Flag for changing behavior of some layers.

Returns:

theano.tensor.matrix

Returns the output layers according to above equation

set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.

class deepensemble.layers.pool.MaxPool1D(pool_size, **kwargs)[source]

Max Pool 1D Layer.

class deepensemble.layers.pool.Pool2D(pool_size, input_shape=None, output_shape=None, stride=(1, 1), pad=(0, 0), ignore_border=True, mode='max')[source]

Pool 2D Layer.

output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample

prob : bool

Flag for changing behavior of some layers.

Returns:

theano.tensor.matrix

Returns the output layers according to above equation

set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.

class deepensemble.layers.pool.MaxPool2D(pool_size, **kwargs)[source]

Max Pool 2D Layer.

Dropout Layer

class deepensemble.layers.dropout.Dropout(input_shape=None, p=0.5, rescale=True, seed=13)[source]
set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.

Recurrent Layers

class deepensemble.layers.recurrent.RecurrentLayer(n_input=None, n_recurrent=None, activation=None)[source]
get_shape_W()[source]

Gets shape weights of layer.

get_shape_Wr()[source]

Gets shape weights of layer.

get_shape_b()[source]

Gets shape bias of layer.

output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample

prob : bool

Returns:

theano.tensor.matrix

Returns the output layers according to above equation:

\[Layer(x) = activation(Wx + b)\]
class deepensemble.layers.recurrent.LSTMLayer(n_input=None, n_recurrent=None, mask=None, activation=<function ActivationFunctions.sigmoid at 0x7f9b55a3a2f0>, activation2=<function ActivationFunctions.tanh at 0x7f9b55a3a378>)[source]
output(x, prob=True)[source]

Return output of layers

Parameters:

x : theano.tensor.matrix

Input sample.

prob : bool

Flag for changing behavior of some layers.

Returns:

theano.tensor.matrix

Returns the output layers according to above equation:

\[Layer(x) = activation(Wx + b)\]

Utils Layers

class deepensemble.layers.utils_layers.MaskLayer(input_shape=None, ratio=0.9, seed=13)[source]

This layer generate a random permutation on index features or inputs of layer.

Parameters:

input_shape : tuple[]

Tuple input layer.

ratio : float

This number is used as ratio

seed

Number of used as seed for random number generator (see numpy.random.seed).

output(_input, prob=True)[source]

Gets output of model

Parameters:

_input : theano.tensor or numpy.array

Input sample.

prob : bool

Flag for changing behavior of some layers.

set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.

class deepensemble.layers.utils_layers.NoiseLayer(input_shape=None, seed=13, rng='normal', **kwargs)[source]

This layer added noise.

Parameters:

input_shape : tuple[]

Tuple input layer.

seed

Number of used as seed for random number generator.

rng : str

Type of distribution (uniform, binomial, normal).

seed

Number of used as seed for random number generator.

kwargs

Parameters of distribution.

output(_input, prob=True)[source]

Gets output of layer.

Parameters:

_input : theano.tensor or numpy.array

Input sample.

prob : bool

Returns:

theano.tensor

Returns input plus noise.

set_input_shape(shape)[source]

Set input shape.

Parameters:

shape : tuple[]

Shape of input.