本文整理汇总了Python中pylearn2.utils.rng.make_theano_rng函数的典型用法代码示例。如果您正苦于以下问题:Python make_theano_rng函数的具体用法?Python make_theano_rng怎么用?Python make_theano_rng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_theano_rng函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:BloodNg,项目名称:pylearn2,代码行数:7,代码来源:sampling.py
示例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) }
开发者ID:fancyspeed,项目名称:pylearn2,代码行数:32,代码来源:rbm.py
示例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)))
开发者ID:SinaHonari,项目名称:pylearn2,代码行数:30,代码来源:mnd.py
示例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]
开发者ID:jbornschein,项目名称:pylearn2,代码行数:7,代码来源:dbm.py
示例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')
开发者ID:HALLAB-Halifax,项目名称:pylearn2,代码行数:8,代码来源:mnd.py
示例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)
开发者ID:123fengye741,项目名称:pylearn2,代码行数:9,代码来源:uniform_hypersphere.py
示例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"])
开发者ID:DevSinghSachan,项目名称:pylearn2,代码行数:9,代码来源:rnn.py
示例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()
开发者ID:ecastrow,项目名称:pl2mind,代码行数:9,代码来源:randomize_snps.py
示例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)
开发者ID:ktho22,项目名称:pylearn2,代码行数:56,代码来源:autoencoder.py
示例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
开发者ID:jbornschein,项目名称:pylearn2,代码行数:10,代码来源:__init__.py
示例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)
开发者ID:AlexArgus,项目名称:pylearn2,代码行数:11,代码来源:test_rbm.py
示例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)
开发者ID:bobchennan,项目名称:pylearn2,代码行数:12,代码来源:test_rbm.py
示例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
开发者ID:EderSantana,项目名称:pylearn2,代码行数:52,代码来源:rbm_tools.py
示例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')
开发者ID:smonami,项目名称:pylearn2,代码行数:13,代码来源:ebm_estimation.py
示例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()
开发者ID:123fengye741,项目名称:pylearn2,代码行数:22,代码来源:test_rng.py
示例16: __init__
def __init__(self, num_chains, num_gibbs_steps, supervised=False, toronto_neg=False, theano_rng=None):
"""
.. todo::
WRITEME properly
toronto_neg: If True, use a bit of mean field in the negative phase
Ruslan Salakhutdinov's matlab code does this.
"""
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]
开发者ID:jpompe,项目名称:pylearn2,代码行数:13,代码来源:dbm.py
示例17: set_rng
def set_rng(self, rng):
"""
SSetup the theano random generator for this class.
Parameters
----------
rng : np.random.RandomState
Random generator from which to generate the seed of
the theano random generator
"""
self.rng = rng
self.theano_rng = make_theano_rng(int(self.rng.randint(2 ** 30)),
which_method=["normal", "uniform"])
开发者ID:edamaraju,项目名称:nice,代码行数:13,代码来源:nice.py
示例18: set_vae
def set_vae(self, vae):
"""
Assigns this `Prior` instance to a VAE.
Parameters
----------
vae : pylearn2.models.vae.VAE
VAE to assign to
"""
if self.get_vae() is not None:
raise RuntimeError("this `Prior` instance already belongs to "
"another VAE")
self.vae = vae
self.rng = self.vae.rng
self.theano_rng = make_theano_rng(int(self.rng.randint(2 ** 30)),
which_method=["normal", "uniform"])
self.batch_size = vae.batch_size
开发者ID:123fengye741,项目名称:pylearn2,代码行数:17,代码来源:prior.py
示例19: __init__
def __init__(self, rbm, particles, rng):
"""
Construct a Sampler.
Parameters
----------
rbm : object
An instance of `RBM` or a derived class, or one implementing \
the `gibbs_step_for_v` interface.
particles : numpy.ndarray
An initial state for the set of persistent Narkov chain particles \
that will be updated at every step of learning.
rng : RandomState object
NumPy random number generator object used to initialize a \
RandomStreams object used in training.
"""
self.__dict__.update(rbm=rbm)
rng = make_np_rng(rng, which_method="randn")
seed = int(rng.randint(2 ** 30))
self.s_rng = make_theano_rng(seed, which_method="binomial")
self.particles = sharedX(particles, name='particles')
开发者ID:fancyspeed,项目名称:pylearn2,代码行数:22,代码来源:rbm.py
示例20: redo_everything
def redo_everything(self):
"""
.. todo::
WRITEME properly
compiles learn_func if necessary
makes new negative chains
does not reset weights or biases
TODO: figure out how to make the semantics of this cleaner / more in line with other models
"""
#compile learn_func if necessary
if self.autonomous:
self.redo_theano()
#make the negative chains
if not self.use_cd:
self.V_chains = self.make_chains(self.bias_vis)
self.V_chains.name = 'dbm_V_chains'
self.H_chains = [ self.make_chains(bias_hid) for bias_hid in self.bias_hid ]
for i, H_chain in enumerate(self.H_chains):
H_chain.name = 'dbm_H[%d]_chain' % i
if self.num_classes > 0:
P = np.zeros((self.negative_chains, self.num_classes)) \
+ T.nnet.softmax( self.bias_class )
temp_theano_rng = make_theano_rng(87, which_method='multinomial')
sample_from = Sampler(temp_theano_rng, 'multinomial')
values = function([],sample_from(P))()
self.Y_chains = sharedX(values, 'Y_chains')
else:
self.Y_chains = None
if hasattr(self, 'init_beta') and self.init_beta is not None:
self.beta = sharedX( np.zeros( self.bias_vis.get_value().shape) + self.init_beta, name = 'beta')
开发者ID:fancyspeed,项目名称:pylearn2,代码行数:37,代码来源:dense_binary_dbm.py
注:本文中的pylearn2.utils.rng.make_theano_rng函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论