Esempio n. 1
0
 def initialize_objective(self):
     self.C, self.c = (
         T.variable(T.random_normal([self.ds, self.ds])),
         T.variable(T.random_normal([self.ds])),
     )
     if self.learn_stdev:
         self.stdev = T.variable(T.to_float(self.cost_stdev))
     else:
         self.stdev = T.to_float(self.cost_stdev)
Esempio n. 2
0
 def initialize_objective(self):
     H, ds, da = self.horizon, self.ds, self.da
     if self.time_varying:
         A = T.concatenate([T.eye(ds), T.zeros([ds, da])], -1)
         self.A = T.variable(A[None] + 1e-2 * T.random_normal([H - 1, ds, ds + da]))
         self.Q_log_diag = T.variable(T.random_normal([H - 1, ds]) + 1)
         self.Q = T.matrix_diag(T.exp(self.Q_log_diag))
     else:
         A = T.concatenate([T.eye(ds), T.zeros([ds, da])], -1)
         self.A = T.variable(A + 1e-2 * T.random_normal([ds, ds + da]))
         self.Q_log_diag = T.variable(T.random_normal([ds]) + 1)
         self.Q = T.matrix_diag(T.exp(self.Q_log_diag))
Esempio n. 3
0
    def _sample(self, num_samples):
        sigma, mu = self.natural_to_regular(self.regular_to_natural(self.get_parameters('regular')))

        L = T.cholesky(sigma)
        sample_shape = T.concat([[num_samples], T.shape(mu)], 0)
        noise = T.random_normal(sample_shape)
        L = T.tile(L[None], T.concat([[num_samples], T.ones([T.rank(sigma)], dtype=np.int32)]))
        return mu[None] + T.matmul(L, noise[..., None])[..., 0]
Esempio n. 4
0
File: vmp.py Progetto: sharadmv/nvmp
def initialize_node(node, children):
    if isinstance(node, Gaussian):
        d = T.shape(node)
        return Gaussian([T.eye(d[-1], batch_shape=d[:-1]), T.random_normal(d)])
    elif isinstance(node, IW):
        d = T.shape(node)
        return IW([(T.to_float(d[-1]) + 1) * T.eye(d[-1], batch_shape=d[:-2]),
                   T.to_float(d[-1]) + 1])
Esempio n. 5
0
 def initialize_objective(self):
     H, ds, da = self.horizon, self.ds, self.da
     if self.time_varying:
         A = T.concatenate(
             [T.eye(ds, batch_shape=[H - 1]),
              T.zeros([H - 1, ds, da])], -1)
         self.A_prior = stats.MNIW([
             2 * T.eye(ds, batch_shape=[H - 1]), A,
             T.eye(ds + da, batch_shape=[H - 1]),
             T.to_float(ds + 2) * T.ones([H - 1])
         ],
                                   parameter_type='regular')
         self.A_variational = stats.MNIW(list(
             map(
                 T.variable,
                 stats.MNIW.regular_to_natural([
                     2 * T.eye(ds, batch_shape=[H - 1]),
                     A + 1e-2 * T.random_normal([H - 1, ds, ds + da]),
                     T.eye(ds + da, batch_shape=[H - 1]),
                     T.to_float(ds + 2) * T.ones([H - 1])
                 ]))),
                                         parameter_type='natural')
     else:
         A = T.concatenate([T.eye(ds), T.zeros([ds, da])], -1)
         self.A_prior = stats.MNIW(
             [2 * T.eye(ds), A,
              T.eye(ds + da),
              T.to_float(ds + 2)],
             parameter_type='regular')
         self.A_variational = stats.MNIW(list(
             map(
                 T.variable,
                 stats.MNIW.regular_to_natural([
                     2 * T.eye(ds),
                     A + 1e-2 * T.random_normal([ds, ds + da]),
                     T.eye(ds + da),
                     T.to_float(ds + 2)
                 ]))),
                                         parameter_type='natural')
Esempio n. 6
0
def glorot_normal(shape):
    fan_in, fan_out = get_fans(shape)
    s = np.sqrt(0.1 / (fan_in + fan_out))
    return T.random_normal(shape, s)
Esempio n. 7
0
def normal(shape, scale=0.05):
    return T.random_normal(shape, mean=0.0, stddev=scale)