Initialization of Parameters

Module that contains functionality to initialize parameters to starting values.

climin.initialize.sparsify_columns(arr, n_non_zero, keep_diagonal=False, random_state=None)

Set all but n_non_zero entries to zero for each column of arr.

This is a common technique to find better starting points for learning deep and/or recurrent networks.

Parameters:

arr : array_like, two dimensional

Array to work upon in place.

n_non_zero : integer

Amount of non zero entries to keep.

keep_diagonal : boolean, optional [default: False]

If set to True and arr is square, do keep the diagonal.

random_state : numpy.random.RandomState object, optional [default

If set, random number generator that will generate the indices corresponding to the zero-valued columns.

Examples

>>> import numpy as np
>>> from climin.initialize import sparsify_columns
>>> arr = np.arange(9).reshape((3, 3))
>>> sparsify_columns(arr, 1)
>>> arr                                         
array([[0, 0, 0],
       [0, 4, 5],
       [6, 0, 0]])
climin.initialize.bound_spectral_radius(arr, bound=1.2)

Set the spectral radius of the square matrix arr to bound.

This is performed by scaling eigenvalues of arr.

Parameters:

arr : array_like, two dimensional

Array to work upon in place.

bound : float, optional, default: 1.2

Examples

>>> import numpy as np
>>> from climin.initialize import bound_spectral_radius
>>> arr = np.arange(9).reshape((3, 3)).astype('float64')
>>> bound_spectral_radius(arr, 1.1)
>>> arr                                 
array([[ -7.86816957e-17,   8.98979486e-02,   1.79795897e-01],
       [  2.69693846e-01,   3.59591794e-01,   4.49489743e-01],
       [  5.39387691e-01,   6.29285640e-01,   7.19183588e-01]])
climin.initialize.randomize_normal(arr, loc=0, scale=1, random_state=None)

Populate an array with random numbers from a normal distribution with mean loc and standard deviation scale.

Parameters:

arr : array_like

Array to work upon in place.

loc : float

Mean of the random numbers.

scale : float

Standard deviation of the random numbers.

random_state : np.random.RandomState object, optional [default

Random number generator that shall generate the random numbers.

Examples

>>> import numpy as np
>>> from climin.initialize import randomize_normal
>>> arr = np.empty((3, 3))
>>> randomize_normal(arr)
>>> arr                                 
array([[ 0.18076413,  0.60880657,  1.20855691],
       [ 1.7799948 , -0.82565481,  0.53875307],
       [-0.67056028, -1.46257419,  1.17033425]])
>>> randomize_normal(arr, 10, 0.1)
>>> arr                                 
array([[ 10.02221481,  10.0982449 ,  10.02495358],
      [  9.99867829,   9.99410111,   9.8242318 ],
      [  9.9383779 ,   9.94880091,  10.03179085]])