desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'.. todo:: WRITEME'
def get_weights_topo(self):
if (not isinstance(self.input_space, Conv2DSpace)): raise NotImplementedError() (W,) = self.transformer.get_params() W = W.T W = W.reshape((self.detector_layer_dim, self.input_space.shape[0], self.input_space.shape[1], self.input_space.nchannels)) W = Conv2DSpace.convert(W, self.input_space....
'.. todo:: WRITEME'
def upward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def downward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def get_monitoring_channels(self):
(W,) = self.transformer.get_params() assert (W.ndim == 2) sq_W = T.sqr(W) row_norms = T.sqrt(sq_W.sum(axis=1)) col_norms = T.sqrt(sq_W.sum(axis=0)) return OrderedDict([('row_norms_min', row_norms.min()), ('row_norms_mean', row_norms.mean()), ('row_norms_max', row_norms.max()), ('col_norms_min', ...
'.. todo:: WRITEME'
def get_monitoring_channels_from_state(self, state):
P = state rval = OrderedDict() vars_and_prefixes = [(P, '')] for (var, prefix) in vars_and_prefixes: v_max = var.max(axis=0) v_min = var.min(axis=0) v_mean = var.mean(axis=0) v_range = (v_max - v_min) for (key, val) in [('max_x.max_u', v_max.max()), ('max_x.mean_u...
'.. todo:: WRITEME'
def sample(self, state_below=None, state_above=None, layer_above=None, theano_rng=None):
if (theano_rng is None): raise ValueError((('theano_rng is required; it just defaults to ' + 'None so that it may appear after layer_above ') + '/ state_above in the list.')) if (state_above is not None): msg = layer_above.downward_message...
'.. todo:: WRITEME'
def downward_message(self, downward_state):
rval = self.transformer.lmul_T(downward_state) if self.requires_reformat: rval = self.desired_space.format_as(rval, self.input_space) return rval
'.. todo:: WRITEME'
def init_mf_state(self):
z = (T.alloc(0.0, self.dbm.batch_size, self.dim).astype(self.b.dtype) + self.b.dimshuffle('x', 0)) rval = T.tanh((self.beta * z)) return rval
'.. todo:: WRITEME properly Returns a shared variable containing an actual state (not a mean field state) for this variable.'
def make_state(self, num_examples, numpy_rng):
driver = numpy_rng.uniform(0.0, 1.0, (num_examples, self.dim)) on_prob = sigmoid_numpy(((2.0 * self.beta.get_value()) * self.b.get_value())) sample = ((2.0 * (driver < on_prob)) - 1.0) rval = sharedX(sample, name='v_sample_shared') return rval
'.. todo:: WRITEME'
def make_symbolic_state(self, num_examples, theano_rng):
mean = T.nnet.sigmoid(((2.0 * self.beta) * self.b)) rval = theano_rng.binomial(size=(num_examples, self.nvis), p=mean) rval = ((2.0 * rval) - 1.0) return rval
'.. todo:: WRITEME'
def expected_energy_term(self, state, average, state_below, average_below):
self.input_space.validate(state_below) if self.requires_reformat: if (not isinstance(state_below, tuple)): for sb in get_debug_values(state_below): if (sb.shape[0] != self.dbm.batch_size): raise ValueError(('self.dbm.batch_size is %d but got ...
'.. todo:: WRITEME properly Used to implement TorontoSparsity. Unclear exactly what properties of it are important or how to implement it for other layers. Properties it must have: output is same kind of data structure (ie, tuple of theano 2-tensors) as mf_update Properties it probably should have for other layer types...
def linear_feed_forward_approximation(self, state_below):
z = (self.beta * (self.transformer.lmul(state_below) + self.b)) if (self.pool_size != 1): raise NotImplementedError() return (z, z)
'.. todo:: WRITEME'
def mf_update(self, state_below, state_above, layer_above=None, double_weights=False, iter_name=None):
self.input_space.validate(state_below) if self.requires_reformat: if (not isinstance(state_below, tuple)): for sb in get_debug_values(state_below): if (sb.shape[0] != self.dbm.batch_size): raise ValueError(('self.dbm.batch_size is %d but got ...
'.. todo:: WRITEME'
def finalize_initialization(self):
if (self.sampling_b_stdev is not None): self.noisy_sampling_b = sharedX(np.zeros((self.layer_above.dbm.batch_size, self.nvis))) updates = OrderedDict() updates[self.boltzmann_bias] = self.boltzmann_bias updates[self.layer_above.W] = self.layer_above.W self.enforce_constraints()
'.. todo:: WRITEME'
def _modify_updates(self, updates):
beta = self.beta if (beta in updates): updated_beta = updates[beta] updates[beta] = T.clip(updated_beta, 1.0, 1000.0) if any(((constraint is not None) for constraint in [self.min_ising_b, self.max_ising_b])): bmn = self.min_ising_b if (bmn is None): bmn = (-100000...
'.. todo:: WRITEME'
def resample_bias_noise(self, batch_size_changed=False):
if batch_size_changed: self.resample_fn = None if (self.resample_fn is None): updates = OrderedDict() if (self.sampling_b_stdev is not None): self.noisy_sampling_b = sharedX(np.zeros((self.dbm.batch_size, self.nvis))) if (self.noisy_sampling_b is not None): ...
'.. todo:: WRITEME'
def get_biases(self):
warnings.warn(('BoltzmannIsingVisible.get_biases returns the ' + 'BOLTZMANN biases, is that what we want?')) return self.boltzmann_bias.get_value()
'.. todo:: WRITEME'
def set_biases(self, biases, recenter=False):
assert False
'.. todo:: WRITEME'
def ising_bias(self, for_sampling=False):
if (for_sampling and (self.layer_above.sampling_b_stdev is not None)): return self.noisy_sampling_b return ((0.5 * self.boltzmann_bias) + (0.25 * self.layer_above.W.sum(axis=1)))
'.. todo:: WRITEME'
def ising_bias_numpy(self):
return ((0.5 * self.boltzmann_bias.get_value()) + (0.25 * self.layer_above.W.get_value().sum(axis=1)))
'.. todo:: WRITEME'
def upward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def get_params(self):
rval = [self.boltzmann_bias] if self.learn_beta: rval.append(self.beta) return rval
'.. todo:: WRITEME'
def sample(self, state_below=None, state_above=None, layer_above=None, theano_rng=None):
assert (state_below is None) msg = layer_above.downward_message(state_above, for_sampling=True) bias = self.ising_bias(for_sampling=True) z = (msg + bias) phi = T.nnet.sigmoid(((2.0 * self.beta) * z)) rval = theano_rng.binomial(size=phi.shape, p=phi, dtype=phi.dtype, n=1) return ((rval * 2.0...
'.. todo:: WRITEME'
def make_state(self, num_examples, numpy_rng):
driver = numpy_rng.uniform(0.0, 1.0, (num_examples, self.nvis)) on_prob = sigmoid_numpy(((2.0 * self.beta.get_value()) * self.ising_bias_numpy())) sample = ((2.0 * (driver < on_prob)) - 1.0) rval = sharedX(sample, name='v_sample_shared') return rval
'.. todo:: WRITEME'
def make_symbolic_state(self, num_examples, theano_rng):
mean = T.nnet.sigmoid(((2.0 * self.beta) * self.ising_bias())) rval = theano_rng.binomial(size=(num_examples, self.nvis), p=mean) rval = ((2.0 * rval) - 1.0) return rval
'.. todo:: WRITEME'
def mf_update(self, state_above, layer_above):
msg = layer_above.downward_message(state_above, for_sampling=True) bias = self.ising_bias(for_sampling=True) z = (msg + bias) rval = T.tanh((self.beta * z)) return rval
'.. todo:: WRITEME'
def expected_energy_term(self, state, average, state_below=None, average_below=None):
assert (state_below is None) assert (average_below is None) assert (average in [True, False]) self.space.validate(state) rval = (- (self.beta * T.dot(state, self.ising_bias()))) assert (rval.ndim == 1) return rval
'.. todo:: WRITEME'
def get_monitoring_channels(self):
rval = OrderedDict() ising_b = self.ising_bias() rval['ising_b_min'] = ising_b.min() rval['ising_b_max'] = ising_b.max() rval['beta'] = self.beta if hasattr(self, 'noisy_sampling_b'): rval['noisy_sampling_b_min'] = self.noisy_sampling_b.min() rval['noisy_sampling_b_max'] = self.n...
'.. todo:: WRITEME'
def get_lr_scalers(self):
if (not hasattr(self, 'W_lr_scale')): self.W_lr_scale = None if (not hasattr(self, 'b_lr_scale')): self.b_lr_scale = None if (not hasattr(self, 'beta_lr_scale')): self.beta_lr_scale = None rval = OrderedDict() if (self.W_lr_scale is not None): W = self.W rval[...
'.. todo:: WRITEME properly Note: this resets parameters!'
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) self.output_spac...
'.. todo:: WRITEME'
def finalize_initialization(self):
if (self.sampling_b_stdev is not None): self.noisy_sampling_b = sharedX(np.zeros((self.dbm.batch_size, self.dim))) if (self.sampling_W_stdev is not None): self.noisy_sampling_W = sharedX(np.zeros((self.input_dim, self.dim)), 'noisy_sampling_W') updates = OrderedDict() updates[self.boltzm...
'.. todo:: WRITEME'
def _modify_updates(self, updates):
beta = self.beta if (beta in updates): updated_beta = updates[beta] updates[beta] = T.clip(updated_beta, 1.0, 1000.0) if any(((constraint is not None) for constraint in [self.min_ising_b, self.max_ising_b, self.min_ising_W, self.max_ising_W])): bmn = self.min_ising_b if (bmn ...
'.. todo:: WRITEME'
def resample_bias_noise(self, batch_size_changed=False):
if batch_size_changed: self.resample_fn = None if (self.resample_fn is None): updates = OrderedDict() if (self.sampling_b_stdev is not None): self.noisy_sampling_b = sharedX(np.zeros((self.dbm.batch_size, self.dim))) if (self.noisy_sampling_b is not None): ...
'.. todo:: WRITEME'
def get_total_state_space(self):
return VectorSpace(self.dim)
'.. todo:: WRITEME'
def get_params(self):
assert (self.boltzmann_b.name is not None) W = self.W assert (W.name is not None) rval = [W] assert (not isinstance(rval, set)) rval = list(rval) assert (self.boltzmann_b not in rval) rval.append(self.boltzmann_b) if self.learn_beta: rval.append(self.beta) return rval
'.. todo:: WRITEME'
def ising_weights(self, for_sampling=False):
if (not hasattr(self, 'sampling_W_stdev')): self.sampling_W_stdev = None if (for_sampling and (self.sampling_W_stdev is not None)): return self.noisy_sampling_W return (0.25 * self.W)
'.. todo:: WRITEME'
def ising_b(self, for_sampling=False):
if (not hasattr(self, 'sampling_b_stdev')): self.sampling_b_stdev = None if (for_sampling and (self.sampling_b_stdev is not None)): return self.noisy_sampling_b elif (self.layer_above is not None): return (((0.5 * self.boltzmann_b) + (0.25 * self.W.sum(axis=0))) + (0.25 * self.layer_...
'.. todo:: WRITEME'
def ising_b_numpy(self):
if (self.layer_above is not None): return (((0.5 * self.boltzmann_b.get_value()) + (0.25 * self.W.get_value().sum(axis=0))) + (0.25 * self.layer_above.W.get_value().sum(axis=1))) else: return ((0.5 * self.boltzmann_b.get_value()) + (0.25 * self.W.get_value().sum(axis=0)))
'.. todo:: WRITEME'
def get_weight_decay(self, coeff):
if isinstance(coeff, str): coeff = float(coeff) assert (isinstance(coeff, float) or hasattr(coeff, 'dtype')) W = self.W return (coeff * T.sqr(W).sum())
'.. todo:: WRITEME'
def get_weights(self):
warnings.warn(('BoltzmannIsingHidden.get_weights returns the ' + 'BOLTZMANN weights, is that what we want?')) W = self.W return W.get_value()
'.. todo:: WRITEME'
def set_weights(self, weights):
warnings.warn(('BoltzmannIsingHidden.set_weights sets the BOLTZMANN ' + 'weights, is that what we want?')) W = self.W W.set_value(weights)
'.. todo:: WRITEME'
def set_biases(self, biases, recenter=False):
self.boltzmann_b.set_value(biases) assert (not recenter)
'.. todo:: WRITEME'
def get_biases(self):
warnings.warn(('BoltzmannIsingHidden.get_biases returns the ' + 'BOLTZMANN biases, is that what we want?')) return self.boltzmann_b.get_value()
'.. todo:: WRITEME'
def get_weights_format(self):
return ('v', 'h')
'.. todo:: WRITEME'
def get_weights_topo(self):
warnings.warn(('BoltzmannIsingHidden.get_weights_topo returns the ' + 'BOLTZMANN weights, is that what we want?')) if (not isinstance(self.input_space, Conv2DSpace)): raise NotImplementedError() W = self.W W = W.T W = W.reshape((self.detector_layer_dim, self.input_...
'.. todo:: WRITEME'
def upward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def downward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def get_monitoring_channels(self):
W = self.W assert (W.ndim == 2) sq_W = T.sqr(W) row_norms = T.sqrt(sq_W.sum(axis=1)) col_norms = T.sqrt(sq_W.sum(axis=0)) rval = OrderedDict([('boltzmann_row_norms_min', row_norms.min()), ('boltzmann_row_norms_mean', row_norms.mean()), ('boltzmann_row_norms_max', row_norms.max()), ('boltzmann_co...
'.. todo:: WRITEME'
def get_monitoring_channels_from_state(self, state):
P = state rval = OrderedDict() vars_and_prefixes = [(P, '')] for (var, prefix) in vars_and_prefixes: v_max = var.max(axis=0) v_min = var.min(axis=0) v_mean = var.mean(axis=0) v_range = (v_max - v_min) for (key, val) in [('max_x.max_u', v_max.max()), ('max_x.mean_u...
'.. todo:: WRITEME'
def sample(self, state_below=None, state_above=None, layer_above=None, theano_rng=None):
if (theano_rng is None): raise ValueError((('theano_rng is required; it just defaults to ' + 'None so that it may appear after layer_above ') + '/ state_above in the list.')) if (state_above is not None): msg = layer_above.downward_message...
'.. todo:: WRITEME'
def downward_message(self, downward_state, for_sampling=False):
rval = T.dot(downward_state, self.ising_weights(for_sampling=for_sampling).T) if self.requires_reformat: rval = self.desired_space.format_as(rval, self.input_space) return rval
'.. todo:: WRITEME'
def init_mf_state(self):
z = (T.alloc(0.0, self.dbm.batch_size, self.dim).astype(self.boltzmann_b.dtype) + self.ising_b().dimshuffle('x', 0)) rval = T.tanh((self.beta * z)) return rval
'.. todo:: WRITEME properly Returns a shared variable containing an actual state (not a mean field state) for this variable.'
def make_state(self, num_examples, numpy_rng):
driver = numpy_rng.uniform(0.0, 1.0, (num_examples, self.dim)) on_prob = sigmoid_numpy(((2.0 * self.beta.get_value()) * self.ising_b_numpy())) sample = ((2.0 * (driver < on_prob)) - 1.0) rval = sharedX(sample, name='v_sample_shared') return rval
'.. todo:: WRITEME'
def make_symbolic_state(self, num_examples, theano_rng):
mean = T.nnet.sigmoid(((2.0 * self.beta) * self.ising_b())) rval = theano_rng.binomial(size=(num_examples, self.dim), p=mean) rval = ((2.0 * rval) - 1.0) return rval
'.. todo:: WRITEME'
def expected_energy_term(self, state, average, state_below, average_below):
self.input_space.validate(state_below) if self.requires_reformat: if (not isinstance(state_below, tuple)): for sb in get_debug_values(state_below): if (sb.shape[0] != self.dbm.batch_size): raise ValueError(('self.dbm.batch_size is %d but got ...
'.. todo:: WRITEME properly Used to implement TorontoSparsity. Unclear exactly what properties of it are important or how to implement it for other layers. Properties it must have: output is same kind of data structure (ie, tuple of theano 2-tensors) as mf_update Properties it probably should have for other layer types...
def linear_feed_forward_approximation(self, state_below):
z = (self.beta * (T.dot(state_below, self.ising_weights()) + self.ising_b())) return z
'.. todo:: WRITEME'
def mf_update(self, state_below, state_above, layer_above=None, double_weights=False, iter_name=None):
self.input_space.validate(state_below) if self.requires_reformat: if (not isinstance(state_below, tuple)): for sb in get_debug_values(state_below): if (sb.shape[0] != self.dbm.batch_size): raise ValueError(('self.dbm.batch_size is %d but got ...
'.. todo:: WRITEME'
def get_l2_act_cost(self, state, target, coeff):
avg = state.mean(axis=0) diff = (avg - target) return (coeff * T.sqr(diff).mean())
'Returns the DBM that this layer belongs to, or None if it has not been assigned to a DBM yet.'
def get_dbm(self):
if hasattr(self, 'dbm'): return self.dbm return None
'Assigns this layer to a DBM. Parameters dbm : WRITEME'
def set_dbm(self, dbm):
assert (self.get_dbm() is None) self.dbm = dbm
'Returns the Space that the layer\'s total state lives in.'
def get_total_state_space(self):
raise NotImplementedError(((str(type(self)) + ' does not implement ') + 'get_total_state_space()'))
'.. todo:: WRITEME'
def get_monitoring_channels(self):
return OrderedDict()
'.. todo:: WRITEME'
def get_monitoring_channels_from_state(self, state):
return OrderedDict()
'Takes total_state and turns it into the state that layer_above should see when computing P( layer_above | this_layer). So far this has two uses: * If this layer consists of a detector sub-layer h that is pooled into a pooling layer p, then total_state = (p,h) but layer_above should only see p. * If the conditional P( ...
def upward_state(self, total_state):
return total_state
'Returns a shared variable containing an actual state (not a mean field state) for this variable. Parameters num_examples : WRITEME numpy_rng : WRITEME Returns WRITEME'
def make_state(self, num_examples, numpy_rng):
raise NotImplementedError(("%s doesn't implement make_state" % type(self)))
'Returns a theano symbolic variable containing an actual state (not a mean field state) for this variable. Parameters num_examples : WRITEME numpy_rng : WRITEME Returns WRITEME'
def make_symbolic_state(self, num_examples, theano_rng):
raise NotImplementedError(("%s doesn't implement make_symbolic_state" % type(self)))
'Returns an expression for samples of this layer\'s state, conditioned on the layers above and below Should be valid as an update to the shared variable returned by self.make_state Parameters state_below : WRITEME Corresponds to layer_below.upward_state(full_state_below), where full_state_below is the same kind of obje...
def sample(self, state_below=None, state_above=None, layer_above=None, theano_rng=None):
if hasattr(self, 'get_sampling_updates'): raise AssertionError((('Looks like ' + str(type(self))) + ' needs to rename get_sampling_updates to sample.')) raise NotImplementedError(("%s doesn't implement sample" % type(self)))
'Returns a term of the expected energy of the entire model. This term should correspond to the expected value of terms of the energy function that: - involve this layer only - if there is a layer below, include terms that involve both this layer and the layer below Do not include terms that involve the layer below only...
def expected_energy_term(self, state, average, state_below, average_below):
raise NotImplementedError((str(type(self)) + ' does not implement expected_energy_term.'))
'Some layers\' initialization depends on layer above being initialized, which is why this method is called after `set_input_space` has been called.'
def finalize_initialization(self):
pass
'Returns the total state of the layer. Returns total_state : member of the input space The total state of the layer.'
def get_total_state_space(self):
return self.get_input_space()
'.. todo:: WRITEME'
def downward_state(self, total_state):
return total_state
'.. todo:: WRITEME'
def get_stdev_rewards(self, state, coeffs):
raise NotImplementedError((str(type(self)) + ' does not implement get_stdev_rewards'))
'.. todo:: WRITEME'
def get_range_rewards(self, state, coeffs):
raise NotImplementedError((str(type(self)) + ' does not implement get_range_rewards'))
'.. todo:: WRITEME'
def get_l1_act_cost(self, state, target, coeff, eps):
raise NotImplementedError((str(type(self)) + ' does not implement get_l1_act_cost'))
'.. todo:: WRITEME'
def get_l2_act_cost(self, state, target, coeff):
raise NotImplementedError((str(type(self)) + ' does not implement get_l2_act_cost'))
'Returns biases : ndarray The numpy value of the biases'
def get_biases(self):
return self.bias.get_value()
'.. todo:: WRITEME'
def set_biases(self, biases, recenter=False):
self.bias.set_value(biases) if recenter: assert self.center self.offset.set_value(sigmoid_numpy(self.bias.get_value()))
'.. todo:: WRITEME'
def upward_state(self, total_state):
if (not hasattr(self, 'center')): self.center = False if self.center: rval = (total_state - self.offset) else: rval = total_state if (not hasattr(self, 'copies')): self.copies = 1 return (rval * self.copies)
'.. todo:: WRITEME'
def get_params(self):
return [self.bias]
'.. todo:: WRITEME'
def sample(self, state_below=None, state_above=None, layer_above=None, theano_rng=None):
assert (state_below is None) if (self.copies != 1): raise NotImplementedError() msg = layer_above.downward_message(state_above) bias = self.bias z = (msg + bias) phi = T.nnet.sigmoid(z) rval = theano_rng.binomial(size=phi.shape, p=phi, dtype=phi.dtype, n=1) return rval
'.. todo:: WRITEME'
def mf_update(self, state_above, layer_above):
msg = layer_above.downward_message(state_above) mu = self.bias z = (msg + mu) rval = T.nnet.sigmoid(z) return rval
'.. todo:: WRITEME'
def make_state(self, num_examples, numpy_rng):
if (not hasattr(self, 'copies')): self.copies = 1 if (self.copies != 1): raise NotImplementedError() driver = numpy_rng.uniform(0.0, 1.0, (num_examples, self.nvis)) mean = sigmoid_numpy(self.bias.get_value()) sample = (driver < mean) rval = sharedX(sample, name='v_sample_shared')...
'.. todo:: WRITEME'
def make_symbolic_state(self, num_examples, theano_rng):
if (not hasattr(self, 'copies')): self.copies = 1 if (self.copies != 1): raise NotImplementedError() mean = T.nnet.sigmoid(self.bias) rval = theano_rng.binomial(size=(num_examples, self.nvis), p=mean, dtype=theano.config.floatX) return rval
'.. todo:: WRITEME'
def expected_energy_term(self, state, average, state_below=None, average_below=None):
if self.center: state = (state - self.offset) assert (state_below is None) assert (average_below is None) assert (average in [True, False]) self.space.validate(state) rval = (- T.dot(state, self.bias)) assert (rval.ndim == 1) return (rval * self.copies)
'.. todo:: WRITEME'
def init_inpainting_state(self, V, drop_mask, noise=False, return_unmasked=False):
assert ((drop_mask is None) or (drop_mask.ndim > 1)) unmasked = T.nnet.sigmoid(self.bias.dimshuffle('x', 0)) assert (unmasked.ndim == 2) assert hasattr(unmasked.owner.op, 'scalar_op') if (drop_mask is not None): masked_mean = (unmasked * drop_mask) else: masked_mean = unmasked ...
'.. todo:: WRITEME'
def inpaint_update(self, state_above, layer_above, drop_mask=None, V=None, return_unmasked=False):
msg = layer_above.downward_message(state_above) mu = self.bias z = (msg + mu) z.name = 'inpainting_z_[unknown_iter]' unmasked = T.nnet.sigmoid(z) if (drop_mask is not None): rval = ((drop_mask * unmasked) + ((1 - drop_mask) * V)) else: rval = unmasked rval.name = 'inpaint...
'.. todo:: WRITEME'
def recons_cost(self, V, V_hat_unmasked, drop_mask=None, use_sum=False):
if use_sum: raise NotImplementedError() V_hat = V_hat_unmasked assert hasattr(V_hat, 'owner') owner = V_hat.owner assert (owner is not None) op = owner.op block_grad = False if is_block_gradient(op): assert isinstance(op.scalar_op, theano.scalar.Identity) block_gr...
'.. todo:: WRITEME'
def get_lr_scalers(self):
if (not hasattr(self, 'W_lr_scale')): self.W_lr_scale = None if (not hasattr(self, 'b_lr_scale')): self.b_lr_scale = None rval = OrderedDict() if (self.W_lr_scale is not None): (W,) = self.transformer.get_params() rval[W] = self.W_lr_scale if (self.b_lr_scale is not N...
'.. todo:: WRITEME Notes This resets parameters!'
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 ((self.d...
'.. todo:: WRITEME'
def get_total_state_space(self):
return CompositeSpace((self.output_space, self.h_space))
'.. todo:: WRITEME'
def get_params(self):
assert (self.b.name is not None) (W,) = self.transformer.get_params() assert (W.name is not None) rval = self.transformer.get_params() assert (not isinstance(rval, set)) rval = list(rval) assert (self.b not in rval) rval.append(self.b) return rval
'.. todo:: WRITEME'
def get_weight_decay(self, coeff):
if isinstance(coeff, str): coeff = float(coeff) assert (isinstance(coeff, float) or hasattr(coeff, 'dtype')) (W,) = self.transformer.get_params() return (coeff * T.sqr(W).sum())
'.. todo:: WRITEME'
def get_weights(self):
if self.requires_reformat: raise NotImplementedError() (W,) = self.transformer.get_params() return W.get_value()
'.. todo:: WRITEME'
def set_weights(self, weights):
(W,) = self.transformer.get_params() W.set_value(weights)
'.. todo:: WRITEME'
def set_biases(self, biases, recenter=False):
self.b.set_value(biases) if recenter: assert self.center if (self.pool_size != 1): raise NotImplementedError() self.offset.set_value(sigmoid_numpy(self.b.get_value()))
'.. todo:: WRITEME'
def get_biases(self):
return self.b.get_value()
'.. todo:: WRITEME'
def get_weights_format(self):
return ('v', 'h')
'.. todo:: WRITEME'
def get_weights_view_shape(self):
total = self.detector_layer_dim cols = self.pool_size if (cols == 1): raise NotImplementedError() rows = (total / cols) return (rows, cols)
'.. todo:: WRITEME'
def get_weights_topo(self):
if (not isinstance(self.input_space, Conv2DSpace)): raise NotImplementedError() (W,) = self.transformer.get_params() W = W.T W = W.reshape((self.detector_layer_dim, self.input_space.shape[0], self.input_space.shape[1], self.input_space.num_channels)) W = Conv2DSpace.convert(W, self.input_spa...
'.. todo:: WRITEME'
def upward_state(self, total_state):
(p, h) = total_state self.h_space.validate(h) self.output_space.validate(p) if (not hasattr(self, 'center')): self.center = False if self.center: return (p - self.offset) if (not hasattr(self, 'copies')): self.copies = 1 return (p * self.copies)