python类cosh()的实例源码

rmatrices.py 文件源码 项目:accpy 作者: kramerfelix 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def quadrf(ev, y):
    L = ev[1]      # length
    k = ev[4]      # quadrupole strength
    if k == 0:
        R = drift(ev, y)
    else:
        wrzlk = sqrt(abs(k))
        Omega = wrzlk*L
        coshom = cosh(Omega)
        sinhom = sinh(Omega)
        cosom = cos(Omega)
        sinom = sin(Omega)
        R = array([
        [cosom,        sinom/wrzlk, 0.,           0.,           0., 0.],
        [-wrzlk*sinom, cosom,       0.,           0.,           0., 0.],
        [0.,            0.,         coshom,       sinhom/wrzlk, 0., 0.],
        [0.,            0.,         wrzlk*sinhom, coshom,       0., 0.],
        [0.,            0.,         0.,           0.,           1., L/(y**2)],
        [0.,            0.,         0.,           0.,           0., 1.]
        ])
    return R
rmatrices.py 文件源码 项目:accpy 作者: kramerfelix 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def quadaf(ev, y):
    L = ev[1]      # length
    k = ev[4]      # quadrupole strength
    if k == 0:
        R = drift(ev, y)
    else:
        wrzlk = sqrt(abs(k))
        Omega = wrzlk*L
        coshom = cosh(Omega)
        sinhom = sinh(Omega)
        cosom = cos(Omega)
        sinom = sin(Omega)
        R = array([
        [coshom,       sinhom/wrzlk, 0.,           0.,          0., 0],
        [wrzlk*sinhom, coshom,       0.,           0.,          0., 0],
        [0.,           0.,           cosom,        sinom/wrzlk, 0., 0],
        [0.,           0.,           -wrzlk*sinom, cosom,       0., 0],
        [0.,           0.,           0.,           0.,          1., L/(y**2)],
        [0.,           0.,           0.,           0.,          0., 1.]
        ])
    return R
tensor_product.py 文件源码 项目:smt 作者: SMTorg 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def _setup(self):
        self.xlimits[:, 0] = -1.
        self.xlimits[:, 1] =  1.

        a = self.options['width']
        if self.options['func'] == 'cos':
            self.func = lambda v: np.cos(a * np.pi * v)
            self.dfunc = lambda v: -a * np.pi * np.sin(a * np.pi * v)
        elif self.options['func'] == 'exp':
            self.func = lambda v: np.exp(a * v)
            self.dfunc = lambda v: a * np.exp(a * v)
        elif self.options['func'] == 'tanh':
            self.func = lambda v: np.tanh(a * v)
            self.dfunc = lambda v: a / np.cosh(a * v) ** 2
        elif self.options['func'] == 'gaussian':
            self.func = lambda v: np.exp(-2. * a * v ** 2)
            self.dfunc = lambda v: -4. * a * v * np.exp(-2. * a * v ** 2)
NuclearOperator.py 文件源码 项目:spectroscopy 作者: jgoodknight 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def potentialFunction(self, x):
        naturalPotential = self.De * (1 - np.exp(-self.a * (x - self.center)))**2 + self.energyOffset
        imaginaryPotential = 0
        try:
            imaginaryPotentialZeros = np.zeros(x.shape)
        except:
            if x > self.startOfAbsorbingPotential:
                imaginaryPotential = -1.0j *self.strength * np.cosh( (np.real(x) - self.mySpace.xMax)**2 / (self.mySpace.Dx*30)**2)**(-2)
            else:
                imaginaryPotential = 0
            return naturalPotential + imaginaryPotential

        if self.absorbingPotential:
            imaginaryPotential = -1.0j *self.strength * np.cosh( (np.real(x) - self.mySpace.xMax)**2 / (self.mySpace.Dx*30)**2)**(-2)
            imaginaryPotential = np.where(x > self.startOfAbsorbingPotential, imaginaryPotential, imaginaryPotentialZeros)
        return naturalPotential + imaginaryPotential
