本文整理汇总了Python中theano.tensor.tile方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.tile方法的具体用法?Python tensor.tile怎么用?Python tensor.tile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.tile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: broadcast_concat
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def broadcast_concat(tensors, axis):
"""
Broadcast tensors together, then concatenate along axis
"""
ndim = tensors[0].ndim
assert all(t.ndim == ndim for t in tensors), "ndims don't match for broadcast_concat: {}".format(tensors)
broadcast_shapes = []
for i in range(ndim):
if i == axis:
broadcast_shapes.append(1)
else:
dim_size = next((t.shape[i] for t in tensors if not t.broadcastable[i]), 1)
broadcast_shapes.append(dim_size)
broadcasted_tensors = []
for t in tensors:
tile_reps = [bshape if t.broadcastable[i] else 1 for i,bshape in enumerate(broadcast_shapes)]
if all(rep is 1 for rep in tile_reps):
# Don't need to broadcast this tensor
broadcasted_tensors.append(t)
else:
broadcasted_tensors.append(T.tile(t, tile_reps))
return T.concatenate(broadcasted_tensors, axis)
示例2: Compatible
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def Compatible(list1, list2):
if len(list1) != len(list2):
return False
for l1, l2 in zip(list1, list2):
if type(l1.get_value()) != type(l2):
return False
if np.isscalar(l1.get_value()):
continue
if l1.get_value().shape != l2.shape:
return False
return True
##generate the tile of a small tensor x, the first 2 dims will be expanded
## x is a small matrix or tensor3 to be tiled, y is a tuple of 2 elements
## This function generates a tile of x by copying it y*y times
## The resultant matrix shall have dimension ( x.shape[0]*y, x.shape[1]*y), consisting of y*y copies of x
示例3: SEard
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def SEard(hyp, X1, X2=None, all_pairs=True):
''' Squard exponential kernel with diagonal scaling matrix
(one lengthscale per dimension)'''
n = 1
idims = 1
if X1.ndim == 2:
n, idims = X1.shape
elif X2.ndim == 2:
n, idims = X2.shape
else:
idims = X1.shape[0]
sf2 = hyp[idims]**2
if (not all_pairs) and (X1 is X2 or X2 is None):
# all the distances are going to be zero
K = tt.tile(sf2, (n,))
return K
ls2 = hyp[:idims]**2
D = utils.maha(X1, X2, tt.diag(1.0/ls2),
all_pairs=all_pairs)
K = sf2*tt.exp(-0.5*D)
return K
示例4: nll_of_x_given_o
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def nll_of_x_given_o(self, input, ordering):
""" Returns the theano graph that computes $-ln p(\bx|o)$.
Parameters
----------
input: 1D vector
One image with shape (nb_channels * images_height * images_width).
ordering: 1D vector of int
List of pixel indices representing the input ordering.
"""
D = int(np.prod(self.image_shape))
mask_o_d = T.zeros((D, D), dtype=theano.config.floatX)
mask_o_d = T.set_subtensor(mask_o_d[T.arange(D), ordering], 1.)
mask_o_lt_d = T.cumsum(mask_o_d, axis=0)
mask_o_lt_d = T.set_subtensor(mask_o_lt_d[1:], mask_o_lt_d[:-1])
mask_o_lt_d = T.set_subtensor(mask_o_lt_d[0, :], 0.)
input = T.tile(input[None, :], (D, 1))
nll = -T.sum(self.lnp_x_o_d_given_x_o_lt_d(input, mask_o_d, mask_o_lt_d))
return nll
示例5: _create_constant_uas_across_datapoints
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def _create_constant_uas_across_datapoints(self):
"""
Helper function. Creates and returns new theano variables representing noise, where noise is the same across
datapoints in the minibatch. Useful for binding the original noise variables in evaluation function where
randomness is required but same predictions are needed across minibatch.
"""
n_data = tt.iscalar('n_data')
net_uas = [tt.tile(self.srng.normal((n_units,), dtype=dtype), [n_data, 1]) for n_units in self.net.n_units[1:]]
uaa = tt.tile(self.srng.normal((self.n_components,), dtype=dtype), [n_data, 1])
uams = [tt.tile(self.srng.normal((self.n_outputs,), dtype=dtype), [n_data, 1]) for _ in xrange(self.n_components)]
uaUs = [tt.tile(self.srng.normal((self.n_outputs**2,), dtype=dtype), [n_data, 1]) for _ in xrange(self.n_components)]
# NOTE: order matters here
uas = net_uas + [uaa] + uams + uaUs
return n_data, uas
示例6: gen
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def gen(self, x, n_samples=None, u=None, rng=np.random):
"""
Generate samples from made conditioned on x. Requires as many evaluations as number of outputs.
:param x: input vector
:param n_samples: number of samples, 1 if None
:param u: random numbers to use in generating samples; if None, new random numbers are drawn
:return: samples
"""
if n_samples is None:
return self.gen(x, 1, u if u is None else u[np.newaxis, :], rng)[0]
y = np.zeros([n_samples, self.n_outputs], dtype=dtype)
u = rng.randn(n_samples, self.n_outputs).astype(dtype) if u is None else u
xy = (np.tile(x, [n_samples, 1]), y)
for i in xrange(1, self.n_outputs + 1):
m, logp = self.eval_comps(xy)
idx = np.argwhere(self.output_order == i)[0, 0]
y[:, idx] = m[:, idx] + np.exp(np.minimum(-0.5 * logp[:, idx], 10.0)) * u[:, idx]
return y
示例7: _L
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def _L(x):
# initialize with zeros
batch_size = x.shape[0]
a = T.zeros((batch_size, num_actuators, num_actuators))
# set diagonal elements
batch_idx = T.extra_ops.repeat(T.arange(batch_size), num_actuators)
diag_idx = T.tile(T.arange(num_actuators), batch_size)
b = T.set_subtensor(a[batch_idx, diag_idx, diag_idx], T.flatten(T.exp(x[:, :num_actuators])))
# set lower triangle
cols = np.concatenate([np.array(range(i), dtype=np.uint) for i in range(num_actuators)])
rows = np.concatenate([np.array([i]*i, dtype=np.uint) for i in range(num_actuators)])
cols_idx = T.tile(T.as_tensor_variable(cols), batch_size)
rows_idx = T.tile(T.as_tensor_variable(rows), batch_size)
batch_idx = T.extra_ops.repeat(T.arange(batch_size), len(cols))
c = T.set_subtensor(b[batch_idx, rows_idx, cols_idx], T.flatten(x[:, num_actuators:]))
return c
示例8: _L
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def _L(x):
# initialize with zeros
batch_size = x.shape[0]
a = T.zeros((batch_size, num_actuators, num_actuators))
# set diagonal elements
batch_idx = T.extra_ops.repeat(T.arange(batch_size), num_actuators)
diag_idx = T.tile(T.arange(num_actuators), batch_size)
b = T.set_subtensor(a[batch_idx, diag_idx, diag_idx], T.flatten(T.exp(x[:, :num_actuators])))
# set lower triangle
cols = np.concatenate([np.array(range(i), dtype=np.uint) for i in xrange(num_actuators)])
rows = np.concatenate([np.array([i]*i, dtype=np.uint) for i in xrange(num_actuators)])
cols_idx = T.tile(T.as_tensor_variable(cols), batch_size)
rows_idx = T.tile(T.as_tensor_variable(rows), batch_size)
batch_idx = T.extra_ops.repeat(T.arange(batch_size), len(cols))
c = T.set_subtensor(b[batch_idx, rows_idx, cols_idx], T.flatten(x[:, num_actuators:]))
return c
示例9: tile
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def tile(x, n):
# TODO: `keras_shape` inference.
return T.tile(x, n)
示例10: create_full_unique
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def create_full_unique(cls, batch_size, num_node_ids, node_state_size, num_edge_types):
"""
Create a 'full unique' graph state (i.e. a graph state where every id has exactly one node) from a spec
batch_size: Number of batches
num_node_ids: An integer giving size of node id
node_state_size: An integer giving size of node state
num_edge_types: An integer giving number of edge types
"""
return cls( T.ones([batch_size, num_node_ids]),
T.tile(T.shape_padleft(T.eye(num_node_ids)), (batch_size,1,1)),
T.zeros([batch_size, num_node_ids, node_state_size]),
T.zeros([batch_size, num_node_ids, num_node_ids, num_edge_types]))
示例11: process
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def process(self, gstate, input_vector, dropout_masks=Ellipsis):
"""
Process an input vector and update the state accordingly. Each node runs a GRU step
with previous state from the node state and input from the vector.
Params:
gstate: A GraphState giving the current state
input_vector: A tensor of the form (n_batch, input_width)
"""
# gstate.node_states is of shape (n_batch, n_nodes, node_state_width)
# input_vector should be broadcasted to match this
if dropout_masks is Ellipsis:
dropout_masks = None
append_masks = False
else:
append_masks = True
prepped_input_vector = T.tile(T.shape_padaxis(input_vector, 1), [1, gstate.n_nodes, 1])
full_input = T.concatenate([gstate.node_ids, prepped_input_vector], 2)
# we flatten to apply GRU
flat_input = full_input.reshape([-1, self._input_width + self._graph_spec.num_node_ids])
flat_state = gstate.node_states.reshape([-1, self._graph_spec.node_state_size])
new_flat_state, dropout_masks = self._update_gru.step(flat_input, flat_state, dropout_masks)
new_node_states = new_flat_state.reshape(gstate.node_states.shape)
new_gstate = gstate.with_updates(node_states=new_node_states)
if append_masks:
return new_gstate, dropout_masks
else:
return new_gstate
示例12: tile
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def tile(x, n):
return T.tile(x, n)
示例13: invert
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def invert(self, constraints, z_i):
[_invert, z_updates, z, beta_r, z_const] = self.opt_model
constraints_t = self.preprocess_constraints(constraints)
[im_c_t, mask_c_t, im_e_t, mask_e_t] = constraints_t # [im_c_t, mask_c_t, im_e_t, mask_e_t]
results = _invert(im_c_t, mask_c_t, im_e_t, mask_e_t, z_i.astype(np.float32))
[gx, cost, cost_all, rec_all, real_all, init_all, sum_e, sum_x_edge] = results
gx_t = (255 * self.inverse_transform(gx, npx=self.npx, nc=self.nc)).astype(np.uint8)
if self.nc == 1:
gx_t = np.tile(gx_t, (1, 1, 1, 3))
z_t = np.tanh(z.get_value()).copy()
return gx_t, z_t, cost_all
示例14: preprocess_constraints
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def preprocess_constraints(self, constraints):
[im_c_o, mask_c_o, im_e_o, mask_e_o] = constraints
im_c = self.transform(im_c_o[np.newaxis, :], self.nc)
mask_c = self.transform_mask(mask_c_o[np.newaxis, :])
im_e = self.transform(im_e_o[np.newaxis, :], self.nc)
mask_t = self.transform_mask(mask_e_o[np.newaxis, :])
mask_e = self.hog.comp_mask(mask_t)
shp = [self.batch_size, 1, 1, 1]
im_c_t = np.tile(im_c, shp)
mask_c_t = np.tile(mask_c, shp)
im_e_t = np.tile(im_e, shp)
mask_e_t = np.tile(mask_e, shp)
return [im_c_t, mask_c_t, im_e_t, mask_e_t]
示例15: gen_samples
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import tile [as 别名]
def gen_samples(self, z0):
samples = self.model.gen_samples(z0=z0)
if self.nc == 1:
samples = np.tile(samples, [1, 1, 1, 3])
return samples