本文整理汇总了Python中cle.cle.cost.Gaussian类的典型用法代码示例。如果您正苦于以下问题:Python Gaussian类的具体用法?Python Gaussian怎么用?Python Gaussian使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gaussian类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cost
def cost(self, X):
if len(X) != 3:
raise ValueError("The number of inputs does not match.")
cost = Gaussian(X[0], X[1], X[2])
if self.use_sum:
return cost.sum()
else:
return cost.mean()
示例2: inner_fn
def inner_fn(x_t, s_tm1, s_tm1_is):
x_1_t = x_1.fprop([x_t])
x_2_t = x_2.fprop([x_1_t])
x_3_t = x_3.fprop([x_2_t])
x_4_t = x_4.fprop([x_3_t])
x_5_t = x_5.fprop([x_4_t])
x_6_t = x_6.fprop([x_5_t])
phi_1_t = phi_1.fprop([x_6_t, s_tm1])
phi_2_t = phi_2.fprop([phi_1_t])
phi_3_t = phi_3.fprop([phi_2_t])
phi_4_t = phi_4.fprop([phi_3_t])
phi_mu_t = phi_mu.fprop([phi_4_t])
phi_sig_t = phi_sig.fprop([phi_4_t])
z_t = prior.fprop([phi_mu_t, phi_sig_t])
kl_t = kl.fprop([phi_mu_t, phi_sig_t])
z_1_t = z_1.fprop([z_t])
z_2_t = z_2.fprop([z_1_t])
z_3_t = z_3.fprop([z_2_t])
z_4_t = z_4.fprop([z_3_t])
theta_1_t = theta_1.fprop([z_4_t, s_tm1])
theta_2_t = theta_2.fprop([theta_1_t])
theta_3_t = theta_3.fprop([theta_2_t])
theta_4_t = theta_4.fprop([theta_3_t])
theta_mu_t = theta_mu.fprop([theta_4_t])
theta_sig_t = theta_sig.fprop([theta_4_t])
s_t = main_lstm.fprop([[x_6_t, z_4_t], [s_tm1]])
x_t_is = T.repeat(x_t, num_sample, axis=0)
x_1_t_is = x_1.fprop([x_t_is])
x_2_t_is = x_2.fprop([x_1_t_is])
x_3_t_is = x_3.fprop([x_2_t_is])
x_4_t_is = x_4.fprop([x_3_t_is])
x_5_t_is = x_5.fprop([x_4_t_is])
x_6_t_is = x_6.fprop([x_5_t_is])
phi_1_t_is = phi_1.fprop([x_6_t_is, s_tm1_is])
phi_2_t_is = phi_2.fprop([phi_1_t_is])
phi_3_t_is = phi_3.fprop([phi_2_t_is])
phi_4_t_is = phi_4.fprop([phi_3_t_is])
phi_mu_t_is = phi_mu.fprop([phi_4_t_is])
phi_sig_t_is = phi_sig.fprop([phi_4_t_is])
z_t_is = prior.sample([phi_mu_t_is, phi_sig_t_is])
z_1_t_is = z_1.fprop([z_t_is])
z_2_t_is = z_2.fprop([z_1_t_is])
z_3_t_is = z_3.fprop([z_2_t_is])
z_4_t_is = z_4.fprop([z_3_t_is])
prior_mu_t_is = T.zeros_like(z_t_is)
prior_sig_t_is = T.ones_like(z_t_is)
theta_1_t_is = theta_1.fprop([z_4_t_is, s_tm1_is])
theta_2_t_is = theta_2.fprop([theta_1_t_is])
theta_3_t_is = theta_3.fprop([theta_2_t_is])
theta_4_t_is = theta_4.fprop([theta_3_t_is])
theta_mu_t_is = theta_mu.fprop([theta_4_t_is])
theta_sig_t_is = theta_sig.fprop([theta_4_t_is])
mll = Gaussian(x_t_is, theta_mu_t_is, theta_sig_t_is) +\
Gaussian(z_t_is, prior_mu_t_is, prior_sig_t_is) -\
Gaussian(z_t_is, phi_mu_t_is, phi_sig_t_is)
mll = mll.reshape((batch_size, num_sample))
mll = logsumexp(-mll, axis=1) - T.log(num_sample)
s_t_is = main_lstm.fprop([[x_6_t_is, z_4_t_is], [s_tm1_is]])
return s_t, s_t_is, kl_t, theta_mu_t, theta_sig_t, mll
示例3: Gaussian
outputs_info=[s_0])
for k, v in updates.iteritems():
k.default_update = v
s_t = s_t[:-1]
s_shape = s_t.shape
s_in = T.concatenate([s_0, s_t.reshape((s_shape[0]*s_shape[1], -1))], axis=0)
theta_1_in = theta_1.fprop([s_in])
theta_2_in = theta_2.fprop([theta_1_in])
theta_3_in = theta_3.fprop([theta_2_in])
theta_4_in = theta_4.fprop([theta_3_in])
theta_mu_in = theta_mu.fprop([theta_4_in])
theta_sig_in = theta_sig.fprop([theta_4_in])
recon = Gaussian(x_in, theta_mu_in, theta_sig_in)
recon = recon.reshape((x_shape[0], x_shape[1]))
recon = recon * x_mask
recon_term = recon.sum(axis=0).mean()
recon_term.name = 'nll'
max_x = x.max()
mean_x = x.mean()
min_x = x.min()
max_x.name = 'max_x'
mean_x.name = 'mean_x'
min_x.name = 'min_x'
max_theta_mu = theta_mu_in.max()
mean_theta_mu = theta_mu_in.mean()
min_theta_mu = theta_mu_in.min()
示例4: Gaussian
theta_1_in = theta_1.fprop([z_4_in, s_in])
theta_2_in = theta_2.fprop([theta_1_in])
theta_3_in = theta_3.fprop([theta_2_in])
theta_4_in = theta_4.fprop([theta_3_in])
theta_mu_in = theta_mu.fprop([theta_4_in])
theta_sig_in = theta_sig.fprop([theta_4_in])
z_shape = phi_mu_t.shape
phi_mu_in = phi_mu_t.reshape((z_shape[0]*z_shape[1], -1))
phi_sig_in = phi_sig_t.reshape((z_shape[0]*z_shape[1], -1))
prior_mu_in = prior_mu_t.reshape((z_shape[0]*z_shape[1], -1))
prior_sig_in = prior_sig_t.reshape((z_shape[0]*z_shape[1], -1))
kl_in = kl.fprop([phi_mu_in, phi_sig_in, prior_mu_in, prior_sig_in])
kl_t = kl_in.reshape((z_shape[0], z_shape[1]))
recon = Gaussian(x_in, theta_mu_in, theta_sig_in)
recon = recon.reshape((x_shape[0], x_shape[1]))
recon_term = recon.mean()
kl_term = kl_t.mean()
nll_lower_bound = recon_term + kl_term
nll_lower_bound.name = 'nll_lower_bound'
mn_x_shape = mn_x.shape
mn_x_in = mn_x.reshape((mn_x_shape[0]*mn_x_shape[1], -1))
mn_x_1_in = x_1.fprop([mn_x_in])
mn_x_2_in = x_2.fprop([mn_x_1_in])
mn_x_3_in = x_3.fprop([mn_x_2_in])
mn_x_4_in = x_4.fprop([mn_x_3_in])
mn_x_4_in = mn_x_4_in.reshape((mn_x_shape[0], mn_x_shape[1], -1))
mn_s_0 = main_lstm.get_init_state(mn_batch_size)
示例5: Gaussian
((s_t, s_t_is, kl_t, theta_mu_t, theta_sig_t, mll), updates) =\
theano.scan(fn=inner_fn,
sequences=[x],
outputs_info=[main_lstm.get_init_state(batch_size),
main_lstm.get_init_state(batch_size*num_sample),
None, None, None, None])
for k, v in updates.iteritems():
k.default_update = v
reshaped_x = x.reshape((x.shape[0]*x.shape[1], -1))
reshaped_theta_mu = theta_mu_t.reshape((theta_mu_t.shape[0]*theta_mu_t.shape[1], -1))
reshaped_theta_sig = theta_sig_t.reshape((theta_sig_t.shape[0]*theta_sig_t.shape[1], -1))
recon = Gaussian(reshaped_x, reshaped_theta_mu, reshaped_theta_sig)
recon = recon.reshape((theta_mu_t.shape[0], theta_mu_t.shape[1]))
recon = recon * x_mask
kl_t = kl_t * x_mask
recon_term = recon.sum(axis=0).mean()
kl_term = kl_t.sum(axis=0).mean()
nll_lower_bound = recon_term + kl_term
nll_lower_bound.name = 'nll_lower_bound'
mll = mll * x_mask
mll = -mll.sum(axis=0).mean()
mll.name = 'marginal_nll'
outputs = [mll, nll_lower_bound]
monitor_fn = theano.function(inputs=[x, x_mask],
示例6: main
#.........这里部分代码省略.........
shared_updates[step_count] = step_count + 1
s_0 = T.switch(T.eq(T.mod(step_count, reset_freq), 0),
rnn.get_init_state(batch_size), rnn_tm1)
x_1_temp = x_1.fprop([x], params)
x_2_temp = x_2.fprop([x_1_temp], params)
x_3_temp = x_3.fprop([x_2_temp], params)
x_4_temp = x_4.fprop([x_3_temp], params)
def inner_fn(x_t, s_tm1):
s_t = rnn.fprop([[x_t], [s_tm1]], params)
return s_t
(s_temp, updates) = theano.scan(fn=inner_fn,
sequences=[x_4_temp],
outputs_info=[s_0])
for k, v in updates.iteritems():
k.default_update = v
shared_updates[rnn_tm1] = s_temp[-1]
s_temp = concatenate([s_0[None, :, :], s_temp[:-1]], axis=0)
theta_1_temp = theta_1.fprop([s_temp], params)
theta_2_temp = theta_2.fprop([theta_1_temp], params)
theta_3_temp = theta_3.fprop([theta_2_temp], params)
theta_4_temp = theta_4.fprop([theta_3_temp], params)
theta_mu_temp = theta_mu.fprop([theta_4_temp], params)
theta_sig_temp = theta_sig.fprop([theta_4_temp], params)
recon = Gaussian(x, theta_mu_temp, theta_sig_temp)
recon_term = recon.mean()
recon_term.name = 'nll'
m_x_1_temp = x_1.fprop([m_x], params)
m_x_2_temp = x_2.fprop([m_x_1_temp], params)
m_x_3_temp = x_3.fprop([m_x_2_temp], params)
m_x_4_temp = x_4.fprop([m_x_3_temp], params)
m_s_0 = rnn.get_init_state(m_batch_size)
(m_s_temp, m_updates) = theano.scan(fn=inner_fn,
sequences=[m_x_4_temp],
outputs_info=[m_s_0])
for k, v in m_updates.iteritems():
k.default_update = v
m_s_temp = concatenate([m_s_0[None, :, :], m_s_temp[:-1]], axis=0)
m_theta_1_temp = theta_1.fprop([m_s_temp], params)
m_theta_2_temp = theta_2.fprop([m_theta_1_temp], params)
m_theta_3_temp = theta_3.fprop([m_theta_2_temp], params)
m_theta_4_temp = theta_4.fprop([m_theta_3_temp], params)
m_theta_mu_temp = theta_mu.fprop([m_theta_4_temp], params)
m_theta_sig_temp = theta_sig.fprop([m_theta_4_temp], params)
m_recon = Gaussian(m_x, m_theta_mu_temp, m_theta_sig_temp)
m_recon_term = m_recon.mean()
m_recon_term.name = 'nll'
max_x = m_x.max()
mean_x = m_x.mean()
min_x = m_x.min()
示例7: Gaussian
encoder_tm1 = enc_t[-1]
decoder_tm1 = dec_t[-1]
dec_shape = dec_t.shape
dec_in = dec_t.reshape((dec_shape[0]*dec_shape[1], -1))
theta_mu_in = theta_mu.fprop([dec_in])
theta_sig_in = theta_sig.fprop([dec_in])
z_shape = phi_mu_t.shape
phi_mu_in = phi_mu_t.reshape((z_shape[0]*z_shape[1], -1))
phi_sig_in = phi_sig_t.reshape((z_shape[0]*z_shape[1], -1))
kl_in = kl.fprop([phi_mu_in, phi_sig_in])
kl_t = kl_in.reshape((z_shape[0], z_shape[1]))
recon = Gaussian(x_in, theta_mu_in, theta_sig_in)
recon = recon.reshape((x_shape[0], x_shape[1]))
recon_term = recon.mean()
kl_term = kl_t.mean()
nll_lower_bound = recon_term + kl_term
nll_lower_bound.name = 'nll_lower_bound'
recon_term.name = 'recon_term'
kl_term.name = 'kl_term'
kl_ratio = kl_term / T.abs_(recon_term)
kl_ratio.name = 'kl_term proportion'
max_x = x.max()
mean_x = x.mean()
min_x = x.min()
max_x.name = 'max_x'
示例8: main
#.........这里部分代码省略.........
params = init_tparams(params)
step_count = sharedX(0, name='step_count')
last_rnn = np.zeros((batch_size, rnn_dim*2), dtype=theano.config.floatX)
rnn_tm1 = sharedX(last_rnn, name='rnn_tm1')
shared_updates = OrderedDict()
shared_updates[step_count] = step_count + 1
s_0 = T.switch(T.eq(T.mod(step_count, reset_freq), 0),
rnn.get_init_state(batch_size), rnn_tm1)
x_1_temp = x_1.fprop([x], params)
x_2_temp = x_2.fprop([x_1_temp], params)
x_3_temp = x_3.fprop([x_2_temp], params)
x_4_temp = x_4.fprop([x_3_temp], params)
def inner_fn(x_t, s_tm1):
phi_1_t = phi_1.fprop([x_t, s_tm1], params)
phi_2_t = phi_2.fprop([phi_1_t], params)
phi_3_t = phi_3.fprop([phi_2_t], params)
phi_4_t = phi_4.fprop([phi_3_t], params)
phi_mu_t = phi_mu.fprop([phi_4_t], params)
phi_sig_t = phi_sig.fprop([phi_4_t], params)
prior_1_t = prior_1.fprop([s_tm1], params)
prior_2_t = prior_2.fprop([prior_1_t], params)
prior_3_t = prior_3.fprop([prior_2_t], params)
prior_4_t = prior_4.fprop([prior_3_t], params)
prior_mu_t = prior_mu.fprop([prior_4_t], params)
prior_sig_t = prior_sig.fprop([prior_4_t], params)
z_t = Gaussian_sample(phi_mu_t, phi_sig_t)
z_1_t = z_1.fprop([z_t], params)
z_2_t = z_2.fprop([z_1_t], params)
z_3_t = z_3.fprop([z_2_t], params)
z_4_t = z_4.fprop([z_3_t], params)
s_t = rnn.fprop([[x_t, z_4_t], [s_tm1]], params)
return s_t, phi_mu_t, phi_sig_t, prior_mu_t, prior_sig_t, z_4_t, z_t
((s_temp, phi_mu_temp, phi_sig_temp, prior_mu_temp, prior_sig_temp, z_4_temp, z_t), updates) =\
theano.scan(fn=inner_fn,
sequences=[x_4_temp],
outputs_info=[s_0, None, None, None, None, None, None])
for k, v in updates.iteritems():
k.default_update = v
shared_updates[rnn_tm1] = s_temp[-1]
s_temp = concatenate([s_0[None, :, :], s_temp[:-1]], axis=0)
theta_1_temp = theta_1.fprop([z_4_temp, s_temp], params)
theta_2_temp = theta_2.fprop([theta_1_temp], params)
theta_3_temp = theta_3.fprop([theta_2_temp], params)
theta_4_temp = theta_4.fprop([theta_3_temp], params)
theta_mu_temp = theta_mu.fprop([theta_4_temp], params)
theta_sig_temp = theta_sig.fprop([theta_4_temp], params)
kl_temp = KLGaussianGaussian(phi_mu_temp, phi_sig_temp, prior_mu_temp, prior_sig_temp)
#### recon = Gaussian(x, theta_mu_temp, theta_sig_temp)
recon = Gaussian(x, theta_mu_temp, theta_sig_temp) - Gaussian(z_t, phi_mu_temp, phi_sig_temp)
recon += Gaussian(z_t, prior_mu_temp, prior_sig_temp)
示例9: main
#.........这里部分代码省略.........
params.update(node.initialize())
params = init_tparams(params)
step_count = sharedX(0, name="step_count")
last_rnn = np.zeros((batch_size, rnn_dim * 2), dtype=theano.config.floatX)
rnn_tm1 = sharedX(last_rnn, name="rnn_tm1")
shared_updates = OrderedDict()
shared_updates[step_count] = step_count + 1
s_0 = T.switch(T.eq(T.mod(step_count, reset_freq), 0), rnn.get_init_state(batch_size), rnn_tm1)
x_1_temp = x_1.fprop([x], params)
x_2_temp = x_2.fprop([x_1_temp], params)
x_3_temp = x_3.fprop([x_2_temp], params)
x_4_temp = x_4.fprop([x_3_temp], params)
def inner_fn(x_t, s_tm1):
phi_1_t = phi_1.fprop([x_t, s_tm1], params)
phi_2_t = phi_2.fprop([phi_1_t], params)
phi_3_t = phi_3.fprop([phi_2_t], params)
phi_4_t = phi_4.fprop([phi_3_t], params)
phi_mu_t = phi_mu.fprop([phi_4_t], params)
phi_sig_t = phi_sig.fprop([phi_4_t], params)
prior_1_t = prior_1.fprop([s_tm1], params)
prior_2_t = prior_2.fprop([prior_1_t], params)
prior_3_t = prior_3.fprop([prior_2_t], params)
prior_4_t = prior_4.fprop([prior_3_t], params)
prior_mu_t = prior_mu.fprop([prior_4_t], params)
prior_sig_t = prior_sig.fprop([prior_4_t], params)
z_t = Gaussian_sample(phi_mu_t, phi_sig_t)
z_1_t = z_1.fprop([z_t], params)
z_2_t = z_2.fprop([z_1_t], params)
z_3_t = z_3.fprop([z_2_t], params)
z_4_t = z_4.fprop([z_3_t], params)
s_t = rnn.fprop([[x_t, z_4_t], [s_tm1]], params)
return s_t, phi_mu_t, phi_sig_t, prior_mu_t, prior_sig_t, z_4_t, z_t
((s_temp, phi_mu_temp, phi_sig_temp, prior_mu_temp, prior_sig_temp, z_4_temp, z_t), updates) = theano.scan(
fn=inner_fn, sequences=[x_4_temp], outputs_info=[s_0, None, None, None, None, None, None]
)
for k, v in updates.iteritems():
k.default_update = v
shared_updates[rnn_tm1] = s_temp[-1]
s_temp = concatenate([s_0[None, :, :], s_temp[:-1]], axis=0)
theta_1_temp = theta_1.fprop([z_4_temp, s_temp], params)
theta_2_temp = theta_2.fprop([theta_1_temp], params)
theta_3_temp = theta_3.fprop([theta_2_temp], params)
theta_4_temp = theta_4.fprop([theta_3_temp], params)
theta_mu_temp = theta_mu.fprop([theta_4_temp], params)
theta_sig_temp = theta_sig.fprop([theta_4_temp], params)
kl_temp = KLGaussianGaussian(phi_mu_temp, phi_sig_temp, prior_mu_temp, prior_sig_temp)
#### recon = Gaussian(x, theta_mu_temp, theta_sig_temp)
recon = Gaussian(x, theta_mu_temp, theta_sig_temp) - Gaussian(z_t, phi_mu_temp, phi_sig_temp)
recon += Gaussian(z_t, prior_mu_temp, prior_sig_temp)
recon_term = recon.mean() / 5.0
示例10: concatenate
sequences=[x_4_temp],
outputs_info=[s_0])
for k, v in updates.iteritems():
k.default_update = v
shared_updates[rnn_tm1] = s_temp[-1]
s_temp = concatenate([s_0[None, :, :], s_temp[:-1]], axis=0)
theta_1_temp = theta_1.fprop([s_temp], params)
theta_2_temp = theta_2.fprop([theta_1_temp], params)
theta_3_temp = theta_3.fprop([theta_2_temp], params)
theta_4_temp = theta_4.fprop([theta_3_temp], params)
theta_mu_temp = theta_mu.fprop([theta_4_temp], params)
theta_sig_temp = theta_sig.fprop([theta_4_temp], params)
recon = Gaussian(x, theta_mu_temp, theta_sig_temp)
recon_term = recon.mean()
recon_term.name = 'nll'
m_s_0 = rnn.get_init_state(m_batch_size)
(m_s_temp, m_updates) = theano.scan(fn=inner_fn,
sequences=[x_4_temp],
outputs_info=[m_s_0])
for k, v in m_updates.iteritems():
k.default_update = v
m_s_temp = concatenate([m_s_0[None, :, :], m_s_temp[:-1]], axis=0)
m_theta_1_temp = theta_1.fprop([m_s_temp], params)
m_theta_2_temp = theta_2.fprop([m_theta_1_temp], params)