kernel_approximation.py 文件源码 项目:Parallel-SGD 作者: angadgill 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _transform_dense(self, X):
        non_zero = (X != 0.0)
        X_nz = X[non_zero]

        X_step = np.zeros_like(X)
        X_step[non_zero] = np.sqrt(X_nz * self.sample_interval_)

        X_new = [X_step]

        log_step_nz = self.sample_interval_ * np.log(X_nz)
        step_nz = 2 * X_nz * self.sample_interval_

        for j in range(1, self.sample_steps):
            factor_nz = np.sqrt(step_nz /
                                np.cosh(np.pi * j * self.sample_interval_))

            X_step = np.zeros_like(X)
            X_step[non_zero] = factor_nz * np.cos(j * log_step_nz)
            X_new.append(X_step)

            X_step = np.zeros_like(X)
            X_step[non_zero] = factor_nz * np.sin(j * log_step_nz)
            X_new.append(X_step)

        return np.hstack(X_new)
BLISS.py 文件源码 项目:Lattice-Based-Signatures 作者: krishnacharya 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def Sign(**kwargs):
    '''
    Algorithm 1, Pg 12 of BLISS paper
    o/p:
    z,c 
    '''
    msg, A, S, m, n, sd, q, M, kappa = kwargs['msg'], kwargs['A'], kwargs['S'], kwargs['m'], kwargs['n'], kwargs['sd'], kwargs['q'], kwargs['M'], kwargs['kappa']
    m_bar = m + n
    D = DiscreteGaussianDistributionLatticeSampler(ZZ**m_bar, sd)
    count = 0
    while(True):
        y = np.array(D()) # m' x 1 
        reduced_Ay = util.vector_to_Zq(np.matmul(A, y), 2*q)
        c = hash_iterative(np.array_str(reduced_Ay) + msg, n, kappa) # still not the hash but this is test run      
        b = util.crypt_secure_randint(0, 1)
        Sc = np.matmul(S,c)
        z = y + ((-1)**b) * Sc
        try:            
            exp_term = exp(float(Sc.dot(Sc)) / (2*sd**2))
            cosh_term = np.cosh(float(z.dot(Sc)) / (sd**2))
            val = exp_term / (cosh_term * M)                
        except OverflowError:
            print "OF"          
            continue            
        if(random.random() < min(val, 1.0)):
            break
        if(count > 10): # beyond 4 rejection sampling iterations are not expected in general 
            raise ValueError("The number of rejection sampling iterations are more than expected")
        count += 1                              
    return z, c
snake.py 文件源码 项目:snake 作者: rhinech 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def gen_samples(self, num_samples):
        """Generate sample for ML near the snake."""

        points = []  # the sample points
        labels = []  # the labels
        whichs = []  # the corresponding node for the sample
        deri_g = []  # the partial derivative to g
        deri_T = []  # the partial derivative to T
        counter = 0
        assert num_samples % self.length == 0
        for i, (v, n) in enumerate(zip(self.vertices, self.normals())):
            for d in np.linspace(-1, 1, num_samples / self.length):
                # geometry
                r = 2 * self.widths[i] * d
                s = v + r * n
                l = array([0.5 * (1. - np.tanh(d)),
                           0.5 * (1. + np.tanh(d))])
                points.append(s)
                labels.append(l)
                whichs.append(i)
                # cal derivatives
                cosh_d = np.cosh(d)
                deri_g.append(1 / (4 * self.widths[i] * cosh_d * cosh_d))
                deri_T.append(d / (2 * self.widths[i] * cosh_d * cosh_d))
                counter += 1
                if counter == num_samples:
                    return array(points), array(labels), array(whichs), array(deri_g), array(deri_T)
