desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'.. todo::
WRITEME'
| def make_node(self, images, acts, denoms, dout):
| if (not isinstance(images.type, CudaNdarrayType)):
inputs = (images, acts, denoms, dout)
names = ('images', 'acts', 'denoms', 'dout')
for (name, var) in zip(names, inputs):
if (not isinstance(var.type, CudaNdarrayType)):
raise TypeError('CrossMapNormUndo: expec... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images, acts, denoms, dout) = inputs
(targets, out_acts) = outputs
fail = sub['fail']
num_braces = 0
size_f = self._size_f
add_scale = self._add_scale
pow_scale = self._pow_scale
blocked = ('true' if self._blocked else 'false')
inplace = ('1' if self._inplace else '0')
scale_tar... |
'.. todo::
WRITEME'
| def grad(self, inputs, dout):
| raise NotImplementedError()
|
'.. todo::
WRITEME'
| @property
def inplace(self):
| return self._inplace
|
'.. todo::
WRITEME'
| def as_inplace(self):
| if self._inplace:
raise ValueError(("%s instance is already inplace, can't convert" % self.__class__.__name__))
return self.__class__(self._size_f, self._add_scale, self._pow_scale, self._blocked, inplace=True)
|
'.. todo::
WRITEME'
| def __str__(self):
| return (self.__class__.__name__ + ('[size_f=%d,add_scale=%.2f,pow_scale=%.2f,blocked=%s,inplace=%s]' % (self._size_f, self._add_scale, self._pow_scale, self._blocked, self._inplace)))
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (8,)
|
'.. todo::
WRITEME'
| def __eq__(self, other):
| return ((type(self) == type(other)) and (self.ds == other.ds) and (self.stride == other.stride) and (self.start == other.start))
|
'.. todo::
WRITEME'
| def __hash__(self):
| return (((hash(type(self)) ^ hash(self.ds)) ^ hash(self.stride)) ^ hash(self.start))
|
'.. todo::
WRITEME'
| def c_header_dirs(self):
| return ([this_dir, config.pthreads.inc_dir] if config.pthreads.inc_dir else [this_dir])
|
'.. todo::
WRITEME'
| def c_headers(self):
| return ['nvmatrix.cuh', 'conv_util.cuh']
|
'.. todo::
WRITEME'
| def c_lib_dirs(self):
| return ([cuda_convnet_loc, config.pthreads.lib_dir] if config.pthreads.lib_dir else [cuda_convnet_loc])
|
'.. todo::
WRITEME'
| def c_libraries(self):
| return (['cuda_convnet', config.pthreads.lib] if config.pthreads.lib else ['cuda_convnet'])
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (1,)
|
'.. todo::
WRITEME'
| def _argument_contiguity_check(self, arg_name):
| return ('\n if (!CudaNdarray_is_c_contiguous(%%(%(arg_name)s)s))\n {\n if (!(%(class_name_caps)s_COPY_NON_CONTIGUOUS)) {\n PyErr_SetStr... |
'.. todo::
WRITEME'
| def make_node(self, images):
| images = as_cuda_ndarray_variable(images)
assert (images.ndim == 4)
channels_broadcastable = images.type.broadcastable[0]
batch_broadcastable = images.type.broadcastable[3]
rows_broadcastable = False
cols_broadcastable = False
targets_broadcastable = (channels_broadcastable, rows_broadcastab... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images,) = inputs
(targets,) = outputs
fail = sub['fail']
num_braces = 0
if self.copy_non_contiguous:
raise UnimplementedError()
else:
basic_setup = '#define MAXPOOL_COPY_NON_CONTIGUOUS 0\n'
setup_nv_images = (self._argument_contiguity_check('images') + '\n ... |
'.. todo::
WRITEME'
| def R_op(self, inp, evals):
| (x,) = inp
(ev,) = evals
if (ev is not None):
ev = gpu_contiguous(ev)
return [MaxPoolRop(self.ds, self.stride, self.start)(x, ev)]
else:
return [None]
|
'.. todo::
WRITEME'
| def grad(self, inp, grads):
| (x,) = inp
(gz,) = grads
gz = gpu_contiguous(gz)
maxout = self(x)
return [MaxPoolGrad(self.ds, self.stride, self.start)(x, maxout, gz)]
|
'.. todo::
WRITEME'
| def make_thunk(self, *args, **kwargs):
| if (not convnet_available()):
raise RuntimeError('Could not compile cuda_convnet')
return super(MaxPool, self).make_thunk(*args, **kwargs)
|
'.. todo::
WRITEME'
| def __eq__(self, other):
| return ((type(self) == type(other)) and (self.ds == other.ds) and (self.stride == other.stride) and (self.start == other.start))
|
'.. todo::
WRITEME'
| def __hash__(self):
| return (((hash(type(self)) ^ hash(self.ds)) ^ hash(self.stride)) ^ hash(self.start))
|
'.. todo::
WRITEME'
| def c_header_dirs(self):
| return [this_dir]
|
'.. todo::
WRITEME'
| def c_headers(self):
| return ['nvmatrix.cuh', 'conv_util.cuh', 'pool_rop.cuh']
|
'.. todo::
WRITEME'
| def c_lib_dirs(self):
| return [cuda_convnet_loc]
|
'.. todo::
WRITEME'
| def c_libraries(self):
| return ['cuda_convnet']
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (1,)
|
'.. todo::
WRITEME'
| def _argument_contiguity_check(self, arg_name):
| return ('\n if (!CudaNdarray_is_c_contiguous(%%(%(arg_name)s)s))\n {\n if (!(%(class_name_caps)s_COPY_NON_CONTIGUOUS)) {\n PyErr_SetStr... |
'.. todo::
WRITEME'
| def make_node(self, images, evals):
| images = as_cuda_ndarray_variable(images)
evals = as_cuda_ndarray_variable(evals)
assert (images.ndim == 4)
assert (evals.ndim == 4)
channels_broadcastable = images.type.broadcastable[0]
batch_broadcastable = images.type.broadcastable[3]
rows_broadcastable = False
cols_broadcastable = Fa... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images, evals) = inputs
(targets,) = outputs
fail = sub['fail']
num_braces = 0
if self.copy_non_contiguous:
raise UnimplementedError()
else:
basic_setup = '#define MAXPOOLROP_COPY_NON_CONTIGUOUS 0\n'
setup_nv_images = (self._argument_contiguity_check('images') + '\n ... |
'.. todo::
WRITEME'
| def make_thunk(self, node, storage_map, compute_map, no_recycling):
| if (not convnet_available()):
raise RuntimeError('Could not compile cuda_convnet')
return super(MaxPoolRop, self).make_thunk(node, storage_map, storage_map, no_recycling)
|
'.. todo::
WRITEME'
| def __eq__(self, other):
| return ((type(self) == type(other)) and (self.ds == other.ds) and (self.stride == other.stride) and (self.start == other.start))
|
'.. todo::
WRITEME'
| def __hash__(self):
| return (((hash(type(self)) ^ hash(self.ds)) ^ hash(self.stride)) ^ hash(self.start))
|
'.. todo::
WRITEME'
| def c_header_dirs(self):
| return ([this_dir, config.pthreads.inc_dir] if config.pthreads.inc_dir else [this_dir])
|
'.. todo::
WRITEME'
| def c_headers(self):
| return ['nvmatrix.cuh', 'conv_util.cuh']
|
'.. todo::
WRITEME'
| def c_lib_dirs(self):
| return ([cuda_convnet_loc, config.pthreads.lib_dir] if config.pthreads.lib_dir else [cuda_convnet_loc])
|
'.. todo::
WRITEME'
| def c_libraries(self):
| return (['cuda_convnet', config.pthreads.lib] if config.pthreads.lib else ['cuda_convnet'])
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (1,)
|
'.. todo::
WRITEME'
| def make_node(self, images, maxout, gz):
| images = as_cuda_ndarray_variable(images)
maxout = as_cuda_ndarray_variable(maxout)
gz = as_cuda_ndarray_variable(gz)
assert (images.ndim == 4)
assert (maxout.ndim == 4)
assert (gz.ndim == 4)
try:
nb_channel = int(get_scalar_constant_value(images.shape[0]))
assert ((nb_channe... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images, maxout, gz) = inputs
(targets,) = outputs
fail = sub['fail']
num_braces = 0
if self.copy_non_contiguous:
raise UnimplementedError()
else:
basic_setup = '#define MAXPOOLGRAD_COPY_NON_CONTIGUOUS 0\n'
setup_nv_images = (self._argument_contiguity_check('images') + ... |
'.. todo::
WRITEME'
| def make_thunk(self, node, storage_map, compute_map, no_recycling):
| if (not convnet_available()):
raise RuntimeError('Could not compile cuda_convnet')
return super(MaxPoolGrad, self).make_thunk(node, storage_map, compute_map, no_recycling)
|
'.. todo::
WRITEME
Parameters
hid_acts : WRITEME
filters : WRITEME
output_shape : 2-element TensorVariable, optional
The spatial shape of the image'
| def make_node(self, hid_acts, filters, output_shape=None):
| if (not isinstance(hid_acts.type, CudaNdarrayType)):
raise TypeError(('ImageActs: expected hid_acts.type to be CudaNdarrayType, got ' + str(hid_acts.type)))
if (not isinstance(filters.type, CudaNdarrayType)):
raise TypeError(('ImageActs: expected filters.type to ... |
'Useful with the hack in profilemode to print the MFlops'
| def flops(self, inputs, outputs):
| (hid_acts, filters, output_shape) = inputs
(out,) = outputs
assert (hid_acts[0] == filters[3])
flops = (((((((hid_acts[3] * filters[0]) * hid_acts[0]) * filters[1]) * filters[2]) * hid_acts[1]) * hid_acts[2]) * 2)
return flops
|
'.. todo::
WRITEME'
| def connection_pattern(self, node):
| return [[1], [1], [0]]
|
'.. todo::
WRITEME'
| def grad(self, inputs, g_outputs):
| (hid_acts, filters, output_shape) = inputs
(g_images,) = g_outputs
g_images = as_cuda_ndarray_variable(g_images)
assert (not isinstance(g_images, list))
global FilterActs
global WeightActs
if (FilterActs is None):
from pylearn2.sandbox.cuda_convnet.filter_acts import FilterActs
... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (hid_acts, filters, output_shape) = inputs
(targets,) = outputs
fail = sub['fail']
basic_setup = '\n #define scaleTargets 0\n #define scaleOutput 1\n '
if self.dense_connectivity:
basic_s... |
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (9,)
|
'.. todo::
WRITEME'
| def __eq__(self, other):
| return ((type(self) == type(other)) and (self.ds == other.ds) and (self.stride == other.stride) and (self.start == other.start))
|
'.. todo::
WRITEME'
| def __hash__(self):
| return (((hash(type(self)) ^ hash(self.ds)) ^ hash(self.stride)) ^ hash(self.start))
|
'.. todo::
WRITEME'
| def c_header_dirs(self):
| return [this_dir]
|
'.. todo::
WRITEME'
| def c_headers(self):
| return ['nvmatrix.cuh', 'conv_util.cuh']
|
'.. todo::
WRITEME'
| def c_lib_dirs(self):
| return [cuda_convnet_loc]
|
'.. todo::
WRITEME'
| def c_libraries(self):
| return ['cuda_convnet']
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (1,)
|
'.. todo::
WRITEME'
| def _argument_contiguity_check(self, arg_name):
| return ('\n if (!CudaNdarray_is_c_contiguous(%%(%(arg_name)s)s))\n {\n if (!(%(class_name_caps)s_COPY_NON_CONTIGUOUS)) {\n PyErr_SetStr... |
'.. todo::
WRITEME'
| def make_node(self, images):
| images = as_cuda_ndarray_variable(images)
assert (images.ndim == 4)
channels_broadcastable = images.type.broadcastable[0]
batch_broadcastable = images.type.broadcastable[3]
rows_broadcastable = False
cols_broadcastable = False
targets_broadcastable = (channels_broadcastable, rows_broadcastab... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images, seed) = inputs
(targets,) = outputs
fail = sub['fail']
num_braces = 0
if self.copy_non_contiguous:
raise UnimplementedError()
else:
basic_setup = '#define STOCHASTICMAXPOOL_COPY_NON_CONTIGUOUS 0\n'
setup_nv_images = (self._argument_contiguity_check('images') + ... |
'.. todo::
WRITEME'
| def grad(self, inp, grads):
| (x, seed) = inp
(gz,) = grads
gz = gpu_contiguous(gz)
maxout = self(x)
return [MaxPoolGrad(self.ds, self.stride, self.start)(x, maxout, gz), zeros_like(seed)]
|
'.. todo::
WRITEME'
| def make_thunk(self, *args, **kwargs):
| if (not convnet_available()):
raise RuntimeError('Could not compile cuda_convnet')
return super(StochasticMaxPool, self).make_thunk(*args, **kwargs)
|
'.. todo::
WRITEME'
| def __eq__(self, other):
| return ((type(self) == type(other)) and (self.ds == other.ds) and (self.stride == other.stride) and (self.start == other.start))
|
'.. todo::
WRITEME'
| def __hash__(self):
| return (((hash(type(self)) ^ hash(self.ds)) ^ hash(self.stride)) ^ hash(self.start))
|
'.. todo::
WRITEME'
| def c_header_dirs(self):
| return [this_dir]
|
'.. todo::
WRITEME'
| def c_headers(self):
| return ['nvmatrix.cuh', 'conv_util.cuh']
|
'.. todo::
WRITEME'
| def c_lib_dirs(self):
| return [cuda_convnet_loc]
|
'.. todo::
WRITEME'
| def c_libraries(self):
| return ['cuda_convnet']
|
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (1,)
|
'.. todo::
WRITEME'
| def _argument_contiguity_check(self, arg_name):
| return ('\n if (!CudaNdarray_is_c_contiguous(%%(%(arg_name)s)s))\n {\n if (!(%(class_name_caps)s_COPY_NON_CONTIGUOUS)) {\n PyErr_SetStr... |
'.. todo::
WRITEME'
| def make_node(self, images):
| images = as_cuda_ndarray_variable(images)
assert (images.ndim == 4)
channels_broadcastable = images.type.broadcastable[0]
batch_broadcastable = images.type.broadcastable[3]
rows_broadcastable = False
cols_broadcastable = False
targets_broadcastable = (channels_broadcastable, rows_broadcastab... |
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| (images,) = inputs
(targets,) = outputs
fail = sub['fail']
num_braces = 0
if self.copy_non_contiguous:
raise UnimplementedError()
else:
basic_setup = '#define WEIGHTEDMAXPOOL_COPY_NON_CONTIGUOUS 0\n'
setup_nv_images = (self._argument_contiguity_check('images') + '\n ... |
'.. todo::
WRITEME'
| def grad(self, inp, grads):
| raise NotImplementedError()
|
'.. todo::
WRITEME'
| def make_thunk(self, node, storage_map, compute_map, no_recycling):
| if (not convnet_available()):
raise RuntimeError('Could not compile cuda_convnet')
return super(WeightedMaxPool, self).make_thunk(node, storage_map, compute_map, no_recycling)
|
'.. todo::
WRITEME'
| def make_node(self, images, hid_grads, output_shape):
| if (not isinstance(images.type, CudaNdarrayType)):
raise TypeError(('WeightActs: expected images.type to be CudaNdarrayType, got ' + str(images.type)))
if (not isinstance(hid_grads.type, CudaNdarrayType)):
raise TypeError(('WeightActs: expected hid_acts.type to b... |
'Useful with the hack in profilemode to print the MFlops'
| def flops(self, inputs, outputs):
| (images, kerns, output_shape) = inputs
(out, partial) = outputs
assert (images[3] == kerns[3])
flops = ((kerns[1] * kerns[2]) * 2)
flops *= (out[1] * out[2])
flops *= ((images[3] * kerns[0]) * images[0])
return flops
|
'.. todo::
WRITEME'
| def c_headers(self):
| headers = super(WeightActs, self).c_headers()
headers.append('weight_acts.cuh')
return headers
|
'.. todo::
WRITEME'
| def c_code(self, node, name, inputs, outputs, sub):
| partial_sum = (self.partial_sum if (self.partial_sum is not None) else 0)
(images, hid_grads, output_shape) = inputs
(weights_grads, partialsum_storage) = outputs
fail = sub['fail']
pad = self.pad
basic_setup = '\n #define scaleTargets 0\n ... |
'.. todo::
WRITEME'
| def c_code_cache_version(self):
| return (7,)
|
'If a layer receives a SequenceSpace it should receive
a tuple of (data, mask). For layers that cannot deal with this
we do the following:
- Unpack (data, mask) and perform the fprop with the data only
- Add the mask back just before returning, so that the next layer
receives a tuple again
Besides the mask, we also nee... | @classmethod
def fprop_wrapper(cls, name, fprop):
| @functools.wraps(fprop)
def outer(self, state_below, return_all=False):
if self._requires_reshape:
if self._requires_unmask:
(state_below, mask) = state_below
if isinstance(state_below, tuple):
ndim = state_below[0].ndim
reshape_siz... |
'Reshapes and unmasks the data before retrieving the monitoring
channels
Parameters
get_layer_monitoring_channels : method
The get_layer_monitoring_channels method to be wrapped'
| @classmethod
def get_layer_monitoring_channels_wrapper(cls, name, get_layer_monitoring_channels):
| @functools.wraps(get_layer_monitoring_channels)
def outer(self, state_below=None, state=None, targets=None):
if (self._requires_reshape and (self.__class__.__name__ == name)):
if self._requires_unmask:
if (state_below is not None):
(state_below, state_belo... |
'This layer wraps cost methods by reshaping the tensor (merging
the time and batch axis) and then taking out all the masked
values before applying the cost method.'
| @classmethod
def cost_wrapper(cls, name, cost):
| @functools.wraps(cost)
def outer(self, Y, Y_hat):
if self._requires_reshape:
if self._requires_unmask:
try:
(Y, Y_mask) = Y
(Y_hat, Y_hat_mask) = Y_hat
except:
log.warning("Lost the mask when... |
'If the cost_matrix is called from within a cost function,
everything is fine, since things were reshaped and unpacked.
In any other case we raise a warning (after which it most likely
crashes).'
| @classmethod
def cost_matrix_wrapper(cls, name, cost_matrix):
| @functools.wraps(cost_matrix)
def outer(self, Y, Y_hat):
if (self._requires_reshape and (inspect.stack()[1][3] != 'cost')):
log.warning('You are using the `cost_matrix` method on a layer which has been wrapped to accept sequence input, might... |
'If the cost_from_cost_matrix is called from within a cost function,
everything is fine, since things were reshaped and unpacked.
In any other case we raise a warning (after which it most likely
crashes).'
| @classmethod
def cost_from_cost_matrix_wrapper(cls, name, cost_from_cost_matrix):
| @functools.wraps(cost_from_cost_matrix)
def outer(self, cost_matrix):
if (self._requires_reshape and (inspect.stack()[1][3] != 'cost')):
log.warning('You are using the `cost_from_cost_matrix` method on a layer which has been wrapped to accept sequ... |
'If this layer is not RNN-adapted, we intercept the call to the
set_input_space method and set the space to a non-sequence space.
This transformation is only applied to whitelisted layers.
Parameters
set_input_space : method
The set_input_space method to be wrapped'
| @classmethod
def set_input_space_wrapper(cls, name, set_input_space):
| @functools.wraps(set_input_space)
def outer(self, input_space):
if ((not self.rnn_friendly) and (name != 'MLP')):
def find_sequence_space(input_space):
'\n Recursive helper function that ... |
'Same thing as set_input_space_wrapper.
Parameters
get_output_space : method
The get_output_space method to be wrapped'
| @classmethod
def get_output_space_wrapper(cls, name, get_output_space):
| @functools.wraps(get_output_space)
def outer(self):
if ((not self.rnn_friendly) and self._requires_reshape and ((not isinstance(get_output_space(self), SequenceSpace)) and (not isinstance(get_output_space(self), SequenceDataSpace)))):
if isinstance(self.mlp.input_space, SequenceSpace):
... |
'Same thing as set_input_space_wrapper.
Parameters
get_target_space : method
The get_target_space method to be wrapped'
| @classmethod
def get_target_space_wrapper(cls, name, get_target_space):
| @functools.wraps(get_target_space)
def outer(self):
if ((not self.rnn_friendly) and self._requires_reshape and ((not isinstance(get_target_space(self), SequenceSpace)) and (not isinstance(get_target_space(self), SequenceDataSpace)))):
if isinstance(self.mlp.input_space, SequenceSpace):
... |
'Skip all tests.'
| def setUp(self):
| raise SkipTest('Sandbox RNNs are disabled.')
|
'Use an RNN without non-linearity to create the Mersenne numbers
(2 ** n - 1) to check whether fprop works correctly.'
| def test_fprop(self):
| rnn = RNN(input_space=SequenceSpace(VectorSpace(dim=1)), layers=[Recurrent(dim=1, layer_name='recurrent', irange=0.1, indices=[(-1)], nonlinearity=(lambda x: x))])
(W, U, b) = rnn.layers[0].get_params()
W.set_value([[1]])
U.set_value([[2]])
(X_data, X_mask) = rnn.get_input_space().make_theano_batch(... |
'Use an RNN to calculate Mersenne number sequences of different
lengths and check whether the costs make sense.'
| def test_cost(self):
| rnn = RNN(input_space=SequenceSpace(VectorSpace(dim=1)), layers=[Recurrent(dim=1, layer_name='recurrent', irange=0, nonlinearity=(lambda x: x)), Linear(dim=1, layer_name='linear', irange=0)])
(W, U, b) = rnn.layers[0].get_params()
W.set_value([[1]])
U.set_value([[2]])
(W, b) = rnn.layers[1].get_para... |
'Testing to see whether the gradient can be calculated when using
a 1-dimensional hidden state.'
| def test_1d_gradient(self):
| rnn = RNN(input_space=SequenceSpace(VectorSpace(dim=1)), layers=[Recurrent(dim=1, layer_name='recurrent', irange=0, nonlinearity=(lambda x: x)), Linear(dim=1, layer_name='linear', irange=0)])
(X_data, X_mask) = rnn.get_input_space().make_theano_batch()
(y_data, y_mask) = rnn.get_output_space().make_theano_b... |
'Testing to see whether the gradient can be calculated.'
| def test_gradient(self):
| rnn = RNN(input_space=SequenceSpace(VectorSpace(dim=1)), layers=[Recurrent(dim=2, layer_name='recurrent', irange=0, nonlinearity=(lambda x: x)), Linear(dim=1, layer_name='linear', irange=0)])
(X_data, X_mask) = rnn.get_input_space().make_theano_batch()
(y_data, y_mask) = rnn.get_output_space().make_theano_b... |
'This is a recursive helper function to go
through the nested spaces and tuples
Parameters
space : Space
source : string'
| @classmethod
def add_mask_source(cls, space, source):
| if isinstance(space, CompositeSpace):
if (not isinstance(space, SequenceSpace)):
source = tuple((cls.add_mask_source(component, source) for (component, source) in zip(space.components, source)))
else:
assert isinstance(source, six.string_types)
source = (source, (... |
'Block monitoring channels if not necessary
Parameters
: todo'
| @wraps(Layer.get_layer_monitoring_channels)
def get_layer_monitoring_channels(self, state_below=None, state=None, targets=None):
| rval = OrderedDict()
if self.use_monitoring_channels:
state = state_below
x = state
state_conc = None
for layer in self.layers:
state_below = state
if (self.x_shortcut and (layer is not self.layers[0]) and (layer is not self.layers[(-1)])):
... |
'A function that adds additive Gaussian
noise
Parameters
param : sharedX
model parameter to be regularized
Returns
param : sharedX
model parameter with additive noise'
| def add_noise(self, param):
| param += self.mlp.theano_rng.normal(size=param.shape, avg=0.0, std=self._std_dev, dtype=param.dtype)
return param
|
'Scan function for case using masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step_mask(self, state_below, mask, state_before, U):
| z = self.nonlinearity((state_below + tensor.dot(state_before, U)))
z = ((mask[:, None] * z) + ((1 - mask[:, None]) * state_before))
return z
|
'Scan function for case without masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step(self, state_below, state_before, U):
| z = self.nonlinearity((state_below + tensor.dot(state_before, U)))
return z
|
'Scan function for case using masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step_mask(self, state_below, mask, state_before, U):
| g_on = (state_below + tensor.dot(state_before[:, :self.dim], U))
i_on = tensor.nnet.sigmoid(g_on[:, :self.dim])
f_on = tensor.nnet.sigmoid(g_on[:, self.dim:(2 * self.dim)])
o_on = tensor.nnet.sigmoid(g_on[:, (2 * self.dim):(3 * self.dim)])
z = tensor.set_subtensor(state_before[:, self.dim:], ((f_on ... |
'Scan function for case without masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step(self, state_below, z, U):
| g_on = (state_below + tensor.dot(z[:, :self.dim], U))
i_on = tensor.nnet.sigmoid(g_on[:, :self.dim])
f_on = tensor.nnet.sigmoid(g_on[:, self.dim:(2 * self.dim)])
o_on = tensor.nnet.sigmoid(g_on[:, (2 * self.dim):(3 * self.dim)])
z = tensor.set_subtensor(z[:, self.dim:], ((f_on * z[:, self.dim:]) + (... |
'Scan function for case using masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step_mask(self, state_below, mask, state_before, U):
| g_on = tensor.inc_subtensor(state_below[:, self.dim:], tensor.dot(state_before, U[:, self.dim:]))
r_on = tensor.nnet.sigmoid(g_on[:, self.dim:(2 * self.dim)])
u_on = tensor.nnet.sigmoid(g_on[:, (2 * self.dim):])
z_t = tensor.tanh((g_on[:, :self.dim] + tensor.dot((r_on * state_before), U[:, :self.dim])))... |
'Scan function for case without masks
Parameters
: todo
state_below : TheanoTensor'
| def fprop_step(self, state_below, state_before, U):
| g_on = tensor.inc_subtensor(state_below[:, self.dim:], tensor.dot(state_before, U[:, self.dim:]))
r_on = tensor.nnet.sigmoid(g_on[:, self.dim:(2 * self.dim)])
u_on = tensor.nnet.sigmoid(g_on[:, (2 * self.dim):])
z_t = tensor.tanh((g_on[:, :self.dim] + tensor.dot((r_on * state_before), U[:, :self.dim])))... |
'Called by self._format_as(space), to check whether self and space
have compatible sizes. Throws a ValueError if they don\'t.'
| @wraps(space.Space._check_sizes)
def _check_sizes(self, space):
| my_dimension = self.get_total_dimension()
other_dimension = space.get_total_dimension()
if (my_dimension != other_dimension):
if isinstance(space, Conv2DSpace):
if ((my_dimension * space.shape[0]) != other_dimension):
raise ValueError(((((((str(self) + ' with total ... |
'Create a known gradient and check whether it is being clipped
correctly'
| def test_gradient_clipping(self):
| mlp = MLP(layers=[Linear(dim=1, irange=0, layer_name='linear')], nvis=1)
(W, b) = mlp.layers[0].get_params()
W.set_value([[10]])
X = mlp.get_input_space().make_theano_batch()
y = mlp.get_output_space().make_theano_batch()
cost = Default()
(gradients, _) = cost.get_gradients(mlp, (X, y))
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.