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


Python tensor.sin方法代码示例

本文整理汇总了Python中theano.tensor.sin方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.sin方法的具体用法?Python tensor.sin怎么用?Python tensor.sin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.sin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def __init__(self):
        def f(x, u, i, terminal):
            if terminal:
                ctrl_cost = T.zeros_like(x[..., 0])
            else:
                ctrl_cost = T.square(u).sum(axis=-1)

            # x: (batch_size, 8)
            # x[..., 0:4]: qpos
            # x[..., 4:8]: qvel, time derivatives of qpos, not used in the cost.
            theta = x[..., 0]  # qpos[0]: angle of joint 0
            phi = x[..., 1]  # qpos[1]: angle of joint 1
            target_xpos = x[..., 2:4]  # qpos[2:4], target x & y coordinate
            body1_xpos = 0.1 * T.stack([T.cos(theta), T.sin(theta)], axis=1)
            tip_xpos_incr = 0.11 * T.stack([T.cos(phi), T.sin(phi)], axis=1)
            tip_xpos = body1_xpos + tip_xpos_incr
            delta = tip_xpos - target_xpos

            state_cost = T.sqrt(T.sum(delta * delta, axis=-1))
            cost = state_cost + ctrl_cost

            return cost

        super().__init__(f, state_size=8, action_size=2) 
开发者ID:HumanCompatibleAI,项目名称:adversarial-policies,代码行数:26,代码来源:mujoco_costs.py

示例2: test_no_leak_many_graphs

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def test_no_leak_many_graphs():
        # Verify no memory leaks when creating and deleting a lot of functions

        # This isn't really a unit test, you have to run it and look at top to
        # see if there's a leak
        for i in xrange(10000):
            x = tensor.vector()
            z = x
            for d in range(10):
                z = tensor.sin(-z + 1)

            f = function([x], z, mode=Mode(optimizer=None, linker='cvm'))
            if not i % 100:
                print(gc.collect())
            sys.stdout.flush()

            gc.collect()
            if 1:
                f([2.0])
                f([3.0])
                f([4.0])
                f([5.0]) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:24,代码来源:test_vm.py

示例3: augment_state

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def augment_state(cls, state):
        """Augments angular state into a non-angular state by replacing theta
        with sin(theta) and cos(theta).

        In this case, it converts:

            [theta, theta'] -> [sin(theta), cos(theta), theta']

        Args:
            state: State vector [reducted_state_size].

        Returns:
            Augmented state size [state_size].
        """
        if state.ndim == 1:
            theta, theta_dot = state
        else:
            theta = state[..., 0].reshape(-1, 1)
            theta_dot = state[..., 1].reshape(-1, 1)

        return np.hstack([np.sin(theta), np.cos(theta), theta_dot]) 
开发者ID:anassinator,项目名称:ilqr,代码行数:23,代码来源:pendulum.py

示例4: reduce_state

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def reduce_state(cls, state):
        """Reduces a non-angular state into an angular state by replacing
        sin(theta) and cos(theta) with theta.

        In this case, it converts:

            [sin(theta), cos(theta), theta'] -> [theta, theta']

        Args:
            state: Augmented state vector [state_size].

        Returns:
            Reduced state size [reducted_state_size].
        """
        if state.ndim == 1:
            sin_theta, cos_theta, theta_dot = state
        else:
            sin_theta = state[..., 0].reshape(-1, 1)
            cos_theta = state[..., 1].reshape(-1, 1)
            theta_dot = state[..., 2].reshape(-1, 1)

        theta = np.arctan2(sin_theta, cos_theta)
        return np.hstack([theta, theta_dot]) 
开发者ID:anassinator,项目名称:ilqr,代码行数:25,代码来源:pendulum.py

示例5: augment_state

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def augment_state(cls, state):
        """Augments angular state into a non-angular state by replacing theta
        with sin(theta) and cos(theta).

        In this case, it converts:

            [x, x', theta, theta'] -> [x, x', sin(theta), cos(theta), theta']

        Args:
            state: State vector [reducted_state_size].

        Returns:
            Augmented state size [state_size].
        """
        if state.ndim == 1:
            x, x_dot, theta, theta_dot = state
        else:
            x = state[..., 0].reshape(-1, 1)
            x_dot = state[..., 1].reshape(-1, 1)
            theta = state[..., 2].reshape(-1, 1)
            theta_dot = state[..., 3].reshape(-1, 1)

        return np.hstack([x, x_dot, np.sin(theta), np.cos(theta), theta_dot]) 