test_core.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_basic_ufuncs(self):
        # Test various functions such as sin, cos.
        (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
        assert_equal(np.cos(x), cos(xm))
        assert_equal(np.cosh(x), cosh(xm))
        assert_equal(np.sin(x), sin(xm))
        assert_equal(np.sinh(x), sinh(xm))
        assert_equal(np.tan(x), tan(xm))
        assert_equal(np.tanh(x), tanh(xm))
        assert_equal(np.sqrt(abs(x)), sqrt(xm))
        assert_equal(np.log(abs(x)), log(xm))
        assert_equal(np.log10(abs(x)), log10(xm))
        assert_equal(np.exp(x), exp(xm))
        assert_equal(np.arcsin(z), arcsin(zm))
        assert_equal(np.arccos(z), arccos(zm))
        assert_equal(np.arctan(z), arctan(zm))
        assert_equal(np.arctan2(x, y), arctan2(xm, ym))
        assert_equal(np.absolute(x), absolute(xm))
        assert_equal(np.angle(x + 1j*y), angle(xm + 1j*ym))
        assert_equal(np.angle(x + 1j*y, deg=True), angle(xm + 1j*ym, deg=True))
        assert_equal(np.equal(x, y), equal(xm, ym))
        assert_equal(np.not_equal(x, y), not_equal(xm, ym))
        assert_equal(np.less(x, y), less(xm, ym))
        assert_equal(np.greater(x, y), greater(xm, ym))
        assert_equal(np.less_equal(x, y), less_equal(xm, ym))
        assert_equal(np.greater_equal(x, y), greater_equal(xm, ym))
        assert_equal(np.conjugate(x), conjugate(xm))
test_core.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_testUfuncRegression(self):
        # Tests new ufuncs on MaskedArrays.
        for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                  'sin', 'cos', 'tan',
                  'arcsin', 'arccos', 'arctan',
                  'sinh', 'cosh', 'tanh',
                  'arcsinh',
                  'arccosh',
                  'arctanh',
                  'absolute', 'fabs', 'negative',
                  'floor', 'ceil',
                  'logical_not',
                  'add', 'subtract', 'multiply',
                  'divide', 'true_divide', 'floor_divide',
                  'remainder', 'fmod', 'hypot', 'arctan2',
                  'equal', 'not_equal', 'less_equal', 'greater_equal',
                  'less', 'greater',
                  'logical_and', 'logical_or', 'logical_xor',
                  ]:
            try:
                uf = getattr(umath, f)
            except AttributeError:
                uf = getattr(fromnumeric, f)
            mf = getattr(numpy.ma.core, f)
            args = self.d[:uf.nin]
            ur = uf(*args)
            mr = mf(*args)
            assert_equal(ur.filled(0), mr.filled(0), f)
            assert_mask_equal(ur.mask, mr.mask, err_msg=f)
