本文整理匯總了Python中theano.tensor.horizontal_stack方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor.horizontal_stack方法的具體用法?Python tensor.horizontal_stack怎麽用?Python tensor.horizontal_stack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類theano.tensor
的用法示例。
在下文中一共展示了tensor.horizontal_stack方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_output_for
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def get_output_for(self, inputs, **kwargs):
"""Compute diffusion convolutional activation of inputs."""
Apow = T.horizontal_stack(*inputs[:-1])
X = inputs[-1]
Apow_dot_X = T.dot(Apow, X)
Apow_dot_X_times_W = Apow_dot_X * self.W
out = self.nonlinearity(Apow_dot_X_times_W)
return out
示例2: __init__
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def __init__(self, inpt, in_sz, n_classes, tied=False):
if tied:
b = share(init_wts(n_classes-1))
w = share(init_wts(in_sz, n_classes-1))
w1 = tt.horizontal_stack(w, tt.zeros((in_sz, 1)))
b1 = tt.concatenate((b, tt.zeros(1)))
self.output = tt.dot(inpt, w1) + b1
else:
b = share(init_wts(n_classes))
w = share(init_wts(in_sz, n_classes))
self.output = tt.dot(inpt, w) + b
self.params = [w, b]
示例3: get_boundary_voxels
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def get_boundary_voxels(self, unique_val):
uv_3d = T.cast(T.round(unique_val[0, :T.prod(self.regular_grid_res)].reshape(self.regular_grid_res, ndim=3)),
'int32')
uv_l = T.horizontal_stack(uv_3d[1:, :, :].reshape((1, -1)),
uv_3d[:, 1:, :].reshape((1, -1)),
uv_3d[:, :, 1:].reshape((1, -1)))
uv_r = T.horizontal_stack(uv_3d[:-1, :, :].reshape((1, -1)),
uv_3d[:, :-1, :].reshape((1, -1)),
uv_3d[:, :, :-1].reshape((1, -1)))
shift = uv_l - uv_r
select_edges = T.neq(shift.reshape((1, -1)), 0)
select_edges_dir = select_edges.reshape((3, -1))
select_voxels = T.zeros_like(uv_3d)
select_voxels = T.inc_subtensor(select_voxels[1:, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:-1, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, 1:, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :-1, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, 1:],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, :-1],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
return select_voxels
# region Geometry
示例4: contribution_universal_drift
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def contribution_universal_drift(self, grid_val=None, weights=None, a=0, b=100000000):
"""
Computation of the contribution of the universal drift at every point to interpolate
Returns:
theano.tensor.vector: Contribution of the universal drift (input) at every point to interpolate
"""
if weights is None:
weights = self.extend_dual_kriging()
if grid_val is None:
grid_val = self.x_to_interpolate()
length_of_CG, length_of_CGI, length_of_U_I, length_of_faults, length_of_C = self.matrices_shapes()
universal_grid_surface_points_matrix = T.horizontal_stack(
grid_val,
(grid_val ** 2),
T.stack((grid_val[:, 0] * grid_val[:, 1],
grid_val[:, 0] * grid_val[:, 2],
grid_val[:, 1] * grid_val[:, 2]), axis=1)).T
# These are the magic terms to get the same as geomodeller
i_rescale_aux = T.repeat(self.gi_reescale, 9)
i_rescale_aux = T.set_subtensor(i_rescale_aux[:3], 1)
_aux_magic_term = T.tile(i_rescale_aux[:self.n_universal_eq_T_op], (grid_val.shape[0], 1)).T
# Drif contribution
f_0 = (T.sum(
weights[
length_of_CG + length_of_CGI:length_of_CG + length_of_CGI + length_of_U_I] * self.gi_reescale * _aux_magic_term *
universal_grid_surface_points_matrix[:self.n_universal_eq_T_op]
, axis=0))
if self.dot_version:
f_0 = T.dot(
weights[length_of_CG + length_of_CGI:length_of_CG + length_of_CGI + length_of_U_I],
self.gi_reescale * _aux_magic_term *
universal_grid_surface_points_matrix[:self.n_universal_eq_T_op])
if not type(f_0) == int:
f_0.name = 'Contribution of the universal drift to the potential field at every point of the grid'
if str(sys._getframe().f_code.co_name) in self.verbose:
f_0 = theano.printing.Print('Universal terms contribution')(f_0)
return f_0
示例5: compute_topology
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def compute_topology(self, unique_val):
uv_3d = T.cast(T.round(unique_val[0, :T.prod(self.regular_grid_res)].reshape(self.regular_grid_res, ndim=3)),
'int32')
uv_l = T.horizontal_stack(uv_3d[1:, :, :].reshape((1, -1)),
uv_3d[:, 1:, :].reshape((1, -1)),
uv_3d[:, :, 1:].reshape((1, -1)))
uv_r = T.horizontal_stack(uv_3d[:-1, :, :].reshape((1, -1)),
uv_3d[:, :-1, :].reshape((1, -1)),
uv_3d[:, :, :-1].reshape((1, -1)))
shift = uv_l - uv_r
select_edges = T.neq(shift.reshape((1, -1)), 0)
select_edges_dir = select_edges.reshape((3, -1))
select_voxels = T.zeros_like(uv_3d)
select_voxels = T.inc_subtensor(select_voxels[1:, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:-1, :, :],
select_edges_dir[0].reshape((self.regular_grid_res - np.array([1, 0, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, 1:, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :-1, :],
select_edges_dir[1].reshape((self.regular_grid_res - np.array([0, 1, 0])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, 1:],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
select_voxels = T.inc_subtensor(select_voxels[:, :, :-1],
select_edges_dir[2].reshape((self.regular_grid_res - np.array([0, 0, 1])),
ndim=3))
uv_lr = T.vertical_stack(uv_l.reshape((1, -1)), uv_r.reshape((1, -1)))
uv_lr_boundaries = uv_lr[T.tile(select_edges.reshape((1, -1)), (2, 1))].reshape((2, -1)).T
# a = T.bincount(uv_lr_boundaries)
edges_id, count_edges = T.extra_ops.Unique(return_counts=True, axis=0)(uv_lr_boundaries)
return select_voxels, edges_id, count_edges
示例6: contribution_universal_drift
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def contribution_universal_drift(self, grid_val, weights=None):
"""
Computation of the contribution of the universal drift at every point to interpolate
Returns:
theano.tensor.vector: Contribution of the universal drift (input) at every point to interpolate
"""
if weights is None:
weights = self.compute_weights()
length_of_CG, length_of_CGI, length_of_U_I, length_of_faults, length_of_C = self.matrices_shapes()
universal_grid_surface_points_matrix = T.horizontal_stack(
grid_val,
(grid_val ** 2),
T.stack((grid_val[:, 0] * grid_val[:, 1],
grid_val[:, 0] * grid_val[:, 2],
grid_val[:, 1] * grid_val[:, 2]), axis=1)).T
i_rescale_aux = T.tile(self.gi_reescale, 9)
i_rescale_aux = T.set_subtensor(i_rescale_aux[:3], 1)
_aux_magic_term = T.tile(i_rescale_aux[:self.n_universal_eq_T_op], (grid_val.shape[0], 1)).T
if self.sparse_version is True:# self.dot_version:
f_0 = T.dot(
weights[length_of_CG + length_of_CGI:length_of_CG + length_of_CGI + length_of_U_I],
(self.gi_reescale * _aux_magic_term *
universal_grid_surface_points_matrix[:self.n_universal_eq_T_op]))
else:
# Drif contribution
f_0 = (T.sum(
weights[
length_of_CG + length_of_CGI:length_of_CG + length_of_CGI + length_of_U_I] * self.gi_reescale *
_aux_magic_term *
universal_grid_surface_points_matrix[:self.n_universal_eq_T_op]
, axis=0))
if not type(f_0) == int:
f_0.name = 'Contribution of the universal drift to the potential field at every point of the grid'
if str(sys._getframe().f_code.co_name) in self.verbose:
f_0 = theano.printing.Print('Universal terms contribution')(f_0)
return f_0
示例7: contribution_gradient
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import horizontal_stack [as 別名]
def contribution_gradient(self, direction='x', grid_val=None, weights=None):
if direction == 'x':
direction_val = 0
if direction == 'y':
direction_val = 1
if direction == 'z':
direction_val = 2
self.gi_reescale = theano.shared(1)
if weights is None:
weights = self.extend_dual_kriging()
if grid_val is None:
grid_val = self.x_to_interpolate()
length_of_CG = self.matrices_shapes()[0]
# Cartesian distances between the point to simulate and the dips
# TODO optimize to compute this only once?
# Euclidean distances
sed_dips_SimPoint = self.squared_euclidean_distances(grid_val, self.dips_position_tiled).T
if 'sed_dips_SimPoint' in self.verbose:
sed_dips_SimPoint = theano.printing.Print('sed_dips_SimPoint')(sed_dips_SimPoint)
# Cartesian distances between dips positions
h_u = T.tile(self.dips_position[:, direction_val] - grid_val[:, direction_val].reshape((grid_val[:, direction_val].shape[0], 1)), 3)
h_v = T.horizontal_stack(
T.tile(self.dips_position[:, 0] - grid_val[:, 0].reshape((grid_val[:, 0].shape[0], 1)),
1),
T.tile(self.dips_position[:, 1] - grid_val[:, 1].reshape((grid_val[:, 1].shape[0], 1)),
1),
T.tile(self.dips_position[:, 2] - grid_val[:, 2].reshape((grid_val[:, 2].shape[0], 1)),
1))
perpendicularity_vector = T.zeros(T.stack(length_of_CG))
perpendicularity_vector = T.set_subtensor(
perpendicularity_vector[self.dips_position.shape[0]*direction_val:self.dips_position.shape[0]*(direction_val+1)], 1)
sigma_0_grad = T.sum(
(weights[:length_of_CG] * (
((-h_u * h_v).T/ sed_dips_SimPoint ** 2) *
((
(sed_dips_SimPoint < self.a_T) * # first derivative
(-self.c_o_T * ((-14 / self.a_T ** 2) + 105 / 4 * sed_dips_SimPoint / self.a_T ** 3 -
35 / 2 * sed_dips_SimPoint ** 3 / self.a_T ** 5 +
21 / 4 * sed_dips_SimPoint ** 5 / self.a_T ** 7))) +
(sed_dips_SimPoint < self.a_T) * # Second derivative
self.c_o_T * 7 * (9 * sed_dips_SimPoint ** 5 - 20 * self.a_T ** 2 * sed_dips_SimPoint ** 3 +
15 * self.a_T ** 4 * sed_dips_SimPoint - 4 * self.a_T ** 5) / (2 * self.a_T ** 7)) -
(perpendicularity_vector.reshape((-1, 1)) *
((sed_dips_SimPoint < self.a_T) * # first derivative
self.c_o_T * ((-14 / self.a_T ** 2) + 105 / 4 * sed_dips_SimPoint / self.a_T ** 3 -
35 / 2 * sed_dips_SimPoint ** 3 / self.a_T ** 5 +
21 / 4 * sed_dips_SimPoint ** 5 / self.a_T ** 7)))
))
, axis=0)
return sigma_0_grad