开发者ID:anassinator,项目名称:ilqr,代码行数:25,代码来源:cartpole.py

示例6: reduce_state

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def reduce_state(cls, state):
        """Reduces a non-angular state into an angular state by replacing
        sin(theta) and cos(theta) with theta.

        In this case, it converts:

            [x, x', sin(theta), cos(theta), theta'] -> [x, x', theta, theta']

        Args:
            state: Augmented state vector [state_size].

        Returns:
            Reduced state size [reducted_state_size].
        """
        if state.ndim == 1:
            x, x_dot, sin_theta, cos_theta, theta_dot = state
        else:
            x = state[..., 0].reshape(-1, 1)
            x_dot = state[..., 1].reshape(-1, 1)
            sin_theta = state[..., 2].reshape(-1, 1)
            cos_theta = state[..., 3].reshape(-1, 1)
            theta_dot = state[..., 4].reshape(-1, 1)

        theta = np.arctan2(sin_theta, cos_theta)
        return np.hstack([x, x_dot, theta, theta_dot]) 
开发者ID:anassinator,项目名称:ilqr,代码行数:27,代码来源:cartpole.py

示例7: gTrig_np

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def gTrig_np(x, angi):
    '''
        Replaces angle dimensions with their complex representation
    '''
    if isinstance(x, list):
        x = np.array(x)
    if x.ndim == 1:
        x = x[None, :]
    D = x.shape[1]
    Da = 2*len(angi)
    n = x.shape[0]
    xang = np.zeros((n, Da))
    xi = x[:, angi]
    xang[:, ::2] = np.sin(xi)
    xang[:, 1::2] = np.cos(xi)

    na_dims = list(set(range(D)).difference(angi))
    xnang = x[:, na_dims]
    m = np.concatenate([xnang, xang], axis=1)

    return m 
开发者ID:mcgillmrl,项目名称:kusanagi,代码行数:23,代码来源:utils_.py

示例8: compute_ortho_grid_inc_obl

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def compute_ortho_grid_inc_obl(self, res, inc, obl):
        """Compute the polynomial basis on the plane of the sky, accounting
        for the map inclination and obliquity."""
        # See NOTE on tt.mgrid bug in `compute_ortho_grid`
        dx = 2.0 / (res - 0.01)
        y, x = tt.mgrid[-1:1:dx, -1:1:dx]
        z = tt.sqrt(1 - x ** 2 - y ** 2)
        y = tt.set_subtensor(y[tt.isnan(z)], np.nan)
        x = tt.reshape(x, [1, -1])
        y = tt.reshape(y, [1, -1])
        z = tt.reshape(z, [1, -1])
        Robl = self.RAxisAngle(tt.as_tensor_variable([0.0, 0.0, 1.0]), -obl)
        Rinc = self.RAxisAngle(
            tt.as_tensor_variable([tt.cos(obl), tt.sin(obl), 0.0]),
            -(0.5 * np.pi - inc),
        )
        R = tt.dot(Robl, Rinc)
        xyz = tt.dot(R, tt.concatenate((x, y, z)))
        x = tt.reshape(xyz[0], [1, -1])
        y = tt.reshape(xyz[1], [1, -1])
        z = tt.reshape(xyz[2], [1, -1])
        lat = tt.reshape(0.5 * np.pi - tt.arccos(y), [1, -1])
        lon = tt.reshape(tt.arctan2(x, z), [1, -1])
        return tt.concatenate((lat, lon)), tt.concatenate((x, y, z)) 
开发者ID:rodluger,项目名称:starry,代码行数:26,代码来源:core.py

示例9: compute_rect_grid

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def compute_rect_grid(self, res):
        """Compute the polynomial basis on a rectangular lat/lon grid."""
        # See NOTE on tt.mgrid bug in `compute_ortho_grid`
        dx = np.pi / (res - 0.01)
        lat, lon = tt.mgrid[
            -np.pi / 2 : np.pi / 2 : dx, -3 * np.pi / 2 : np.pi / 2 : 2 * dx
        ]
        x = tt.reshape(tt.cos(lat) * tt.cos(lon), [1, -1])
        y = tt.reshape(tt.cos(lat) * tt.sin(lon), [1, -1])
        z = tt.reshape(tt.sin(lat), [1, -1])
        R = self.RAxisAngle(tt.as_tensor_variable([1.0, 0.0, 0.0]), -np.pi / 2)
        return (
            tt.concatenate(
                (
                    tt.reshape(lat, [1, -1]),
                    tt.reshape(lon + 0.5 * np.pi, [1, -1]),
                )
            ),
            tt.dot(R, tt.concatenate((x, y, z))),
        ) 