test_old_ma.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_testUfuncs1(self):
        # Test various functions such as sin, cos.
        (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
        self.assertTrue(eq(np.cos(x), cos(xm)))
        self.assertTrue(eq(np.cosh(x), cosh(xm)))
        self.assertTrue(eq(np.sin(x), sin(xm)))
        self.assertTrue(eq(np.sinh(x), sinh(xm)))
        self.assertTrue(eq(np.tan(x), tan(xm)))
        self.assertTrue(eq(np.tanh(x), tanh(xm)))
        with np.errstate(divide='ignore', invalid='ignore'):
            self.assertTrue(eq(np.sqrt(abs(x)), sqrt(xm)))
            self.assertTrue(eq(np.log(abs(x)), log(xm)))
            self.assertTrue(eq(np.log10(abs(x)), log10(xm)))
        self.assertTrue(eq(np.exp(x), exp(xm)))
        self.assertTrue(eq(np.arcsin(z), arcsin(zm)))
        self.assertTrue(eq(np.arccos(z), arccos(zm)))
        self.assertTrue(eq(np.arctan(z), arctan(zm)))
        self.assertTrue(eq(np.arctan2(x, y), arctan2(xm, ym)))
        self.assertTrue(eq(np.absolute(x), absolute(xm)))
        self.assertTrue(eq(np.equal(x, y), equal(xm, ym)))
        self.assertTrue(eq(np.not_equal(x, y), not_equal(xm, ym)))
        self.assertTrue(eq(np.less(x, y), less(xm, ym)))
        self.assertTrue(eq(np.greater(x, y), greater(xm, ym)))
        self.assertTrue(eq(np.less_equal(x, y), less_equal(xm, ym)))
        self.assertTrue(eq(np.greater_equal(x, y), greater_equal(xm, ym)))
        self.assertTrue(eq(np.conjugate(x), conjugate(xm)))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, ym))))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((x, y))))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, y))))
        self.assertTrue(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
test_old_ma.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_testUfuncRegression(self):
        f_invalid_ignore = [
            'sqrt', 'arctanh', 'arcsin', 'arccos',
            'arccosh', 'arctanh', 'log', 'log10', 'divide',
            'true_divide', 'floor_divide', 'remainder', 'fmod']
        for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                  'sin', 'cos', 'tan',
                  'arcsin', 'arccos', 'arctan',
                  'sinh', 'cosh', 'tanh',
                  'arcsinh',
                  'arccosh',
                  'arctanh',
                  'absolute', 'fabs', 'negative',
                  'floor', 'ceil',
                  'logical_not',
                  'add', 'subtract', 'multiply',
                  'divide', 'true_divide', 'floor_divide',
                  'remainder', 'fmod', 'hypot', 'arctan2',
                  'equal', 'not_equal', 'less_equal', 'greater_equal',
                  'less', 'greater',
                  'logical_and', 'logical_or', 'logical_xor']:
            try:
                uf = getattr(umath, f)
            except AttributeError:
                uf = getattr(fromnumeric, f)
            mf = getattr(np.ma, f)
            args = self.d[:uf.nin]
            with np.errstate():
                if f in f_invalid_ignore:
                    np.seterr(invalid='ignore')
                if f in ['arctanh', 'log', 'log10']:
                    np.seterr(divide='ignore')
                ur = uf(*args)
                mr = mf(*args)
            self.assertTrue(eq(ur.filled(0), mr.filled(0), f))
            self.assertTrue(eqmask(ur.mask, mr.mask))
trig.py 文件源码 项目:Sverchok 作者: Sverchok 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def cosh(x: Number = 0.0) -> Number:
    return np.cosh(x)
act_func.py 文件源码 项目:ANN-PONR-Python3 作者: anon-42 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def tanh(x, y):
    if y == 0:
        return (2 / (1 + np.exp(-2*x))) - 1
    else:
        return 1 / ((np.cosh(x))**2)
newton.py 文件源码 项目:nanopores 作者: mitschabaude 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def poisson_from_positiveK(mean):
    # solve x/(1 - exp(-x)) == mean
    def f(x):
        return x/(1. - np.exp(-x))
    def f1(x):
        return (np.expm1(x) - x)/(2.*np.cosh(x) - 2.)

    x = solve(mean, f, f1, mean, n=10)
    return x
randomwalk.py 文件源码 项目:nanopores 作者: mitschabaude 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def poisson_from_positiveK(mean):
    # solve x/(1 - exp(-x)) == mean
    def f(x):
        return x/(1. - np.exp(-x))
    def f1(x):
        return (np.expm1(x) - x)/(2.*np.cosh(x) - 2.)

    x = solve_newton(mean, f, f1, mean, n=10)
    return x
func_trigonometric.py 文件源码 项目:PyGLM 作者: Zuzu-Typ 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def cosh(v):
    return v.__class__(numpy.cosh(v))
characteristic_funs.py 文件源码 项目:fftoptionlib 作者: arraystream 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def cir_int_rt_chf(u, t, k, theta, sigma, r0):
    r = np.sqrt(k ** 2 - 1j * u * 2 * sigma ** 2)
    cosh_fun = np.cosh(r * t / 2)
    sinh_fun = np.sinh(r * t / 2)
    coth_fun = cosh_fun / sinh_fun
    a_t_v = np.exp(t * theta * (k ** 2) / (sigma ** 2)) / (cosh_fun + (k / r) * sinh_fun) ** (
        2 * k * theta / (sigma ** 2))
    b_t_v = 2 * 1j * u / (k + r * coth_fun)
    return a_t_v * np.exp(b_t_v * r0)
