コード例 #1
0
ファイル: distributions.py プロジェクト: slucia/breze
 def _init_distribution(self):
     if self.pooling:
         DiagGauss.__init__(self, self.rnn.output[:, : self.n_output], self.rnn.output[:, self.n_output :], self.rng)
     else:
         DiagGauss.__init__(
             self, self.rnn.output[:, :, : self.n_output], self.rnn.output[:, :, self.n_output :], self.rng
         )
コード例 #2
0
 def _init_distribution(self):
     if self.pooling:
         DiagGauss.__init__(self, self.rnn.output[:, :self.n_output],
                            self.rnn.output[:, self.n_output:], self.rng)
     else:
         DiagGauss.__init__(self, self.rnn.output[:, :, :self.n_output],
                            self.rnn.output[:, :, self.n_output:], self.rng)
コード例 #3
0
 def _init_distribution(self):
     var = self.std**2 + 1e-5
     if self.pooling:
         DiagGauss.__init__(self, self.rnn.output[:, :self.n_output],
                            var.dimshuffle('x', 0), self.rng)
     else:
         DiagGauss.__init__(self, self.rnn.output[:, :, :self.n_output],
                            var.dimshuffle('x', 'x', 0), self.rng)
コード例 #4
0
ファイル: distributions.py プロジェクト: Wiebke/breze
 def _init_distribution(self):
     var = self.std ** 2 + 1e-5
     if self.pooling:
         DiagGauss.__init__(
             self,
             self.rnn.output[:, :self.n_output],
             var.dimshuffle('x', 0),
             self.rng)
     else:
         DiagGauss.__init__(
             self,
             self.rnn.output[:, :, :self.n_output],
             var.dimshuffle('x', 'x', 0),
             self.rng)
コード例 #5
0
n, m = 10, 5
A, B = T.matrices('A', 'B')
X = np.empty((3, 4), dtype=np.float32)
print 'X shape =', X.shape

# # this works
# S = theano.shared(np.random.randn(n, m))
# sample = T.tile(S[np.newaxis, :, :], (A.shape[0], 1, 1), ndim=3)



# this does not work
mean_val, var_val = (np.random.randn(n, m) for _ in xrange(2))
var_val = var_val**2 + 1e-5
mean_raw, var_raw = (theano.shared(v) for v in (mean_val, var_val))

mean, var = (T.tile(v[np.newaxis, :, :], (A.shape[0], 1, 1), ndim=3) for v in (mean_raw, var_raw))
gaus = DiagGauss(mean, var)
sample = gaus.sample()


foo_sample_A = theano.function([A], sample)
print 'foo_sample_A.shape =', foo_sample_A(X).shape     # (3, 10, 5)

sample += B[0, 0] * 0   # to avoid unused input errorr
sample = theano.clone(sample, {A: B})   # this should fix the missing input error, but doesn't

foo_sample_B = theano.function([B], sample)
print 'foo_sample_B.shape =', foo_sample_B(X).shape     # error
コード例 #6
0
pmp_input = NormalGauss(shape)
sample = pmp_input.sample()
sample = T.tile(sample, (timesteps, 1, 1), ndim=len(shape))

mean = sample[:, :, :n_mean_par]
var = sample[:, :, n_mean_par:]**2
uu = mean

pmp = ProbabilisticMovementPrimitive(n_bases,
                                     mean,
                                     var**2,
                                     uu,
                                     width=width,
                                     eps=1e-5)

diag = DiagGauss(dmean, dvar**2)

kl_coord_wise = kl_div(diag, pmp)
kl_sample_wise = kl_coord_wise.sum(axis=2)
kl = kl_sample_wise.mean()

grad_kl = T.grad(kl, [dmean, dvar])

foo_kl = theano.function([dmean, dvar], kl)
foo_grad = theano.function([dmean, dvar], grad_kl)


def evaluate(trials, repeats_per_trial, batch_size):
    kls = []
    grads = []