本文整理汇总了Python中pylearn2.utils.rng.make_theano_rng函数的典型用法代码示例。如果您正苦于以下问题:Python make_theano_rng函数的具体用法?Python make_theano_rng怎么用?Python make_theano_rng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_theano_rng函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, theano_rng = None, seed=None, input_space=None):
super(SampleBernoulli, self).__init__()
assert theano_rng is None or seed is None
theano_rng = make_theano_rng(theano_rng if theano_rng is not None else seed,
2012+11+22, which_method='binomial')
self.__dict__.update(locals())
del self.self
示例2: get_monitoring_channels
def get_monitoring_channels(self, data):
"""
.. todo::
WRITEME
"""
V = data
theano_rng = make_theano_rng(None, 42, which_method="binomial")
#TODO: re-enable this in the case where self.transformer
#is a matrix multiply
#norms = theano_norms(self.weights)
H = self.mean_h_given_v(V)
h = H.mean(axis=0)
return { 'bias_hid_min' : T.min(self.bias_hid),
'bias_hid_mean' : T.mean(self.bias_hid),
'bias_hid_max' : T.max(self.bias_hid),
'bias_vis_min' : T.min(self.bias_vis),
'bias_vis_mean' : T.mean(self.bias_vis),
'bias_vis_max': T.max(self.bias_vis),
'h_min' : T.min(h),
'h_mean': T.mean(h),
'h_max' : T.max(h),
#'W_min' : T.min(self.weights),
#'W_max' : T.max(self.weights),
#'W_norms_min' : T.min(norms),
#'W_norms_max' : T.max(norms),
#'W_norms_mean' : T.mean(norms),
'reconstruction_error' : self.reconstruction_error(V, theano_rng) }
示例3: __init__
def __init__(self, sigma, mu, seed=42):
"""
.. todo::
WRITEME properly
Parameters
-----------
sigma: a numpy ndarray of shape (n,n)
mu: a numpy ndarray of shape (n,)
seed: the seed for the theano random number generator used to sample from this distribution"""
self.sigma = sigma
self.mu = mu
if not (len(mu.shape) == 1):
raise Exception('mu has shape ' + str(mu.shape) +
' (it should be a vector)')
self.sigma_inv = solve(self.sigma, N.identity(mu.shape[0]),
sym_pos=True)
self.L = cholesky(self.sigma)
self.s_rng = make_theano_rng(seed, which_method='normal')
#Compute logZ
#log Z = log 1/( (2pi)^(-k/2) |sigma|^-1/2 )
# = log 1 - log (2pi^)(-k/2) |sigma|^-1/2
# = 0 - log (2pi)^(-k/2) - log |sigma|^-1/2
# = (k/2) * log(2pi) + (1/2) * log |sigma|
k = float(self.mu.shape[0])
self.logZ = 0.5 * (k * N.log(2. * N.pi) + N.log(det(sigma)))
示例4: __init__
def __init__(self, num_chains, num_gibbs_steps, supervised=False,
toronto_neg=False, theano_rng=None):
self.__dict__.update(locals())
del self.self
self.theano_rng = make_theano_rng(theano_rng, 2012+10+14,
which_method="binomial")
assert supervised in [True, False]
示例5: __init__
def __init__(self, init_beta, nvis):
self.__dict__.update(locals())
del self.self
self.beta = sharedX(np.ones((nvis,))*init_beta)
assert self.beta.ndim == 1
self.s_rng = make_theano_rng(None, 17, which_method='normal')
示例6: __init__
def __init__(self, dim, radius):
self.dim = dim
self.radius = radius
self.s_rng = make_theano_rng(None, 42, which_method='normal')
log_C = ((float(self.dim) / 2.) * N.log(N.pi) -
gammaln(1. + float(self.dim) / 2.))
self.logZ = N.log(self.dim) + log_C + (self.dim - 1) * N.log(radius)
assert not N.isnan(self.logZ)
assert not N.isinf(self.logZ)
示例7: __init__
def __init__(self, layers, batch_size=None, input_space=None,
input_source='features', nvis=None, seed=None,
layer_name=None, **kwargs):
input_source = self.add_mask_source(input_space, input_source)
super(RNN, self).__init__(layers, batch_size, input_space,
input_source, nvis, seed, layer_name,
**kwargs)
self.theano_rng = make_theano_rng(int(self.rng.randint(2 ** 30)),
which_method=["normal", "uniform"])
示例8: __init__
def __init__(self, theano_rng = None, seed=None,
input_space=None, corruption_prob=0.1):
super(RandomizeSNPs, self).__init__()
assert theano_rng is None or seed is None
theano_rng = make_theano_rng(theano_rng if theano_rng is not None else seed,
2012+11+22, which_method='binomial')
self.__dict__.update(locals())
del self.self
self.set_fn()
示例9: __init__
def __init__(self, nvis, nhid, act_enc, act_dec, tied_weights=False, irange=1e-3, rng=9001):
super(Autoencoder, self).__init__()
assert nvis > 0, "Number of visible units must be non-negative"
assert nhid > 0, "Number of hidden units must be positive"
self.input_space = VectorSpace(nvis)
self.output_space = VectorSpace(nhid)
# Save a few parameters needed for resizing
self.nhid = nhid
self.irange = irange
self.tied_weights = tied_weights
self.rng = make_np_rng(rng, which_method="randn")
self._initialize_hidbias()
if nvis > 0:
self._initialize_visbias(nvis)
self._initialize_weights(nvis)
else:
self.visbias = None
self.weights = None
seed = int(self.rng.randint(2 ** 30))
# why a theano rng? should we remove it?
self.s_rng = make_theano_rng(seed, which_method="uniform")
if tied_weights and self.weights is not None:
self.w_prime = self.weights.T
else:
self._initialize_w_prime(nvis)
def _resolve_callable(conf, conf_attr):
"""
.. todo::
WRITEME
"""
if conf[conf_attr] is None or conf[conf_attr] == "linear":
return None
# If it's a callable, use it directly.
if hasattr(conf[conf_attr], "__call__"):
return conf[conf_attr]
elif conf[conf_attr] in globals() and hasattr(globals()[conf[conf_attr]], "__call__"):
return globals()[conf[conf_attr]]
elif hasattr(tensor.nnet, conf[conf_attr]):
return getattr(tensor.nnet, conf[conf_attr])
elif hasattr(tensor, conf[conf_attr]):
return getattr(tensor, conf[conf_attr])
else:
raise ValueError("Couldn't interpret %s value: '%s'" % (conf_attr, conf[conf_attr]))
self.act_enc = _resolve_callable(locals(), "act_enc")
self.act_dec = _resolve_callable(locals(), "act_dec")
self._params = [self.visbias, self.hidbias, self.weights]
if not self.tied_weights:
self._params.append(self.w_prime)
示例10: __init__
def __init__(self, dbm):
"""
.. todo::
WRITEME
"""
super(DBMSampler, self).__init__()
self.theano_rng = make_theano_rng(None, 2012+10+14, which_method="binomial")
self.dbm = dbm
assert len(self.dbm.hidden_layers) == 1
示例11: test_gibbs_step_for_v
def test_gibbs_step_for_v():
# Just tests that gibbs_step_for_v can be called
# without crashing
model = RBM(nvis=2, nhid=3)
theano_rng = make_theano_rng(17, which_method='binomial')
X = T.matrix()
Y = model.gibbs_step_for_v(X, theano_rng)
示例12: test_gibbs_step_for_v
def test_gibbs_step_for_v():
#Just tests that gibbs_step_for_v can be called
#without crashing (protection against refactoring
#damage, aren't interpreted languages great?)
model = RBM(nvis = 2, nhid = 3)
theano_rng = make_theano_rng(17, which_method='binomial')
X = T.matrix()
Y = model.gibbs_step_for_v(X, theano_rng)
示例13: rbm_ais_gibbs_for_v
def rbm_ais_gibbs_for_v(rbmA_params, rbmB_params, beta, v_sample, seed=23098):
"""
.. todo::
WRITEME
Parameters
----------
rbmA_params : list
Parameters of the baserate model (usually infinite temperature). List \
should be of length 3 and contain numpy.ndarrays corresponding to \
model parameters (weights, visbias, hidbias).
rbmB_params : list
Similar to `rbmA_params`, but for model at temperature 1.
beta : theano.shared
Scalar, represents inverse temperature at which we wish to sample from.
v_sample : theano.shared
Matrix of shape (n_runs, nvis), state of current particles.
seed : int
Optional seed parameter for sampling from binomial units.
"""
(weights_a, visbias_a, hidbias_a) = rbmA_params
(weights_b, visbias_b, hidbias_b) = rbmB_params
theano_rng = make_theano_rng(seed, which_method='binomial')
# equation 15 (Salakhutdinov & Murray 2008)
ph_a = nnet.sigmoid((1 - beta) * (tensor.dot(v_sample, weights_a) +
hidbias_a))
ha_sample = theano_rng.binomial(size=(v_sample.shape[0], len(hidbias_a)),
n=1, p=ph_a, dtype=config.floatX)
# equation 16 (Salakhutdinov & Murray 2008)
ph_b = nnet.sigmoid(beta * (tensor.dot(v_sample, weights_b) + hidbias_b))
hb_sample = theano_rng.binomial(size=(v_sample.shape[0], len(hidbias_b)),
n=1, p=ph_b, dtype=config.floatX)
# equation 17 (Salakhutdinov & Murray 2008)
pv_act = (1 - beta) * (tensor.dot(ha_sample, weights_a.T) + visbias_a) + \
beta * (tensor.dot(hb_sample, weights_b.T) + visbias_b)
pv = nnet.sigmoid(pv_act)
new_v_sample = theano_rng.binomial(
size=(v_sample.shape[0], len(visbias_b)),
n=1, p=pv, dtype=config.floatX
)
return new_v_sample
示例14: __init__
def __init__(self, nsteps, seed=42):
"""
Parametes
---------
nsteps: int
number of Markov chain steps for the negative sample
seed: int
seed for the random number generator
"""
super(CDk, self).__init__()
self.nsteps = nsteps
self.rng = make_theano_rng(seed, which_method='binomial')
示例15: test_theano_rng
def test_theano_rng():
"""
Tests that the four possible ways of creating
a theano RNG give the same results with the same seed
"""
rngs = [make_theano_rng(rng_or_seed=42, which_method='uniform'),
make_theano_rng(rng_or_seed=RandomStreams(42),
which_method='uniform'),
make_theano_rng(default_seed=42),
make_theano_rng()]
functions = [theano.function([], rng.uniform(size=(100,)))
for rng in rngs]
random_numbers = functions[0]()
equals = numpy.ones((100,))
for function in functions[1:]:
equal = random_numbers == function()
equals *= equal
assert equals.all()