test_core.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_basic_ufuncs(self):
        # Test various functions such as sin, cos.
        (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
        assert_equal(np.cos(x), cos(xm))
        assert_equal(np.cosh(x), cosh(xm))
        assert_equal(np.sin(x), sin(xm))
        assert_equal(np.sinh(x), sinh(xm))
        assert_equal(np.tan(x), tan(xm))
        assert_equal(np.tanh(x), tanh(xm))
        assert_equal(np.sqrt(abs(x)), sqrt(xm))
        assert_equal(np.log(abs(x)), log(xm))
        assert_equal(np.log10(abs(x)), log10(xm))
        assert_equal(np.exp(x), exp(xm))
        assert_equal(np.arcsin(z), arcsin(zm))
        assert_equal(np.arccos(z), arccos(zm))
        assert_equal(np.arctan(z), arctan(zm))
        assert_equal(np.arctan2(x, y), arctan2(xm, ym))
        assert_equal(np.absolute(x), absolute(xm))
        assert_equal(np.angle(x + 1j*y), angle(xm + 1j*ym))
        assert_equal(np.angle(x + 1j*y, deg=True), angle(xm + 1j*ym, deg=True))
        assert_equal(np.equal(x, y), equal(xm, ym))
        assert_equal(np.not_equal(x, y), not_equal(xm, ym))
        assert_equal(np.less(x, y), less(xm, ym))
        assert_equal(np.greater(x, y), greater(xm, ym))
        assert_equal(np.less_equal(x, y), less_equal(xm, ym))
        assert_equal(np.greater_equal(x, y), greater_equal(xm, ym))
        assert_equal(np.conjugate(x), conjugate(xm))
test_core.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_testUfuncRegression(self):
        # Tests new ufuncs on MaskedArrays.
        for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                  'sin', 'cos', 'tan',
                  'arcsin', 'arccos', 'arctan',
                  'sinh', 'cosh', 'tanh',
                  'arcsinh',
                  'arccosh',
                  'arctanh',
                  'absolute', 'fabs', 'negative',
                  'floor', 'ceil',
                  'logical_not',
                  'add', 'subtract', 'multiply',
                  'divide', 'true_divide', 'floor_divide',
                  'remainder', 'fmod', 'hypot', 'arctan2',
                  'equal', 'not_equal', 'less_equal', 'greater_equal',
                  'less', 'greater',
                  'logical_and', 'logical_or', 'logical_xor',
                  ]:
            try:
                uf = getattr(umath, f)
            except AttributeError:
                uf = getattr(fromnumeric, f)
            mf = getattr(numpy.ma.core, f)
            args = self.d[:uf.nin]
            ur = uf(*args)
            mr = mf(*args)
            assert_equal(ur.filled(0), mr.filled(0), f)
            assert_mask_equal(ur.mask, mr.mask, err_msg=f)
