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


Python hermite.hermval方法代码示例

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


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

示例1: test_hermval

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_hermval(self):
        #check empty input
        assert_equal(herm.hermval([], [1]).size, 0)

        #check normal input)
        x = np.linspace(-1, 1)
        y = [polyval(x, c) for c in Hlist]
        for i in range(10):
            msg = "At i=%d" % i
            tgt = y[i]
            res = herm.hermval(x, [0]*i + [1])
            assert_almost_equal(res, tgt, err_msg=msg)

        #check that shape is preserved
        for i in range(3):
            dims = [2]*i
            x = np.zeros(dims)
            assert_equal(herm.hermval(x, [1]).shape, dims)
            assert_equal(herm.hermval(x, [1, 0]).shape, dims)
            assert_equal(herm.hermval(x, [1, 0, 0]).shape, dims) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_hermite.py

示例2: test_hermvander

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_hermvander(self):
        # check for 1d x
        x = np.arange(3)
        v = herm.hermvander(x, 3)
        assert_(v.shape == (3, 4))
        for i in range(4):
            coef = [0]*i + [1]
            assert_almost_equal(v[..., i], herm.hermval(x, coef))

        # check for 2d x
        x = np.array([[1, 2], [3, 4], [5, 6]])
        v = herm.hermvander(x, 3)
        assert_(v.shape == (3, 2, 4))
        for i in range(4):
            coef = [0]*i + [1]
            assert_almost_equal(v[..., i], herm.hermval(x, coef)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_hermite.py

示例3: test_displaced_squeezed_state_fock

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_displaced_squeezed_state_fock(self, r_d, phi_d, r_s, phi_s, hbar, cutoff, tol):
        """test displaced squeezed state returns correct Fock basis state vector"""
        state = utils.displaced_squeezed_state(r_d, phi_d, r_s, phi_s, basis="fock", fock_dim=cutoff, hbar=hbar)
        a = r_d * np.exp(1j * phi_d)

        if r_s == 0:
            pytest.skip("test only non-zero squeezing")

        n = np.arange(cutoff)
        gamma = a * np.cosh(r_s) + np.conj(a) * np.exp(1j * phi_s) * np.sinh(r_s)
        coeff = np.diag(
            (0.5 * np.exp(1j * phi_s) * np.tanh(r_s)) ** (n / 2) / np.sqrt(fac(n) * np.cosh(r_s))
        )

        expected = H(gamma / np.sqrt(np.exp(1j * phi_s) * np.sinh(2 * r_s)), coeff)
        expected *= np.exp(
            -0.5 * np.abs(a) ** 2 - 0.5 * np.conj(a) ** 2 * np.exp(1j * phi_s) * np.tanh(r_s)
        )

        assert np.allclose(state, expected, atol=tol, rtol=0) 
开发者ID:XanaduAI,项目名称:strawberryfields,代码行数:22,代码来源:test_utils.py

示例4: test_hermval

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_hermval(self) :
        #check empty input
        assert_equal(herm.hermval([], [1]).size, 0)

        #check normal input)
        x = np.linspace(-1, 1)
        y = [polyval(x, c) for c in Hlist]
        for i in range(10) :
            msg = "At i=%d" % i
            ser = np.zeros
            tgt = y[i]
            res = herm.hermval(x, [0]*i + [1])
            assert_almost_equal(res, tgt, err_msg=msg)

        #check that shape is preserved
        for i in range(3) :
            dims = [2]*i
            x = np.zeros(dims)
            assert_equal(herm.hermval(x, [1]).shape, dims)
            assert_equal(herm.hermval(x, [1, 0]).shape, dims)
            assert_equal(herm.hermval(x, [1, 0, 0]).shape, dims) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_hermite.py

示例5: test_hermvander

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_hermvander(self) :
        # check for 1d x
        x = np.arange(3)
        v = herm.hermvander(x, 3)
        assert_(v.shape == (3, 4))
        for i in range(4) :
            coef = [0]*i + [1]
            assert_almost_equal(v[..., i], herm.hermval(x, coef))

        # check for 2d x
        x = np.array([[1, 2], [3, 4], [5, 6]])
        v = herm.hermvander(x, 3)
        assert_(v.shape == (3, 2, 4))
        for i in range(4) :
            coef = [0]*i + [1]
            assert_almost_equal(v[..., i], herm.hermval(x, coef)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_hermite.py

示例6: pre_calc

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def pre_calc(self, x, y, beta, n_order, center_x, center_y):
        """
        calculates the H_n(x) and H_n(y) for a given x-array and y-array
        :param x:
        :param y:
        :param amp:
        :param beta:
        :param n_order:
        :param center_x:
        :param center_y:
        :return: list of H_n(x) and H_n(y)
        """

        n = len(np.atleast_1d(x))
        x_ = x - center_x
        y_ = y - center_y
        H_x = np.empty((n_order+1, n))
        H_y = np.empty((n_order+1, n))
        for n in range(0,n_order+1):
            prefactor = 1./np.sqrt(2**n*np.sqrt(np.pi)*math.factorial(n))
            n_array = np.zeros(n+1)
            n_array[n] = 1
            H_x[n] = hermite.hermval(x_/beta, n_array) * prefactor * np.exp(-(x_/beta)**2/2.)
            H_y[n] = hermite.hermval(y_/beta, n_array) * prefactor * np.exp(-(y_/beta)**2/2.)
        return H_x, H_y 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:27,代码来源:shapelet_pot_cartesian.py

示例7: __init__

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def __init__(self, interpolation=False, precalc=False, stable_cut=True, cut_scale=5):
        """
        load interpolation of the Hermite polynomials in a range [-30,30] in order n<= 150
        :return:
        """
        self._interpolation = interpolation
        self._precalc = precalc
        self._stable_cut = stable_cut
        self._cut_scale = cut_scale
        if interpolation:
            n_order = 50
            self.H_interp = [[] for i in range(0, n_order)]
            self.x_grid = np.linspace(-50, 50, 6000)
            for k in range(0, n_order):
                n_array = np.zeros(k+1)
                n_array[k] = 1
                values = self.hermval(self.x_grid, n_array)
                self.H_interp[k] = values 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:20,代码来源:shapelets.py

示例8: hermval

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def hermval(self, x, n_array, tensor=True):
        """
        computes the Hermit polynomial as numpy.polynomial.hermite.hermval
        difference: for values more than sqrt(n_max + 1) * cut_scale, the value is set to zero
        this should be faster and numerically stable

        :param x: array of values
        :param n_array: list of coeffs in H_n
        :param cut_scale: scale where the polynomial will be set to zero
        :return: see numpy.polynomial.hermite.hermval
        """
        if not self._stable_cut:
            return hermite.hermval(x, n_array, tensor=tensor)
        else:
            n_max = len(n_array)
            x_cut = np.sqrt(n_max + 1) * self._cut_scale
            if isinstance(x, int) or isinstance(x, float):
                if x >= x_cut:
                    return 0
                else:
                    return hermite.hermval(x, n_array)
            else:
                out = np.zeros_like(x)
                out[x < x_cut] = hermite.hermval(x[x < x_cut], n_array, tensor=tensor)
                return out 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:27,代码来源:shapelets.py

示例9: H_n

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def H_n(self, n, x):
        """
        constructs the Hermite polynomial of order n at position x (dimensionless)

        :param n: The n'the basis function.
        :type name: int.
        :param x: 1-dim position (dimensionless)
        :type state: float or numpy array.
        :returns:  array-- H_n(x).
        :raises: AttributeError, KeyError
        """
        if not self._interpolation:
            n_array = np.zeros(n+1)
            n_array[n] = 1
            return self.hermval(x, n_array, tensor=False)  # attention, this routine calculates every single hermite polynomial and multiplies it with zero (exept the right one)
        else:
            return np.interp(x, self.x_grid, self.H_interp[n]) 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:19,代码来源:shapelets.py

示例10: test_hermval

# 需要导入模块: from numpy.polynomial import hermite [as 别名]
# 或者: from numpy.polynomial.hermite import hermval [as 别名]
def test_hermval(self):
        x = np.linspace(0, 2000, 2001)
        n_array = [1, 2, 3, 0, 1]
        import numpy.polynomial.hermite as hermite
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        shape_true = out_true * np.exp(-x ** 2 / 2.)
        shape_approx = out_approx * np.exp(-x ** 2 / 2.)
        npt.assert_almost_equal(shape_approx, shape_true, decimal=6)

        x = 2
        n_array = [1, 2, 3, 0, 1]
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        npt.assert_almost_equal(out_approx, out_true, decimal=6)

        x = 2001
        n_array = [1, 2, 3, 0, 1]
        out_true = hermite.hermval(x, n_array)
        out_approx = self.shapelets.hermval(x, n_array)
        shape_true = out_true * np.exp(-x**2/2.)
        shape_approx = out_approx * np.exp(-x ** 2 / 2.)
        npt.assert_almost_equal(shape_approx, shape_true, decimal=6) 
开发者ID:sibirrer,项目名称:lenstronomy,代码行数:25,代码来源:test_shapelets.py


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