开发者ID:rodluger,项目名称:starry,代码行数:22,代码来源:core.py

示例10: sin

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def sin(x):
    return T.sin(x) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:4,代码来源:theano_backend.py

示例11: get_output_for

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def get_output_for(self, input, **kwargs):
        X = input / T.exp(self.log_sigma)
        f = T.exp(-.5 * T.sum(X ** 2, axis=1))[:, np.newaxis]
        angles = T.dot(X, self.freqs.T)
        return T.concatenate([T.sin(angles) * f, T.cos(angles) * f], axis=1) 
开发者ID:djsutherland,项目名称:opt-mmd,代码行数:7,代码来源:layers.py

示例12: sin

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def sin(x):
    """
    Elemwise sinus of `x`.

    """
    # see decorator for function body 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:8,代码来源:basic.py

示例13: test_no_leak_many_call_nonlazy

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def test_no_leak_many_call_nonlazy():
        # Verify no memory leaks when calling a function a lot of times

        # This isn't really a unit test, you have to run it and look at top to
        # see if there's a leak.

        def build_graph(x, depth=5):
            z = x
            for d in range(depth):
                z = tensor.sin(-z + 1)
            return z

        def time_linker(name, linker):
            steps_a = 10
            x = tensor.dvector()
            a = build_graph(x, steps_a)

            f_a = function([x], a,
                           mode=Mode(optimizer=None,
                                     linker=linker()))
            inp = numpy.random.rand(1000000)
            for i in xrange(500):
                f_a(inp)
        print(1)
        time_linker('vmLinker_C',
                    lambda: vm.VM_Linker(allow_gc=False, use_cloop=True))
        print(2)
        time_linker('vmLinker',
                    lambda: vm.VM_Linker(allow_gc=False, use_cloop=False)) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:31,代码来源:test_vm.py

示例14: test_opt_gpujoin_joinvectors_elemwise_then_minusone

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def test_opt_gpujoin_joinvectors_elemwise_then_minusone():
    # from a bug in gpu normal sampling
    _a = numpy.asarray([1, 2, 3, 4], dtype='float32')
    _b = numpy.asarray([5, 6, 7, 8], dtype='float32')
    a = cuda.shared_constructor(_a)
    b = cuda.shared_constructor(_b)

    a_prime = tensor.cos(a)
    b_prime = tensor.sin(b)

    c = tensor.join(0, a_prime, b_prime)

    d = c[:-1]

    f = theano.function([], d, mode=mode_with_gpu)

    graph_nodes = f.maker.fgraph.toposort()

    assert isinstance(graph_nodes[-1].op, cuda.HostFromGpu)
    assert isinstance(graph_nodes[-2].op, cuda.GpuSubtensor)
    assert isinstance(graph_nodes[-3].op, cuda.GpuJoin)

    concat = numpy.concatenate([numpy.cos(_a), numpy.sin(_b)], axis=0)
    concat = concat[:-1]

    assert numpy.allclose(numpy.asarray(f()), concat) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:28,代码来源:test_opt.py

示例15: get_output

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import sin [as 别名]
def get_output(self, train=False):
        rnorm = self.omega / np.sqrt(2*np.pi)*self.kappa
        val = - self.omega**2 / (8 * self.kappa**2)
        dir1 = 4 * (self._outter(self.x, tensor.cos(self.theta)) +
                    self._outter(self.y, tensor.sin(self.theta)))**2
        dir2 = (-self._outter(self.x, tensor.sin(self.theta)) +
                self._outter(self.y, tensor.cos(self.theta)))**2
        ex = 1j * (self.omega * self._outter(tensor.cos(self.theta), self.x) +
                   self.omega * self._outter(tensor.sin(self.theta), self.y))
        output = rnorm * tensor.exp(val * (dir1 + dir2)) * (tensor.exp(ex)
                                                            - tensor.exp(-self.kappa**2 / 2))
        return output 
开发者ID:AgnezIO,项目名称:agnez,代码行数:14,代码来源:gaborfitting.py


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