test_old_ma.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_testUfuncs1(self):
        # Test various functions such as sin, cos.
        (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
        self.assertTrue(eq(np.cos(x), cos(xm)))
        self.assertTrue(eq(np.cosh(x), cosh(xm)))
        self.assertTrue(eq(np.sin(x), sin(xm)))
        self.assertTrue(eq(np.sinh(x), sinh(xm)))
        self.assertTrue(eq(np.tan(x), tan(xm)))
        self.assertTrue(eq(np.tanh(x), tanh(xm)))
        with np.errstate(divide='ignore', invalid='ignore'):
            self.assertTrue(eq(np.sqrt(abs(x)), sqrt(xm)))
            self.assertTrue(eq(np.log(abs(x)), log(xm)))
            self.assertTrue(eq(np.log10(abs(x)), log10(xm)))
        self.assertTrue(eq(np.exp(x), exp(xm)))
        self.assertTrue(eq(np.arcsin(z), arcsin(zm)))
        self.assertTrue(eq(np.arccos(z), arccos(zm)))
        self.assertTrue(eq(np.arctan(z), arctan(zm)))
        self.assertTrue(eq(np.arctan2(x, y), arctan2(xm, ym)))
        self.assertTrue(eq(np.absolute(x), absolute(xm)))
        self.assertTrue(eq(np.equal(x, y), equal(xm, ym)))
        self.assertTrue(eq(np.not_equal(x, y), not_equal(xm, ym)))
        self.assertTrue(eq(np.less(x, y), less(xm, ym)))
        self.assertTrue(eq(np.greater(x, y), greater(xm, ym)))
        self.assertTrue(eq(np.less_equal(x, y), less_equal(xm, ym)))
        self.assertTrue(eq(np.greater_equal(x, y), greater_equal(xm, ym)))
        self.assertTrue(eq(np.conjugate(x), conjugate(xm)))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, ym))))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((x, y))))
        self.assertTrue(eq(np.concatenate((x, y)), concatenate((xm, y))))
        self.assertTrue(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
test_old_ma.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_testUfuncRegression(self):
        f_invalid_ignore = [
            'sqrt', 'arctanh', 'arcsin', 'arccos',
            'arccosh', 'arctanh', 'log', 'log10', 'divide',
            'true_divide', 'floor_divide', 'remainder', 'fmod']
        for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                  'sin', 'cos', 'tan',
                  'arcsin', 'arccos', 'arctan',
                  'sinh', 'cosh', 'tanh',
                  'arcsinh',
                  'arccosh',
                  'arctanh',
                  'absolute', 'fabs', 'negative',
                  'floor', 'ceil',
                  'logical_not',
                  'add', 'subtract', 'multiply',
                  'divide', 'true_divide', 'floor_divide',
                  'remainder', 'fmod', 'hypot', 'arctan2',
                  'equal', 'not_equal', 'less_equal', 'greater_equal',
                  'less', 'greater',
                  'logical_and', 'logical_or', 'logical_xor']:
            try:
                uf = getattr(umath, f)
            except AttributeError:
                uf = getattr(fromnumeric, f)
            mf = getattr(np.ma, f)
            args = self.d[:uf.nin]
            with np.errstate():
                if f in f_invalid_ignore:
                    np.seterr(invalid='ignore')
                if f in ['arctanh', 'log', 'log10']:
                    np.seterr(divide='ignore')
                ur = uf(*args)
                mr = mf(*args)
            self.assertTrue(eq(ur.filled(0), mr.filled(0), f))
            self.assertTrue(eqmask(ur.mask, mr.mask))
pairwise_interactions.py 文件源码 项目:dynamiq_engine 作者: dynamiq-md 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def dfdx(self, x):
        sech_aR = 1.0 / np.cosh(self.a * (x - self.R0))
        return self.V0*self.a*sech_aR*sech_aR
pairwise_interactions.py 文件源码 项目:dynamiq_engine 作者: dynamiq-md 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def d2fdx2(self, x):
        sech_aR = 1.0 / np.cosh(self.a * (x - self.R0))
        tanh_aR = np.tanh(self.a * (x-self.R0))
        return -2.0 * self.V0 * self.a * self.a * sech_aR * sech_aR * tanh_aR
trigonometric.py 文件源码 项目:dsfaker 作者: Dubrzr 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, generator: Generator=Autoincrement()):
        super().__init__(numpy.cosh, generator)
test_scalar_ops.py 文件源码 项目:drmad 作者: bigaidream-projects 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_cosh():
    fun = lambda x : 3.0 * np.cosh(x)
    d_fun = grad(fun)
    check_grads(fun, npr.randn())
    check_grads(d_fun, npr.randn())
