Parameter initialization

class blocks.initialization.Constant(constant)

Bases: blocks.initialization.NdarrayInitialization

Initialize parameters to a constant.

The constant may be a scalar or a ndarray of any shape that is broadcastable with the requested parameter arrays.

Parameters:constant (ndarray) – The initialization value to use. Must be a scalar or an ndarray (or compatible object, such as a nested list) that has a shape that is broadcastable with any shape requested by initialize.
generate(rng, shape)
class blocks.initialization.Identity(mult=1)

Bases: blocks.initialization.NdarrayInitialization

Initialize to the identity matrix.

Only works for 2D arrays. If the number of columns is not equal to the number of rows, the array will be truncated or padded with zeros.

Parameters:mult (float, optional) – Multiply the identity matrix with a scalar. Defaults to 1.
generate(rng, shape)
class blocks.initialization.IsotropicGaussian(std=1, mean=0)

Bases: blocks.initialization.NdarrayInitialization

Initialize parameters from an isotropic Gaussian distribution.

Parameters:
  • std (float, optional) – The standard deviation of the Gaussian distribution. Defaults to 1.
  • mean (float, optional) – The mean of the Gaussian distribution. Defaults to 0

Notes

Be careful: the standard deviation goes first and the mean goes second!

generate(rng, shape)
class blocks.initialization.NdarrayInitialization

Bases: object

Base class specifying the interface for ndarray initialization.

generate(rng, shape)

Generate an initial set of parameters from a given distribution.

Parameters:
Returns:

output – An ndarray with values drawn from the distribution specified by this object, of shape shape, with dtype config.floatX.

Return type:

ndarray

initialize(var, rng, shape=None)

Initialize a shared variable with generated parameters.

Parameters:
class blocks.initialization.Orthogonal(scale=1)

Bases: blocks.initialization.NdarrayInitialization

Initialize a random orthogonal matrix.

Only works for 2D arrays.

Parameters:
  • scale (float, optional) – Multiply the resulting matrix with a scalar. Defaults to 1. For a discussion of the importance of scale for training time and generalization refer to [Saxe2013].
  • .. – [Saxe2014] Saxe, A.M., McClelland, J.L., Ganguli, S., 2013. Exact solutions to the nonlinear dynamics of learning in deep linear neural networks. arXiv:1312.6120 [cond-mat, q-bio, stat].
generate(rng, shape)
class blocks.initialization.Sparse(num_init, weights_init, sparse_init=None)

Bases: blocks.initialization.NdarrayInitialization

Initialize only a fraction of the weights, row-wise.

Parameters:
  • num_init (int or float) – If int, this is the number of weights to initialize per row. If float, it’s the fraction of the weights per row to initialize.
  • weights_init (NdarrayInitialization instance) – The initialization scheme to initialize the weights with.
  • sparse_init (NdarrayInitialization instance, optional) – What to set the non-initialized weights to (0. by default)
generate(rng, shape)
class blocks.initialization.Uniform(mean=0.0, width=None, std=None)

Bases: blocks.initialization.NdarrayInitialization

Initialize parameters from a uniform distribution.

Parameters:
  • mean (float, optional) – The mean of the uniform distribution (i.e. the center of mass for the density function); Defaults to 0.
  • width (float, optional) – One way of specifying the range of the uniform distribution. The support will be [mean - width/2, mean + width/2]. Exactly one of width or std must be specified.
  • std (float, optional) – An alternative method of specifying the range of the uniform distribution. Chooses the width of the uniform such that random variates will have a desired standard deviation. Exactly one of width or std must be specified.
generate(rng, shape)