desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Compute and return eigen{values,vectors} of X\'s covariance matrix. Parameters X : WRITEME Returns All eigenvalues in decreasing order matrix containing corresponding eigenvectors in its columns'
def _cov_eigen(self, X):
raise NotImplementedError(('Not implemented in _PCABase. Use a ' + 'subclass (and implement it there).'))
'.. todo:: WRITEME'
def get_input_type(self):
return csr_matrix
'.. todo:: WRITEME'
def _cov_eigen(self, X):
(n, d) = X.shape cov = numpy.zeros((d, d)) batch_size = self.minibatch_size for i in xrange(0, n, batch_size): logger.info(' DCTB processing example {0}'.format(i)) end = min(n, (i + batch_size)) x = (X[i:end, :].todense() - self.mean_) assert (x.shape[0] == (end - ...
'Compute the PCA transformation matrix. Given a rectangular matrix :math:`X = USV` such that :math:`S` is a diagonal matrix with :math:`X`\'s singular values along its diagonal, returns :math:`W = V^{-1}`. If mean is provided, :math:`X` will not be centered first. Parameters X : numpy.ndarray Matrix of shape (n, d) on ...
def train(self, X):
assert sparse.issparse(X) logger.info('computing mean') self.mean_ = numpy.asarray(X.mean(axis=0))[0, :] super(SparseMatPCA, self).train(X, mean=self.mean_)
'.. todo:: WRITEME'
def __call__(self, inputs):
self._update_cutoff() Y = structured_dot(inputs, self.W[:, :self.component_cutoff]) Z = (Y - tensor.dot(self.mean, self.W[:, :self.component_cutoff])) if self.whiten: Z /= tensor.sqrt(self.v[:self.component_cutoff]) return Z
'Returns a compiled theano function to compute a representation Parameters name : str WRITEME'
def function(self, name=None):
inputs = SparseType('csr', dtype=theano.config.floatX)() return theano.function([inputs], self(inputs), name=name)
'Perform online computation of covariance matrix eigen{values,vectors}. Parameters X : WRITEME Returns WRITEME'
def _cov_eigen(self, X):
num_components = min(self.num_components, X.shape[1]) pca_estimator = PcaOnlineEstimator(X.shape[1], n_eigen=num_components, minibatch_size=self.minibatch_size, centering=False) logger.debug(('*' * 50)) for i in range(X.shape[0]): if (((i + 1) % (X.shape[0] / 50)) == 0): logger.debug...
'.. todo:: WRITEME'
def __call__(self, X):
X = X.T (m, n) = X.shape mean = X.mean(axis=0) rval = N.zeros((n, n)) for i in xrange(0, m, self.batch_size): B = (X[i:(i + self.batch_size), :] - mean) rval += N.dot(B.T, B) return (rval / float((m - 1)))
'Perform direct computation of covariance matrix eigen{values,vectors}. Parameters X : WRITEME Returns WRITEME'
def _cov_eigen(self, X):
(v, W) = linalg.eigh(self.cov(X.T)) return (v[::(-1)], W[:, ::(-1)])
'Compute covariance matrix eigen{values,vectors} via Singular Value Decomposition (SVD). Parameters X : WRITEME Returns WRITEME'
def _cov_eigen(self, X):
(U, s, Vh) = linalg.svd(X, full_matrices=False) return ((s ** 2), Vh.T)
'.. todo:: WRITEME'
def train(self, X, mean=None):
warnings.warn('You should probably be using SparseMatPCA, unless your design matrix fits in memory.') (n, d) = X.shape mean = X.mean(axis=0) mean_matrix = csr_matrix(mean.repeat(n).reshape((d, n))).T X = (X - mean_matrix) super(SparsePCA, self).train(X, mean=n...
'Perform direct computation of covariance matrix eigen{values,vectors}, given a scipy.sparse matrix. Parameters X : WRITEME Returns WRITEME'
def _cov_eigen(self, X):
(v, W) = eigen_symmetric((X.T.dot(X) / X.shape[0]), k=self.num_components) return (v[::(-1)], W[:, ::(-1)])
'Compute and return the PCA transformation of sparse data. Precondition: `self.mean` has been subtracted from inputs. The reason for this is that, as far as I can tell, there is no way to subtract a vector from a sparse matrix without constructing an intermediary dense matrix, in theano; even the hack used in `train()`...
def __call__(self, inputs):
self._update_cutoff() Y = structured_dot(inputs, self.W[:, :self.component_cutoff]) if self.whiten: Y /= tensor.sqrt(self.v[:self.component_cutoff]) return Y
'Returns a compiled theano function to compute a representation Parameters name : str WRITEME Returns WRITEME'
def function(self, name=None):
inputs = SparseType('csr', dtype=theano.config.floatX)() return theano.function([inputs], self(inputs), name=name)
'.. todo:: WRITEME'
def observe(self, x):
assert (numpy.size(x) == self.n_dim) self.n_observations += 1 row = (self.n_eigen + self.minibatch_index) self.Xt[row] = x self.x_sum *= self.gamma self.x_sum += x normalizer = ((1.0 - pow(self.gamma, self.n_observations)) / (1.0 - self.gamma)) if self.centering: self.Xt[row] -= ...
'.. todo:: WRITEME'
def reevaluate(self):
assert (self.minibatch_index == self.minibatch_size) for i in range((self.n_eigen + self.minibatch_size)): self.G[(i, i)] += self.regularizer (self.d, self.V) = linalg.eigh(self.G) self.Ut = numpy.dot(self.V[:, (- self.n_eigen):].transpose(), self.Xt) rn = pow(self.gamma, ((-0.5) * (self.min...
'.. todo:: WRITEME'
def getLeadingEigen(self):
normalizer = ((1.0 - pow(self.gamma, (self.n_observations - self.minibatch_index))) / (1.0 - self.gamma)) eigvals = (self.d[(- self.n_eigen):] / normalizer) eigvecs = numpy.zeros([self.n_eigen, self.n_dim]) for i in range(self.n_eigen): eigvecs[i] = (self.Ut[((- self.n_eigen) + i)] / numpy.sqrt(...
'Returns rval : str A string representation of the object. In this case, just the class name.'
def __str__(self):
return 'Maxout'
'Tells the layer to use the specified input space. This resets parameters! The weight matrix is initialized with the size needed to receive input from this space. Parameters space : Space The Space that the input will lie in.'
def set_input_space(self, space):
self.input_space = space if isinstance(space, VectorSpace): self.requires_reformat = False self.input_dim = space.dim else: self.requires_reformat = True self.input_dim = space.get_total_dimension() self.desired_space = VectorSpace(self.input_dim) if (not (0 == ((...
'Replaces the values in `updates` if needed to enforce the options set in the __init__ method, including `mask_weights` Parameters updates : OrderedDict A dictionary mapping parameters (including parameters not belonging to this model) to updated values of those parameters. The dictionary passed in contains the updates...
def _modify_updates(self, updates):
if (not hasattr(self, 'mask_weights')): self.mask_weights = None if (self.mask_weights is not None): (W,) = self.transformer.get_params() if (W in updates): updates[W] = (updates[W] * self.mask)
'Tells the layer to use the specified input space. This resets parameters! The kernel tensor is initialized with the size needed to receive input from this space. Parameters space : Space The Space that the input will lie in.'
def set_input_space(self, space):
rng = self.mlp.rng setup_detector_layer_c01b(layer=self, input_space=space, rng=rng) detector_shape = self.detector_space.shape def handle_pool_shape(idx): if (self.pool_shape[idx] < 1): raise ValueError(('bad pool shape: ' + str(self.pool_shape))) if (self.pool_shap...
'Tells the layer to use the specified input space. This resets parameters! The weight tensor is initialized with the size needed to receive input from this space. Parameters space : Space The Space that the input will lie in.'
def set_input_space(self, space):
self.input_space = space if (not isinstance(self.input_space, Conv2DSpace)): raise TypeError(((('The input to a convolutional layer should be a Conv2DSpace, but layer ' + self.layer_name) + ' got ') + str(type(self.input_space)))) self.desired_space = Co...
'Returns norms : theano 4 tensor A theano expression for the norms of the different filters in the layer. TODO: explain significance of each of the 4 axes, and what order they\'ll be in.'
def get_filter_norms(self, W=None):
if (W is None): (W,) = self.transformer.get_params() assert (W.ndim == 7) sq_W = T.sqr(W) norms = T.sqrt(sq_W.sum(axis=(2, 3, 4))) return norms
'(Symbolically) corrupt the inputs with a noise process. Parameters inputs : tensor_like, or list of tensor_likes Theano symbolic(s) representing a (list of) (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_lik...
def __call__(self, inputs):
if isinstance(inputs, tensor.Variable): return self._corrupt(inputs) else: return [self._corrupt(inp) for inp in inputs]
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
raise NotImplementedError()
'.. todo:: WRITEME'
def corruption_free_energy(self, corrupted_X, X):
raise NotImplementedError()
'.. todo:: WRITEME'
def __call__(self, inputs):
return inputs
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
return (self.s_rng.binomial(size=x.shape, n=1, p=(1 - self.corruption_level), dtype=theano.config.floatX) * x)
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
if (self.corruption_level < 1e-05): return x dropped = super(DropoutCorruptor, self)._corrupt(x) return ((1.0 / (1.0 - self.corruption_level)) * dropped)
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
noise = self.s_rng.normal(size=x.shape, avg=0.0, std=self.corruption_level, dtype=theano.config.floatX) return (noise + x)
'.. todo:: WRITEME'
def corruption_free_energy(self, corrupted_X, X):
axis = range(1, len(X.type.broadcastable)) rval = (T.sum(T.sqr((corrupted_X - X)), axis=axis) / (2.0 * (self.corruption_level ** 2.0))) assert (len(rval.type.broadcastable) == 1) return rval
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
a = self.s_rng.binomial(size=x.shape, p=(1 - self.corruption_level), dtype=theano.config.floatX) b = self.s_rng.binomial(size=x.shape, p=0.5, dtype=theano.config.floatX) c = (T.eq(a, 0) * b) return ((x * a) + c)
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
num_examples = x.shape[0] num_classes = x.shape[1] keep_mask = T.addbroadcast(self.s_rng.binomial(size=(num_examples, 1), p=(1 - self.corruption_level), dtype='int8'), 1) pvals = T.alloc((1.0 / num_classes), num_classes) one_hot = self.s_rng.multinomial(size=(num_examples,), pvals=pvals) return ...
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
noise = self.s_rng.normal(size=x.shape, avg=0.0, std=self.corruption_level, dtype=theano.config.floatX) return rescaled_softmax((x + noise))
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
return self.s_rng.binomial(size=x.shape, p=x, dtype=theano.config.floatX)
'Treats each row in matrix as a multinomial trial. Parameters x : tensor_like x must be a matrix where all elements are non-negative (with at least one non-zero element) Returns y : tensor_like y will have the same shape as x. Each row in y will be a one hot vector, and can be viewed as the outcome of the multinomial t...
def _corrupt(self, x):
normalized = (x / x.sum(axis=1, keepdims=True)) return self.s_rng.multinomial(pvals=normalized, dtype=theano.config.floatX)
'Corrupts a single tensor_like object. Parameters x : tensor_like Theano symbolic representing a (mini)batch of inputs to be corrupted, with the first dimension indexing training examples and the second indexing data dimensions. Returns corrupted : tensor_like Theano symbolic representing the corresponding corrupted in...
def _corrupt(self, x):
result = x for c in reversed(self._corruptors): result = c(result) return result
'.. todo:: WRITEME properly Parameters X : WRITEME Must contain only examples that lie on the hypersphere'
def free_energy(self, X):
return T.zeros_like(X[:, 0])
'.. todo:: WRITEME'
def log_prob(self, X):
return ((- self.free_energy(X)) - self.logZ)
'.. todo:: WRITEME'
def random_design_matrix(self, m):
Z = self.s_rng.normal(size=(m, self.dim), avg=0.0, std=1.0, dtype=config.floatX) Z.name = 'UH.rdm.Z' sq_norm_Z = T.sum(T.sqr(Z), axis=1) sq_norm_Z.name = 'UH.rdm.sq_norm_Z' eps = 1e-06 mask = (sq_norm_Z < eps) mask.name = 'UH.rdm.mask' Z = ((Z.T * (1.0 - mask)) + mask).T Z.name = 'UH...
'.. todo:: WRITEME'
def sample_integer(self, m):
return N.nonzero(self.rng.multinomial(pvals=self.pi, n=1, size=(m,)))[1]
'.. todo:: WRITEME'
def free_energy(self, X):
return (0.5 * T.sum(T.dot((X - self.mu), T.dot(self.sigma_inv, T.transpose((X - self.mu))))))
'.. todo:: WRITEME'
def log_prob(self, X):
return ((- self.free_energy(X)) - self.logZ)
'.. todo:: WRITEME'
def random_design_matrix(self, m):
Z = self.s_rng.normal(size=(m, self.mu.shape[0]), avg=0.0, std=1.0, dtype=config.floatX) return (self.mu + T.dot(Z, self.L.T))
'.. todo:: WRITEME properly Parameters X : WRITEME A theano variable containing a design matrix of observations of the random vector to condition on.'
def random_design_matrix(self, X):
Z = self.s_rng.normal(size=X.shape, avg=X, std=(1.0 / T.sqrt(self.beta)), dtype=config.floatX) return Z
'.. todo:: WRITEME properly A property of conditional distributions P(Y|X) Return true if P(y|x) = P(x|y) for all x,y'
def is_symmetric(self):
return True
'Evaluates the log likelihood of a set of datapoints with respect to the probability distribution. Parameters x : numpy matrix The set of points for which you want to evaluate the log likelihood.'
def get_ll(self, x, batch_size=10):
inds = range(x.shape[0]) n_batches = int(numpy.ceil((float(len(inds)) / batch_size))) lls = [] for i in range(n_batches): lls.extend(self.lpdf(x[inds[i::n_batches]])) return numpy.array(lls).mean()
'.. todo:: WRITEME * What does this function do? * How should inputs be formatted? is it a single tensor, a list of tensors, a tuple of tensors?'
def __call__(self, inputs):
raise NotImplementedError(((str(type(self)) + 'does not implement ') + 'Block.__call__'))
'Returns a compiled theano function to compute a representation Parameters name : string, optional name of the function'
def function(self, name=None):
inputs = tensor.matrix() if self.cpu_only: return theano.function([inputs], self(inputs), name=name, mode=get_default_mode().excluding('gpu')) else: return theano.function([inputs], self(inputs), name=name)
'.. todo:: WRITEME'
def perform(self, X):
if (self.fn is None): self.fn = self.function('perform') return self.fn(X)
'.. todo:: WRITEME'
def inverse(self):
raise NotImplementedError()
'.. todo:: WRITEME'
def set_input_space(self, space):
raise NotImplementedError(('%s does not implement set_input_space yet' % str(type(self))))
'.. todo:: WRITEME'
def get_input_space(self):
raise NotImplementedError(('%s does not implement get_input_space yet' % str(type(self))))
'.. todo:: WRITEME'
def get_output_space(self):
raise NotImplementedError(('%s does not implement get_output_space yet' % str(type(self))))
'.. todo:: WRITEME'
def layers(self):
return list(self._layers)
'.. todo:: WRITEME'
def __len__(self):
return len(self._layers)
'Return the output representation of all layers, including the inputs. Parameters inputs : tensor_like or list of tensor_likes Theano symbolic (or list thereof) representing the input minibatch(es) to be encoded. Assumed to be 2-tensors, with the first dimension indexing training examples and the second indexing data d...
def __call__(self, inputs):
repr = [inputs] for layer in self._layers: outputs = layer(repr[(-1)]) repr.append(outputs) return repr
'Compile a function computing representations on given layers. Parameters name : string, optional name of the function repr_index : int, optional Index of the hidden representation to return. 0 means the input, -1 the last output. sparse_input : bool, optional WRITEME Returns WRITEME'
def function(self, name=None, repr_index=(-1), sparse_input=False):
if sparse_input: inputs = SparseType('csr', dtype=theano.config.floatX)() else: inputs = tensor.matrix() return theano.function([inputs], outputs=self(inputs)[repr_index], name=name)
'Compile a function concatenating representations on given layers. Parameters name : string, optional name of the function start_index : int, optional Index of the hidden representation to start the concatenation. 0 means the input, -1 the last output. end_index : int, optional Index of the hidden representation from w...
def concat(self, name=None, start_index=(-1), end_index=None):
inputs = tensor.matrix() return theano.function([inputs], outputs=tensor.concatenate(self(inputs)[start_index:end_index]), name=name)
'Add a new layer on top of the last one Parameters layer : WRITEME'
def append(self, layer):
self._layers.append(layer) if (self._params is not None): self._params.update(layer._params)
'.. todo:: WRITEME'
def get_input_space(self):
return self._layers[0].get_input_space()
'.. todo:: WRITEME'
def get_output_space(self):
return self._layers[(-1)].get_output_space()
'.. todo:: WRITEME'
def set_input_space(self, space):
for layer in self._layers: layer.set_input_space(space) space = layer.get_output_space()
'.. 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, top_down):
images = as_cuda_ndarray_variable(images) top_down = as_cuda_ndarray_variable(top_down) assert (images.ndim == 4) assert (top_down.ndim == 4) channels_broadcastable = images.type.broadcastable[0] batch_broadcastable = images.type.broadcastable[3] rows_broadcastable = False cols_broadcast...
'.. todo:: WRITEME'
def c_code(self, node, name, inputs, outputs, sub):
(images, top_down) = inputs (ptargets, htargets) = outputs fail = sub['fail'] num_braces = 0 if self.copy_non_contiguous: raise UnimplementedError() else: basic_setup = '#define PROBMAXPOOL_COPY_NON_CONTIGUOUS 0\n' setup_nv_images = (self._argument_contiguity_check('ima...
'.. todo:: WRITEME'
def grad(self, inp, grads):
(x, top_down) = inp (p, h) = self(x, top_down) (gp, gh) = grads gp_iszero = 0.0 gh_iszero = 0.0 if isinstance(gp.type, theano.gradient.DisconnectedType): gp = tensor.zeros_like(p) gp_iszero = 1.0 if isinstance(gh.type, theano.gradient.DisconnectedType): gh = tensor.ze...
'.. todo:: WRITEME'
def make_thunk(self, *args, **kwargs):
if (not convnet_available()): raise RuntimeError('Could not compile cuda_convnet') return super(ProbMaxPool, 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, 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, p, h, gp, gh, gp_iszero, gh_iszero):
p = as_cuda_ndarray_variable(p) h = as_cuda_ndarray_variable(h) gp = as_cuda_ndarray_variable(gp) gh = as_cuda_ndarray_variable(gh) assert (p.ndim == 4) assert (h.ndim == 4) assert (gp.ndim == 4) assert (gh.ndim == 4) try: nb_channel = int(get_scalar_constant_value(h.shape[0]...
'.. todo:: WRITEME'
def c_code(self, node, name, inputs, outputs, sub):
(p, h, gp, gh, gp_iszero, gh_iszero) = inputs (targets_z, targets_t) = outputs fail = sub['fail'] num_braces = 0 if self.copy_non_contiguous: raise UnimplementedError() else: basic_setup = '#define PROBMAXPOOLGRAD_COPY_NON_CONTIGUOUS 0\n' setup_nv_h = (self._argument_co...
'.. 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(ProbMaxPoolGrad, self).make_thunk(node, storage_map, compute_map, no_recycling)
'.. todo:: WRITEME'
def make_node(self, images, filters):
if (not isinstance(images.type, CudaNdarrayType)): raise TypeError(('FilterActs: expected images.type to be CudaNdarrayType, got ' + str(images.type))) if (not isinstance(filters.type, CudaNdarrayType)): raise TypeError(('FilterActs: expected filters.type to be ...
'Useful with the hack in profilemode to print the MFlops'
def flops(self, inputs, outputs):
(images, kerns) = inputs (out,) = outputs assert (images[0] == kerns[0]) flops = ((kerns[1] * kerns[2]) * 2) flops *= (out[1] * out[2]) flops *= ((images[0] * kerns[3]) * images[3]) return flops
'.. todo:: WRITEME'
def c_code(self, node, name, inputs, outputs, sub):
(images, filters) = inputs (targets,) = outputs fail = sub['fail'] basic_setup = '\n #define scaleTargets 0\n #define scaleOutput 1\n ' if self.dense_connectivity: basic_setup += '\n ...
'.. todo:: WRITEME'
def c_code_cache_version(self):
return (10,)
'.. todo:: WRITEME'
def R_op(self, inputs, evals):
(images, filters) = inputs (images_ev, filters_ev) = evals if ('Cuda' not in str(type(images))): raise TypeError('inputs must be cuda') if ('Cuda' not in str(type(filters))): raise TypeError('filters must be cuda') if (filters_ev is not None): sol = self(ima...
'.. todo:: WRITEME'
def grad(self, inputs, dout):
(images, filters) = inputs if ('Cuda' not in str(type(images))): raise TypeError('inputs must be cuda') if ('Cuda' not in str(type(filters))): raise TypeError('filters must be cuda') (dout,) = dout dout = gpu_contiguous(dout) if ('Cuda' not in str(type(dout))): ...
'.. todo:: WRITEME'
def __hash__(self):
return hash((self._size_f, self._add_scale, self._pow_scale, self._blocked))
'.. todo:: WRITEME'
def __eq__(self, other):
return ((type(self) == type(other)) and (hash(self) == hash(other)))
'.. todo:: WRITEME'
def make_node(self, images):
if (not isinstance(images.type, CudaNdarrayType)): raise TypeError(('CrossMapNorm: expected images.type to be CudaNdarrayType, got ' + str(images.type))) assert (images.ndim == 4) targets_broadcastable = images.type.broadcastable targets_type = CudaNdarrayType(broadcastable=...
'.. todo:: WRITEME'
def c_code(self, node, name, inputs, outputs, sub):
(images,) = inputs (targets, denoms) = 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') class_name = self.__class__.__name__ class_name_upper = class_name.upper...
'.. todo:: WRITEME'
def grad(self, inputs, dout):
(images,) = inputs (acts, denoms) = self(images) (dout, _) = dout dout = as_cuda_ndarray_variable(dout) dout = gpu_contiguous(dout) grad_op = CrossMapNormUndo(self._size_f, self._add_scale, self._pow_scale, self._blocked, inplace=False) return [grad_op(images, acts, denoms, dout)[0]]
'.. todo:: WRITEME'
def __str__(self):
return (self.__class__.__name__ + ('[size_f=%d,add_scale=%f,pow_scale=%f,blocked=%s]' % (self._size_f, self._add_scale, self._pow_scale, self._blocked)))
'.. todo:: WRITEME'
def c_code_cache_version(self):
return (6,)
'.. todo:: WRITEME'
def __hash__(self):
super_hash = super(CrossMapNormUndo, self).__hash__() return hash((super_hash, self._inplace))