当前位置: 首页>>代码示例>>Python>>正文


Python tensor.horizontal_stack方法代码示例

本文整理汇总了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 
开发者ID:jcatw,项目名称:dcnn,代码行数:16,代码来源:layers.py

示例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] 
开发者ID:rakeshvar,项目名称:rnn_ctc,代码行数:14,代码来源:outlayers.py

示例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 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:43,代码来源:theano_graph_pro.py

示例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 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:48,代码来源:theano_export.py

示例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 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:46,代码来源:theano_graph_pro.py

示例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 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:46,代码来源:theano_graph_pro.py

示例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 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:63,代码来源:theano_graph.py


注:本文中的theano.tensor.horizontal_stack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。