fip_dynamics.py 文件源码 项目:dynamic-walking 作者: stephane-caron 项目源码 文件源码 阅读 49 收藏 0 点赞 0 评论 0
def integrate_fip(p, v, z, dt, omega2):
    """
    Integrate the equation of motion of the Floating-base Inverted Pendulum.

    Parameters
    ----------
    p : array, shape=(3,)
        Initial position.
    v : array, shape=(3,)
        Initial velocity.
    z : array, shape=(3,)
        ZMP location throughout the integration.
    dt : scalar
        Integration step.
    omega2 : scalar
        FIP constant.

    Returns
    -------
    p_next : array, shape=(3,)
        Position at the end of the integration step.
    v_next : array, shape=(3,)
        Velocity at the end of the integration step.

    Note
    ----
    The Linear Inverted Pendulum Mode (LIPM) is a special case of the FIP, so
    this function also applies to COP-based controllers.
    """
    omega = sqrt(omega2)
    a = omega2 * (p - z) + gravity
    p_next = p + v / omega * sinh(omega * dt) \
        + a / omega2 * (cosh(omega * dt) - 1.)
    v_next = v * cosh(omega * dt) + a / omega * sinh(omega * dt)
    return p_next, v_next
expr.py 文件源码 项目:fluxion 作者: fluxion 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def evaluate(self, x):
        return numpy.cosh(x)
expr.py 文件源码 项目:fluxion 作者: fluxion 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def cosh(x):
    return Apply(Cosh(), x)
controller.py 文件源码 项目:airhockey 作者: jnez71 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def __init__(self, kp, kd, kv, kw, N, u_limit=[100, 100], nn_limit=[100, 100]):
        """
        kp:  Proportional feedback gains.
        kd:  Derivative feedback gains.
        kv:  Input-side learning gain (scalar).
        kw:  Output-side learning gain (scalar).
        N:   Number of neurons.
        u_limit: Limit on total output effort.
        nn_limit: Limit on NN component feedforward effort.

        The user must actively set self.learn = True to
        have the NN start learning.

        """
        self.nstates = 2 * len(kp)
        self.ncontrols = len(kp)
        self.nsigs = N

        self.sig = lambda x: np.concatenate(([1], np.tanh(x)))
        self.sigp = lambda x: np.tile(1/(np.cosh(x)**2), (self.nsigs+1, 1))

        self.set_gains(kp, kd, kv, kw)
        self.u_limit = np.array(u_limit, dtype=np.float32)
        self.nn_limit = np.array(nn_limit, dtype=np.float32)

        self.V = np.zeros((self.nstates+1, self.nsigs))
        self.W = np.zeros((self.nsigs+1, self.ncontrols))
        self.y = np.zeros(self.ncontrols)

        self.saturated = False
        self.learn = False

########################
test_core.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_basic_ufuncs(self):
        # Test various functions such as sin, cos.
        (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
        assert_equal(np.cos(x), cos(xm))
        assert_equal(np.cosh(x), cosh(xm))
        assert_equal(np.sin(x), sin(xm))
        assert_equal(np.sinh(x), sinh(xm))
        assert_equal(np.tan(x), tan(xm))
        assert_equal(np.tanh(x), tanh(xm))
        assert_equal(np.sqrt(abs(x)), sqrt(xm))
        assert_equal(np.log(abs(x)), log(xm))
        assert_equal(np.log10(abs(x)), log10(xm))
        assert_equal(np.exp(x), exp(xm))
        assert_equal(np.arcsin(z), arcsin(zm))
        assert_equal(np.arccos(z), arccos(zm))
        assert_equal(np.arctan(z), arctan(zm))
        assert_equal(np.arctan2(x, y), arctan2(xm, ym))
        assert_equal(np.absolute(x), absolute(xm))
        assert_equal(np.angle(x + 1j*y), angle(xm + 1j*ym))
        assert_equal(np.angle(x + 1j*y, deg=True), angle(xm + 1j*ym, deg=True))
        assert_equal(np.equal(x, y), equal(xm, ym))
        assert_equal(np.not_equal(x, y), not_equal(xm, ym))
        assert_equal(np.less(x, y), less(xm, ym))
        assert_equal(np.greater(x, y), greater(xm, ym))
        assert_equal(np.less_equal(x, y), less_equal(xm, ym))
        assert_equal(np.greater_equal(x, y), greater_equal(xm, ym))
        assert_equal(np.conjugate(x), conjugate(xm))


问题


面经


文章

微信
公众号

扫码关注公众号