我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用lasagne.init.Uniform()。
def __init__(self, incomings, num_units, nonlinearity=nonlinearities.sigmoid, W=init.Uniform(), b = init.Constant(0.0), **kwargs): super(MergeDense, self).__init__(incomings=incomings, **kwargs) self.num_units = num_units self.input_shapes = [ inc.output_shape for inc in incomings ] self.weights = [ self.get_weights(W, shape=input_shape, name='W%d' % i) for i, input_shape in enumerate(self.input_shapes) ] self.b = self.add_param(b, (self.num_units,), name="b", regularizable=False) self.nonlinearity = nonlinearity
def __init__(self): super(FlatSpec, self).__init__(testval=init.Uniform(1))
def __init__(self, Period=init.Uniform((10,100)), Shift=init.Uniform( (0., 1000.)), On_End=init.Constant(0.05)): self.Period = Period self.Shift = Shift self.On_End = On_End
def __init__(self, incoming, gamma=init.Uniform([0.95, 1.05]), beta=init.Constant(0.), nonlinearity=nonlinearities.rectify, epsilon=0.001, **kwargs): super(BatchNormalizationLayer, self).__init__(incoming, **kwargs) if nonlinearity is None: self.nonlinearity = nonlinearities.identity else: self.nonlinearity = nonlinearity self.num_units = int(numpy.prod(self.input_shape[1:])) self.gamma = self.add_param(gamma, (self.num_units,), name="BatchNormalizationLayer:gamma", regularizable=True, gamma=True, trainable=True) self.beta = self.add_param(beta, (self.num_units,), name="BatchNormalizationLayer:beta", regularizable=False) self.epsilon = epsilon self.mean_inference = theano.shared( numpy.zeros((1, self.num_units), dtype=theano.config.floatX), borrow=True, broadcastable=(True, False)) self.mean_inference.name = "shared:mean" self.variance_inference = theano.shared( numpy.zeros((1, self.num_units), dtype=theano.config.floatX), borrow=True, broadcastable=(True, False)) self.variance_inference.name = "shared:variance"
def __init__( self, env_spec, hidden_sizes=(32, 32), hidden_nonlinearity=NL.rectify, hidden_W_init=LI.HeUniform(), hidden_b_init=LI.Constant(0.), output_nonlinearity=NL.tanh, output_W_init=LI.Uniform(-3e-3, 3e-3), output_b_init=LI.Uniform(-3e-3, 3e-3), bn=False): Serializable.quick_init(self, locals()) l_obs = L.InputLayer(shape=(None, env_spec.observation_space.flat_dim)) l_hidden = l_obs if bn: l_hidden = batch_norm(l_hidden) for idx, size in enumerate(hidden_sizes): l_hidden = L.DenseLayer( l_hidden, num_units=size, W=hidden_W_init, b=hidden_b_init, nonlinearity=hidden_nonlinearity, name="h%d" % idx ) if bn: l_hidden = batch_norm(l_hidden) l_output = L.DenseLayer( l_hidden, num_units=env_spec.action_space.flat_dim, W=output_W_init, b=output_b_init, nonlinearity=output_nonlinearity, name="output" ) # Note the deterministic=True argument. It makes sure that when getting # actions from single observations, we do not update params in the # batch normalization layers action_var = L.get_output(l_output, deterministic=True) self._output_layer = l_output self._f_actions = ext.compile_function([l_obs.input_var], action_var) super(DeterministicMLPPolicy, self).__init__(env_spec) LasagnePowered.__init__(self, [l_output])
def __init__(self, incoming, num_units, W_in_to_hid=init.Uniform(), W_hid_to_hid=init.Uniform(), b=init.Constant(0.), nonlinearity=nonlinearities.rectify, hid_init=init.Constant(0.), backwards=False, learn_init=False, gradient_steps=-1, grad_clipping=0, unroll_scan=False, precompute_input=True, mask_input=None, only_return_final=False, p=0., **kwargs): if isinstance(incoming, tuple): input_shape = incoming else: input_shape = incoming.output_shape # Retrieve the supplied name, if it exists; otherwise use '' if 'name' in kwargs: basename = kwargs['name'] + '.' # Create a separate version of kwargs for the contained layers # which does not include 'name' layer_kwargs = dict((key, arg) for key, arg in kwargs.items() if key != 'name') else: basename = '' layer_kwargs = kwargs # We will be passing the input at each time step to the dense layer, # so we need to remove the second dimension (the time dimension) in_to_hid = DenseLayer(InputLayer((None,) + input_shape[2:]), num_units, W=W_in_to_hid, b=b, nonlinearity=None, name=basename + 'input_to_hidden', **layer_kwargs) # The hidden-to-hidden layer expects its inputs to have num_units # features because it recycles the previous hidden state hid_to_hid = DenseLayer(InputLayer((None, num_units)), num_units, W=W_hid_to_hid, b=None, nonlinearity=None, name=basename + 'hidden_to_hidden', **layer_kwargs) # Make child layer parameters intuitively accessible self.W_in_to_hid = in_to_hid.W self.W_hid_to_hid = hid_to_hid.W self.b = in_to_hid.b # Just use the CustomRecurrentLayer with the DenseLayers we created super(RecurrentLayer, self).__init__( incoming, in_to_hid, hid_to_hid, nonlinearity=nonlinearity, hid_init=hid_init, backwards=backwards, learn_init=learn_init, gradient_steps=gradient_steps, grad_clipping=grad_clipping, unroll_scan=unroll_scan, precompute_input=precompute_input, mask_input=mask_input, only_return_final=only_return_final, p=p, **kwargs)