當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。